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