1
0
mirror of https://git.sr.ht/~cadence/bibliogram synced 2024-11-22 16:17:29 +00:00

Redirect to a lowercase username

Lowercase seems to be the canonical form of username on Instagram.
This commit is contained in:
Cadence Ember 2020-04-06 13:53:01 +12:00
parent d9d47b1f36
commit 160fa7d843
No known key found for this signature in database
GPG Key ID: 128B99B1B74A6412

View File

@ -43,6 +43,7 @@ module.exports = [
username = username.replace(/^(https?:\/\/)?([a-z]+\.)?instagram\.com\//, "") username = username.replace(/^(https?:\/\/)?([a-z]+\.)?instagram\.com\//, "")
username = username.replace(/^\@+/, "") username = username.replace(/^\@+/, "")
username = username.replace(/\/+$/, "") username = username.replace(/\/+$/, "")
username = username.toLowerCase()
return redirect(`/u/${username}`, 301) return redirect(`/u/${username}`, 301)
} else { } else {
return render(400, "pug/friendlyerror.pug", { return render(400, "pug/friendlyerror.pug", {
@ -57,6 +58,10 @@ module.exports = [
}, },
{ {
route: `/u/(${constants.external.username_regex})`, methods: ["GET"], code: ({url, fill}) => { route: `/u/(${constants.external.username_regex})`, methods: ["GET"], code: ({url, fill}) => {
if (fill[0] !== fill[0].toLowerCase()) { // some capital letters
return Promise.resolve(redirect(`/u/${fill[0].toLowerCase()}`, 301))
}
const params = url.searchParams const params = url.searchParams
return fetchUser(fill[0], false).then(async user => { return fetchUser(fill[0], false).then(async user => {
const page = +params.get("page") const page = +params.get("page")