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
1 changed files with 5 additions and 0 deletions

View File

@ -43,6 +43,7 @@ module.exports = [
username = username.replace(/^(https?:\/\/)?([a-z]+\.)?instagram\.com\//, "")
username = username.replace(/^\@+/, "")
username = username.replace(/\/+$/, "")
username = username.toLowerCase()
return redirect(`/u/${username}`, 301)
} else {
return render(400, "pug/friendlyerror.pug", {
@ -57,6 +58,10 @@ module.exports = [
},
{
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
return fetchUser(fill[0], false).then(async user => {
const page = +params.get("page")