feat(web): separate build sources and localize time
This commit is contained in:
1 parent
89cd92f7ee
commit
10aa0304e4
9 files changed
+60
-17
No files matched your search
@@ -1 +1,37 @@
|
||||
export const buildInfo = __WEBDROP_BUILD_INFO__;
|
||||
const shanghaiTime = new Intl.DateTimeFormat('en-CA', {
|
||||
timeZone: 'Asia/Shanghai',
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hourCycle: 'h23',
|
||||
});
|
||||
|
||||
function shortCommit(commit: string): string {
|
||||
return commit === 'unknown' ? commit : commit.slice(0, 7);
|
||||
}
|
||||
|
||||
function knownTag(tag: string): string {
|
||||
return tag === 'unknown' ? '' : tag;
|
||||
}
|
||||
|
||||
function formatShanghai(iso: string): string {
|
||||
const date = new Date(iso);
|
||||
if (Number.isNaN(date.getTime())) return '未知';
|
||||
|
||||
const parts = Object.fromEntries(shanghaiTime.formatToParts(date).map(({ type, value }) => [type, value]));
|
||||
return `${parts.year}-${parts.month}-${parts.day} ${parts.hour}:${parts.minute}`;
|
||||
}
|
||||
|
||||
const source = __WEBDROP_BUILD_INFO__;
|
||||
|
||||
export const buildInfo = {
|
||||
frontendVersion: source.frontendVersion,
|
||||
frontendCommit: shortCommit(source.frontendCommit),
|
||||
frontendTag: knownTag(source.frontendTag),
|
||||
backendCommit: shortCommit(source.backendCommit),
|
||||
backendTag: knownTag(source.backendTag),
|
||||
builtAt: source.builtAt,
|
||||
builtAtShanghai: formatShanghai(source.builtAt),
|
||||
};
|
||||
Reference in new issue
Block a user