fix: Sync time is updated even if upload failed

This commit is contained in:
Peng-YM
2022-07-08 10:26:05 +08:00
parent 2ee515dc23
commit b1d811e4c5
6 changed files with 26 additions and 14 deletions

View File

@@ -104,16 +104,26 @@ async function gistBackup(req, res) {
try {
let content;
const settings = $.read(SETTINGS_KEY);
const updated = settings.syncTime;
switch (action) {
case 'upload':
// update syncTime.
// update syncTime
settings.syncTime = new Date().getTime();
$.write(settings, SETTINGS_KEY);
content = $.read('#sub-store');
if ($.env.isNode)
content = JSON.stringify($.cache, null, ` `);
$.info(`上传备份中...`);
await gist.upload({ [GIST_BACKUP_FILE_NAME]: { content } });
try {
await gist.upload({
[GIST_BACKUP_FILE_NAME]: { content },
});
} catch (err) {
// restore syncTime if upload failed
settings.syncTime = updated;
$.write(settings, SETTINGS_KEY);
throw err;
}
break;
case 'download':
$.info(`还原备份中...`);

View File

@@ -62,8 +62,10 @@ async function updateArtifactStore() {
try {
const gistId = await manager.locate();
settings.artifactStore = `https://gist.github.com/${githubUser}/${gistId}`;
$.write(settings, SETTINGS_KEY);
if (gistId !== -1) {
settings.artifactStore = `https://gist.github.com/${githubUser}/${gistId}`;
$.write(settings, SETTINGS_KEY);
}
} catch (err) {
$.error('Failed to fetch artifact store for User: ' + githubUser);
}