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