Fix card url matching regex

This commit is contained in:
xmflsct 2022-12-12 22:56:31 +01:00
parent 96497aad25
commit 17d4245cd9
1 changed files with 13 additions and 7 deletions

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