-
Notifications
You must be signed in to change notification settings - Fork 66.9k
Expand file tree
/
Copy pathis-archived-version.ts
More file actions
39 lines (33 loc) · 1.28 KB
/
is-archived-version.ts
File metadata and controls
39 lines (33 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import patterns from '@/frame/lib/patterns'
import { deprecated } from '@/versions/lib/enterprise-server-releases'
import type { ExtendedRequest } from '@/types'
type IsArchivedInfo = {
isArchived?: boolean
requestedVersion?: string
}
export function isArchivedVersion(req: ExtendedRequest): IsArchivedInfo {
// if this is an assets path, use the referrer
// if this is a docs path, use the req.path
const pathToCheck = patterns.assetPaths.test(req.path) ? req.get('referrer') : req.path
return isArchivedVersionByPath(pathToCheck || '')
}
export function isArchivedVersionByPath(pathToCheck: string): IsArchivedInfo {
// ignore paths that don't have an enterprise version number
if (
!(
patterns.getEnterpriseVersionNumber.test(pathToCheck) ||
patterns.getEnterpriseServerNumber.test(pathToCheck)
)
) {
return {}
}
// extract enterprise version from path, e.g. 2.16
const requestedVersion = pathToCheck.includes('enterprise-server@')
? pathToCheck.match(patterns.getEnterpriseServerNumber)?.[1]
: pathToCheck.match(patterns.getEnterpriseVersionNumber)?.[1]
// bail if the request version is not deprecated
if (!requestedVersion || !deprecated.includes(requestedVersion)) {
return {}
}
return { isArchived: true, requestedVersion }
}