From 0fec6e10477b1c1b95d9469fbaf4e249a3722f12 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 +++++ packages/backend/src/server/api/endpoints/ap/get.ts | 4 ++-- packages/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 | 4 ++-- .../api/endpoints/drive/files/upload-from-url.ts | 4 ++-- .../src/server/api/endpoints/export-custom-emojis.ts | 4 ++-- .../src/server/api/endpoints/following/create.ts | 4 ++-- .../src/server/api/endpoints/following/delete.ts | 4 ++-- .../src/server/api/endpoints/following/invalidate.ts | 4 ++-- .../src/server/api/endpoints/gallery/posts/create.ts | 4 ++-- .../src/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 ++-- .../src/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 ++-- .../src/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 +++--- .../backend/src/server/api/endpoints/notes/create.ts | 4 ++-- .../backend/src/server/api/endpoints/notes/delete.ts | 6 +++--- .../server/api/endpoints/notes/reactions/delete.ts | 6 +++--- .../src/server/api/endpoints/notes/unrenote.ts | 6 +++--- .../backend/src/server/api/endpoints/pages/create.ts | 4 ++-- .../backend/src/server/api/endpoints/pages/update.ts | 4 ++-- .../server/api/endpoints/request-reset-password.ts | 4 ++-- .../src/server/api/endpoints/users/recommendation.ts | 4 ++-- packages/backend/src/server/web/index.ts | 12 ++++++------ 34 files changed, 77 insertions(+), 73 deletions(-) diff --git a/packages/backend/package.json b/packages/backend/package.json index c3b838e36..6fb5479ed 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -69,7 +69,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.6", diff --git a/packages/backend/src/const.ts b/packages/backend/src/const.ts index 6d3b9559e..38bb79a2d 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 4c3dbecfa..559bc277f 100644 --- a/packages/backend/src/server/api/endpoints/ap/get.ts +++ b/packages/backend/src/server/api/endpoints/ap/get.ts @@ -1,6 +1,6 @@ import define from '../../define.js'; import Resolver from '@/remote/activitypub/resolver.js'; -import ms from 'ms'; +import { HOUR } from '@/const.js'; export const meta = { tags: ['federation'], @@ -8,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 6442a1412..7426daeec 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 0540e6ab0..4e88f32fb 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 77e17b3ba..37215bbd6 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 7397fd9ce..68ddd586e 100644 --- a/packages/backend/src/server/api/endpoints/drive/files/create.ts +++ b/packages/backend/src/server/api/endpoints/drive/files/create.ts @@ -1,10 +1,10 @@ -import ms from 'ms'; import { addFile } from '@/services/drive/add-file.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'], @@ -12,7 +12,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 2a12f12a8..88a448f21 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,14 +1,14 @@ -import ms from 'ms'; import { uploadFromUrl } from '@/services/drive/upload-from-url.js'; import define from '../../../define.js'; import { DriveFiles } from '@/models/index.js'; import { publishMainStream } from '@/services/stream.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 5fe622932..3dc9d4e9f 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 02a030cd5..3a12a55b8 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 2f41b16e9..a454f2d72 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 18ec5affe..cf3a21406 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 c2f96560c..61bf99411 100644 --- a/packages/backend/src/server/api/endpoints/gallery/posts/create.ts +++ b/packages/backend/src/server/api/endpoints/gallery/posts/create.ts @@ -1,9 +1,9 @@ -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 { 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/gallery/posts/update.ts b/packages/backend/src/server/api/endpoints/gallery/posts/update.ts index 96ce5c72f..7e49d4e28 100644 --- a/packages/backend/src/server/api/endpoints/gallery/posts/update.ts +++ b/packages/backend/src/server/api/endpoints/gallery/posts/update.ts @@ -1,7 +1,7 @@ -import ms from 'ms'; import define from '../../../define.js'; import { DriveFiles, GalleryPosts } from '@/models/index.js'; import { DriveFile } from '@/models/entities/drive-file.js'; +import { HOUR } from '@/const.js'; export const meta = { tags: ['gallery'], @@ -11,7 +11,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 aed4c2e0a..682d39552 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 058d77b3c..3d56ab7ee 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 c0216fac0..b6cc1eea4 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 4b85a4555..4856b84ab 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 fa5c1f5e5..1aa02707d 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 0bcbf37dd..5e5bcba7a 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 ee2abbea1..28d9d38fa 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 b3b3b3923..4165da020 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 64f5ec05f..6b3949c99 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 331807852..7cfb88978 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 f66d75873..17d295700 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 0baeb0230..aeac02d39 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'; @@ -10,6 +9,7 @@ import { MAX_NOTE_TEXT_LENGTH } from '@/const.js'; import { noteVisibilities } from '../../../../types.js'; import { ApiError } from '../../error.js'; import define from '../../define.js'; +import { HOUR } from '@/const.js'; export const meta = { tags: ['notes'], @@ -17,7 +17,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 c23ceeb5b..9c3ca136c 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 c13cafa21..83fdf6959 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 3fba0efe0..1c7fa6812 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 b008cde84..e7b78fb38 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 d241f585a..8230ea09b 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 9c2462312..d76f3254a 100644 --- a/packages/backend/src/server/api/endpoints/request-reset-password.ts +++ b/packages/backend/src/server/api/endpoints/request-reset-password.ts @@ -1,11 +1,11 @@ import rndstr from 'rndstr'; -import ms from 'ms'; import { IsNull } from 'typeorm'; import config from '@/config/index.js'; import { Users, UserProfiles, PasswordResetRequests } from '@/models/index.js'; import { sendEmail } from '@/services/send-email.js'; import { genId } from '@/misc/gen-id.js'; import define from '../define.js'; +import { HOUR } from '@/const.js'; export const meta = { tags: ['reset password'], @@ -15,7 +15,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 e7654e171..d4dc524d9 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 682497e28..3e2011587 100644 --- a/packages/backend/src/server/web/index.ts +++ b/packages/backend/src/server/web/index.ts @@ -5,7 +5,6 @@ import { dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; import { readFileSync } from 'node:fs'; -import ms from 'ms'; 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, }); });