mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-12-01 17:03:04 +00:00
fix: 简单处理下 Loon 解析器等脚本中未初始化设置报错的问题
This commit is contained in:
14 files changed
+30
-20
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.36.38",
|
||||
"version": "2.36.39",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
|
||||
"main": "src/main.js",
|
||||
"packageManager": "pnpm@11.0.9",
|
||||
|
||||
@@ -43,7 +43,7 @@ import {
|
||||
if (col_names.length > 0)
|
||||
await produceArtifacts(col_names, 'collection');
|
||||
} else {
|
||||
const settings = $.read(SETTINGS_KEY);
|
||||
const settings = $.read(SETTINGS_KEY) || {};
|
||||
const artifacts = $.read(ARTIFACTS_KEY);
|
||||
if (!artifacts || artifacts.length === 0) return;
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ export default function register($app) {
|
||||
async function restoreArtifacts(_, res) {
|
||||
$.info('开始恢复远程配置...');
|
||||
try {
|
||||
const { gistToken, syncPlatform } = $.read(SETTINGS_KEY);
|
||||
const { gistToken, syncPlatform } = $.read(SETTINGS_KEY) || {};
|
||||
if (!gistToken) {
|
||||
return Promise.reject('未设置 GitHub Token!');
|
||||
}
|
||||
@@ -355,7 +355,7 @@ function getArtifactGistEmptyFileFallback() {
|
||||
}
|
||||
|
||||
async function syncToGist(files, options = {}) {
|
||||
const { gistToken, syncPlatform } = $.read(SETTINGS_KEY);
|
||||
const { gistToken, syncPlatform } = $.read(SETTINGS_KEY) || {};
|
||||
if (!gistToken) {
|
||||
return Promise.reject('未设置 GitHub Token!');
|
||||
}
|
||||
@@ -398,7 +398,7 @@ async function syncToGist(files, options = {}) {
|
||||
} catch (e) {}
|
||||
|
||||
const url = body?.html_url ?? body?.web_url;
|
||||
const settings = $.read(SETTINGS_KEY);
|
||||
const settings = $.read(SETTINGS_KEY) || {};
|
||||
if (url) {
|
||||
$.log(`同步 Gist 后, 找到 Sub-Store Gist: ${url}`);
|
||||
settings.artifactStore = url;
|
||||
|
||||
@@ -91,7 +91,7 @@ export default function serve() {
|
||||
next();
|
||||
return;
|
||||
} else {
|
||||
const settings = $.read(SETTINGS_KEY);
|
||||
const settings = $.read(SETTINGS_KEY) || {};
|
||||
if (settings?.appearanceSetting?.invalidShareFakeNode) {
|
||||
req.query._fakeNode = true;
|
||||
req.url = req.url.replace(
|
||||
@@ -395,7 +395,7 @@ export default function serve() {
|
||||
name: req.params.name,
|
||||
});
|
||||
if (!token) {
|
||||
const settings = $.read(SETTINGS_KEY);
|
||||
const settings = $.read(SETTINGS_KEY) || {};
|
||||
if (
|
||||
settings?.appearanceSetting
|
||||
?.invalidShareFakeNode
|
||||
|
||||
@@ -243,7 +243,7 @@ async function gistBackupAction(
|
||||
action,
|
||||
{ keep, encode, tokenStrategy: queryTokenStrategy } = {},
|
||||
) {
|
||||
const settings = $.read(SETTINGS_KEY);
|
||||
const settings = $.read(SETTINGS_KEY) || {};
|
||||
const { gistToken, syncPlatform } = settings;
|
||||
if (!gistToken) throw new Error('GitHub Token is required for backup!');
|
||||
|
||||
@@ -397,7 +397,7 @@ async function gistBackupAction(
|
||||
async function gistBackup(req, res) {
|
||||
const { action, keep, encode, tokenStrategy } = req.query;
|
||||
// read token
|
||||
const { gistToken } = $.read(SETTINGS_KEY);
|
||||
const { gistToken } = $.read(SETTINGS_KEY) || {};
|
||||
if (!gistToken) {
|
||||
failed(
|
||||
res,
|
||||
|
||||
@@ -100,7 +100,7 @@ async function getSettings(req, res) {
|
||||
|
||||
async function updateSettings(req, res) {
|
||||
try {
|
||||
const settings = $.read(SETTINGS_KEY);
|
||||
const settings = $.read(SETTINGS_KEY) || {};
|
||||
const newSettings = {
|
||||
...settings,
|
||||
...req.body,
|
||||
@@ -207,7 +207,7 @@ async function updateSettings(req, res) {
|
||||
}
|
||||
|
||||
export async function updateAvatar() {
|
||||
const settings = $.read(SETTINGS_KEY);
|
||||
const settings = $.read(SETTINGS_KEY) || {};
|
||||
const {
|
||||
githubUser: username,
|
||||
syncPlatform,
|
||||
@@ -273,7 +273,7 @@ export async function updateAvatar() {
|
||||
|
||||
export async function updateArtifactStore() {
|
||||
$.log('Updating artifact store');
|
||||
const settings = $.read(SETTINGS_KEY);
|
||||
const settings = $.read(SETTINGS_KEY) || {};
|
||||
const { gistToken, syncPlatform } = settings;
|
||||
if (gistToken) {
|
||||
const manager = new Gist({
|
||||
|
||||
@@ -160,6 +160,16 @@ describe('download github proxy regex', function () {
|
||||
expect(capturedUrls).to.deep.equal(['https://example.com/archive.txt']);
|
||||
});
|
||||
|
||||
it('uses download defaults when settings are missing', async function () {
|
||||
delete state[SETTINGS_KEY];
|
||||
|
||||
await download('https://example.com/no-settings.txt');
|
||||
|
||||
expect(capturedUrls).to.deep.equal([
|
||||
'https://example.com/no-settings.txt',
|
||||
]);
|
||||
});
|
||||
|
||||
it('matches regex patterns case-insensitively by default', async function () {
|
||||
state[SETTINGS_KEY].githubProxyRegex =
|
||||
'^https://RAW\\.GITHUBUSERCONTENT\\.COM';
|
||||
|
||||
@@ -2,8 +2,8 @@ import { SETTINGS_KEY } from '@/constants';
|
||||
import $ from '@/core/app';
|
||||
|
||||
export function getCreateItemPosition() {
|
||||
const createItemPosition =
|
||||
$.read(SETTINGS_KEY)?.appearanceSetting?.createItemPosition;
|
||||
const createItemPosition = ($.read(SETTINGS_KEY) || {}).appearanceSetting
|
||||
?.createItemPosition;
|
||||
|
||||
return createItemPosition === 'top' ? 'top' : 'bottom';
|
||||
}
|
||||
@@ -170,7 +170,7 @@ export default async function download(
|
||||
defaultUserAgent,
|
||||
defaultTimeout,
|
||||
cacheThreshold: defaultCacheThreshold,
|
||||
} = $.read(SETTINGS_KEY);
|
||||
} = $.read(SETTINGS_KEY) || {};
|
||||
const cacheThreshold = defaultCacheThreshold || 1024;
|
||||
let proxy = customProxy || defaultProxy;
|
||||
if ($.env.isNode) {
|
||||
|
||||
@@ -64,7 +64,7 @@ export async function getFlowHeaders(
|
||||
: { insecure: true }
|
||||
: undefined;
|
||||
const { defaultProxy, defaultFlowUserAgent, defaultTimeout } =
|
||||
$.read(SETTINGS_KEY);
|
||||
$.read(SETTINGS_KEY) || {};
|
||||
let proxy = customProxy || defaultProxy;
|
||||
if ($.env.isNode) {
|
||||
proxy = proxy || eval('process.env.SUB_STORE_BACKEND_DEFAULT_PROXY');
|
||||
|
||||
@@ -57,7 +57,7 @@ export default class Gist {
|
||||
constructor({ token, key, syncPlatform }) {
|
||||
const { isStash, isLoon, isShadowRocket, isQX } = ENV();
|
||||
const { defaultProxy, githubApiTimeout, githubProxy, githubApiUrl } =
|
||||
$.read(SETTINGS_KEY);
|
||||
$.read(SETTINGS_KEY) || {};
|
||||
const githubApiRequestTimeout = githubApiTimeout || 10000;
|
||||
const githubGistBaseURL = getGithubGistBaseURL({
|
||||
githubApiUrl,
|
||||
|
||||
@@ -89,7 +89,7 @@ function normalizeTTL(ttl) {
|
||||
}
|
||||
|
||||
function getTTL() {
|
||||
const settings = $.read(SETTINGS_KEY);
|
||||
const settings = $.read(SETTINGS_KEY) || {};
|
||||
let ttl = settings?.headersCacheTtl;
|
||||
if (ttl) {
|
||||
ttl = Number(ttl);
|
||||
|
||||
@@ -89,7 +89,7 @@ function normalizeTTL(ttl) {
|
||||
}
|
||||
|
||||
function getTTL() {
|
||||
const settings = $.read(SETTINGS_KEY);
|
||||
const settings = $.read(SETTINGS_KEY) || {};
|
||||
let ttl = settings?.resourceCacheTtl;
|
||||
if (ttl) {
|
||||
ttl = Number(ttl);
|
||||
|
||||
@@ -89,7 +89,7 @@ function normalizeTTL(ttl) {
|
||||
}
|
||||
|
||||
function getTTL() {
|
||||
const settings = $.read(SETTINGS_KEY);
|
||||
const settings = $.read(SETTINGS_KEY) || {};
|
||||
let ttl = settings?.scriptCacheTtl;
|
||||
if (ttl) {
|
||||
ttl = Number(ttl);
|
||||
|
||||
Reference in new issue
Block a user