Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Open ahs.app links in the app. #28

Open
xingyzt opened this issue Feb 28, 2021 · 0 comments
Open

Open ahs.app links in the app. #28

xingyzt opened this issue Feb 28, 2021 · 0 comments
Assignees
Labels
Android For Android version enhancement New feature or request iOS For iOS version

Comments

@xingyzt
Copy link
Member

xingyzt commented Feb 28, 2021

Background

Android and iOS have an "app link" feature where apps can suggest URLs of specified domains to be opened natively.

We should direct the apps to open ahs.app links in order to not confuse app users when there are two possible views, and to gain the performance of native apps.

Parsing the URLs

ahs.app hosts articles in the following URL formats:
https://ahs.app/ARTICLE_TITLE/SCRAMBLED_ARTICLE_ID
https://ahs.app/SCRAMBLED_ARTICLE_ID
for example:
https://ahs.app/Teen-De-Stress-Kit/qrfpevcgvir-zrzbenoyr-xhqh
https://ahs.app/rkpryyrag-fnzr-rpuvqan

Article IDs are scrambled by a simple symmetric ROT13 cipher, which substitutes each letter with another 13 steps down the alphabet.

There are no trailing slashes as they are automatically redirected by the web server.

Swift:

func rot13(id: String) -> String {
    return String(Array(id).map {
        $0.isLetter ? "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".index(of:$0)!] : $0
    })
}

func id(url: String) -> String {
    return rot13(id: url.components(separatedBy: "/").last!)
}

Kotlin:

fun rot13(id: String): String = id.map {
    if(it.isLetter())
        "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"
    	.get("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".indexOf(it))
   else it
}.joinToString("")

fun id(url: String): String = rot13(url.split('/').last())
@xingyzt xingyzt added Android For Android version enhancement New feature or request iOS For iOS version labels Feb 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android For Android version enhancement New feature or request iOS For iOS version
Projects
None yet
Development

No branches or pull requests

5 participants