diff --git a/src/api/artifacts/index.ts b/src/api/artifacts/index.ts index f1cf624f4..96ff46567 100644 --- a/src/api/artifacts/index.ts +++ b/src/api/artifacts/index.ts @@ -47,5 +47,11 @@ export function useArtifactsApi() { method: 'get', }); }, + restoreArtifacts: (): AxiosPromise => { + return request({ + url: '/api/artifacts/restore', + method: 'get', + }); + }, }; } diff --git a/src/locales/en.ts b/src/locales/en.ts index 599154548..7e6816d13 100644 --- a/src/locales/en.ts +++ b/src/locales/en.ts @@ -503,7 +503,7 @@ export default { }, deleteArt: { title: 'Delete Sync Configuration', - desc: 'Are you sure to delete sync configuration {displayName}? \nDeleted cannot be restored!', + desc: 'Are you sure to delete sync configuration {displayName}? \nDeleted cannot be restored!\n\n⚠️ If the current item has been synced before, an attempt will be made to delete the gist file.', succeedNotify: 'Successfully deleted!', btn: { confirm: 'Delete', @@ -560,7 +560,11 @@ export default { noUrl: 'Once you have successfully checked and uploaded the synchronized configuration, you can view the gist.', cancel: 'Cancel', confirm: 'View Gist', - } + }, + download: { + content: '⚠️ This feature will only add files to the sync configuration that are not already in the sync configuration.\nYou need to manually set the source.', + confirm: 'Restore From Gist', + }, }, themeSettingPage: { themeSettingTitle: 'Appearance', diff --git a/src/locales/zh.ts b/src/locales/zh.ts index 77442dc0c..7806b124e 100644 --- a/src/locales/zh.ts +++ b/src/locales/zh.ts @@ -505,7 +505,7 @@ export default { }, deleteArt: { title: '删除同步配置', - desc: '是否确认删除同步配置 {displayName}?删除后不可恢复!', + desc: '是否确认删除同步配置 {displayName}?删除后不可恢复!\n\n⚠️ 若当前同步配置进行过同步, 将尝试删除对应的 gist 文件', succeedNotify: '删除同步配置成功!', btn: { confirm: '确认删除', @@ -561,7 +561,11 @@ export default { noUrl: '检查成功并上传同步配置后 即可查看', cancel: '取消', confirm: '查看 gist', - } + }, + download: { + content: '⚠️ 只会获取不在同步配置中的 gist 文件\n你需要手动设置来源', + confirm: '从 gist 恢复', + }, }, themeSettingPage: { themeSettingTitle: '外观设置', diff --git a/src/store/artifacts.ts b/src/store/artifacts.ts index e7fcd984c..7ec923e57 100644 --- a/src/store/artifacts.ts +++ b/src/store/artifacts.ts @@ -55,6 +55,19 @@ export const useArtifactsStore = defineStore('artifactsStore', { }); } }, + async restoreArtifacts() { + const { showNotify } = useAppNotifyStore(); + + const res = await artifactsApi.restoreArtifacts(); + if (res?.data?.status === 'success') { + await this.fetchArtifactsData(); + showNotify({ + type: "success", + title: t(`myPage.notify.restore.succeed`), + content: ``, + }); + } + }, async syncAllArtifact() { const { showNotify } = useAppNotifyStore(); diff --git a/src/views/Sync.vue b/src/views/Sync.vue index e7e062e6c..c0bb30a77 100644 --- a/src/views/Sync.vue +++ b/src/views/Sync.vue @@ -49,6 +49,19 @@ v-if="!uploadAllIsLoading" /> + + +

{{ $t(`syncPage.title`) }}

+ + + { await artifactsStore.syncAllArtifact(); uploadAllIsLoading.value = false; }; +const downloadAllIsLoading = ref(false); +const downloadAll = async () => { + downloadAllIsLoading.value = true; + Dialog({ + popClass: 'auto-dialog', + title: t(`syncPage.preview.title`), + content: artifactStoreUrl.value ? `${t('syncPage.download.content')}\n\n${t('syncPage.preview.content', { status: artifactStoreStatus.value || 'VALID' })}\n${t('syncPage.preview.url')}` : `${t('syncPage.download.content')}\n\n${t('syncPage.preview.content', { status: artifactStoreStatus.value || '-' })}\n${t('syncPage.preview.noUrl')}`, + noOkBtn: !artifactStoreUrl.value, + okText: t(`syncPage.download.confirm`), + cancelText: t(`syncPage.preview.cancel`), + // @ts-ignore + closeOnClickOverlay: true, + onOk: async () => { + try { + await artifactsStore.restoreArtifacts(); + } catch (e) { + showNotify({ + title: t("myPage.notify.restore.failed"), + type: "danger", + content: `${ e.message ?? e}`, + }); + } finally { + downloadAllIsLoading.value = false; + } + }, + onCancel: async () => { + downloadAllIsLoading.value = false; + }, + }); +}; const refresh = () => { initStores(true, true, false);