mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-12 04:18:59 +08:00
feat: Add artifactStore URL in settings
This commit is contained in:
parent
240156daef
commit
07cae95ff4
6
backend/dist/cron-sync-artifacts.min.js
vendored
6
backend/dist/cron-sync-artifacts.min.js
vendored
File diff suppressed because one or more lines are too long
6
backend/dist/sub-store-parser.loon.min.js
vendored
6
backend/dist/sub-store-parser.loon.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sub-store",
|
"name": "sub-store",
|
||||||
"version": "2.8.0",
|
"version": "2.8.1",
|
||||||
"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,16 +1,18 @@
|
|||||||
import { SETTINGS_KEY } from '@/constants';
|
import { SETTINGS_KEY, ARTIFACT_REPOSITORY_KEY } from '@/constants';
|
||||||
import { success } from './response';
|
import { success } from './response';
|
||||||
import $ from '@/core/app';
|
import $ from '@/core/app';
|
||||||
|
import Gist from '@/utils/gist';
|
||||||
|
|
||||||
export default function register($app) {
|
export default function register($app) {
|
||||||
const settings = $.read(SETTINGS_KEY);
|
const settings = $.read(SETTINGS_KEY);
|
||||||
if (!settings) $.write({}, SETTINGS_KEY);
|
if (!settings) $.write({}, SETTINGS_KEY);
|
||||||
if (!settings.avatarUrl) updateGitHubAvatar();
|
|
||||||
$app.route('/api/settings').get(getSettings).patch(updateSettings);
|
$app.route('/api/settings').get(getSettings).patch(updateSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSettings(req, res) {
|
async function getSettings(req, res) {
|
||||||
const settings = $.read(SETTINGS_KEY);
|
const settings = $.read(SETTINGS_KEY);
|
||||||
|
if (!settings.avatarUrl) await updateGitHubAvatar();
|
||||||
|
if (!settings.artifactStore) await updateArtifactStore();
|
||||||
success(res, settings);
|
success(res, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,6 +24,7 @@ async function updateSettings(req, res) {
|
|||||||
};
|
};
|
||||||
$.write(newSettings, SETTINGS_KEY);
|
$.write(newSettings, SETTINGS_KEY);
|
||||||
await updateGitHubAvatar();
|
await updateGitHubAvatar();
|
||||||
|
await updateArtifactStore();
|
||||||
success(res, newSettings);
|
success(res, newSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,3 +49,23 @@ async function updateGitHubAvatar() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function updateArtifactStore() {
|
||||||
|
console.log('Updating artifact store');
|
||||||
|
const settings = $.read(SETTINGS_KEY);
|
||||||
|
const { githubUser, gistToken } = settings;
|
||||||
|
if (githubUser && gistToken) {
|
||||||
|
const manager = new Gist({
|
||||||
|
token: gistToken,
|
||||||
|
key: ARTIFACT_REPOSITORY_KEY,
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const gistId = await manager.locate();
|
||||||
|
settings.artifactStore = `https://gist.github.com/${githubUser}/${gistId}`;
|
||||||
|
$.write(settings, SETTINGS_KEY);
|
||||||
|
} catch (err) {
|
||||||
|
$.error('Failed to fetch artifact store for User: ' + githubUser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
6
backend/sub-store.min.js
vendored
6
backend/sub-store.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user