mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-04-23 06:09:33 +08:00
Merge branch 'master' into feature-gui-for-cores
This commit is contained in:
commit
32f591ec56
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.14.308",
|
||||
"version": "2.14.310",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
||||
"main": "src/main.js",
|
||||
"scripts": {
|
||||
@ -17,6 +17,7 @@
|
||||
"author": "Peng-YM",
|
||||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"@maxmind/geoip2-node": "^5.0.0",
|
||||
"automerge": "1.0.1-preview.7",
|
||||
"body-parser": "^1.19.0",
|
||||
"connect-history-api-fallback": "^2.0.0",
|
||||
|
11325
backend/pnpm-lock.yaml
generated
11325
backend/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -15,7 +15,7 @@ import $ from '@/core/app';
|
||||
import { FILES_KEY, MODULES_KEY } from '@/constants';
|
||||
import { findByName } from '@/utils/database';
|
||||
import { produceArtifact } from '@/restful/sync';
|
||||
import { getFlag, getISO } from '@/utils/geo';
|
||||
import { getFlag, getISO, MMDB } from '@/utils/geo';
|
||||
import Gist from '@/utils/gist';
|
||||
|
||||
function preprocess(raw) {
|
||||
@ -273,6 +273,7 @@ export const ProxyUtils = {
|
||||
yaml: YAML,
|
||||
getFlag,
|
||||
getISO,
|
||||
MMDB,
|
||||
Gist,
|
||||
};
|
||||
|
||||
|
@ -14,7 +14,13 @@ import $ from '@/core/app';
|
||||
|
||||
const tasks = new Map();
|
||||
|
||||
export default async function download(rawUrl, ua, timeout, proxy) {
|
||||
export default async function download(
|
||||
rawUrl,
|
||||
ua,
|
||||
timeout,
|
||||
proxy,
|
||||
skipCustomCache,
|
||||
) {
|
||||
let $arguments = {};
|
||||
let url = rawUrl.replace(/#noFlow$/, '');
|
||||
const rawArgs = url.split('#');
|
||||
@ -39,6 +45,23 @@ export default async function download(rawUrl, ua, timeout, proxy) {
|
||||
? `#sub-store-cached-custom-${$arguments?.cacheKey}`
|
||||
: undefined;
|
||||
|
||||
if (customCacheKey && !skipCustomCache) {
|
||||
const cached = $.read(customCacheKey);
|
||||
if (cached) {
|
||||
$.info(
|
||||
`乐观缓存: URL ${url}\n本次返回自定义缓存 ${$arguments?.cacheKey}\n并进行请求 尝试更新缓存`,
|
||||
);
|
||||
download(
|
||||
rawUrl.replace(/(\?|&)cacheKey=.*?(&|$)/, ''),
|
||||
ua,
|
||||
timeout,
|
||||
proxy,
|
||||
true,
|
||||
);
|
||||
return cached;
|
||||
}
|
||||
}
|
||||
|
||||
// const downloadUrlMatch = url.match(/^\/api\/(file|module)\/(.+)/);
|
||||
// if (downloadUrlMatch) {
|
||||
// let type = downloadUrlMatch?.[1];
|
||||
@ -81,7 +104,7 @@ export default async function download(rawUrl, ua, timeout, proxy) {
|
||||
|
||||
// try to find in app cache
|
||||
const cached = resourceCache.get(id);
|
||||
if (!$arguments?.noCache && cached) {
|
||||
if (!$arguments?.noCache && cached && !skipCustomCache) {
|
||||
$.info(`使用缓存: ${url}`);
|
||||
result = cached;
|
||||
} else {
|
||||
@ -120,6 +143,9 @@ export default async function download(rawUrl, ua, timeout, proxy) {
|
||||
if (shouldCache) {
|
||||
resourceCache.set(id, body);
|
||||
if (customCacheKey) {
|
||||
$.info(
|
||||
`URL ${url}\n写入自定义缓存 ${$arguments?.cacheKey}`,
|
||||
);
|
||||
$.write(body, customCacheKey);
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
import $ from '@/core/app';
|
||||
|
||||
const ISOFlags = {
|
||||
'🏳️🌈': ['EXP', 'BAND'],
|
||||
'🇸🇱': ['TEST', 'SOS'],
|
||||
@ -427,3 +429,31 @@ export function getFlag(name) {
|
||||
export function getISO(name) {
|
||||
return ISOFlags[getFlag(name)]?.[0];
|
||||
}
|
||||
|
||||
export class MMDB {
|
||||
constructor({ country, asn } = {}) {
|
||||
if ($.env.isNode) {
|
||||
const Reader = eval(`require("@maxmind/geoip2-node")`).Reader;
|
||||
const fs = eval("require('fs')");
|
||||
const countryFile =
|
||||
country || eval('process.env.SUB_STORE_MMDB_COUNTRY_PATH');
|
||||
const asnFile = asn || eval('process.env.SUB_STORE_MMDB_ASN_PATH');
|
||||
if (countryFile) {
|
||||
this.countryReader = Reader.openBuffer(
|
||||
fs.readFileSync(countryFile),
|
||||
);
|
||||
}
|
||||
if (asnFile) {
|
||||
if (!fs.existsSync(asnFile))
|
||||
throw new Error('GeoLite2 ASN MMDB does not exist');
|
||||
this.asnReader = Reader.openBuffer(fs.readFileSync(asnFile));
|
||||
}
|
||||
}
|
||||
}
|
||||
geoip(ip) {
|
||||
return this.countryReader?.country(ip)?.country?.isoCode;
|
||||
}
|
||||
ipaso(ip) {
|
||||
return this.asnReader?.asn(ip)?.autonomousSystemOrganization;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user