chore: replace new Date().getTime() with Date.now()

959cc8ff37

Co-authored-by: zyoshoka <107108195+zyoshoka@users.noreply.github.com>
This commit is contained in:
naskya 2024-04-08 16:58:43 +09:00
parent fce0e5a218
commit 30619301d3
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
10 changed files with 14 additions and 18 deletions

View file

@ -10,7 +10,7 @@ import { LessThan } from "typeorm";
export default function () { export default function () {
async function tick() { async function tick() {
await AttestationChallenges.delete({ await AttestationChallenges.delete({
createdAt: LessThan(new Date(new Date().getTime() - 5 * 60 * 1000)), createdAt: LessThan(new Date(Date.now() - 5 * 60 * 1000)),
}); });
} }

View file

@ -18,7 +18,7 @@ nativeInitIdGenerator(length, fingerprint);
* Ref: https://github.com/paralleldrive/cuid2#parameterized-length * Ref: https://github.com/paralleldrive/cuid2#parameterized-length
*/ */
export function genId(date?: Date): string { export function genId(date?: Date): string {
return nativeCreateId((date ?? new Date()).getTime()); return nativeCreateId(date?.getTime() ?? Date.now());
} }
export function getTimestamp(id: string): number { export function getTimestamp(id: string): number {

View file

@ -3,7 +3,7 @@ import type { User } from "@/models/entities/user.js";
export default (object: any, user: { id: User["id"] }) => { export default (object: any, user: { id: User["id"] }) => {
const activity = { const activity = {
id: `${config.url}/users/${user.id}#updates/${new Date().getTime()}`, id: `${config.url}/users/${user.id}#updates/${Date.now()}`,
actor: `${config.url}/users/${user.id}`, actor: `${config.url}/users/${user.id}`,
type: "Update", type: "Update",
to: ["https://www.w3.org/ns/activitystreams#Public"], to: ["https://www.w3.org/ns/activitystreams#Public"],

View file

@ -117,10 +117,7 @@ export default define(meta, paramDef, async (ps, user) => {
}); });
// Expired challenge (> 5min old) // Expired challenge (> 5min old)
if ( if (Date.now() - attestationChallenge.createdAt.getTime() >= 5 * 60 * 1000) {
new Date().getTime() - attestationChallenge.createdAt.getTime() >=
5 * 60 * 1000
) {
throw new Error("expired challenge"); throw new Error("expired challenge");
} }

View file

@ -185,7 +185,7 @@ export default async (ctx: Koa.Context) => {
id: body.challengeId, id: body.challengeId,
}); });
if (new Date().getTime() - challenge.createdAt.getTime() >= 5 * 60 * 1000) { if (Date.now() - challenge.createdAt.getTime() >= 5 * 60 * 1000) {
await fail(403, { await fail(403, {
id: "2715a88a-2125-4013-932f-aa6fe72792da", id: "2715a88a-2125-4013-932f-aa6fe72792da",
}); });

View file

@ -158,7 +158,7 @@ mastoRouter.post("/oauth/token", async (ctx) => {
access_token: uuid(), access_token: uuid(),
token_type: "Bearer", token_type: "Bearer",
scope: "read", scope: "read",
created_at: Math.floor(new Date().getTime() / 1000), created_at: Math.floor(Date.now() / 1000),
}; };
ctx.body = ret; ctx.body = ret;
return; return;
@ -193,7 +193,7 @@ mastoRouter.post("/oauth/token", async (ctx) => {
access_token: atData.accessToken, access_token: atData.accessToken,
token_type: "Bearer", token_type: "Bearer",
scope: body.scope || "read write follow push", scope: body.scope || "read write follow push",
created_at: Math.floor(new Date().getTime() / 1000), created_at: Math.floor(Date.now() / 1000),
}; };
serverLogger.info("token-response", ret); serverLogger.info("token-response", ret);
ctx.body = ret; ctx.body = ret;

View file

@ -92,7 +92,7 @@ export async function pushNotification<T extends keyof pushNotificationsTypes>(
? truncateNotification(body as Packed<"Notification">) ? truncateNotification(body as Packed<"Notification">)
: body, : body,
userId, userId,
dateTime: new Date().getTime(), dateTime: Date.now(),
}), }),
{ {
proxy: config.proxy, proxy: config.proxy,

View file

@ -37,7 +37,7 @@ const _time =
const invalid = Number.isNaN(_time); const invalid = Number.isNaN(_time);
const absolute = !invalid ? dateTimeFormat.format(_time) : i18n.ts._ago.invalid; const absolute = !invalid ? dateTimeFormat.format(_time) : i18n.ts._ago.invalid;
const now = ref((props.origin ?? new Date()).getTime()); const now = ref(props.origin?.getTime() ?? Date.now());
const relative = computed<string>(() => { const relative = computed<string>(() => {
if (props.mode === "absolute") return ""; // absoluterelative使 if (props.mode === "absolute") return ""; // absoluterelative使
if (invalid) return i18n.ts._ago.invalid; if (invalid) return i18n.ts._ago.invalid;
@ -77,7 +77,7 @@ const relative = computed<string>(() => {
let tickId: number; let tickId: number;
function tick() { function tick() {
const _now = new Date().getTime(); const _now = Date.now();
const agoPrev = (now.value - _time) / 1000; /* ms */ // interval const agoPrev = (now.value - _time) / 1000; /* ms */ // interval
now.value = _now; now.value = _now;

View file

@ -74,9 +74,9 @@ watch(showColon, (v) => {
}); });
const tick = () => { const tick = () => {
const now = new Date(); const now = Date.now();
ss.value = Math.floor(now.getTime() / 1000).toString(); ss.value = Math.floor(now / 1000).toString();
ms.value = Math.floor((now.getTime() % 1000) / 10) ms.value = Math.floor((now % 1000) / 10)
.toString() .toString()
.padStart(2, "0"); .padStart(2, "0");
if (ss.value !== prevSec) showColon.value = true; if (ss.value !== prevSec) showColon.value = true;

View file

@ -71,8 +71,7 @@ globalThis.addEventListener("push", (ev) => {
case "notification": case "notification":
case "unreadAntennaNote": case "unreadAntennaNote":
// 1日以上経過している場合は無視 // 1日以上経過している場合は無視
if (new Date().getTime() - data.dateTime > 1000 * 60 * 60 * 24) if (Date.now() - data.dateTime > 1000 * 60 * 60 * 24) break;
break;
return createNotification(data); return createNotification(data);
case "readAllNotifications": case "readAllNotifications":