Line data Source code
1 : import type { LocationQuery } from 'vue-router'
2 :
3 : import { capturePreservedQuery } from '@/platform/navigation/preservedQueryManager'
4 : import { PRESERVED_QUERY_NAMESPACES } from '@/platform/navigation/preservedQueryNamespaces'
5 :
6 2356 : const SHARE_QUERY_KEY = 'share'
7 2356 : const MAX_SHARE_ID_LENGTH = 128
8 2356 : const SHARE_ID_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/
9 :
10 2 : export function isValidShareId(shareId: string): boolean {
11 2 : return shareId.length <= MAX_SHARE_ID_LENGTH && SHARE_ID_PATTERN.test(shareId)
12 : }
13 :
14 0 : export function preserveLoggedOutShareAuthAttribution(
15 : query: LocationQuery,
16 : isLoggedIn: boolean
17 : ): void {
18 0 : if (isLoggedIn) return
19 :
20 0 : const shareId = query[SHARE_QUERY_KEY]
21 0 : if (typeof shareId !== 'string' || !isValidShareId(shareId)) return
22 :
23 0 : capturePreservedQuery(
24 : PRESERVED_QUERY_NAMESPACES.SHARE_AUTH,
25 : { [SHARE_QUERY_KEY]: shareId },
26 : [SHARE_QUERY_KEY]
27 : )
28 : }
|