1
0
mirror of https://github.com/tooot-app/app synced 2024-12-22 07:34:06 +01:00

Fix card url matching regex

This commit is contained in:
xmflsct 2022-12-12 22:56:31 +01:00
parent 96497aad25
commit 17d4245cd9

View File

@ -30,18 +30,24 @@ const matchAccount = (
// https://social.xmflsct.com/web/accounts/14195 <- default
// https://social.xmflsct.com/web/@tooot <- pretty ! cannot be searched on the same instance
// https://social.xmflsct.com/@tooot <- pretty
const matcherAccount = new RegExp(/(https?:\/\/)?([^\/]+)(\/web|\/web\/accounts)?\/([0-9]+|@.+)/)
const matcherAccount = new RegExp(
/(https?:\/\/)?([^\/]+)(\/web\/accounts\/([0-9]+)|\/web\/(@.+)|\/(@.+))/
)
const matched = url.match(matcherAccount)
if (matched) {
const hostname = matched[2]
const style = matched[4].startsWith('@') ? 'pretty' : 'default'
const account = matched[4]
const account = matched.filter(i => i).reverse()?.[0]
if (account) {
const style = account.startsWith('@') ? 'pretty' : 'default'
const instanceUrl = getInstanceUrl(store.getState())
return style === 'default'
? { id: account, style, sameInstance: hostname === instanceUrl }
: { username: account, style, sameInstance: hostname === instanceUrl }
const instanceUrl = getInstanceUrl(store.getState())
return style === 'default'
? { id: account, style, sameInstance: hostname === instanceUrl }
: { username: account, style, sameInstance: hostname === instanceUrl }
} else {
return null
}
}
return null