Skip to content

Commit

Permalink
Merge pull request #203 from mash-up-kr/fix/avocado-url-bug
Browse files Browse the repository at this point in the history
fix: Avocado ShareURL Bug
  • Loading branch information
K-Diger committed Sep 21, 2024
2 parents 9047ba7 + 7c8a84f commit ffdbbeb
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ class ShareUrlIdParser(
properties: AvocadoProperties,
) : AvocadoOriginMapIdParser {
private val regex: Regex = properties.url.regex.share.toRegex()
private val idParameterRegex: Regex = "id=(\\d+)".toRegex()
private val mapIdRegexList: List<Regex> =
mutableListOf(
"place/(\\d+)".toRegex(),
"id=(\\d+)".toRegex(),
)

private val client: RestClient = RestClient.builder().build()

override fun getParserBySupportedUrl(url: String): AvocadoOriginMapIdParser? = takeIf { regex.matches(url) }
Expand All @@ -70,8 +75,10 @@ class ShareUrlIdParser(
.retrieve()
.toEntity(Map::class.java)
if (response.statusCode.is3xxRedirection && response.headers.location != null) {
return idParameterRegex.find(response.headers.location.toString())
.parseFromMatchResult()
return mapIdRegexList.firstNotNullOfOrNull { regex ->
regex.find(response.headers.location.toString())
?.groupValues?.getOrNull(1)?.let { OriginMapId(it) }
}
}
return null
}
Expand Down

0 comments on commit ffdbbeb

Please sign in to comment.