mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-10 15:19:03 +08:00
feat: 取消 github 用户名绑定关系(现在用户名错误只影响头像), 增加最近一次 gist 检查状态
This commit is contained in:
parent
1bc44ccde8
commit
af6904ea50
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.14.167",
|
||||
"version": "2.14.169",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
||||
"main": "src/main.js",
|
||||
"scripts": {
|
||||
|
@ -19,6 +19,7 @@ async function getSettings(req, res) {
|
||||
if (!settings.avatarUrl) await updateGitHubAvatar();
|
||||
if (!settings.artifactStore) await updateArtifactStore();
|
||||
success(res, settings);
|
||||
// TODO: 缺错误处理 前端也缺
|
||||
}
|
||||
|
||||
async function updateSettings(req, res) {
|
||||
@ -31,6 +32,7 @@ async function updateSettings(req, res) {
|
||||
await updateGitHubAvatar();
|
||||
await updateArtifactStore();
|
||||
success(res, newSettings);
|
||||
// TODO: 缺错误处理 前端也缺
|
||||
}
|
||||
|
||||
export async function updateGitHubAvatar() {
|
||||
@ -70,17 +72,20 @@ export async function updateArtifactStore() {
|
||||
});
|
||||
|
||||
try {
|
||||
const gistId = await manager.locate();
|
||||
if (gistId !== -1) {
|
||||
settings.artifactStore = `https://gist.github.com/${githubUser}/${gistId}`;
|
||||
$.write(settings, SETTINGS_KEY);
|
||||
const gist = await manager.locate();
|
||||
if (gist?.html_url) {
|
||||
$.log(`找到 Sub-Store Gist: ${gist.html_url}`);
|
||||
// 只需要保证 token 是对的, 现在 username 错误只会导致头像错误
|
||||
settings.artifactStore = gist.html_url;
|
||||
settings.artifactStoreStatus = 'VALID';
|
||||
} else {
|
||||
$.error(`找不到 Sub-Store Gist`);
|
||||
settings.artifactStoreStatus = 'NOT FOUND';
|
||||
}
|
||||
} catch (err) {
|
||||
$.error(
|
||||
`Failed to fetch artifact store for User: ${githubUser}. Reason: ${
|
||||
err.message ?? err
|
||||
}`,
|
||||
);
|
||||
}
|
||||
$.error(`查找 Sub-Store Gist 时发生错误: ${err.message ?? err}`);
|
||||
settings.artifactStoreStatus = 'ERROR';
|
||||
}
|
||||
$.write(settings, SETTINGS_KEY);
|
||||
}
|
||||
}
|
||||
|
@ -32,10 +32,10 @@ export default class Gist {
|
||||
const gists = JSON.parse(response.body);
|
||||
for (let g of gists) {
|
||||
if (g.description === this.key) {
|
||||
return g.id;
|
||||
return g;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
@ -44,9 +44,15 @@ export default class Gist {
|
||||
return Promise.reject('未提供需上传的文件');
|
||||
}
|
||||
|
||||
const id = await this.locate();
|
||||
const gist = await this.locate();
|
||||
|
||||
if (id === -1) {
|
||||
if (gist?.id) {
|
||||
// update an existing gist
|
||||
return this.http.patch({
|
||||
url: `/gists/${gist.id}`,
|
||||
body: JSON.stringify({ files }),
|
||||
});
|
||||
} else {
|
||||
// create a new gist for backup
|
||||
return this.http.post({
|
||||
url: '/gists',
|
||||
@ -56,29 +62,23 @@ export default class Gist {
|
||||
files,
|
||||
}),
|
||||
});
|
||||
} else {
|
||||
// update an existing gist
|
||||
return this.http.patch({
|
||||
url: `/gists/${id}`,
|
||||
body: JSON.stringify({ files }),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async download(filename) {
|
||||
const id = await this.locate();
|
||||
if (id === -1) {
|
||||
return Promise.reject('未找到Gist备份!');
|
||||
} else {
|
||||
const gist = await this.locate();
|
||||
if (gist?.id) {
|
||||
try {
|
||||
const { files } = await this.http
|
||||
.get(`/gists/${id}`)
|
||||
.get(`/gists/${gist.id}`)
|
||||
.then((resp) => JSON.parse(resp.body));
|
||||
const url = files[filename].raw_url;
|
||||
return await this.http.get(url).then((resp) => resp.body);
|
||||
} catch (err) {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
} else {
|
||||
return Promise.reject('找不到 Sub-Store Gist');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user