Skip to content

Commit 999e0f1

Browse files
committed
feat(info): 将 Release Size 转换成人类可读
1 parent 95a8986 commit 999e0f1

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

os-checks/pages/info.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@
238238
<script setup lang="ts">
239239
import type { Pkg, PkgInfo, Test } from '~/shared/info';
240240
import { unique_field, unique_field_bool, InfoCols } from '~/shared/info';
241+
import { formatBytes } from '~/shared/columns-select';
241242
import { FilterMatchMode } from '@primevue/core/api';
242243
import type { DataTableSortMeta } from 'primevue/datatable';
243244
@@ -282,7 +283,7 @@ const summaryTable = computed<SummaryTable[]>(() => {
282283
version: pkg.version,
283284
release_count: pkg.release_count,
284285
last_release_time: fmtDateTime(pkg.last_release_time),
285-
last_release_size: pkg.last_release_size,
286+
last_release_size: pkg.last_release_size ? formatBytes(pkg.last_release_size): null,
286287
diag_total_count: pkg.diag_total_count,
287288
testcases: pkg.testcases?.pkg_tests_count ?? null,
288289
testcases_color,
@@ -338,7 +339,7 @@ type SummaryTable = {
338339
authors: string[] | null; description: string; categories: string[] | null;
339340
documentation: string | null; readme: string | null; homepage: string | null; latest_doc: string | null;
340341
diag_total_count: number | null; last_commit_time: string; release_count: number | null;
341-
last_release_size: number | null; last_release_time: string | null;
342+
last_release_size: string | null; last_release_time: string;
342343
};
343344
const data = ref<SummaryTable[]>([]);
344345
watch(summaryTable, (val) => data.value = val);

os-checks/pages/repos.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@
117117
<script setup lang="ts">
118118
import { FilterMatchMode } from '@primevue/core/api';
119119
import type { DataTableSortMeta } from 'primevue/datatable';
120-
import { formatBytes, RepoCols } from '~/shared/repos';
120+
import { RepoCols } from '~/shared/repos';
121+
import { formatBytes } from '~/shared/columns-select';
121122
import type { Output, Repo } from '~/shared/repos';
122123
123124
useHead({ title: 'Repositories Information' });

os-checks/shared/columns-select.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,15 @@ export class Cols {
7373
}
7474
}
7575

76+
export function formatBytes(bytes: number, decimals = 0) {
77+
if (bytes === 0) { return '0 B'; }
78+
79+
const k = 1024; // 1KB = 1024 bytes
80+
const dm = decimals < 0 ? 0 : decimals; // 小数位数
81+
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
82+
83+
const i = Math.floor(Math.log(bytes) / Math.log(k));
84+
85+
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
86+
}
87+

os-checks/shared/repos.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,6 @@ export type Output = {
7171
contributors: Contributor[],
7272
}
7373

74-
export function formatBytes(bytes: number, decimals = 0) {
75-
if (bytes === 0) { return '0 B'; }
76-
77-
const k = 1024; // 1KB = 1024 bytes
78-
const dm = decimals < 0 ? 0 : decimals; // 小数位数
79-
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
80-
81-
const i = Math.floor(Math.log(bytes) / Math.log(k));
82-
83-
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
84-
}
85-
8674
export type Repo = {
8775
idx: number,
8876
user: string,

0 commit comments

Comments
 (0)