20 lines
536 B
TypeScript
20 lines
536 B
TypeScript
import { parseObjectUrl } from '@/lib/urlGenerator'
|
|
|
|
export function resolveAuthorHashIdOrPubkey(pubkeyParam: string | string[] | undefined): string | null {
|
|
if (typeof pubkeyParam !== 'string') {
|
|
return null
|
|
}
|
|
|
|
const urlMatch = pubkeyParam.match(/^([a-f0-9]+)_(\d+)_(\d+)$/i)
|
|
if (urlMatch?.[1]) {
|
|
return urlMatch[1]
|
|
}
|
|
|
|
const parsedUrl = parseObjectUrl(`https://zapwall.fr/author/${pubkeyParam}`)
|
|
if (parsedUrl.objectType === 'author' && parsedUrl.idHash) {
|
|
return parsedUrl.idHash
|
|
}
|
|
|
|
return pubkeyParam
|
|
}
|