remove support for 0.8 version URLs (found while investigating #188)

This commit is contained in:
Kevin Hester 2020-11-17 19:54:48 +08:00
parent 31e0136b2a
commit 88b1ad5443

View file

@ -31,17 +31,17 @@ data class Channel(
MeshProtos.ChannelSettings.newBuilder().setName(defaultChannelName)
.setModemConfig(MeshProtos.ChannelSettings.ModemConfig.Bw125Cr45Sf128).build()
)
private const val prefixRoot = "https://www.meshtastic.org/c/"
const val prefix = "$prefixRoot#"
const val prefix = "https://www.meshtastic.org/c/#"
private const val base64Flags = Base64.URL_SAFE + Base64.NO_WRAP
private fun urlToSettings(url: Uri): MeshProtos.ChannelSettings {
val urlStr = url.toString()
// Let the path optionally include the # character (or not) so we can work with old URLs generated by old versions of the app
val pathRegex = Regex("$prefixRoot#?(.*)")
// We no longer support the super old (about 0.8ish? verison of the URLs that don't use the # separator - I doubt
// anyone is still using that old format
val pathRegex = Regex("$prefix(.*)")
val (base64) = pathRegex.find(urlStr)?.destructured
?: throw MalformedURLException("Not a meshtastic URL: ${urlStr.take(40)}")
val bytes = Base64.decode(base64, base64Flags)