Skip to content

Commit

Permalink
feat: simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Oct 29, 2024
1 parent ce5c987 commit 7206894
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 533 deletions.
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@
"@gkd-kit/api": "0.5.0",
"@gkd-kit/selector": "0.4.2",
"@gkd-kit/wasm_matches": "0.0.1",
"@rushstack/eslint-patch": "1.10.4",
"@tsconfig/node20": "20.1.4",
"@types/file-saver": "2.0.7",
"@types/fs-extra": "11.0.4",
"@types/node": "22.7.5",
"@types/qrcode": "1.5.5",
"@vitejs/plugin-legacy": "5.4.2",
"@vitejs/plugin-vue": "5.1.4",
"@vitejs/plugin-vue-jsx": "4.0.1",
Expand All @@ -48,7 +46,6 @@
"eslint-plugin-unused-imports": "4.1.4",
"eslint-plugin-vue": "9.28.0",
"file-saver": "2.0.5",
"fs-extra": "11.2.0",
"json5": "2.2.3",
"jszip": "3.10.1",
"lint-staged": "15.2.10",
Expand All @@ -58,7 +55,6 @@
"p-limit": "6.1.0",
"pinia": "2.2.4",
"prettier": "3.3.3",
"qrcode": "1.5.4",
"sass": "1.79.4",
"simple-git": "3.27.0",
"simple-git-hooks": "2.11.1",
Expand All @@ -67,7 +63,7 @@
"universal-base64url": "1.1.0",
"unocss": "0.63.4",
"unplugin-auto-import": "0.18.3",
"unplugin-data": "0.1.0",
"unplugin-data": "0.1.1",
"unplugin-vue-components": "0.27.4",
"user-attachments": "1.1.2",
"vite": "5.4.8",
Expand Down
250 changes: 5 additions & 245 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

30 changes: 0 additions & 30 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,36 +64,6 @@ const router = createRouter({
next();
},
},
{
path: '/s',
component: () => import('@/views/PreviewSharePage.vue'),
beforeEnter(to, _, next) {
if (to.query.url) {
const u = toValidURL(String(to.query.url));
if (u) {
return next();
}
}
return next({ path: '/404' });
},
},
{
path: '/s/:github_asset_id',
component: () => import('@/views/PreviewSharePage.vue'),
beforeEnter(to, _, next) {
const github_asset_id = String(to.params.github_asset_id).match(
/^\d+/,
)?.[0];
if (!github_asset_id) {
return next({ path: '/404' });
}
if (to.params.github_asset_id === github_asset_id) {
return next();
} else {
return next('/s/' + github_asset_id);
}
},
},
{
path: '/selector',
component: () => import('@/views/SelectorPage.vue'),
Expand Down
7 changes: 7 additions & 0 deletions src/utils/chunk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type loadAsyncType = (typeof import('jszip'))['loadAsync'];

export type JSZipType = typeof import('jszip');
export const JSZipAsync = import('jszip').then((r) => r.default);
export const loadAsync: loadAsyncType = async (data, options?) => {
return import('jszip').then((r) => r.loadAsync(data, options));
};
8 changes: 4 additions & 4 deletions src/utils/export.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { saveAs } from 'file-saver';
import JSZip from 'jszip';
import pLimit from 'p-limit';
import { uploadAsset } from './github';
import { delay } from './others';
import { screenshotStorage } from './snapshot';
import Compressor from 'compressorjs';
import type { Snapshot } from './types';
import { getImageId } from './url';
import { JSZipAsync } from './chunk';

export const snapshotAsZip = async (snapshot: Snapshot) => {
const zip = new JSZip();
const zip = new (await JSZipAsync)();
zip
.file(`snapshot.json`, JSON.stringify(snapshot))
.file(`screenshot.png`, (await screenshotStorage.getItem(snapshot.id))!);
Expand Down Expand Up @@ -49,7 +49,7 @@ export const exportSnapshotAsJpg = async (snapshot: Snapshot) => {
};

export const batchJpgDownloadZip = async (snapshots: Snapshot[]) => {
const zip = new JSZip();
const zip = new (await JSZipAsync)();
for (const snapshot of snapshots) {
await delay();
zip.file(snapshot.id + `.jpg`, snapshotAsJpg(snapshot));
Expand All @@ -62,7 +62,7 @@ export const batchJpgDownloadZip = async (snapshots: Snapshot[]) => {
};

export const batchZipDownloadZip = async (snapshots: Snapshot[]) => {
const zip = new JSZip();
const zip = new (await JSZipAsync)();
for (const snapshot of snapshots) {
await delay();
zip.file(snapshot.id + `.zip`, await snapshotAsZip(snapshot));
Expand Down
5 changes: 3 additions & 2 deletions src/utils/import.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { fileOpen } from 'browser-fs-access';
import JSZip, { loadAsync } from 'jszip';
import pLimit from 'p-limit';
import { message } from './discrete';
import { enhanceFetch } from './fetch';
import { isZipBf } from './file_type';
import { setSnapshot, snapshotStorage } from './snapshot';
import type { Snapshot } from './types';
import { getImportFileUrl, getImportId } from './url';
import { loadAsync } from './chunk';
import type { JSZipType } from './chunk';

const parseZip = async (zip: JSZip) => {
const parseZip = async (zip: JSZipType) => {
const snapshotFile = zip.filter((s) => s.endsWith(`.json`))[0];
const screenshotFile = zip.filter((s) => s.endsWith(`.png`))[0];
if (!snapshotFile || !screenshotFile) {
Expand Down
124 changes: 0 additions & 124 deletions src/views/PreviewSharePage.vue

This file was deleted.

111 changes: 0 additions & 111 deletions src/views/home/BuildShareDlg.vue

This file was deleted.

Loading

0 comments on commit 7206894

Please sign in to comment.