2021-07-14 23:49:18 +03:00
|
|
|
import patterns from '../lib/patterns.js'
|
|
|
|
import { deprecated } from '../lib/enterprise-server-releases.js'
|
2020-11-18 02:46:30 +03:00
|
|
|
|
2021-07-15 00:35:01 +03:00
|
|
|
export default function isArchivedVersion(req) {
|
2020-11-18 20:52:53 +03:00
|
|
|
// if this is an assets path, use the referrer
|
2020-11-18 20:57:24 +03:00
|
|
|
// if this is a docs path, use the req.path
|
2021-07-15 00:35:01 +03:00
|
|
|
const pathToCheck = patterns.assetPaths.test(req.path) ? req.get('referrer') : req.path
|
2020-11-18 20:52:53 +03:00
|
|
|
|
2020-11-18 02:46:30 +03:00
|
|
|
// ignore paths that don't have an enterprise version number
|
2021-07-15 00:35:01 +03:00
|
|
|
if (
|
|
|
|
!(
|
|
|
|
patterns.getEnterpriseVersionNumber.test(pathToCheck) ||
|
|
|
|
patterns.getEnterpriseServerNumber.test(pathToCheck)
|
|
|
|
)
|
|
|
|
) {
|
2020-11-18 23:18:50 +03:00
|
|
|
return {}
|
|
|
|
}
|
2020-11-18 02:46:30 +03:00
|
|
|
|
|
|
|
// extract enterprise version from path, e.g. 2.16
|
2020-11-18 20:52:53 +03:00
|
|
|
const requestedVersion = pathToCheck.includes('enterprise-server@')
|
|
|
|
? pathToCheck.match(patterns.getEnterpriseServerNumber)[1]
|
|
|
|
: pathToCheck.match(patterns.getEnterpriseVersionNumber)[1]
|
2020-11-18 02:46:30 +03:00
|
|
|
|
|
|
|
// bail if the request version is not deprecated
|
2020-11-18 23:18:50 +03:00
|
|
|
if (!deprecated.includes(requestedVersion)) {
|
|
|
|
return {}
|
|
|
|
}
|
2020-11-18 02:46:30 +03:00
|
|
|
|
2020-11-18 23:18:50 +03:00
|
|
|
return { isArchived: true, requestedVersion }
|
2020-11-18 02:46:30 +03:00
|
|
|
}
|