Skip to content

Commit

Permalink
fix: 尝试修复同步
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Jan 13, 2024
1 parent c406022 commit e2d7632
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store-front-end",
"version": "2.14.45",
"version": "2.14.46",
"private": true,
"scripts": {
"dev": "vite --host",
Expand Down Expand Up @@ -61,4 +61,4 @@
"vue-tsc": "^0.35.2",
"workbox-window": "^7.0.0"
}
}
}
8 changes: 4 additions & 4 deletions src/api/artifacts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export function useArtifactsApi() {
method: 'get',
});
},
syncOneArtifact: (name: string): AxiosPromise<MyAxiosRes> => {
syncOneArtifact: (name: string, method = 'get'): AxiosPromise<MyAxiosRes> => {
return request({
url: `/api/sync/artifact/${encodeURIComponent(name)}`,
method: 'get',
method,
});
},
createArtifact: (data: Artifact): AxiosPromise<MyAxiosRes> => {
Expand All @@ -41,10 +41,10 @@ export function useArtifactsApi() {
method: 'delete',
});
},
syncAllArtifact: (): AxiosPromise<MyAxiosRes> => {
syncAllArtifact: (method = 'get'): AxiosPromise<MyAxiosRes> => {
return request({
url: '/api/sync/artifacts',
method: 'get',
method,
});
},
};
Expand Down
11 changes: 9 additions & 2 deletions src/components/ArtifactsListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
</template>

<script lang="ts" setup>
import semverGt from 'semver/functions/gt';
import singboxIcon from '@/assets/icons/sing-box.png';
import clashIcon from '@/assets/icons/clash.png';
import clashMetaIcon from '@/assets/icons/clashmeta.png';
Expand All @@ -112,7 +113,7 @@ import { useGlobalStore } from '@/store/global';
import { useHostAPI } from '@/hooks/useHostAPI';
const globalStore = useGlobalStore();
const { isLeftRight, isSimpleMode } = storeToRefs(globalStore);
const { env, isLeftRight, isSimpleMode } = storeToRefs(globalStore);
const { copy, isSupported } = useClipboard();
const { toClipboard: copyFallback } = useV3Clipboard();
Expand Down Expand Up @@ -302,7 +303,13 @@ const onClickSync = async () => {
cover: true,
id: 'sync-toast',
});
await artifactsStore.syncOneArtifact(artifact.value.name);
let method = 'get'
try {
if (semverGt(env.value.version, '2.14.151')) {
method = 'post'
}
} catch (e) {}
await artifactsStore.syncOneArtifact(artifact.value.name, method);
Toast.hide('sync-toast');
};
Expand Down
8 changes: 4 additions & 4 deletions src/store/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ export const useArtifactsStore = defineStore('artifactsStore', {
});
}
},
async syncAllArtifact() {
async syncAllArtifact(method: string) {
const { showNotify } = useAppNotifyStore();

const res = await artifactsApi.syncAllArtifact();
const res = await artifactsApi.syncAllArtifact(method);
if (res?.data?.status === 'success') {
await this.fetchArtifactsData();
showNotify({
Expand All @@ -67,10 +67,10 @@ export const useArtifactsStore = defineStore('artifactsStore', {
});
}
},
async syncOneArtifact(name: string) {
async syncOneArtifact(name: string, method: string) {
const { showNotify } = useAppNotifyStore();

const res = await artifactsApi.syncOneArtifact(name);
const res = await artifactsApi.syncOneArtifact(name, method);
if (res?.data?.status === 'success') {
const index = this.artifacts.findIndex(item => item.name === name);
this.artifacts[index] = res.data.data;
Expand Down
9 changes: 8 additions & 1 deletion src/views/Sync.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
</template>

<script lang="ts" setup>
import semverGt from 'semver/functions/gt';
import ArtifactsListItem from "@/components/ArtifactsListItem.vue";
import { useArtifactsStore } from "@/store/artifacts";
import { storeToRefs } from "pinia";
Expand Down Expand Up @@ -203,7 +204,13 @@ const uploadAllIsDisabled = computed(() => {
const uploadAllIsLoading = ref(false);
const uploadAll = async () => {
uploadAllIsLoading.value = true;
await artifactsStore.syncAllArtifact();
let method = 'get'
try {
if (semverGt(env.value.version, '2.14.151')) {
method = 'post'
}
} catch (e) {}
await artifactsStore.syncAllArtifact(method);
uploadAllIsLoading.value = false;
};
Expand Down

0 comments on commit e2d7632

Please sign in to comment.