remove ms dependency

This commit is contained in:
Johann150 2022-07-14 00:01:23 +02:00 committed by ThatOneCalculator
parent 20763a84ee
commit d6a95797d8
34 changed files with 80 additions and 78 deletions

View file

@ -74,7 +74,6 @@
"mime-types": "2.1.35", "mime-types": "2.1.35",
"misskey-js": "0.0.14", "misskey-js": "0.0.14",
"mocha": "10.0.0", "mocha": "10.0.0",
"ms": "3.0.0-canary.1",
"multer": "1.4.4", "multer": "1.4.4",
"nested-property": "4.0.0", "nested-property": "4.0.0",
"node-fetch": "3.2.9", "node-fetch": "3.2.9",

View file

@ -1,5 +1,10 @@
export const MAX_NOTE_TEXT_LENGTH = 3000; 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_ONLINE_THRESHOLD = 1000 * 60 * 10; // 10min
export const USER_ACTIVE_THRESHOLD = 1000 * 60 * 60 * 24 * 3; // 3days export const USER_ACTIVE_THRESHOLD = 1000 * 60 * 60 * 24 * 3; // 3days

View file

@ -1,7 +1,6 @@
import define from '../../define.js'; import define from '../../define.js';
import Resolver from '@/remote/activitypub/resolver.js'; import Resolver from '@/remote/activitypub/resolver.js';
import { ApiError } from '../../error.js'; import { HOUR } from '@/const.js';
import ms from 'ms';
export const meta = { export const meta = {
tags: ['federation'], tags: ['federation'],
@ -9,7 +8,7 @@ export const meta = {
requireCredential: true, requireCredential: true,
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 30, max: 30,
}, },

View file

@ -11,8 +11,8 @@ import { Note } from '@/models/entities/note.js';
import { CacheableLocalUser, User } from '@/models/entities/user.js'; import { CacheableLocalUser, User } from '@/models/entities/user.js';
import { fetchMeta } from '@/misc/fetch-meta.js'; import { fetchMeta } from '@/misc/fetch-meta.js';
import { isActor, isPost, getApId } from '@/remote/activitypub/type.js'; import { isActor, isPost, getApId } from '@/remote/activitypub/type.js';
import ms from 'ms';
import { SchemaType } from '@/misc/schema.js'; import { SchemaType } from '@/misc/schema.js';
import { HOUR } from '@/const.js';
export const meta = { export const meta = {
tags: ['federation'], tags: ['federation'],
@ -20,7 +20,7 @@ export const meta = {
requireCredential: true, requireCredential: true,
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 30, max: 30,
}, },

View file

@ -1,15 +1,15 @@
import ms from 'ms';
import create from '@/services/blocking/create.js'; import create from '@/services/blocking/create.js';
import define from '../../define.js'; import define from '../../define.js';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
import { getUser } from '../../common/getters.js'; import { getUser } from '../../common/getters.js';
import { Blockings, NoteWatchings, Users } from '@/models/index.js'; import { Blockings, NoteWatchings, Users } from '@/models/index.js';
import { HOUR } from '@/const.js';
export const meta = { export const meta = {
tags: ['account'], tags: ['account'],
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 100, max: 100,
}, },

View file

@ -1,15 +1,15 @@
import ms from 'ms';
import deleteBlocking from '@/services/blocking/delete.js'; import deleteBlocking from '@/services/blocking/delete.js';
import define from '../../define.js'; import define from '../../define.js';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
import { getUser } from '../../common/getters.js'; import { getUser } from '../../common/getters.js';
import { Blockings, Users } from '@/models/index.js'; import { Blockings, Users } from '@/models/index.js';
import { HOUR } from '@/const.js';
export const meta = { export const meta = {
tags: ['account'], tags: ['account'],
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 100, max: 100,
}, },

View file

@ -1,4 +1,3 @@
import ms from 'ms';
import { addFile } from '@/services/drive/add-file.js'; import { addFile } from '@/services/drive/add-file.js';
import { DriveFiles } from '@/models/index.js'; import { DriveFiles } from '@/models/index.js';
import { DB_MAX_IMAGE_COMMENT_LENGTH } from '@/misc/hard-limits.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 define from '../../../define.js';
import { apiLogger } from '../../../logger.js'; import { apiLogger } from '../../../logger.js';
import { ApiError } from '../../../error.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 = { export const meta = {
tags: ['drive'], tags: ['drive'],
@ -14,7 +16,7 @@ export const meta = {
requireCredential: true, requireCredential: true,
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 120, max: 120,
}, },

View file

@ -1,15 +1,13 @@
import ms from 'ms';
import { uploadFromUrl } from '@/services/drive/upload-from-url.js'; import { uploadFromUrl } from '@/services/drive/upload-from-url.js';
import { DriveFiles } from '@/models/index.js'; import { DriveFiles } from '@/models/index.js';
import { publishMainStream } from '@/services/stream.js'; import { publishMainStream } from '@/services/stream.js';
import { DB_MAX_IMAGE_COMMENT_LENGTH } from '@/misc/hard-limits.js'; import { HOUR } from '@/const.js';
import define from '../../../define.js';
export const meta = { export const meta = {
tags: ['drive'], tags: ['drive'],
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 60, max: 60,
}, },

View file

@ -1,12 +1,12 @@
import ms from 'ms';
import { createExportCustomEmojisJob } from '@/queue/index.js'; import { createExportCustomEmojisJob } from '@/queue/index.js';
import define from '../define.js'; import define from '../define.js';
import { HOUR } from '@/const.js';
export const meta = { export const meta = {
secure: true, secure: true,
requireCredential: true, requireCredential: true,
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 1, max: 1,
}, },
} as const; } as const;

View file

@ -1,16 +1,16 @@
import ms from 'ms';
import create from '@/services/following/create.js'; import create from '@/services/following/create.js';
import define from '../../define.js'; import define from '../../define.js';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
import { getUser } from '../../common/getters.js'; import { getUser } from '../../common/getters.js';
import { Followings, Users } from '@/models/index.js'; import { Followings, Users } from '@/models/index.js';
import { IdentifiableError } from '@/misc/identifiable-error.js'; import { IdentifiableError } from '@/misc/identifiable-error.js';
import { HOUR } from '@/const.js';
export const meta = { export const meta = {
tags: ['following', 'users'], tags: ['following', 'users'],
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 100, max: 100,
}, },

View file

@ -1,15 +1,15 @@
import ms from 'ms';
import deleteFollowing from '@/services/following/delete.js'; import deleteFollowing from '@/services/following/delete.js';
import define from '../../define.js'; import define from '../../define.js';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
import { getUser } from '../../common/getters.js'; import { getUser } from '../../common/getters.js';
import { Followings, Users } from '@/models/index.js'; import { Followings, Users } from '@/models/index.js';
import { HOUR } from '@/const.js';
export const meta = { export const meta = {
tags: ['following', 'users'], tags: ['following', 'users'],
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 100, max: 100,
}, },

View file

@ -1,15 +1,15 @@
import ms from 'ms';
import deleteFollowing from '@/services/following/delete.js'; import deleteFollowing from '@/services/following/delete.js';
import define from '../../define.js'; import define from '../../define.js';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
import { getUser } from '../../common/getters.js'; import { getUser } from '../../common/getters.js';
import { Followings, Users } from '@/models/index.js'; import { Followings, Users } from '@/models/index.js';
import { HOUR } from '@/const.js';
export const meta = { export const meta = {
tags: ['following', 'users'], tags: ['following', 'users'],
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 100, max: 100,
}, },

View file

@ -1,10 +1,10 @@
import ms from 'ms';
import define from '../../../define.js'; import define from '../../../define.js';
import { DriveFiles, GalleryPosts } from '@/models/index.js'; import { DriveFiles, GalleryPosts } from '@/models/index.js';
import { genId } from '../../../../../misc/gen-id.js'; import { genId } from '../../../../../misc/gen-id.js';
import { GalleryPost } from '@/models/entities/gallery-post.js'; import { GalleryPost } from '@/models/entities/gallery-post.js';
import { ApiError } from '../../../error.js'; import { ApiError } from '../../../error.js';
import { DriveFile } from '@/models/entities/drive-file.js'; import { DriveFile } from '@/models/entities/drive-file.js';
import { HOUR } from '@/const.js';
export const meta = { export const meta = {
tags: ['gallery'], tags: ['gallery'],
@ -14,7 +14,7 @@ export const meta = {
kind: 'write:gallery', kind: 'write:gallery',
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 300, max: 300,
}, },

View file

@ -1,9 +1,9 @@
import ms from 'ms';
import define from '../../../define.js'; import define from '../../../define.js';
import { DriveFiles, GalleryPosts } from '@/models/index.js'; import { DriveFiles, GalleryPosts } from '@/models/index.js';
import { GalleryPost } from '@/models/entities/gallery-post.js'; import { GalleryPost } from '@/models/entities/gallery-post.js';
import { ApiError } from '../../../error.js'; import { ApiError } from '../../../error.js';
import { DriveFile } from '@/models/entities/drive-file.js'; import { DriveFile } from '@/models/entities/drive-file.js';
import { HOUR } from '@/const.js';
export const meta = { export const meta = {
tags: ['gallery'], tags: ['gallery'],
@ -13,7 +13,7 @@ export const meta = {
kind: 'write:gallery', kind: 'write:gallery',
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 300, max: 300,
}, },

View file

@ -1,12 +1,12 @@
import define from '../../define.js'; import define from '../../define.js';
import { createExportBlockingJob } from '@/queue/index.js'; import { createExportBlockingJob } from '@/queue/index.js';
import ms from 'ms'; import { HOUR } from '@/const.js';
export const meta = { export const meta = {
secure: true, secure: true,
requireCredential: true, requireCredential: true,
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 1, max: 1,
}, },
} as const; } as const;

View file

@ -1,12 +1,12 @@
import define from '../../define.js'; import define from '../../define.js';
import { createExportFollowingJob } from '@/queue/index.js'; import { createExportFollowingJob } from '@/queue/index.js';
import ms from 'ms'; import { HOUR } from '@/const.js';
export const meta = { export const meta = {
secure: true, secure: true,
requireCredential: true, requireCredential: true,
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 1, max: 1,
}, },
} as const; } as const;

View file

@ -1,12 +1,12 @@
import define from '../../define.js'; import define from '../../define.js';
import { createExportMuteJob } from '@/queue/index.js'; import { createExportMuteJob } from '@/queue/index.js';
import ms from 'ms'; import { HOUR } from '@/const.js';
export const meta = { export const meta = {
secure: true, secure: true,
requireCredential: true, requireCredential: true,
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 1, max: 1,
}, },
} as const; } as const;

View file

@ -1,12 +1,12 @@
import define from '../../define.js'; import define from '../../define.js';
import { createExportNotesJob } from '@/queue/index.js'; import { createExportNotesJob } from '@/queue/index.js';
import ms from 'ms'; import { DAY } from '@/const.js';
export const meta = { export const meta = {
secure: true, secure: true,
requireCredential: true, requireCredential: true,
limit: { limit: {
duration: ms('1day'), duration: DAY,
max: 1, max: 1,
}, },
} as const; } as const;

View file

@ -1,12 +1,12 @@
import define from '../../define.js'; import define from '../../define.js';
import { createExportUserListsJob } from '@/queue/index.js'; import { createExportUserListsJob } from '@/queue/index.js';
import ms from 'ms'; import { MINUTE } from '@/const.js';
export const meta = { export const meta = {
secure: true, secure: true,
requireCredential: true, requireCredential: true,
limit: { limit: {
duration: ms('1min'), duration: MINUTE,
max: 1, max: 1,
}, },
} as const; } as const;

View file

@ -1,15 +1,15 @@
import define from '../../define.js'; import define from '../../define.js';
import { createImportBlockingJob } from '@/queue/index.js'; import { createImportBlockingJob } from '@/queue/index.js';
import ms from 'ms';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
import { DriveFiles } from '@/models/index.js'; import { DriveFiles } from '@/models/index.js';
import { HOUR } from '@/const.js';
export const meta = { export const meta = {
secure: true, secure: true,
requireCredential: true, requireCredential: true,
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 1, max: 1,
}, },

View file

@ -1,14 +1,14 @@
import define from '../../define.js'; import define from '../../define.js';
import { createImportFollowingJob } from '@/queue/index.js'; import { createImportFollowingJob } from '@/queue/index.js';
import ms from 'ms';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
import { DriveFiles } from '@/models/index.js'; import { DriveFiles } from '@/models/index.js';
import { HOUR } from '@/const.js';
export const meta = { export const meta = {
secure: true, secure: true,
requireCredential: true, requireCredential: true,
limit: { limit: {
duration: ms('1hour'), duratition: HOUR,
max: 1, max: 1,
}, },

View file

@ -1,15 +1,15 @@
import define from '../../define.js'; import define from '../../define.js';
import { createImportMutingJob } from '@/queue/index.js'; import { createImportMutingJob } from '@/queue/index.js';
import ms from 'ms';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
import { DriveFiles } from '@/models/index.js'; import { DriveFiles } from '@/models/index.js';
import { HOUR } from '@/const.js';
export const meta = { export const meta = {
secure: true, secure: true,
requireCredential: true, requireCredential: true,
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 1, max: 1,
}, },

View file

@ -1,14 +1,14 @@
import define from '../../define.js'; import define from '../../define.js';
import { createImportUserListsJob } from '@/queue/index.js'; import { createImportUserListsJob } from '@/queue/index.js';
import ms from 'ms';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
import { DriveFiles } from '@/models/index.js'; import { DriveFiles } from '@/models/index.js';
import { HOUR } from '@/const.js';
export const meta = { export const meta = {
secure: true, secure: true,
requireCredential: true, requireCredential: true,
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 1, max: 1,
}, },

View file

@ -2,12 +2,12 @@ import { publishMainStream } from '@/services/stream.js';
import define from '../../define.js'; import define from '../../define.js';
import rndstr from 'rndstr'; import rndstr from 'rndstr';
import config from '@/config/index.js'; import config from '@/config/index.js';
import ms from 'ms';
import bcrypt from 'bcryptjs'; import bcrypt from 'bcryptjs';
import { Users, UserProfiles } from '@/models/index.js'; import { Users, UserProfiles } from '@/models/index.js';
import { sendEmail } from '@/services/send-email.js'; import { sendEmail } from '@/services/send-email.js';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
import { validateEmailForAccount } from '@/services/validate-email-for-account.js'; import { validateEmailForAccount } from '@/services/validate-email-for-account.js';
import { HOUR } from '@/const.js';
export const meta = { export const meta = {
requireCredential: true, requireCredential: true,
@ -15,7 +15,7 @@ export const meta = {
secure: true, secure: true,
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 3, max: 3,
}, },

View file

@ -1,8 +1,8 @@
import define from '../../../define.js'; import define from '../../../define.js';
import ms from 'ms';
import { ApiError } from '../../../error.js'; import { ApiError } from '../../../error.js';
import { MessagingMessages } from '@/models/index.js'; import { MessagingMessages } from '@/models/index.js';
import { deleteMessage } from '@/services/messages/delete.js'; import { deleteMessage } from '@/services/messages/delete.js';
import { SECOND, HOUR } from '@/const.js';
export const meta = { export const meta = {
tags: ['messaging'], tags: ['messaging'],
@ -12,9 +12,9 @@ export const meta = {
kind: 'write:messaging', kind: 'write:messaging',
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 300, max: 300,
minInterval: ms('1sec'), minInterval: SECOND,
}, },
errors: { errors: {

View file

@ -1,4 +1,3 @@
import ms from 'ms';
import { In } from 'typeorm'; import { In } from 'typeorm';
import create from '@/services/note/create.js'; import create from '@/services/note/create.js';
import { User } from '@/models/entities/user.js'; import { User } from '@/models/entities/user.js';
@ -11,7 +10,7 @@ import { HOUR } from '@/const.js';
import { noteVisibilities } from '../../../../types.js'; import { noteVisibilities } from '../../../../types.js';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
import define from '../../define.js'; import define from '../../define.js';
import { getNote } from '../../common/getters.js'; import { HOUR } from '@/const.js';
export const meta = { export const meta = {
tags: ['notes'], tags: ['notes'],
@ -19,7 +18,7 @@ export const meta = {
requireCredential: true, requireCredential: true,
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 300, max: 300,
}, },

View file

@ -1,9 +1,9 @@
import ms from 'ms';
import deleteNote from '@/services/note/delete.js'; import deleteNote from '@/services/note/delete.js';
import { Users } from '@/models/index.js'; import { Users } from '@/models/index.js';
import define from '../../define.js'; import define from '../../define.js';
import { getNote } from '../../common/getters.js'; import { getNote } from '../../common/getters.js';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
import { SECOND, HOUR } from '@/const.js';
export const meta = { export const meta = {
tags: ['notes'], tags: ['notes'],
@ -13,9 +13,9 @@ export const meta = {
kind: 'write:notes', kind: 'write:notes',
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 300, max: 300,
minInterval: ms('1sec'), minInterval: SECOND,
}, },
errors: { errors: {

View file

@ -1,8 +1,8 @@
import ms from 'ms';
import deleteReaction from '@/services/note/reaction/delete.js'; import deleteReaction from '@/services/note/reaction/delete.js';
import define from '../../../define.js'; import define from '../../../define.js';
import { getNote } from '../../../common/getters.js'; import { getNote } from '../../../common/getters.js';
import { ApiError } from '../../../error.js'; import { ApiError } from '../../../error.js';
import { SECOND, HOUR } from '@/const.js';
export const meta = { export const meta = {
tags: ['reactions', 'notes'], tags: ['reactions', 'notes'],
@ -12,9 +12,9 @@ export const meta = {
kind: 'write:reactions', kind: 'write:reactions',
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 60, max: 60,
minInterval: ms('3sec'), minInterval: 3 * SECOND,
}, },
errors: { errors: {

View file

@ -1,9 +1,9 @@
import ms from 'ms';
import deleteNote from '@/services/note/delete.js'; import deleteNote from '@/services/note/delete.js';
import { Notes, Users } from '@/models/index.js'; import { Notes, Users } from '@/models/index.js';
import define from '../../define.js'; import define from '../../define.js';
import { getNote } from '../../common/getters.js'; import { getNote } from '../../common/getters.js';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
import { SECOND, HOUR } from '@/const.js';
export const meta = { export const meta = {
tags: ['notes'], tags: ['notes'],
@ -13,9 +13,9 @@ export const meta = {
kind: 'write:notes', kind: 'write:notes',
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 300, max: 300,
minInterval: ms('1sec'), minInterval: SECOND,
}, },
errors: { errors: {

View file

@ -1,9 +1,9 @@
import ms from 'ms';
import { Pages, DriveFiles } from '@/models/index.js'; import { Pages, DriveFiles } from '@/models/index.js';
import { genId } from '@/misc/gen-id.js'; import { genId } from '@/misc/gen-id.js';
import { Page } from '@/models/entities/page.js'; import { Page } from '@/models/entities/page.js';
import define from '../../define.js'; import define from '../../define.js';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
import { HOUR } from '@/const.js';
export const meta = { export const meta = {
tags: ['pages'], tags: ['pages'],
@ -13,7 +13,7 @@ export const meta = {
kind: 'write:pages', kind: 'write:pages',
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 300, max: 300,
}, },

View file

@ -1,8 +1,8 @@
import ms from 'ms';
import { Not } from 'typeorm'; import { Not } from 'typeorm';
import { Pages, DriveFiles } from '@/models/index.js'; import { Pages, DriveFiles } from '@/models/index.js';
import define from '../../define.js'; import define from '../../define.js';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
import { HOUR } from '@/const.js';
export const meta = { export const meta = {
tags: ['pages'], tags: ['pages'],
@ -12,7 +12,7 @@ export const meta = {
kind: 'write:pages', kind: 'write:pages',
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 300, max: 300,
}, },

View file

@ -1,5 +1,4 @@
import rndstr from 'rndstr'; import rndstr from 'rndstr';
import ms from 'ms';
import { IsNull } from 'typeorm'; import { IsNull } from 'typeorm';
import { publishMainStream } from '@/services/stream.js'; import { publishMainStream } from '@/services/stream.js';
import config from '@/config/index.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 { genId } from '@/misc/gen-id.js';
import { ApiError } from '../error.js'; import { ApiError } from '../error.js';
import define from '../define.js'; import define from '../define.js';
import { HOUR } from '@/const.js';
export const meta = { export const meta = {
tags: ['reset password'], tags: ['reset password'],
@ -17,7 +17,7 @@ export const meta = {
description: 'Request a users password to be reset.', description: 'Request a users password to be reset.',
limit: { limit: {
duration: ms('1hour'), duration: HOUR,
max: 3, max: 3,
}, },

View file

@ -1,8 +1,8 @@
import ms from 'ms';
import { Users, Followings } from '@/models/index.js'; import { Users, Followings } from '@/models/index.js';
import define from '../../define.js'; import define from '../../define.js';
import { generateMutedUserQueryForUsers } from '../../common/generate-muted-user-query.js'; import { generateMutedUserQueryForUsers } from '../../common/generate-muted-user-query.js';
import { generateBlockedUserQuery, generateBlockQueryForUsers } from '../../common/generate-block-query.js'; import { generateBlockedUserQuery, generateBlockQueryForUsers } from '../../common/generate-block-query.js';
import { DAY } from '@/const.js';
export const meta = { export const meta = {
tags: ['users'], tags: ['users'],
@ -39,7 +39,7 @@ export default define(meta, paramDef, async (ps, me) => {
.where('user.isLocked = FALSE') .where('user.isLocked = FALSE')
.andWhere('user.isExplorable = TRUE') .andWhere('user.isExplorable = TRUE')
.andWhere('user.host IS NULL') .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 }) .andWhere('user.id != :meId', { meId: me.id })
.orderBy('user.followersCount', 'DESC'); .orderBy('user.followersCount', 'DESC');

View file

@ -4,8 +4,7 @@
import { dirname } from 'node:path'; import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url'; import { fileURLToPath } from 'node:url';
import { PathOrFileDescriptor, readFileSync } from 'node:fs'; import { readFileSync } from 'node:fs';
import ms from 'ms';
import Koa from 'koa'; import Koa from 'koa';
import Router from '@koa/router'; import Router from '@koa/router';
import send from 'koa-send'; import send from 'koa-send';
@ -27,6 +26,7 @@ import { genOpenapiSpec } from '../api/openapi/gen-spec.js';
import { urlPreviewHandler } from './url-preview.js'; import { urlPreviewHandler } from './url-preview.js';
import { manifestHandler } from './manifest.js'; import { manifestHandler } from './manifest.js';
import packFeed from './feed.js'; import packFeed from './feed.js';
import { MINUTE, DAY } from '@/const.js';
const _filename = fileURLToPath(import.meta.url); const _filename = fileURLToPath(import.meta.url);
const _dirname = dirname(_filename); const _dirname = dirname(_filename);
@ -100,21 +100,21 @@ const router = new Router();
router.get('/static-assets/(.*)', async ctx => { router.get('/static-assets/(.*)', async ctx => {
await send(ctx as any, ctx.path.replace('/static-assets/', ''), { await send(ctx as any, ctx.path.replace('/static-assets/', ''), {
root: staticAssets, root: staticAssets,
maxage: ms('7 days'), maxage: 7 * DAY,
}); });
}); });
router.get('/client-assets/(.*)', async ctx => { router.get('/client-assets/(.*)', async ctx => {
await send(ctx as any, ctx.path.replace('/client-assets/', ''), { await send(ctx as any, ctx.path.replace('/client-assets/', ''), {
root: clientAssets, root: clientAssets,
maxage: ms('7 days'), maxage: 7 * DAY,
}); });
}); });
router.get('/assets/(.*)', async ctx => { router.get('/assets/(.*)', async ctx => {
await send(ctx as any, ctx.path.replace('/assets/', ''), { await send(ctx as any, ctx.path.replace('/assets/', ''), {
root: 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, { await send(ctx as any, path, {
root: `${_dirname}/../../../node_modules/@discordapp/twemoji/dist/svg/`, 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 => { router.get(`/sw.js`, async ctx => {
await send(ctx as any, `/sw.js`, { await send(ctx as any, `/sw.js`, {
root: swAssets, root: swAssets,
maxage: ms('10 minutes'), maxage: 10 * MINUTE,
}); });
}); });