mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-11 07:40:26 +08:00
44 lines
877 B
JavaScript
44 lines
877 B
JavaScript
const pathToRegExp = require('path-to-regexp');
|
|
|
|
const paired = (route, path) => {
|
|
const options = {
|
|
sensitive: true,
|
|
strict: true,
|
|
};
|
|
|
|
return pathToRegExp(route, [], options).exec(path);
|
|
};
|
|
|
|
const validityCheck = (routes, exclude, path) => {
|
|
let match = false;
|
|
let routeExpire = false;
|
|
|
|
for (let i = 0; i < routes.length; i++) {
|
|
let route = routes[i];
|
|
|
|
if (typeof routes[i] === 'object') {
|
|
route = routes[i].path;
|
|
routeExpire = routes[i].expire;
|
|
}
|
|
|
|
if (paired(route, path)) {
|
|
match = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
for (let j = 0; j < exclude.length; j++) {
|
|
if (paired(exclude[j], path)) {
|
|
match = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return { match, routeExpire };
|
|
};
|
|
|
|
module.exports = {
|
|
paired,
|
|
validityCheck,
|
|
};
|