mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-14 10:55:54 +08:00
fix: 配置接口补齐错误处理
This commit is contained in:
parent
c7d00ac512
commit
099ae5ad83
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.14.185",
|
||||
"version": "2.14.186",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
||||
"main": "src/main.js",
|
||||
"scripts": {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { SETTINGS_KEY, ARTIFACT_REPOSITORY_KEY } from '@/constants';
|
||||
import { success } from './response';
|
||||
import { success, failed } from './response';
|
||||
import { InternalServerError } from '@/restful/errors';
|
||||
import $ from '@/core/app';
|
||||
import Gist from '@/utils/gist';
|
||||
|
||||
@ -10,29 +11,52 @@ export default function register($app) {
|
||||
}
|
||||
|
||||
async function getSettings(req, res) {
|
||||
let settings = $.read(SETTINGS_KEY);
|
||||
if (!settings) {
|
||||
settings = {};
|
||||
$.write(settings, SETTINGS_KEY);
|
||||
}
|
||||
try {
|
||||
let settings = $.read(SETTINGS_KEY);
|
||||
if (!settings) {
|
||||
settings = {};
|
||||
$.write(settings, SETTINGS_KEY);
|
||||
}
|
||||
|
||||
if (!settings.avatarUrl) await updateGitHubAvatar();
|
||||
if (!settings.artifactStore) await updateArtifactStore();
|
||||
success(res, settings);
|
||||
// TODO: 缺错误处理 前端也缺
|
||||
if (!settings.avatarUrl) await updateGitHubAvatar();
|
||||
if (!settings.artifactStore) await updateArtifactStore();
|
||||
|
||||
success(res, settings);
|
||||
} catch (e) {
|
||||
$.error(`Failed to get settings: ${e.message ?? e}`);
|
||||
failed(
|
||||
res,
|
||||
new InternalServerError(
|
||||
`FAILED_TO_GET_SETTINGS`,
|
||||
`Failed to get settings`,
|
||||
`Reason: ${e.message ?? e}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function updateSettings(req, res) {
|
||||
const settings = $.read(SETTINGS_KEY);
|
||||
const newSettings = {
|
||||
...settings,
|
||||
...req.body,
|
||||
};
|
||||
$.write(newSettings, SETTINGS_KEY);
|
||||
await updateGitHubAvatar();
|
||||
await updateArtifactStore();
|
||||
success(res, newSettings);
|
||||
// TODO: 缺错误处理 前端也缺
|
||||
try {
|
||||
const settings = $.read(SETTINGS_KEY);
|
||||
const newSettings = {
|
||||
...settings,
|
||||
...req.body,
|
||||
};
|
||||
$.write(newSettings, SETTINGS_KEY);
|
||||
await updateGitHubAvatar();
|
||||
await updateArtifactStore();
|
||||
success(res, newSettings);
|
||||
} catch (e) {
|
||||
$.error(`Failed to update settings: ${e.message ?? e}`);
|
||||
failed(
|
||||
res,
|
||||
new InternalServerError(
|
||||
`FAILED_TO_UPDATE_SETTINGS`,
|
||||
`Failed to update settings`,
|
||||
`Reason: ${e.message ?? e}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateGitHubAvatar() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user