From f1a64d5294fea8fab2f5054df09f18be8ce4ebbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=A0=E4=B8=8B=20=E5=85=8B=E5=BD=A6?= Date: Sun, 10 Aug 2025 21:39:12 +0900 Subject: [PATCH] simplify new Date().getTime() --- src/mixins/_request.ts | 2 +- src/mixins/browsing.ts | 2 +- src/mixins/utils.ts | 3 +-- tests/browsing/utils.test.ts | 5 +---- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/mixins/_request.ts b/src/mixins/_request.ts index c0786c0..766e225 100644 --- a/src/mixins/_request.ts +++ b/src/mixins/_request.ts @@ -51,7 +51,7 @@ export async function request(endpoint: string, options: FetchData) { ...CONSTANTS2.HEADERS, ...auth_headers, "Content-Type": "application/json", - "X-Goog-Request-Time": (new Date()).getTime().toString(), + "X-Goog-Request-Time": Date.now().toString(), ...options.headers, }, params: { diff --git a/src/mixins/browsing.ts b/src/mixins/browsing.ts index f40362b..42dabd3 100644 --- a/src/mixins/browsing.ts +++ b/src/mixins/browsing.ts @@ -388,7 +388,7 @@ export async function get_song( parse_format, ), expires: new Date( - new Date().getTime() + + Date.now() + (Number(response.streamingData.expiresInSeconds) * 1000), ), videoDetails: { diff --git a/src/mixins/utils.ts b/src/mixins/utils.ts index 7976608..1e62cc0 100644 --- a/src/mixins/utils.ts +++ b/src/mixins/utils.ts @@ -27,8 +27,7 @@ export function prepare_like_endpoint(status: LikeStatus) { export function get_timestamp() { const one_day = 24 * 60 * 60 * 1000; - return Math.round((new Date().getTime() - new Date(0).getTime()) / one_day) - - 7; + return Math.round(Date.now() / one_day) - 7; } export async function check_auth() { diff --git a/tests/browsing/utils.test.ts b/tests/browsing/utils.test.ts index 16af264..55da4d0 100644 --- a/tests/browsing/utils.test.ts +++ b/tests/browsing/utils.test.ts @@ -11,10 +11,7 @@ import * as muse from "../../src/mod.ts" it("get_timestamp", () => { const one_day = 24 * 60 * 60 * 1000; - const timestamp = Math.round( - (new Date().getTime() - new Date(0).getTime()) / - one_day, - ) - 7; + const timestamp = Math.round(Date.now() / one_day) - 7; assertEquals(muse.get_timestamp(), timestamp); });