From d6a95797d884ef9aad6dd3bcb2fb05e930d8ec50 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Thu, 14 Jul 2022 00:01:23 +0200 Subject: [PATCH] remove ms dependency --- packages/backend/package.json | 1 - packages/backend/src/const.ts | 5 +++++ .../backend/src/server/api/endpoints/ap/get.ts | 5 ++--- .../backend/src/server/api/endpoints/ap/show.ts | 4 ++-- .../src/server/api/endpoints/blocking/create.ts | 4 ++-- .../src/server/api/endpoints/blocking/delete.ts | 4 ++-- .../src/server/api/endpoints/drive/files/create.ts | 6 ++++-- .../api/endpoints/drive/files/upload-from-url.ts | 6 ++---- .../server/api/endpoints/export-custom-emojis.ts | 4 ++-- .../src/server/api/endpoints/following/create.ts | 4 ++-- .../src/server/api/endpoints/following/delete.ts | 4 ++-- .../server/api/endpoints/following/invalidate.ts | 4 ++-- .../server/api/endpoints/gallery/posts/create.ts | 4 ++-- .../server/api/endpoints/gallery/posts/update.ts | 4 ++-- .../src/server/api/endpoints/i/export-blocking.ts | 4 ++-- .../src/server/api/endpoints/i/export-following.ts | 4 ++-- .../src/server/api/endpoints/i/export-mute.ts | 4 ++-- .../src/server/api/endpoints/i/export-notes.ts | 4 ++-- .../server/api/endpoints/i/export-user-lists.ts | 4 ++-- .../src/server/api/endpoints/i/import-blocking.ts | 4 ++-- .../src/server/api/endpoints/i/import-following.ts | 4 ++-- .../src/server/api/endpoints/i/import-muting.ts | 4 ++-- .../server/api/endpoints/i/import-user-lists.ts | 4 ++-- .../src/server/api/endpoints/i/update-email.ts | 4 ++-- .../api/endpoints/messaging/messages/delete.ts | 6 +++--- .../src/server/api/endpoints/notes/create.ts | 5 ++--- .../src/server/api/endpoints/notes/delete.ts | 6 +++--- .../server/api/endpoints/notes/reactions/delete.ts | 6 +++--- .../src/server/api/endpoints/notes/unrenote.ts | 6 +++--- .../src/server/api/endpoints/pages/create.ts | 4 ++-- .../src/server/api/endpoints/pages/update.ts | 4 ++-- .../server/api/endpoints/request-reset-password.ts | 4 ++-- .../server/api/endpoints/users/recommendation.ts | 4 ++-- packages/backend/src/server/web/index.ts | 14 +++++++------- 34 files changed, 80 insertions(+), 78 deletions(-) diff --git a/packages/backend/package.json b/packages/backend/package.json index 45fe74dbc9..72e5af7074 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -74,7 +74,6 @@ "mime-types": "2.1.35", "misskey-js": "0.0.14", "mocha": "10.0.0", - "ms": "3.0.0-canary.1", "multer": "1.4.4", "nested-property": "4.0.0", "node-fetch": "3.2.9", diff --git a/packages/backend/src/const.ts b/packages/backend/src/const.ts index 6d3b9559e8..38bb79a2da 100644 --- a/packages/backend/src/const.ts +++ b/packages/backend/src/const.ts @@ -1,5 +1,10 @@ export const MAX_NOTE_TEXT_LENGTH = 3000; +export const SECOND = 1000; +export const MINUTE = 60 * SEC; +export const HOUR = 60 * MIN; +export const DAY = 24 * HOUR; + export const USER_ONLINE_THRESHOLD = 1000 * 60 * 10; // 10min export const USER_ACTIVE_THRESHOLD = 1000 * 60 * 60 * 24 * 3; // 3days diff --git a/packages/backend/src/server/api/endpoints/ap/get.ts b/packages/backend/src/server/api/endpoints/ap/get.ts index 0cbe7ebc67..559bc277f3 100644 --- a/packages/backend/src/server/api/endpoints/ap/get.ts +++ b/packages/backend/src/server/api/endpoints/ap/get.ts @@ -1,7 +1,6 @@ import define from '../../define.js'; import Resolver from '@/remote/activitypub/resolver.js'; -import { ApiError } from '../../error.js'; -import ms from 'ms'; +import { HOUR } from '@/const.js'; export const meta = { tags: ['federation'], @@ -9,7 +8,7 @@ export const meta = { requireCredential: true, limit: { - duration: ms('1hour'), + duration: HOUR, max: 30, }, diff --git a/packages/backend/src/server/api/endpoints/ap/show.ts b/packages/backend/src/server/api/endpoints/ap/show.ts index 6442a1412c..7426daeec8 100644 --- a/packages/backend/src/server/api/endpoints/ap/show.ts +++ b/packages/backend/src/server/api/endpoints/ap/show.ts @@ -11,8 +11,8 @@ import { Note } from '@/models/entities/note.js'; import { CacheableLocalUser, User } from '@/models/entities/user.js'; import { fetchMeta } from '@/misc/fetch-meta.js'; import { isActor, isPost, getApId } from '@/remote/activitypub/type.js'; -import ms from 'ms'; import { SchemaType } from '@/misc/schema.js'; +import { HOUR } from '@/const.js'; export const meta = { tags: ['federation'], @@ -20,7 +20,7 @@ export const meta = { requireCredential: true, limit: { - duration: ms('1hour'), + duration: HOUR, max: 30, }, diff --git a/packages/backend/src/server/api/endpoints/blocking/create.ts b/packages/backend/src/server/api/endpoints/blocking/create.ts index 0540e6ab0f..4e88f32fb7 100644 --- a/packages/backend/src/server/api/endpoints/blocking/create.ts +++ b/packages/backend/src/server/api/endpoints/blocking/create.ts @@ -1,15 +1,15 @@ -import ms from 'ms'; import create from '@/services/blocking/create.js'; import define from '../../define.js'; import { ApiError } from '../../error.js'; import { getUser } from '../../common/getters.js'; import { Blockings, NoteWatchings, Users } from '@/models/index.js'; +import { HOUR } from '@/const.js'; export const meta = { tags: ['account'], limit: { - duration: ms('1hour'), + duration: HOUR, max: 100, }, diff --git a/packages/backend/src/server/api/endpoints/blocking/delete.ts b/packages/backend/src/server/api/endpoints/blocking/delete.ts index 77e17b3ba9..37215bbd66 100644 --- a/packages/backend/src/server/api/endpoints/blocking/delete.ts +++ b/packages/backend/src/server/api/endpoints/blocking/delete.ts @@ -1,15 +1,15 @@ -import ms from 'ms'; import deleteBlocking from '@/services/blocking/delete.js'; import define from '../../define.js'; import { ApiError } from '../../error.js'; import { getUser } from '../../common/getters.js'; import { Blockings, Users } from '@/models/index.js'; +import { HOUR } from '@/const.js'; export const meta = { tags: ['account'], limit: { - duration: ms('1hour'), + duration: HOUR, max: 100, }, diff --git a/packages/backend/src/server/api/endpoints/drive/files/create.ts b/packages/backend/src/server/api/endpoints/drive/files/create.ts index ddcbd62889..a37e6cf0c0 100644 --- a/packages/backend/src/server/api/endpoints/drive/files/create.ts +++ b/packages/backend/src/server/api/endpoints/drive/files/create.ts @@ -1,4 +1,3 @@ -import ms from 'ms'; import { addFile } from '@/services/drive/add-file.js'; import { DriveFiles } from '@/models/index.js'; import { DB_MAX_IMAGE_COMMENT_LENGTH } from '@/misc/hard-limits.js'; @@ -7,6 +6,9 @@ import { fetchMeta } from '@/misc/fetch-meta.js'; import define from '../../../define.js'; import { apiLogger } from '../../../logger.js'; import { ApiError } from '../../../error.js'; +import { DriveFiles } from '@/models/index.js'; +import { DB_MAX_IMAGE_COMMENT_LENGTH } from '@/misc/hard-limits.js'; +import { HOUR } from '@/const.js'; export const meta = { tags: ['drive'], @@ -14,7 +16,7 @@ export const meta = { requireCredential: true, limit: { - duration: ms('1hour'), + duration: HOUR, max: 120, }, diff --git a/packages/backend/src/server/api/endpoints/drive/files/upload-from-url.ts b/packages/backend/src/server/api/endpoints/drive/files/upload-from-url.ts index eb8071c3c9..610a35e929 100644 --- a/packages/backend/src/server/api/endpoints/drive/files/upload-from-url.ts +++ b/packages/backend/src/server/api/endpoints/drive/files/upload-from-url.ts @@ -1,15 +1,13 @@ -import ms from 'ms'; import { uploadFromUrl } from '@/services/drive/upload-from-url.js'; import { DriveFiles } from '@/models/index.js'; import { publishMainStream } from '@/services/stream.js'; -import { DB_MAX_IMAGE_COMMENT_LENGTH } from '@/misc/hard-limits.js'; -import define from '../../../define.js'; +import { HOUR } from '@/const.js'; export const meta = { tags: ['drive'], limit: { - duration: ms('1hour'), + duration: HOUR, max: 60, }, diff --git a/packages/backend/src/server/api/endpoints/export-custom-emojis.ts b/packages/backend/src/server/api/endpoints/export-custom-emojis.ts index 5fe622932d..3dc9d4e9fa 100644 --- a/packages/backend/src/server/api/endpoints/export-custom-emojis.ts +++ b/packages/backend/src/server/api/endpoints/export-custom-emojis.ts @@ -1,12 +1,12 @@ -import ms from 'ms'; import { createExportCustomEmojisJob } from '@/queue/index.js'; import define from '../define.js'; +import { HOUR } from '@/const.js'; export const meta = { secure: true, requireCredential: true, limit: { - duration: ms('1hour'), + duration: HOUR, max: 1, }, } as const; diff --git a/packages/backend/src/server/api/endpoints/following/create.ts b/packages/backend/src/server/api/endpoints/following/create.ts index 02a030cd5e..3a12a55b8e 100644 --- a/packages/backend/src/server/api/endpoints/following/create.ts +++ b/packages/backend/src/server/api/endpoints/following/create.ts @@ -1,16 +1,16 @@ -import ms from 'ms'; import create from '@/services/following/create.js'; import define from '../../define.js'; import { ApiError } from '../../error.js'; import { getUser } from '../../common/getters.js'; import { Followings, Users } from '@/models/index.js'; import { IdentifiableError } from '@/misc/identifiable-error.js'; +import { HOUR } from '@/const.js'; export const meta = { tags: ['following', 'users'], limit: { - duration: ms('1hour'), + duration: HOUR, max: 100, }, diff --git a/packages/backend/src/server/api/endpoints/following/delete.ts b/packages/backend/src/server/api/endpoints/following/delete.ts index 2f41b16e9a..a454f2d723 100644 --- a/packages/backend/src/server/api/endpoints/following/delete.ts +++ b/packages/backend/src/server/api/endpoints/following/delete.ts @@ -1,15 +1,15 @@ -import ms from 'ms'; import deleteFollowing from '@/services/following/delete.js'; import define from '../../define.js'; import { ApiError } from '../../error.js'; import { getUser } from '../../common/getters.js'; import { Followings, Users } from '@/models/index.js'; +import { HOUR } from '@/const.js'; export const meta = { tags: ['following', 'users'], limit: { - duration: ms('1hour'), + duration: HOUR, max: 100, }, diff --git a/packages/backend/src/server/api/endpoints/following/invalidate.ts b/packages/backend/src/server/api/endpoints/following/invalidate.ts index 18ec5affe8..cf3a21406f 100644 --- a/packages/backend/src/server/api/endpoints/following/invalidate.ts +++ b/packages/backend/src/server/api/endpoints/following/invalidate.ts @@ -1,15 +1,15 @@ -import ms from 'ms'; import deleteFollowing from '@/services/following/delete.js'; import define from '../../define.js'; import { ApiError } from '../../error.js'; import { getUser } from '../../common/getters.js'; import { Followings, Users } from '@/models/index.js'; +import { HOUR } from '@/const.js'; export const meta = { tags: ['following', 'users'], limit: { - duration: ms('1hour'), + duration: HOUR, max: 100, }, diff --git a/packages/backend/src/server/api/endpoints/gallery/posts/create.ts b/packages/backend/src/server/api/endpoints/gallery/posts/create.ts index 8074a3b34f..eec4d2ba13 100644 --- a/packages/backend/src/server/api/endpoints/gallery/posts/create.ts +++ b/packages/backend/src/server/api/endpoints/gallery/posts/create.ts @@ -1,10 +1,10 @@ -import ms from 'ms'; import define from '../../../define.js'; import { DriveFiles, GalleryPosts } from '@/models/index.js'; import { genId } from '../../../../../misc/gen-id.js'; import { GalleryPost } from '@/models/entities/gallery-post.js'; import { ApiError } from '../../../error.js'; import { DriveFile } from '@/models/entities/drive-file.js'; +import { HOUR } from '@/const.js'; export const meta = { tags: ['gallery'], @@ -14,7 +14,7 @@ export const meta = { kind: 'write:gallery', limit: { - duration: ms('1hour'), + duration: HOUR, max: 300, }, diff --git a/packages/backend/src/server/api/endpoints/gallery/posts/update.ts b/packages/backend/src/server/api/endpoints/gallery/posts/update.ts index 82fe38078e..b333d947dd 100644 --- a/packages/backend/src/server/api/endpoints/gallery/posts/update.ts +++ b/packages/backend/src/server/api/endpoints/gallery/posts/update.ts @@ -1,9 +1,9 @@ -import ms from 'ms'; import define from '../../../define.js'; import { DriveFiles, GalleryPosts } from '@/models/index.js'; import { GalleryPost } from '@/models/entities/gallery-post.js'; import { ApiError } from '../../../error.js'; import { DriveFile } from '@/models/entities/drive-file.js'; +import { HOUR } from '@/const.js'; export const meta = { tags: ['gallery'], @@ -13,7 +13,7 @@ export const meta = { kind: 'write:gallery', limit: { - duration: ms('1hour'), + duration: HOUR, max: 300, }, diff --git a/packages/backend/src/server/api/endpoints/i/export-blocking.ts b/packages/backend/src/server/api/endpoints/i/export-blocking.ts index aed4c2e0a3..682d395523 100644 --- a/packages/backend/src/server/api/endpoints/i/export-blocking.ts +++ b/packages/backend/src/server/api/endpoints/i/export-blocking.ts @@ -1,12 +1,12 @@ import define from '../../define.js'; import { createExportBlockingJob } from '@/queue/index.js'; -import ms from 'ms'; +import { HOUR } from '@/const.js'; export const meta = { secure: true, requireCredential: true, limit: { - duration: ms('1hour'), + duration: HOUR, max: 1, }, } as const; diff --git a/packages/backend/src/server/api/endpoints/i/export-following.ts b/packages/backend/src/server/api/endpoints/i/export-following.ts index 058d77b3c2..3d56ab7eef 100644 --- a/packages/backend/src/server/api/endpoints/i/export-following.ts +++ b/packages/backend/src/server/api/endpoints/i/export-following.ts @@ -1,12 +1,12 @@ import define from '../../define.js'; import { createExportFollowingJob } from '@/queue/index.js'; -import ms from 'ms'; +import { HOUR } from '@/const.js'; export const meta = { secure: true, requireCredential: true, limit: { - duration: ms('1hour'), + duration: HOUR, max: 1, }, } as const; diff --git a/packages/backend/src/server/api/endpoints/i/export-mute.ts b/packages/backend/src/server/api/endpoints/i/export-mute.ts index c0216fac0c..b6cc1eea45 100644 --- a/packages/backend/src/server/api/endpoints/i/export-mute.ts +++ b/packages/backend/src/server/api/endpoints/i/export-mute.ts @@ -1,12 +1,12 @@ import define from '../../define.js'; import { createExportMuteJob } from '@/queue/index.js'; -import ms from 'ms'; +import { HOUR } from '@/const.js'; export const meta = { secure: true, requireCredential: true, limit: { - duration: ms('1hour'), + duration: HOUR, max: 1, }, } as const; diff --git a/packages/backend/src/server/api/endpoints/i/export-notes.ts b/packages/backend/src/server/api/endpoints/i/export-notes.ts index 4b85a45554..4856b84ab2 100644 --- a/packages/backend/src/server/api/endpoints/i/export-notes.ts +++ b/packages/backend/src/server/api/endpoints/i/export-notes.ts @@ -1,12 +1,12 @@ import define from '../../define.js'; import { createExportNotesJob } from '@/queue/index.js'; -import ms from 'ms'; +import { DAY } from '@/const.js'; export const meta = { secure: true, requireCredential: true, limit: { - duration: ms('1day'), + duration: DAY, max: 1, }, } as const; diff --git a/packages/backend/src/server/api/endpoints/i/export-user-lists.ts b/packages/backend/src/server/api/endpoints/i/export-user-lists.ts index fa5c1f5e5a..1aa02707df 100644 --- a/packages/backend/src/server/api/endpoints/i/export-user-lists.ts +++ b/packages/backend/src/server/api/endpoints/i/export-user-lists.ts @@ -1,12 +1,12 @@ import define from '../../define.js'; import { createExportUserListsJob } from '@/queue/index.js'; -import ms from 'ms'; +import { MINUTE } from '@/const.js'; export const meta = { secure: true, requireCredential: true, limit: { - duration: ms('1min'), + duration: MINUTE, max: 1, }, } as const; diff --git a/packages/backend/src/server/api/endpoints/i/import-blocking.ts b/packages/backend/src/server/api/endpoints/i/import-blocking.ts index 0bcbf37ddd..5e5bcba7ac 100644 --- a/packages/backend/src/server/api/endpoints/i/import-blocking.ts +++ b/packages/backend/src/server/api/endpoints/i/import-blocking.ts @@ -1,15 +1,15 @@ import define from '../../define.js'; import { createImportBlockingJob } from '@/queue/index.js'; -import ms from 'ms'; import { ApiError } from '../../error.js'; import { DriveFiles } from '@/models/index.js'; +import { HOUR } from '@/const.js'; export const meta = { secure: true, requireCredential: true, limit: { - duration: ms('1hour'), + duration: HOUR, max: 1, }, diff --git a/packages/backend/src/server/api/endpoints/i/import-following.ts b/packages/backend/src/server/api/endpoints/i/import-following.ts index ee2abbea19..28d9d38fa4 100644 --- a/packages/backend/src/server/api/endpoints/i/import-following.ts +++ b/packages/backend/src/server/api/endpoints/i/import-following.ts @@ -1,14 +1,14 @@ import define from '../../define.js'; import { createImportFollowingJob } from '@/queue/index.js'; -import ms from 'ms'; import { ApiError } from '../../error.js'; import { DriveFiles } from '@/models/index.js'; +import { HOUR } from '@/const.js'; export const meta = { secure: true, requireCredential: true, limit: { - duration: ms('1hour'), + duratition: HOUR, max: 1, }, diff --git a/packages/backend/src/server/api/endpoints/i/import-muting.ts b/packages/backend/src/server/api/endpoints/i/import-muting.ts index b3b3b39238..4165da020a 100644 --- a/packages/backend/src/server/api/endpoints/i/import-muting.ts +++ b/packages/backend/src/server/api/endpoints/i/import-muting.ts @@ -1,15 +1,15 @@ import define from '../../define.js'; import { createImportMutingJob } from '@/queue/index.js'; -import ms from 'ms'; import { ApiError } from '../../error.js'; import { DriveFiles } from '@/models/index.js'; +import { HOUR } from '@/const.js'; export const meta = { secure: true, requireCredential: true, limit: { - duration: ms('1hour'), + duration: HOUR, max: 1, }, diff --git a/packages/backend/src/server/api/endpoints/i/import-user-lists.ts b/packages/backend/src/server/api/endpoints/i/import-user-lists.ts index 64f5ec05fd..6b3949c993 100644 --- a/packages/backend/src/server/api/endpoints/i/import-user-lists.ts +++ b/packages/backend/src/server/api/endpoints/i/import-user-lists.ts @@ -1,14 +1,14 @@ import define from '../../define.js'; import { createImportUserListsJob } from '@/queue/index.js'; -import ms from 'ms'; import { ApiError } from '../../error.js'; import { DriveFiles } from '@/models/index.js'; +import { HOUR } from '@/const.js'; export const meta = { secure: true, requireCredential: true, limit: { - duration: ms('1hour'), + duration: HOUR, max: 1, }, diff --git a/packages/backend/src/server/api/endpoints/i/update-email.ts b/packages/backend/src/server/api/endpoints/i/update-email.ts index 3318078523..7cfb88978c 100644 --- a/packages/backend/src/server/api/endpoints/i/update-email.ts +++ b/packages/backend/src/server/api/endpoints/i/update-email.ts @@ -2,12 +2,12 @@ import { publishMainStream } from '@/services/stream.js'; import define from '../../define.js'; import rndstr from 'rndstr'; import config from '@/config/index.js'; -import ms from 'ms'; import bcrypt from 'bcryptjs'; import { Users, UserProfiles } from '@/models/index.js'; import { sendEmail } from '@/services/send-email.js'; import { ApiError } from '../../error.js'; import { validateEmailForAccount } from '@/services/validate-email-for-account.js'; +import { HOUR } from '@/const.js'; export const meta = { requireCredential: true, @@ -15,7 +15,7 @@ export const meta = { secure: true, limit: { - duration: ms('1hour'), + duration: HOUR, max: 3, }, diff --git a/packages/backend/src/server/api/endpoints/messaging/messages/delete.ts b/packages/backend/src/server/api/endpoints/messaging/messages/delete.ts index f66d75873c..17d2957006 100644 --- a/packages/backend/src/server/api/endpoints/messaging/messages/delete.ts +++ b/packages/backend/src/server/api/endpoints/messaging/messages/delete.ts @@ -1,8 +1,8 @@ import define from '../../../define.js'; -import ms from 'ms'; import { ApiError } from '../../../error.js'; import { MessagingMessages } from '@/models/index.js'; import { deleteMessage } from '@/services/messages/delete.js'; +import { SECOND, HOUR } from '@/const.js'; export const meta = { tags: ['messaging'], @@ -12,9 +12,9 @@ export const meta = { kind: 'write:messaging', limit: { - duration: ms('1hour'), + duration: HOUR, max: 300, - minInterval: ms('1sec'), + minInterval: SECOND, }, errors: { diff --git a/packages/backend/src/server/api/endpoints/notes/create.ts b/packages/backend/src/server/api/endpoints/notes/create.ts index d8954ec737..5144fcf0cd 100644 --- a/packages/backend/src/server/api/endpoints/notes/create.ts +++ b/packages/backend/src/server/api/endpoints/notes/create.ts @@ -1,4 +1,3 @@ -import ms from 'ms'; import { In } from 'typeorm'; import create from '@/services/note/create.js'; import { User } from '@/models/entities/user.js'; @@ -11,7 +10,7 @@ import { HOUR } from '@/const.js'; import { noteVisibilities } from '../../../../types.js'; import { ApiError } from '../../error.js'; import define from '../../define.js'; -import { getNote } from '../../common/getters.js'; +import { HOUR } from '@/const.js'; export const meta = { tags: ['notes'], @@ -19,7 +18,7 @@ export const meta = { requireCredential: true, limit: { - duration: ms('1hour'), + duration: HOUR, max: 300, }, diff --git a/packages/backend/src/server/api/endpoints/notes/delete.ts b/packages/backend/src/server/api/endpoints/notes/delete.ts index 3169db43ca..34d23448ea 100644 --- a/packages/backend/src/server/api/endpoints/notes/delete.ts +++ b/packages/backend/src/server/api/endpoints/notes/delete.ts @@ -1,9 +1,9 @@ -import ms from 'ms'; import deleteNote from '@/services/note/delete.js'; import { Users } from '@/models/index.js'; import define from '../../define.js'; import { getNote } from '../../common/getters.js'; import { ApiError } from '../../error.js'; +import { SECOND, HOUR } from '@/const.js'; export const meta = { tags: ['notes'], @@ -13,9 +13,9 @@ export const meta = { kind: 'write:notes', limit: { - duration: ms('1hour'), + duration: HOUR, max: 300, - minInterval: ms('1sec'), + minInterval: SECOND, }, errors: { diff --git a/packages/backend/src/server/api/endpoints/notes/reactions/delete.ts b/packages/backend/src/server/api/endpoints/notes/reactions/delete.ts index b8e234bb41..c25d88d1b5 100644 --- a/packages/backend/src/server/api/endpoints/notes/reactions/delete.ts +++ b/packages/backend/src/server/api/endpoints/notes/reactions/delete.ts @@ -1,8 +1,8 @@ -import ms from 'ms'; import deleteReaction from '@/services/note/reaction/delete.js'; import define from '../../../define.js'; import { getNote } from '../../../common/getters.js'; import { ApiError } from '../../../error.js'; +import { SECOND, HOUR } from '@/const.js'; export const meta = { tags: ['reactions', 'notes'], @@ -12,9 +12,9 @@ export const meta = { kind: 'write:reactions', limit: { - duration: ms('1hour'), + duration: HOUR, max: 60, - minInterval: ms('3sec'), + minInterval: 3 * SECOND, }, errors: { diff --git a/packages/backend/src/server/api/endpoints/notes/unrenote.ts b/packages/backend/src/server/api/endpoints/notes/unrenote.ts index 400eefb707..1089a9e375 100644 --- a/packages/backend/src/server/api/endpoints/notes/unrenote.ts +++ b/packages/backend/src/server/api/endpoints/notes/unrenote.ts @@ -1,9 +1,9 @@ -import ms from 'ms'; import deleteNote from '@/services/note/delete.js'; import { Notes, Users } from '@/models/index.js'; import define from '../../define.js'; import { getNote } from '../../common/getters.js'; import { ApiError } from '../../error.js'; +import { SECOND, HOUR } from '@/const.js'; export const meta = { tags: ['notes'], @@ -13,9 +13,9 @@ export const meta = { kind: 'write:notes', limit: { - duration: ms('1hour'), + duration: HOUR, max: 300, - minInterval: ms('1sec'), + minInterval: SECOND, }, errors: { diff --git a/packages/backend/src/server/api/endpoints/pages/create.ts b/packages/backend/src/server/api/endpoints/pages/create.ts index b008cde84e..e7b78fb385 100644 --- a/packages/backend/src/server/api/endpoints/pages/create.ts +++ b/packages/backend/src/server/api/endpoints/pages/create.ts @@ -1,9 +1,9 @@ -import ms from 'ms'; import { Pages, DriveFiles } from '@/models/index.js'; import { genId } from '@/misc/gen-id.js'; import { Page } from '@/models/entities/page.js'; import define from '../../define.js'; import { ApiError } from '../../error.js'; +import { HOUR } from '@/const.js'; export const meta = { tags: ['pages'], @@ -13,7 +13,7 @@ export const meta = { kind: 'write:pages', limit: { - duration: ms('1hour'), + duration: HOUR, max: 300, }, diff --git a/packages/backend/src/server/api/endpoints/pages/update.ts b/packages/backend/src/server/api/endpoints/pages/update.ts index d241f585aa..8230ea09bd 100644 --- a/packages/backend/src/server/api/endpoints/pages/update.ts +++ b/packages/backend/src/server/api/endpoints/pages/update.ts @@ -1,8 +1,8 @@ -import ms from 'ms'; import { Not } from 'typeorm'; import { Pages, DriveFiles } from '@/models/index.js'; import define from '../../define.js'; import { ApiError } from '../../error.js'; +import { HOUR } from '@/const.js'; export const meta = { tags: ['pages'], @@ -12,7 +12,7 @@ export const meta = { kind: 'write:pages', limit: { - duration: ms('1hour'), + duration: HOUR, max: 300, }, diff --git a/packages/backend/src/server/api/endpoints/request-reset-password.ts b/packages/backend/src/server/api/endpoints/request-reset-password.ts index 511a6bbb53..ddf1939039 100644 --- a/packages/backend/src/server/api/endpoints/request-reset-password.ts +++ b/packages/backend/src/server/api/endpoints/request-reset-password.ts @@ -1,5 +1,4 @@ import rndstr from 'rndstr'; -import ms from 'ms'; import { IsNull } from 'typeorm'; import { publishMainStream } from '@/services/stream.js'; import config from '@/config/index.js'; @@ -8,6 +7,7 @@ import { sendEmail } from '@/services/send-email.js'; import { genId } from '@/misc/gen-id.js'; import { ApiError } from '../error.js'; import define from '../define.js'; +import { HOUR } from '@/const.js'; export const meta = { tags: ['reset password'], @@ -17,7 +17,7 @@ export const meta = { description: 'Request a users password to be reset.', limit: { - duration: ms('1hour'), + duration: HOUR, max: 3, }, diff --git a/packages/backend/src/server/api/endpoints/users/recommendation.ts b/packages/backend/src/server/api/endpoints/users/recommendation.ts index e7654e1714..d4dc524d9a 100644 --- a/packages/backend/src/server/api/endpoints/users/recommendation.ts +++ b/packages/backend/src/server/api/endpoints/users/recommendation.ts @@ -1,8 +1,8 @@ -import ms from 'ms'; import { Users, Followings } from '@/models/index.js'; import define from '../../define.js'; import { generateMutedUserQueryForUsers } from '../../common/generate-muted-user-query.js'; import { generateBlockedUserQuery, generateBlockQueryForUsers } from '../../common/generate-block-query.js'; +import { DAY } from '@/const.js'; export const meta = { tags: ['users'], @@ -39,7 +39,7 @@ export default define(meta, paramDef, async (ps, me) => { .where('user.isLocked = FALSE') .andWhere('user.isExplorable = TRUE') .andWhere('user.host IS NULL') - .andWhere('user.updatedAt >= :date', { date: new Date(Date.now() - ms('7days')) }) + .andWhere('user.updatedAt >= :date', { date: new Date(Date.now() - (7 * DAY)) }) .andWhere('user.id != :meId', { meId: me.id }) .orderBy('user.followersCount', 'DESC'); diff --git a/packages/backend/src/server/web/index.ts b/packages/backend/src/server/web/index.ts index dab80814fd..1d201d712a 100644 --- a/packages/backend/src/server/web/index.ts +++ b/packages/backend/src/server/web/index.ts @@ -4,8 +4,7 @@ import { dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; -import { PathOrFileDescriptor, readFileSync } from 'node:fs'; -import ms from 'ms'; +import { readFileSync } from 'node:fs'; import Koa from 'koa'; import Router from '@koa/router'; import send from 'koa-send'; @@ -27,6 +26,7 @@ import { genOpenapiSpec } from '../api/openapi/gen-spec.js'; import { urlPreviewHandler } from './url-preview.js'; import { manifestHandler } from './manifest.js'; import packFeed from './feed.js'; +import { MINUTE, DAY } from '@/const.js'; const _filename = fileURLToPath(import.meta.url); const _dirname = dirname(_filename); @@ -100,21 +100,21 @@ const router = new Router(); router.get('/static-assets/(.*)', async ctx => { await send(ctx as any, ctx.path.replace('/static-assets/', ''), { root: staticAssets, - maxage: ms('7 days'), + maxage: 7 * DAY, }); }); router.get('/client-assets/(.*)', async ctx => { await send(ctx as any, ctx.path.replace('/client-assets/', ''), { root: clientAssets, - maxage: ms('7 days'), + maxage: 7 * DAY, }); }); router.get('/assets/(.*)', async ctx => { await send(ctx as any, ctx.path.replace('/assets/', ''), { root: assets, - maxage: ms('7 days'), + maxage: 7 * DAY, }); }); @@ -137,7 +137,7 @@ router.get('/twemoji/(.*)', async ctx => { await send(ctx as any, path, { root: `${_dirname}/../../../node_modules/@discordapp/twemoji/dist/svg/`, - maxage: ms('30 days'), + maxage: 30 * DAY, }); }); @@ -188,7 +188,7 @@ router.get('/twemoji-badge/(.*)', async ctx => { router.get(`/sw.js`, async ctx => { await send(ctx as any, `/sw.js`, { root: swAssets, - maxage: ms('10 minutes'), + maxage: 10 * MINUTE, }); });