Skip to content

Commit

Permalink
fix: detectSnapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Nov 10, 2024
1 parent 72d9c18 commit e2f5466
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
16 changes: 4 additions & 12 deletions src/components/ActionCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,8 @@ const props = withDefaults(
const router = useRouter();
const { snapshotImportId, snapshotImageId } = useStorageStore();
const exportJpg = useTask(async () =>
exportSnapshotAsJpg((await snapshotStorage.getItem(props.snapshot.id))!),
);
const exportZip = useTask(async () =>
exportSnapshotAsZip((await snapshotStorage.getItem(props.snapshot.id))!),
);
const exportJpg = useTask(async () => exportSnapshotAsJpg(props.snapshot));
const exportZip = useTask(async () => exportSnapshotAsZip(props.snapshot));
const previewUrl = computed(() => {
return router.resolve({
Expand All @@ -50,9 +46,7 @@ const previewUrl = computed(() => {
const exportJpgUrl = useTask(async () => {
await waitShareAgree();
const imageId = await exportSnapshotAsImageId(
(await snapshotStorage.getItem(props.snapshot.id))!,
);
const imageId = await exportSnapshotAsImageId(props.snapshot);
showTextDLg({
title: `分享链接`,
content: getImagUrl(imageId),
Expand All @@ -61,9 +55,7 @@ const exportJpgUrl = useTask(async () => {
const exportZipUrl = useTask(async () => {
await waitShareAgree();
const importId = await exportSnapshotAsImportId(
(await snapshotStorage.getItem(props.snapshot.id))!,
);
const importId = await exportSnapshotAsImportId(props.snapshot);
showTextDLg({
title: `分享链接`,
content: location.origin + `/i/${importId}`,
Expand Down
21 changes: 14 additions & 7 deletions src/store/snapshot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
detectSnapshot,
exportSnapshotAsImageId,
exportSnapshotAsImportId,
} from '@/utils/export';
Expand Down Expand Up @@ -115,17 +116,26 @@ export const useSnapshotStore = defineStore('snapshot', () => {
if (autoUpload.value && snapshot.value && !importId.value) {
exportSnapshotAsImportId(snapshot.value);
}
if (autoUpload.value && snapshot.value && importId.value) {
detectSnapshot(importId.value);
}
});
const rootNode = computed(() => {
const nodes = computed(() => {
if (snapshot.value && settingsStore.inited) {
if (snapshot.value.nodes.length <= settingsStore.maxShowNodeSize) {
return listToTree(snapshot.value.nodes);
return structuredClone(snapshot.value.nodes);
} else {
return listToTree(
return structuredClone(
snapshot.value.nodes.slice(0, settingsStore.maxShowNodeSize),
);
}
}
return [];
});
const rootNode = computed(() => {
if (nodes.value.length) {
return listToTree(nodes.value);
}
return undefined;
});
const missNodeSize = computed(() => {
Expand Down Expand Up @@ -154,10 +164,7 @@ export const useSnapshotStore = defineStore('snapshot', () => {
});
const updatePosition = (position: Position) => {
focusPosition.value = position;
const resultNodes = findNodesByXy(
snapshot.value?.nodes,
focusPosition.value,
);
const resultNodes = findNodesByXy(nodes.value, focusPosition.value);
if (resultNodes.length) {
updateFocusNode(resultNodes[0]);
}
Expand Down
8 changes: 6 additions & 2 deletions src/utils/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Snapshot } from './types';
import { getImageId } from './url';
import { JSZipAsync } from './chunk';

export const snapshotAsZip = async (snapshot: Snapshot) => {
const snapshotAsZip = async (snapshot: Snapshot) => {
const zip = new (await JSZipAsync)();
zip
.file(`snapshot.json`, JSON.stringify(snapshot))
Expand Down Expand Up @@ -102,6 +102,7 @@ export const exportSnapshotAsImportId = async (snapshot: Snapshot) => {
).then((r) => {
snapshotImportId[snapshot.id] = r.id;
importSnapshotId[r.id] = snapshot.id;
detectFetchSnapshot(r.id);
return r.id;
})
);
Expand Down Expand Up @@ -134,6 +135,9 @@ export const batchCreateZipUrl = async (snapshots: Snapshot[]) => {
}, []);
};

const detectFetchSnapshot = async (importId: number | string) => {
return fetch(`https://detect.gkd.li/api/detectSnapshot?importId=` + importId);
};
export const detectSnapshot = async (importId: number | string | undefined) => {
if (!importId) return;
if (!Number.isSafeInteger(+importId)) {
Expand All @@ -144,5 +148,5 @@ export const detectSnapshot = async (importId: number | string | undefined) => {
if (importSnapshotId[importId]) {
return;
}
await fetch(`https://detect.gkd.li/api/detectSnapshot?importId=` + importId);
await detectFetchSnapshot(importId);
};
1 change: 0 additions & 1 deletion src/utils/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {
} from './types';

export const listToTree = (nodes: RawNode[]) => {
// nodes = structuredClone(nodes);
nodes.forEach((node) => {
node.attr ??= { name: `NULL` } as any;
node.children ??= [];
Expand Down
2 changes: 0 additions & 2 deletions src/views/ImportPage.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script setup lang="tsx">
import { loadingBar, message } from '@/utils/discrete';
import { detectSnapshot } from '@/utils/export';
import { gmOk } from '@/utils/gm';
import { importFromNetwork } from '@/utils/import';
import { delay, filterQuery } from '@/utils/others';
Expand Down Expand Up @@ -58,7 +57,6 @@ onMounted(async () => {
const snapshot = result.value;
if (snapshot?.id) {
if (importId) {
detectSnapshot(importId);
importSnapshotId[importId] = snapshot.id;
snapshotImportId[snapshot.id] = importId;
}
Expand Down

0 comments on commit e2f5466

Please sign in to comment.