Skip to content

Commit

Permalink
feat: 支持从 gist 获取不在同步配置中的 gist 文件(后端 > 2.14.170)
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Jan 16, 2024
1 parent 1e8372f commit 29e7104
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/api/artifacts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,11 @@ export function useArtifactsApi() {
method: 'get',
});
},
restoreArtifacts: (): AxiosPromise<MyAxiosRes> => {
return request({
url: '/api/artifacts/restore',
method: 'get',
});
},
};
}
8 changes: 6 additions & 2 deletions src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 6 additions & 2 deletions src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ export default {
},
deleteArt: {
title: '删除同步配置',
desc: '是否确认删除同步配置 {displayName}?删除后不可恢复!',
desc: '是否确认删除同步配置 {displayName}?删除后不可恢复!\n\n⚠️ 若当前同步配置进行过同步, 将尝试删除对应的 gist 文件',
succeedNotify: '删除同步配置成功!',
btn: {
confirm: '确认删除',
Expand Down Expand Up @@ -561,7 +561,11 @@ export default {
noUrl: '检查成功并上传同步配置后 即可查看',
cancel: '取消',
confirm: '查看 gist',
}
},
download: {
content: '⚠️ 只会获取不在同步配置中的 gist 文件\n你需要手动设置来源',
confirm: '从 gist 恢复',
},
},
themeSettingPage: {
themeSettingTitle: '外观设置',
Expand Down
13 changes: 13 additions & 0 deletions src/store/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
56 changes: 56 additions & 0 deletions src/views/Sync.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@
v-if="!uploadAllIsLoading"
/>
</nut-button>
<nut-button
class="upload-all-btn btn"
type="info"
plain
size="small"
:loading="downloadAllIsLoading"
@click="downloadAll"
>
<font-awesome-icon
icon="fa-solid fa-cloud-arrow-down"
v-if="!downloadAllIsLoading"
/>
</nut-button>
<nut-button
class="preview-btn btn"
type="info"
Expand Down Expand Up @@ -95,6 +108,19 @@
<div class="sticky-title-wrapper sync-title">
<p class="list-title">{{ $t(`syncPage.title`) }}</p>
<div class="actions-wrapper">
<nut-button
class="upload-all-btn btn"
type="info"
plain
size="small"
:loading="downloadAllIsLoading"
@click="downloadAll"
>
<font-awesome-icon
icon="fa-solid fa-cloud-arrow-down"
v-if="!downloadAllIsLoading"
/>
</nut-button>
<nut-button
class="preview-btn btn"
type="info"
Expand Down Expand Up @@ -222,6 +248,36 @@ const uploadAll = async () => {
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);
Expand Down

0 comments on commit 29e7104

Please sign in to comment.