Skip to content

Commit a4e55fd

Browse files
committed
feat: fileSizeDesc
1 parent 35c60cb commit a4e55fd

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

docs/.vitepress/components/ApkTable.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import { betaRelease, stableRelease } from '../data/apk.load';
77
<thead>
88
<tr>
99
<th>版本</th>
10-
<th>下载链接</th>
11-
<th>更新日期</th>
10+
<th>下载</th>
11+
<th>大小</th>
12+
<th>日期</th>
1213
<th>备注</th>
1314
</tr>
1415
</thead>
@@ -21,6 +22,7 @@ import { betaRelease, stableRelease } from '../data/apk.load';
2122
:name="stableRelease.filename"
2223
/>
2324
</td>
25+
<td>{{ stableRelease.fileSizeDesc }}</td>
2426
<td>{{ stableRelease.date }}</td>
2527
<td>稳定版</td>
2628
</tr>
@@ -29,6 +31,7 @@ import { betaRelease, stableRelease } from '../data/apk.load';
2931
<td>
3032
<DownloadText :href="betaRelease.href" :name="betaRelease.filename" />
3133
</td>
34+
<td>{{ betaRelease.fileSizeDesc }}</td>
3235
<td>{{ betaRelease.date }}</td>
3336
<td>更新快不稳定</td>
3437
</tr>

docs/.vitepress/data/apk.load.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
1-
import { cutsomFetch } from './fetch';
1+
import { customFetch } from './fetch';
22

33
export interface VersionInfo {
44
name: string;
55
date: string;
66
href: string;
77
filename: string;
8+
fileSizeDesc: string;
89
}
910
export interface ApkData {
1011
stable: VersionInfo;
1112
beta: VersionInfo;
1213
}
1314

15+
const getFileSizeDesc = (size: number): string => {
16+
if (size < 1024) {
17+
return size + 'B';
18+
}
19+
if (size < 1024 * 1024) {
20+
return (size / 1024).toFixed(2) + 'KB';
21+
}
22+
if (size < 1024 * 1024 * 1024) {
23+
return (size / (1024 * 1024)).toFixed(2) + 'MB';
24+
}
25+
return (size / (1024 * 1024 * 1024)).toFixed(2) + 'GB';
26+
};
27+
1428
const getVersionInfo = async (url: string): Promise<VersionInfo> => {
15-
const r = await cutsomFetch(url).then((r) => r.json());
29+
const r = await customFetch(url).then((r) => r.json());
1630
return {
1731
name: r.versionName,
1832
href: new URL(r.downloadUrl, url).href,
19-
date: String(r.date || '').substring(0, 10),
20-
filename: 'gkd-v' + r.versionName + '.apk',
33+
date: r.date,
34+
filename: 'v' + r.versionName + '.apk',
35+
fileSizeDesc: getFileSizeDesc(r.fileSize),
2136
};
2237
};
2338

docs/.vitepress/data/fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const retryCount = 10;
22

3-
export const cutsomFetch = async (
3+
export const customFetch = async (
44
input: string | URL | globalThis.Request,
55
init?: RequestInit,
66
) => {

docs/.vitepress/data/mirror.load.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { cutsomFetch } from './fetch';
1+
import { customFetch } from './fetch';
22

33
const getPkgLatestVersion = async (name: string): Promise<string> => {
44
const url = `https://registry.npmjs.org/${name}/latest`;
5-
return cutsomFetch(url).then((r) =>
5+
return customFetch(url).then((r) =>
66
r.json().then((j) => j.version as string),
77
);
88
};

docs/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default defineConfig({
88
data({
99
include: (v) => v.endsWith('.load.ts'),
1010
}),
11-
unocss(),
11+
unocss({ inspector: false }),
1212
mirror(),
1313
],
1414
server: {

0 commit comments

Comments
 (0)