feat: Add artifactStore URL in settings

This commit is contained in:
Peng-YM
2022-07-07 22:40:43 +08:00
parent 240156daef
commit 07cae95ff4
5 changed files with 36 additions and 13 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.8.0",
"version": "2.8.1",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
+26 -3
View File
@@ -1,16 +1,18 @@
import { SETTINGS_KEY } from '@/constants';
import { SETTINGS_KEY, ARTIFACT_REPOSITORY_KEY } from '@/constants';
import { success } from './response';
import $ from '@/core/app';
import Gist from '@/utils/gist';
export default function register($app) {
const settings = $.read(SETTINGS_KEY);
if (!settings) $.write({}, SETTINGS_KEY);
if (!settings.avatarUrl) updateGitHubAvatar();
$app.route('/api/settings').get(getSettings).patch(updateSettings);
}
function getSettings(req, res) {
async function getSettings(req, res) {
const settings = $.read(SETTINGS_KEY);
if (!settings.avatarUrl) await updateGitHubAvatar();
if (!settings.artifactStore) await updateArtifactStore();
success(res, settings);
}
@@ -22,6 +24,7 @@ async function updateSettings(req, res) {
};
$.write(newSettings, SETTINGS_KEY);
await updateGitHubAvatar();
await updateArtifactStore();
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);
}
}
}
+3 -3
View File
File diff suppressed because one or more lines are too long