diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2ffe6dc2e169e845ba74035b3442af3614d51c7b..d9d6702e80ee4596e2bac888c048983f019e210a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -240,36 +240,6 @@ SQLã§ã¯é…列ã®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã¯**1始ã¾ã‚Š**。 MongoDBã®æ™‚ã¨ã¯é•ã„ã€findOneã§ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’å–å¾—ã™ã‚‹æ™‚ã«å¯¾è±¡ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒå˜åœ¨ã—ãªã„å ´åˆ **`undefined`** ãŒè¿”ã£ã¦ãã‚‹ã®ã§æ³¨æ„。 MongoDBã¯`null`ã§è¿”ã—ã¦ãã¦ãŸã®ã§ã€ãã®æ„Ÿè¦šã§`if (x === null)`ã¨ã‹æ›¸ãã¨ãƒã‚°ã‚‹ã€‚代ã‚ã‚Šã«`if (x == null)`ã¨æ›¸ã„ã¦ãã ã•ã„ -### ç°¡ç´ ãª`undefined`ãƒã‚§ãƒƒã‚¯ -データベースã‹ã‚‰ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’å–å¾—ã™ã‚‹ã¨ãã«ã€ãƒ—ãƒã‚°ãƒ©ãƒ ã®æµã‚Œçš„ã«(ã»ã¼)絶対`undefined`ã«ã¯ãªã‚‰ãªã„å ´åˆã§ã‚‚ã€`undefined`ãƒã‚§ãƒƒã‚¯ã—ãªã„ã¨TypeScriptã«æ€’られã¾ã™ã€‚ -ã§ã‚‚ã„ã¡ã„ã¡è¤‡æ•°è¡Œã‚’費やã—ã¦ã€ç™ºç”Ÿã™ã‚‹ã¯ãšã®ãªã„`undefined`ã‚’ãƒã‚§ãƒƒã‚¯ã™ã‚‹ã®ã‚‚é¢å€’ãªã®ã§ã€`ensure`ã¨ã„ã†ãƒ¦ãƒ¼ãƒ†ã‚£ãƒªãƒ†ã‚£é–¢æ•°ã‚’用æ„ã—ã¦ã„ã¾ã™ã€‚ -例ãˆã°ã€ -``` ts -const user = await Users.findOne(userId); -// ã“ã®æ™‚点㧠user ã®åž‹ã¯ User | undefined -if (user == null) { - throw 'missing user'; -} -// ã“ã®æ™‚点㧠user ã®åž‹ã¯ User -``` -ã¨ã„ã†å‡¦ç†ã‚’`ensure`を使ã†ã¨ -``` ts -const user = await Users.findOne(userId).then(ensure); -// ã“ã®æ™‚点㧠user ã®åž‹ã¯ User -``` -ã¨ã„ã†é¢¨ã«æ›¸ã‘ã¾ã™ã€‚ -ã‚‚ã¡ã‚ã‚“`ensure`内部ã§ã‚¨ãƒ©ãƒ¼ã‚’æ¡ã‚Šã¤ã¶ã™ã‚ˆã†ãªã“ã¨ã¯ã—ã¦ãŠã‚‰ãšã€ä¸‡ãŒä¸€`undefined`ã ã£ãŸå ´åˆã¯PromiseãŒRejectã•ã‚Œå¾Œç¶šã®å‡¦ç†ã¯å®Ÿè¡Œã•ã‚Œã¾ã›ã‚“。 -``` ts -const user = await Users.findOne(userId).then(ensure); -// 万ãŒä¸€ Users.findOne ã®çµæžœãŒ undefined ã ã£ãŸã‚‰ã€ensure ã§ã‚¨ãƒ©ãƒ¼ãŒç™ºç”Ÿã™ã‚‹ã®ã§ -// ã“ã®è¡Œã«åˆ°é”ã™ã‚‹ã“ã¨ã¯ç„¡ã„ -// ãªã®ã§ã€.then(ensure) 㯠-// if (user == null) { -// throw 'missing user'; -// } -// ã®ç³–衣構文ã®ã‚ˆã†ãªæ‰±ã„ã§ã™ -``` - ### Migration作æˆæ–¹æ³• ``` npx ts-node ./node_modules/typeorm/cli.js migration:generate -n 変更ã®åå‰ diff --git a/src/misc/check-hit-antenna.ts b/src/misc/check-hit-antenna.ts index 562d054563fae33e56edb6c4e882cceb74eeb520..0464f141316be781db526dd7f7eee0f246ce24a2 100644 --- a/src/misc/check-hit-antenna.ts +++ b/src/misc/check-hit-antenna.ts @@ -4,7 +4,6 @@ import { User } from '../models/entities/user'; import { UserListJoinings, UserGroupJoinings } from '../models'; import parseAcct from './acct/parse'; import { getFullApAccount } from './convert-host'; -import { ensure } from '../prelude/ensure'; export async function checkHitAntenna(antenna: Antenna, note: Note, noteUser: User, followers: User['id'][]): Promise<boolean> { if (note.visibility === 'specified') return false; @@ -24,7 +23,7 @@ export async function checkHitAntenna(antenna: Antenna, note: Note, noteUser: Us if (!listUsers.includes(note.userId)) return false; } else if (antenna.src === 'group') { - const joining = await UserGroupJoinings.findOne(antenna.userGroupJoiningId!).then(ensure); + const joining = await UserGroupJoinings.findOneOrFail(antenna.userGroupJoiningId!); const groupUsers = (await UserGroupJoinings.find({ userGroupId: joining.userGroupId diff --git a/src/misc/fetch-proxy-account.ts b/src/misc/fetch-proxy-account.ts index 0094ab8a5617b241f6c7ab22a6cbaa57b339044d..537edf2891a5575fb61563ac147dfa244a711472 100644 --- a/src/misc/fetch-proxy-account.ts +++ b/src/misc/fetch-proxy-account.ts @@ -1,10 +1,9 @@ import { fetchMeta } from './fetch-meta'; import { ILocalUser } from '../models/entities/user'; import { Users } from '../models'; -import { ensure } from '../prelude/ensure'; export async function fetchProxyAccount(): Promise<ILocalUser | null> { const meta = await fetchMeta(); if (meta.proxyAccountId == null) return null; - return await Users.findOne(meta.proxyAccountId).then(ensure) as ILocalUser; + return await Users.findOneOrFail(meta.proxyAccountId) as ILocalUser; } diff --git a/src/models/repositories/abuse-user-report.ts b/src/models/repositories/abuse-user-report.ts index dbdaa5ee15258ba824a0c137a3bb646d56654c4c..cb33d2506e21e7c4f3f8588518fa003c85ba2c0a 100644 --- a/src/models/repositories/abuse-user-report.ts +++ b/src/models/repositories/abuse-user-report.ts @@ -1,7 +1,6 @@ import { EntityRepository, Repository } from 'typeorm'; import { Users } from '..'; import { AbuseUserReport } from '../entities/abuse-user-report'; -import { ensure } from '../../prelude/ensure'; import { awaitAll } from '../../prelude/await-all'; @EntityRepository(AbuseUserReport) @@ -9,7 +8,7 @@ export class AbuseUserReportRepository extends Repository<AbuseUserReport> { public async pack( src: AbuseUserReport['id'] | AbuseUserReport, ) { - const report = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const report = typeof src === 'object' ? src : await this.findOneOrFail(src); return await awaitAll({ id: report.id, diff --git a/src/models/repositories/antenna.ts b/src/models/repositories/antenna.ts index 16ef2e5a390f506d025de2bfa03bbc91df096b48..b20da26c5db1b6d73cd75acbed4ad3d7fae93df7 100644 --- a/src/models/repositories/antenna.ts +++ b/src/models/repositories/antenna.ts @@ -1,6 +1,5 @@ import { EntityRepository, Repository } from 'typeorm'; import { Antenna } from '../entities/antenna'; -import { ensure } from '../../prelude/ensure'; import { SchemaType } from '../../misc/schema'; import { AntennaNotes, UserGroupJoinings } from '..'; @@ -11,7 +10,7 @@ export class AntennaRepository extends Repository<Antenna> { public async pack( src: Antenna['id'] | Antenna, ): Promise<PackedAntenna> { - const antenna = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const antenna = typeof src === 'object' ? src : await this.findOneOrFail(src); const hasUnreadNote = (await AntennaNotes.findOne({ antennaId: antenna.id, read: false })) != null; const userGroupJoining = antenna.userGroupJoiningId ? await UserGroupJoinings.findOne(antenna.userGroupJoiningId) : null; diff --git a/src/models/repositories/app.ts b/src/models/repositories/app.ts index 45d8d16c516e353869cb037d61cf806e1695c814..f5cc10787aac5d1b3626426f4fc9b29ecc2ab911 100644 --- a/src/models/repositories/app.ts +++ b/src/models/repositories/app.ts @@ -1,7 +1,6 @@ import { EntityRepository, Repository } from 'typeorm'; import { App } from '../entities/app'; import { AccessTokens } from '..'; -import { ensure } from '../../prelude/ensure'; import { SchemaType } from '../../misc/schema'; export type PackedApp = SchemaType<typeof packedAppSchema>; @@ -23,7 +22,7 @@ export class AppRepository extends Repository<App> { includeProfileImageIds: false }, options); - const app = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const app = typeof src === 'object' ? src : await this.findOneOrFail(src); return { id: app.id, diff --git a/src/models/repositories/auth-session.ts b/src/models/repositories/auth-session.ts index a6a4d46de641f9b89fb2ffffefa9d516aa2e7363..e985d6925fc1a369b47e637dcd4fe3393dc739af 100644 --- a/src/models/repositories/auth-session.ts +++ b/src/models/repositories/auth-session.ts @@ -1,7 +1,6 @@ import { EntityRepository, Repository } from 'typeorm'; import { Apps } from '..'; import { AuthSession } from '../entities/auth-session'; -import { ensure } from '../../prelude/ensure'; import { awaitAll } from '../../prelude/await-all'; @EntityRepository(AuthSession) @@ -10,7 +9,7 @@ export class AuthSessionRepository extends Repository<AuthSession> { src: AuthSession['id'] | AuthSession, me?: any ) { - const session = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const session = typeof src === 'object' ? src : await this.findOneOrFail(src); return await awaitAll({ id: session.id, diff --git a/src/models/repositories/blocking.ts b/src/models/repositories/blocking.ts index 9ebe6bbf59bcff0b880a6ed0a7e9452a19865687..314f459e65d261c4adb0aac5188506fa08c032ec 100644 --- a/src/models/repositories/blocking.ts +++ b/src/models/repositories/blocking.ts @@ -1,7 +1,6 @@ import { EntityRepository, Repository } from 'typeorm'; import { Users } from '..'; import { Blocking } from '../entities/blocking'; -import { ensure } from '../../prelude/ensure'; import { awaitAll } from '../../prelude/await-all'; import { SchemaType } from '../../misc/schema'; @@ -13,7 +12,7 @@ export class BlockingRepository extends Repository<Blocking> { src: Blocking['id'] | Blocking, me?: any ): Promise<PackedBlocking> { - const blocking = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const blocking = typeof src === 'object' ? src : await this.findOneOrFail(src); return await awaitAll({ id: blocking.id, diff --git a/src/models/repositories/channel.ts b/src/models/repositories/channel.ts index 2a90419922632fca47bb526be85e317781dc5a65..2654c9d6f34cf56f3cdf70dd94c90cbd4d871af2 100644 --- a/src/models/repositories/channel.ts +++ b/src/models/repositories/channel.ts @@ -1,6 +1,5 @@ import { EntityRepository, Repository } from 'typeorm'; import { Channel } from '../entities/channel'; -import { ensure } from '../../prelude/ensure'; import { SchemaType } from '../../misc/schema'; import { DriveFiles, ChannelFollowings, NoteUnreads } from '..'; import { User } from '../entities/user'; @@ -13,7 +12,7 @@ export class ChannelRepository extends Repository<Channel> { src: Channel['id'] | Channel, me?: User['id'] | User | null | undefined, ): Promise<PackedChannel> { - const channel = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const channel = typeof src === 'object' ? src : await this.findOneOrFail(src); const meId = me ? typeof me === 'string' ? me : me.id : null; const banner = channel.bannerId ? await DriveFiles.findOne(channel.bannerId) : null; diff --git a/src/models/repositories/clip.ts b/src/models/repositories/clip.ts index 11f743349fa95c6b8335485d17d460a0bc88601b..84891a4372396e80d213b246cb2f8d4b0bc63930 100644 --- a/src/models/repositories/clip.ts +++ b/src/models/repositories/clip.ts @@ -1,6 +1,5 @@ import { EntityRepository, Repository } from 'typeorm'; import { Clip } from '../entities/clip'; -import { ensure } from '../../prelude/ensure'; import { SchemaType } from '../../misc/schema'; import { Users } from '..'; import { awaitAll } from '../../prelude/await-all'; @@ -12,7 +11,7 @@ export class ClipRepository extends Repository<Clip> { public async pack( src: Clip['id'] | Clip, ): Promise<PackedClip> { - const clip = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const clip = typeof src === 'object' ? src : await this.findOneOrFail(src); return await awaitAll({ id: clip.id, diff --git a/src/models/repositories/drive-file.ts b/src/models/repositories/drive-file.ts index ab22d2dc09bc976e19d23bb93b93e42daa178d97..3d013b8bb2cfdc5cc73252c48040cc9bc8772f4f 100644 --- a/src/models/repositories/drive-file.ts +++ b/src/models/repositories/drive-file.ts @@ -3,7 +3,6 @@ import { DriveFile } from '../entities/drive-file'; import { Users, DriveFolders } from '..'; import { User } from '../entities/user'; import { toPuny } from '../../misc/convert-host'; -import { ensure } from '../../prelude/ensure'; import { awaitAll } from '../../prelude/await-all'; import { SchemaType } from '../../misc/schema'; import config from '../../config'; @@ -103,7 +102,7 @@ export class DriveFileRepository extends Repository<DriveFile> { self: false }, options); - const file = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const file = typeof src === 'object' ? src : await this.findOneOrFail(src); const meta = await fetchMeta(); diff --git a/src/models/repositories/drive-folder.ts b/src/models/repositories/drive-folder.ts index dee424cccbc84a00737035ea3ef4dd4d231a1443..2a18220384be2565018fca9e25bd761ecdde1d40 100644 --- a/src/models/repositories/drive-folder.ts +++ b/src/models/repositories/drive-folder.ts @@ -1,7 +1,6 @@ import { EntityRepository, Repository } from 'typeorm'; import { DriveFolders, DriveFiles } from '..'; import { DriveFolder } from '../entities/drive-folder'; -import { ensure } from '../../prelude/ensure'; import { awaitAll } from '../../prelude/await-all'; import { SchemaType } from '../../misc/schema'; @@ -26,7 +25,7 @@ export class DriveFolderRepository extends Repository<DriveFolder> { detail: false }, options); - const folder = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const folder = typeof src === 'object' ? src : await this.findOneOrFail(src); return await awaitAll({ id: folder.id, diff --git a/src/models/repositories/emoji.ts b/src/models/repositories/emoji.ts index b485b37da58977c57b86cc3e216eb949785e25f9..3490a6ac86ebad2c434ccc788d0639511789267a 100644 --- a/src/models/repositories/emoji.ts +++ b/src/models/repositories/emoji.ts @@ -1,13 +1,12 @@ import { EntityRepository, Repository } from 'typeorm'; import { Emoji } from '../entities/emoji'; -import { ensure } from '../../prelude/ensure'; @EntityRepository(Emoji) export class EmojiRepository extends Repository<Emoji> { public async pack( src: Emoji['id'] | Emoji, ) { - const emoji = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const emoji = typeof src === 'object' ? src : await this.findOneOrFail(src); return { id: emoji.id, diff --git a/src/models/repositories/follow-request.ts b/src/models/repositories/follow-request.ts index 451ed8e2d5e23ded46ce3f9194b41348b8cefd6d..0d96b8eb53db564acd82f262322feddfcb3ef34f 100644 --- a/src/models/repositories/follow-request.ts +++ b/src/models/repositories/follow-request.ts @@ -1,7 +1,6 @@ import { EntityRepository, Repository } from 'typeorm'; import { FollowRequest } from '../entities/follow-request'; import { Users } from '..'; -import { ensure } from '../../prelude/ensure'; @EntityRepository(FollowRequest) export class FollowRequestRepository extends Repository<FollowRequest> { @@ -9,7 +8,7 @@ export class FollowRequestRepository extends Repository<FollowRequest> { src: FollowRequest['id'] | FollowRequest, me?: any ) { - const request = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const request = typeof src === 'object' ? src : await this.findOneOrFail(src); return { id: request.id, diff --git a/src/models/repositories/following.ts b/src/models/repositories/following.ts index 58728a338043a9e9ae2f0daf52561596f4cbb29e..986f107e7df928ad3c4925f40dfae9d573d9e5ea 100644 --- a/src/models/repositories/following.ts +++ b/src/models/repositories/following.ts @@ -1,7 +1,6 @@ import { EntityRepository, Repository } from 'typeorm'; import { Users } from '..'; import { Following } from '../entities/following'; -import { ensure } from '../../prelude/ensure'; import { awaitAll } from '../../prelude/await-all'; import { SchemaType } from '../../misc/schema'; @@ -57,7 +56,7 @@ export class FollowingRepository extends Repository<Following> { populateFollower?: boolean; } ): Promise<PackedFollowing> { - const following = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const following = typeof src === 'object' ? src : await this.findOneOrFail(src); if (opts == null) opts = {}; diff --git a/src/models/repositories/games/reversi/game.ts b/src/models/repositories/games/reversi/game.ts index c380f5251e151320698ca65e08663acca9ac79ff..e23247f6649e9a117ecec37fd343025c01ad4899 100644 --- a/src/models/repositories/games/reversi/game.ts +++ b/src/models/repositories/games/reversi/game.ts @@ -1,7 +1,6 @@ import { EntityRepository, Repository } from 'typeorm'; import { Users } from '../../..'; import { ReversiGame } from '../../../entities/games/reversi/game'; -import { ensure } from '../../../../prelude/ensure'; @EntityRepository(ReversiGame) export class ReversiGameRepository extends Repository<ReversiGame> { @@ -16,7 +15,7 @@ export class ReversiGameRepository extends Repository<ReversiGame> { detail: true }, options); - const game = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const game = typeof src === 'object' ? src : await this.findOneOrFail(src); const meId = me ? typeof me === 'string' ? me : me.id : null; return { diff --git a/src/models/repositories/games/reversi/matching.ts b/src/models/repositories/games/reversi/matching.ts index 86c9204456593f24d5d7b3a1d24637ec410c3fec..51f17c9a4e2b3493385a7429fdf5dd45d5d74e82 100644 --- a/src/models/repositories/games/reversi/matching.ts +++ b/src/models/repositories/games/reversi/matching.ts @@ -1,7 +1,6 @@ import { EntityRepository, Repository } from 'typeorm'; import { ReversiMatching } from '../../../entities/games/reversi/matching'; import { Users } from '../../..'; -import { ensure } from '../../../../prelude/ensure'; import { awaitAll } from '../../../../prelude/await-all'; @EntityRepository(ReversiMatching) @@ -10,7 +9,7 @@ export class ReversiMatchingRepository extends Repository<ReversiMatching> { src: ReversiMatching['id'] | ReversiMatching, me: any ) { - const matching = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const matching = typeof src === 'object' ? src : await this.findOneOrFail(src); return await awaitAll({ id: matching.id, diff --git a/src/models/repositories/messaging-message.ts b/src/models/repositories/messaging-message.ts index d70e95bc122da7b0f8b34c1f0b9bc38751a6bb1e..0e04c258647d067c6ec5656db418b4a1613fd241 100644 --- a/src/models/repositories/messaging-message.ts +++ b/src/models/repositories/messaging-message.ts @@ -1,7 +1,6 @@ import { EntityRepository, Repository } from 'typeorm'; import { MessagingMessage } from '../entities/messaging-message'; import { Users, DriveFiles, UserGroups } from '..'; -import { ensure } from '../../prelude/ensure'; import { SchemaType } from '../../misc/schema'; export type PackedMessagingMessage = SchemaType<typeof packedMessagingMessageSchema>; @@ -25,7 +24,7 @@ export class MessagingMessageRepository extends Repository<MessagingMessage> { populateGroup: true, }; - const message = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const message = typeof src === 'object' ? src : await this.findOneOrFail(src); return { id: message.id, diff --git a/src/models/repositories/moderation-logs.ts b/src/models/repositories/moderation-logs.ts index d6e04795bbf6dd2aa6c4187ff1c85fe00c803894..3d4c075701ab14bf75c8467fb819935a49eb6ada 100644 --- a/src/models/repositories/moderation-logs.ts +++ b/src/models/repositories/moderation-logs.ts @@ -1,7 +1,6 @@ import { EntityRepository, Repository } from 'typeorm'; import { Users } from '..'; import { ModerationLog } from '../entities/moderation-log'; -import { ensure } from '../../prelude/ensure'; import { awaitAll } from '../../prelude/await-all'; @EntityRepository(ModerationLog) @@ -9,7 +8,7 @@ export class ModerationLogRepository extends Repository<ModerationLog> { public async pack( src: ModerationLog['id'] | ModerationLog, ) { - const log = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const log = typeof src === 'object' ? src : await this.findOneOrFail(src); return await awaitAll({ id: log.id, diff --git a/src/models/repositories/muting.ts b/src/models/repositories/muting.ts index 763e04bb3d7943dd3cf4c43106477ee40b515b81..5fd409df787b360d34aeef27f6e0669d50b4ab7c 100644 --- a/src/models/repositories/muting.ts +++ b/src/models/repositories/muting.ts @@ -1,7 +1,6 @@ import { EntityRepository, Repository } from 'typeorm'; import { Users } from '..'; import { Muting } from '../entities/muting'; -import { ensure } from '../../prelude/ensure'; import { awaitAll } from '../../prelude/await-all'; import { SchemaType } from '../../misc/schema'; @@ -13,7 +12,7 @@ export class MutingRepository extends Repository<Muting> { src: Muting['id'] | Muting, me?: any ): Promise<PackedMuting> { - const muting = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const muting = typeof src === 'object' ? src : await this.findOneOrFail(src); return await awaitAll({ id: muting.id, diff --git a/src/models/repositories/note-favorite.ts b/src/models/repositories/note-favorite.ts index 37cfbc0025b1a86c1c20df57fe6d0fefa7dd2248..eb2ffff4c1f90e928fa1ca34552f96beb2bde253 100644 --- a/src/models/repositories/note-favorite.ts +++ b/src/models/repositories/note-favorite.ts @@ -1,7 +1,6 @@ import { EntityRepository, Repository } from 'typeorm'; import { NoteFavorite } from '../entities/note-favorite'; import { Notes } from '..'; -import { ensure } from '../../prelude/ensure'; @EntityRepository(NoteFavorite) export class NoteFavoriteRepository extends Repository<NoteFavorite> { @@ -9,7 +8,7 @@ export class NoteFavoriteRepository extends Repository<NoteFavorite> { src: NoteFavorite['id'] | NoteFavorite, me?: any ) { - const favorite = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const favorite = typeof src === 'object' ? src : await this.findOneOrFail(src); return { id: favorite.id, diff --git a/src/models/repositories/note-reaction.ts b/src/models/repositories/note-reaction.ts index 3439f3c8cb8334857c7bac9d06a2580476a86d1e..785a876bf8a605e338ba3a5e6fe7314c2d58a00c 100644 --- a/src/models/repositories/note-reaction.ts +++ b/src/models/repositories/note-reaction.ts @@ -1,7 +1,6 @@ import { EntityRepository, Repository } from 'typeorm'; import { NoteReaction } from '../entities/note-reaction'; import { Users } from '..'; -import { ensure } from '../../prelude/ensure'; import { SchemaType } from '../../misc/schema'; import { convertLegacyReaction } from '../../misc/reaction-lib'; @@ -13,7 +12,7 @@ export class NoteReactionRepository extends Repository<NoteReaction> { src: NoteReaction['id'] | NoteReaction, me?: any ): Promise<PackedNoteReaction> { - const reaction = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const reaction = typeof src === 'object' ? src : await this.findOneOrFail(src); return { id: reaction.id, diff --git a/src/models/repositories/note.ts b/src/models/repositories/note.ts index b60744bb2babe9381f6f3a218d515c3c08351ed2..87ca5eb9ec2d61bc0371eb9a800814a374186cc8 100644 --- a/src/models/repositories/note.ts +++ b/src/models/repositories/note.ts @@ -2,7 +2,6 @@ import { EntityRepository, Repository, In } from 'typeorm'; import { Note } from '../entities/note'; import { User } from '../entities/user'; import { Emojis, Users, PollVotes, DriveFiles, NoteReactions, Followings, Polls, Channels } from '..'; -import { ensure } from '../../prelude/ensure'; import { SchemaType } from '../../misc/schema'; import { awaitAll } from '../../prelude/await-all'; import { convertLegacyReaction, convertLegacyReactions, decodeReaction } from '../../misc/reaction-lib'; @@ -92,11 +91,11 @@ export class NoteRepository extends Repository<Note> { }, options); const meId = me ? typeof me === 'string' ? me : me.id : null; - const note = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const note = typeof src === 'object' ? src : await this.findOneOrFail(src); const host = note.userHost; async function populatePoll() { - const poll = await Polls.findOne(note.id).then(ensure); + const poll = await Polls.findOneOrFail(note.id); const choices = poll.choices.map(c => ({ text: c, votes: poll.votes[poll.choices.indexOf(c)], diff --git a/src/models/repositories/notification.ts b/src/models/repositories/notification.ts index 40f43d6c15d7d8c832d64bbf23d0c472275fb931..16de6c8c25df8bccd1b0e360ac980ff8bfc672c7 100644 --- a/src/models/repositories/notification.ts +++ b/src/models/repositories/notification.ts @@ -1,7 +1,6 @@ import { EntityRepository, Repository } from 'typeorm'; import { Users, Notes, UserGroupInvitations, AccessTokens } from '..'; import { Notification } from '../entities/notification'; -import { ensure } from '../../prelude/ensure'; import { awaitAll } from '../../prelude/await-all'; import { SchemaType } from '../../misc/schema'; @@ -12,8 +11,8 @@ export class NotificationRepository extends Repository<Notification> { public async pack( src: Notification['id'] | Notification, ): Promise<PackedNotification> { - const notification = typeof src === 'object' ? src : await this.findOne(src).then(ensure); - const token = notification.appAccessTokenId ? await AccessTokens.findOne(notification.appAccessTokenId).then(ensure) : null; + const notification = typeof src === 'object' ? src : await this.findOneOrFail(src); + const token = notification.appAccessTokenId ? await AccessTokens.findOneOrFail(notification.appAccessTokenId) : null; return await awaitAll({ id: notification.id, diff --git a/src/models/repositories/page-like.ts b/src/models/repositories/page-like.ts index 3e7e803fdb16daa43d2aab118bff1a7467ca8169..94b1685e5ed8fb09d4002e03fbcfff2abc953926 100644 --- a/src/models/repositories/page-like.ts +++ b/src/models/repositories/page-like.ts @@ -1,7 +1,6 @@ import { EntityRepository, Repository } from 'typeorm'; import { PageLike } from '../entities/page-like'; import { Pages } from '..'; -import { ensure } from '../../prelude/ensure'; @EntityRepository(PageLike) export class PageLikeRepository extends Repository<PageLike> { @@ -9,7 +8,7 @@ export class PageLikeRepository extends Repository<PageLike> { src: PageLike['id'] | PageLike, me?: any ) { - const like = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const like = typeof src === 'object' ? src : await this.findOneOrFail(src); return { id: like.id, diff --git a/src/models/repositories/page.ts b/src/models/repositories/page.ts index 3889bf59a715a3f2d0262ea0ce4fe27c09db11c4..1b30b6645b980f8636a0075b6dbfd3509b50621b 100644 --- a/src/models/repositories/page.ts +++ b/src/models/repositories/page.ts @@ -5,7 +5,6 @@ import { Users, DriveFiles, PageLikes } from '..'; import { awaitAll } from '../../prelude/await-all'; import { DriveFile } from '../entities/drive-file'; import { User } from '../entities/user'; -import { ensure } from '../../prelude/ensure'; export type PackedPage = SchemaType<typeof packedPageSchema>; @@ -16,7 +15,7 @@ export class PageRepository extends Repository<Page> { me?: User['id'] | User | null | undefined, ): Promise<PackedPage> { const meId = me ? typeof me === 'string' ? me : me.id : null; - const page = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const page = typeof src === 'object' ? src : await this.findOneOrFail(src); const attachedFiles: Promise<DriveFile | undefined>[] = []; const collectFile = (xs: any[]) => { diff --git a/src/models/repositories/user-group-invitation.ts b/src/models/repositories/user-group-invitation.ts index 0d3ad525c376aabd836497c4a540179cbf467809..2aa890361c386be4816d76051c93f7cd5fca9140 100644 --- a/src/models/repositories/user-group-invitation.ts +++ b/src/models/repositories/user-group-invitation.ts @@ -1,14 +1,13 @@ import { EntityRepository, Repository } from 'typeorm'; import { UserGroupInvitation } from '../entities/user-group-invitation'; import { UserGroups } from '..'; -import { ensure } from '../../prelude/ensure'; @EntityRepository(UserGroupInvitation) export class UserGroupInvitationRepository extends Repository<UserGroupInvitation> { public async pack( src: UserGroupInvitation['id'] | UserGroupInvitation, ) { - const invitation = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const invitation = typeof src === 'object' ? src : await this.findOneOrFail(src); return { id: invitation.id, diff --git a/src/models/repositories/user-group.ts b/src/models/repositories/user-group.ts index 5ff75047c876d7a3044886ed3703b0827f179983..a1b226f154e5c015d362148248451665369c070b 100644 --- a/src/models/repositories/user-group.ts +++ b/src/models/repositories/user-group.ts @@ -1,6 +1,5 @@ import { EntityRepository, Repository } from 'typeorm'; import { UserGroup } from '../entities/user-group'; -import { ensure } from '../../prelude/ensure'; import { UserGroupJoinings } from '..'; import { SchemaType } from '../../misc/schema'; @@ -11,7 +10,7 @@ export class UserGroupRepository extends Repository<UserGroup> { public async pack( src: UserGroup['id'] | UserGroup, ): Promise<PackedUserGroup> { - const userGroup = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const userGroup = typeof src === 'object' ? src : await this.findOneOrFail(src); const users = await UserGroupJoinings.find({ userGroupId: userGroup.id diff --git a/src/models/repositories/user-list.ts b/src/models/repositories/user-list.ts index 8842118be44e4e49e3a0ae503151148a3fd709fe..9421aeb0c7b9c18eb2dd6f8ab1ab8f718113cc78 100644 --- a/src/models/repositories/user-list.ts +++ b/src/models/repositories/user-list.ts @@ -1,6 +1,5 @@ import { EntityRepository, Repository } from 'typeorm'; import { UserList } from '../entities/user-list'; -import { ensure } from '../../prelude/ensure'; import { UserListJoinings } from '..'; import { SchemaType } from '../../misc/schema'; @@ -11,7 +10,7 @@ export class UserListRepository extends Repository<UserList> { public async pack( src: UserList['id'] | UserList, ): Promise<PackedUserList> { - const userList = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const userList = typeof src === 'object' ? src : await this.findOneOrFail(src); const users = await UserListJoinings.find({ userListId: userList.id diff --git a/src/models/repositories/user.ts b/src/models/repositories/user.ts index a3453b1aa61a199522665a696fb6544c3cf760a4..7502e7a08e733f0a3939424299bf50921767d461 100644 --- a/src/models/repositories/user.ts +++ b/src/models/repositories/user.ts @@ -2,7 +2,6 @@ import $ from 'cafy'; import { EntityRepository, Repository, In, Not } from 'typeorm'; import { User, ILocalUser, IRemoteUser } from '../entities/user'; import { Emojis, Notes, NoteUnreads, FollowRequests, Notifications, MessagingMessages, UserNotePinings, Followings, Blockings, Mutings, UserProfiles, UserSecurityKeys, UserGroupJoinings, Pages, Announcements, AnnouncementReads, Antennas, AntennaNotes, ChannelFollowings, Instances } from '..'; -import { ensure } from '../../prelude/ensure'; import config from '../../config'; import { SchemaType } from '../../misc/schema'; import { awaitAll } from '../../prelude/await-all'; @@ -157,7 +156,7 @@ export class UserRepository extends Repository<User> { includeSecrets: false }, options); - const user = typeof src === 'object' ? src : await this.findOne(src).then(ensure); + const user = typeof src === 'object' ? src : await this.findOneOrFail(src); const meId = me ? typeof me === 'string' ? me : me.id : null; const relation = meId && (meId !== user.id) && opts.detail ? await this.getRelation(meId, user.id) : null; @@ -165,7 +164,7 @@ export class UserRepository extends Repository<User> { where: { userId: user.id }, order: { id: 'DESC' } }) : []; - const profile = opts.detail ? await UserProfiles.findOne(user.id).then(ensure) : null; + const profile = opts.detail ? await UserProfiles.findOneOrFail(user.id) : null; const falsy = opts.detail ? false : undefined; diff --git a/src/prelude/ensure.ts b/src/prelude/ensure.ts deleted file mode 100644 index 1af281c05650104938bae478a914e0955ca5f34e..0000000000000000000000000000000000000000 --- a/src/prelude/ensure.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * 値㌠null ã¾ãŸã¯ undefined ã®å ´åˆã¯ã‚¨ãƒ©ãƒ¼ã‚’発生ã•ã›ã€ãã†ã§ãªã„å ´åˆã¯å€¤ã‚’ãã®ã¾ã¾è¿”ã—ã¾ã™ - */ -export function ensure<T>(x: T): NonNullable<T> { - if (x == null) { - throw new Error('ã¬ã‚‹ã½'); - } else { - return x!; - } -} diff --git a/src/queue/processors/db/export-notes.ts b/src/queue/processors/db/export-notes.ts index 0fd8c02c4ad6731d546b877742de2bc80a796b39..f76a47aacd01002f9d9b63940c548bff66a09dda 100644 --- a/src/queue/processors/db/export-notes.ts +++ b/src/queue/processors/db/export-notes.ts @@ -9,7 +9,6 @@ import { Users, Notes, Polls } from '../../../models'; import { MoreThan } from 'typeorm'; import { Note } from '../../../models/entities/note'; import { Poll } from '../../../models/entities/poll'; -import { ensure } from '../../../prelude/ensure'; const logger = queueLogger.createSubLogger('export-notes'); @@ -70,7 +69,7 @@ export async function exportNotes(job: Bull.Job, done: any): Promise<void> { for (const note of notes) { let poll: Poll | undefined; if (note.hasPoll) { - poll = await Polls.findOne({ noteId: note.id }).then(ensure); + poll = await Polls.findOneOrFail({ noteId: note.id }); } const content = JSON.stringify(serialize(note, poll)); await new Promise((res, rej) => { diff --git a/src/remote/activitypub/db-resolver.ts b/src/remote/activitypub/db-resolver.ts index cad2212b7082e5b38ca5a57bb2f401ef205c8000..26162b6b23a13a19023ee1bd9a484ef288b3c04f 100644 --- a/src/remote/activitypub/db-resolver.ts +++ b/src/remote/activitypub/db-resolver.ts @@ -6,7 +6,6 @@ import { MessagingMessage } from '../../models/entities/messaging-message'; import { Notes, Users, UserPublickeys, MessagingMessages } from '../../models'; import { IObject, getApId } from './type'; import { resolvePerson } from './models/person'; -import { ensure } from '../../prelude/ensure'; import escapeRegexp = require('escape-regexp'); export default class DbResolver { @@ -99,7 +98,7 @@ export default class DbResolver { if (user == null) return null; - const key = await UserPublickeys.findOne(user.id).then(ensure); + const key = await UserPublickeys.findOneOrFail(user.id); return { user, diff --git a/src/remote/activitypub/models/image.ts b/src/remote/activitypub/models/image.ts index 84a1040b2e7a03b6e14db377fe44f0fde9c0ef5c..dd8086cbeb7e2bce35b25770ff8ad4d9edd22319 100644 --- a/src/remote/activitypub/models/image.ts +++ b/src/remote/activitypub/models/image.ts @@ -5,7 +5,6 @@ import { fetchMeta } from '../../../misc/fetch-meta'; import { apLogger } from '../logger'; import { DriveFile } from '../../../models/entities/drive-file'; import { DriveFiles } from '../../../models'; -import { ensure } from '../../../prelude/ensure'; const logger = apLogger; @@ -40,7 +39,7 @@ export async function createImage(actor: IRemoteUser, value: any): Promise<Drive uri: image.url }); - file = await DriveFiles.findOne(file.id).then(ensure); + file = await DriveFiles.findOneOrFail(file.id); } } diff --git a/src/remote/activitypub/models/note.ts b/src/remote/activitypub/models/note.ts index feaee2f63094705eb4a31e5b7097beadacb2bd5e..e3488800ca397f021e471778c6eecf27757ba005 100644 --- a/src/remote/activitypub/models/note.ts +++ b/src/remote/activitypub/models/note.ts @@ -21,7 +21,6 @@ import { IObject, getOneApId, getApId, getOneApHrefNullable, validPost, IPost, i import { Emoji } from '../../../models/entities/emoji'; import { genId } from '../../../misc/gen-id'; import { fetchMeta } from '../../../misc/fetch-meta'; -import { ensure } from '../../../prelude/ensure'; import { getApLock } from '../../../misc/app-lock'; import { createMessage } from '../../../services/messages/create'; import { parseAudience } from '../audience'; @@ -201,7 +200,7 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s // vote if (reply && reply.hasPoll) { - const poll = await Polls.findOne(reply.id).then(ensure); + const poll = await Polls.findOneOrFail(reply.id); const tryCreateVote = async (name: string, index: number): Promise<null> => { if (poll.expiresAt && Date.now() > new Date(poll.expiresAt).getTime()) { diff --git a/src/remote/activitypub/models/person.ts b/src/remote/activitypub/models/person.ts index 73a2ebc0232af298dd33ec011285372fd3149ce5..5840d67020ca26858219ba5ff46fe5b164224628 100644 --- a/src/remote/activitypub/models/person.ts +++ b/src/remote/activitypub/models/person.ts @@ -24,7 +24,6 @@ import { toPuny } from '../../../misc/convert-host'; import { UserProfile } from '../../../models/entities/user-profile'; import { validActor } from '../../../remote/activitypub/type'; import { getConnection } from 'typeorm'; -import { ensure } from '../../../prelude/ensure'; import { toArray } from '../../../prelude/array'; import { fetchInstanceMetadata } from '../../../services/fetch-instance-metadata'; import { normalizeForSearch } from '../../../misc/normalize-for-search'; @@ -457,7 +456,7 @@ export function analyzeAttachments(attachments: IObject | IObject[] | undefined) } export async function updateFeatured(userId: User['id']) { - const user = await Users.findOne(userId).then(ensure); + const user = await Users.findOneOrFail(userId); if (!Users.isRemoteUser(user)) return; if (!user.featured) return; diff --git a/src/remote/activitypub/renderer/follow-user.ts b/src/remote/activitypub/renderer/follow-user.ts index 6d354803e5c3d4396072f4f391a04b81a3b10a20..bfc91bb4cbc769f19c34aaba58b5124645d02e57 100644 --- a/src/remote/activitypub/renderer/follow-user.ts +++ b/src/remote/activitypub/renderer/follow-user.ts @@ -1,13 +1,12 @@ import config from '../../../config'; import { Users } from '../../../models'; import { User } from '../../../models/entities/user'; -import { ensure } from '../../../prelude/ensure'; /** * Convert (local|remote)(Follower|Followee)ID to URL * @param id Follower|Followee ID */ export default async function renderFollowUser(id: User['id']): Promise<any> { - const user = await Users.findOne(id).then(ensure); + const user = await Users.findOneOrFail(id); return Users.isLocalUser(user) ? `${config.url}/users/${user.id}` : user.uri; } diff --git a/src/remote/activitypub/renderer/index.ts b/src/remote/activitypub/renderer/index.ts index a34febff2f022e2fc4ffa53376b5cd3489f9ec26..e74affdadfbed367ee82dea3eae08781cae898f5 100644 --- a/src/remote/activitypub/renderer/index.ts +++ b/src/remote/activitypub/renderer/index.ts @@ -4,7 +4,6 @@ import { IActivity } from '../type'; import { LdSignature } from '../misc/ld-signature'; import { ILocalUser } from '../../../models/entities/user'; import { UserKeypairs } from '../../../models'; -import { ensure } from '../../../prelude/ensure'; export const renderActivity = (x: any): IActivity | null => { if (x == null) return null; @@ -24,9 +23,9 @@ export const renderActivity = (x: any): IActivity | null => { export const attachLdSignature = async (activity: any, user: ILocalUser): Promise<IActivity | null> => { if (activity == null) return null; - const keypair = await UserKeypairs.findOne({ + const keypair = await UserKeypairs.findOneOrFail({ userId: user.id - }).then(ensure); + }); const obj = { // as non-standards diff --git a/src/remote/activitypub/renderer/note.ts b/src/remote/activitypub/renderer/note.ts index 6878a402b805e24ac47817a709a59ef491df5cb2..8e3e0e9ba1edb0019c3c4d7206748217b346d6c7 100644 --- a/src/remote/activitypub/renderer/note.ts +++ b/src/remote/activitypub/renderer/note.ts @@ -10,7 +10,6 @@ import { DriveFiles, Notes, Users, Emojis, Polls } from '../../../models'; import { In } from 'typeorm'; import { Emoji } from '../../../models/entities/emoji'; import { Poll } from '../../../models/entities/poll'; -import { ensure } from '../../../prelude/ensure'; export default async function renderNote(note: Note, dive = true, isTalk = false): Promise<any> { const getPromisedFiles = async (ids: string[]) => { @@ -54,7 +53,7 @@ export default async function renderNote(note: Note, dive = true, isTalk = false } } - const user = await Users.findOne(note.userId).then(ensure); + const user = await Users.findOneOrFail(note.userId); const attributedTo = `${config.url}/users/${user.id}`; diff --git a/src/remote/activitypub/renderer/person.ts b/src/remote/activitypub/renderer/person.ts index 4462f88315d267f9fdbab90af3d5b9880dc4087c..4907e3bc6f7f234caea596429851d0e69e6d3db4 100644 --- a/src/remote/activitypub/renderer/person.ts +++ b/src/remote/activitypub/renderer/person.ts @@ -9,7 +9,6 @@ import renderEmoji from './emoji'; import { IIdentifier } from '../models/identifier'; import renderHashtag from './hashtag'; import { DriveFiles, UserProfiles, UserKeypairs } from '../../../models'; -import { ensure } from '../../../prelude/ensure'; export async function renderPerson(user: ILocalUser) { const id = `${config.url}/users/${user.id}`; @@ -18,7 +17,7 @@ export async function renderPerson(user: ILocalUser) { const [avatar, banner, profile] = await Promise.all([ user.avatarId ? DriveFiles.findOne(user.avatarId) : Promise.resolve(undefined), user.bannerId ? DriveFiles.findOne(user.bannerId) : Promise.resolve(undefined), - UserProfiles.findOne(user.id).then(ensure) + UserProfiles.findOneOrFail(user.id) ]); const attachment: { @@ -50,7 +49,7 @@ export async function renderPerson(user: ILocalUser) { ...hashtagTags, ]; - const keypair = await UserKeypairs.findOne(user.id).then(ensure); + const keypair = await UserKeypairs.findOneOrFail(user.id); const person = { type: isSystem ? 'Application' : user.isBot ? 'Service' : 'Person', diff --git a/src/remote/activitypub/request.ts b/src/remote/activitypub/request.ts index 0edfcee1e33d32630d0e1b1bd79544fc02a6072c..2f0735163528e84e2aed3eefdebcb06a5dd511e2 100644 --- a/src/remote/activitypub/request.ts +++ b/src/remote/activitypub/request.ts @@ -6,7 +6,6 @@ import * as crypto from 'crypto'; import config from '../../config'; import { ILocalUser } from '../../models/entities/user'; import { UserKeypairs } from '../../models'; -import { ensure } from '../../prelude/ensure'; import { getAgentByUrl } from '../../misc/fetch'; import { URL } from 'url'; import got from 'got'; @@ -23,9 +22,9 @@ export default async (user: ILocalUser, url: string, object: any) => { sha256.update(data); const hash = sha256.digest('base64'); - const keypair = await UserKeypairs.findOne({ + const keypair = await UserKeypairs.findOneOrFail({ userId: user.id - }).then(ensure); + }); await new Promise((resolve, reject) => { const req = https.request({ @@ -75,9 +74,9 @@ export default async (user: ILocalUser, url: string, object: any) => { export async function signedGet(url: string, user: ILocalUser) { const timeout = 10 * 1000; - const keypair = await UserKeypairs.findOne({ + const keypair = await UserKeypairs.findOneOrFail({ userId: user.id - }).then(ensure); + }); const req = got.get<any>(url, { headers: { diff --git a/src/server/activitypub.ts b/src/server/activitypub.ts index c665fe28cae512a3bab67d15baa928bc618c3c5e..bf712586255dd39312d2ac2db87643dc6a9d20ff 100644 --- a/src/server/activitypub.ts +++ b/src/server/activitypub.ts @@ -16,7 +16,6 @@ import { isSelfHost } from '../misc/convert-host'; import { Notes, Users, Emojis, UserKeypairs, NoteReactions } from '../models'; import { ILocalUser, User } from '../models/entities/user'; import { In } from 'typeorm'; -import { ensure } from '../prelude/ensure'; import { renderLike } from '../remote/activitypub/renderer/like'; // Init router @@ -136,7 +135,7 @@ router.get('/users/:user/publickey', async ctx => { return; } - const keypair = await UserKeypairs.findOne(user.id).then(ensure); + const keypair = await UserKeypairs.findOneOrFail(user.id); if (Users.isLocalUser(user)) { ctx.body = renderActivity(renderKey(user, keypair)); diff --git a/src/server/activitypub/featured.ts b/src/server/activitypub/featured.ts index 80a7852f5964e36ce563efbac9f62bc5ade75935..66ad2aa86e37d7728eecc8d21ce231060751932a 100644 --- a/src/server/activitypub/featured.ts +++ b/src/server/activitypub/featured.ts @@ -5,7 +5,6 @@ import renderOrderedCollection from '../../remote/activitypub/renderer/ordered-c import { setResponseType } from '../activitypub'; import renderNote from '../../remote/activitypub/renderer/note'; import { Users, Notes, UserNotePinings } from '../../models'; -import { ensure } from '../../prelude/ensure'; export default async (ctx: Router.RouterContext) => { const userId = ctx.params.user; @@ -27,7 +26,7 @@ export default async (ctx: Router.RouterContext) => { }); const pinnedNotes = await Promise.all(pinings.map(pining => - Notes.findOne(pining.noteId).then(ensure))); + Notes.findOneOrFail(pining.noteId))); const renderedNotes = await Promise.all(pinnedNotes.map(note => renderNote(note))); diff --git a/src/server/activitypub/outbox.ts b/src/server/activitypub/outbox.ts index 03cf65bce63585c22189ff65a17e031e31d8c9f4..3c1b07a6796803bcccd39a69966640e21a8e2e43 100644 --- a/src/server/activitypub/outbox.ts +++ b/src/server/activitypub/outbox.ts @@ -15,7 +15,6 @@ import { Users, Notes } from '../../models'; import { makePaginationQuery } from '../api/common/make-pagination-query'; import { Brackets } from 'typeorm'; import { Note } from '../../models/entities/note'; -import { ensure } from '../../prelude/ensure'; export default async (ctx: Router.RouterContext) => { const userId = ctx.params.user; @@ -101,7 +100,7 @@ export default async (ctx: Router.RouterContext) => { */ export async function packActivity(note: Note): Promise<any> { if (note.renoteId && note.text == null && !note.hasPoll && (note.fileIds == null || note.fileIds.length === 0)) { - const renote = await Notes.findOne(note.renoteId).then(ensure); + const renote = await Notes.findOneOrFail(note.renoteId); return renderAnnounce(renote.uri ? renote.uri : `${config.url}/notes/${renote.id}`, note); } diff --git a/src/server/api/authenticate.ts b/src/server/api/authenticate.ts index 0785372b3b6379bfd616092a6d1d8c9e30b2f825..0374ca35ea8fc87bd515fbd886c5e6adb21d6255 100644 --- a/src/server/api/authenticate.ts +++ b/src/server/api/authenticate.ts @@ -1,7 +1,6 @@ import isNativeToken from './common/is-native-token'; import { User } from '../../models/entities/user'; import { Users, AccessTokens, Apps } from '../../models'; -import { ensure } from '../../prelude/ensure'; import { AccessToken } from '../../models/entities/access-token'; export default async (token: string): Promise<[User | null | undefined, AccessToken | null | undefined]> => { @@ -43,7 +42,7 @@ export default async (token: string): Promise<[User | null | undefined, AccessTo if (accessToken.appId) { const app = await Apps - .findOne(accessToken.appId).then(ensure); + .findOneOrFail(accessToken.appId); return [user, { id: accessToken.id, diff --git a/src/server/api/common/inject-featured.ts b/src/server/api/common/inject-featured.ts index 098d20e72d066622d266fd8da0f21e619eb5e796..3f47c133859eb42a9f21bcf0f27f1d5c1258ae23 100644 --- a/src/server/api/common/inject-featured.ts +++ b/src/server/api/common/inject-featured.ts @@ -3,7 +3,6 @@ import { Note } from '../../../models/entities/note'; import { User } from '../../../models/entities/user'; import { Notes, UserProfiles, NoteReactions } from '../../../models'; import { generateMutedUserQuery } from './generate-muted-user-query'; -import { ensure } from '../../../prelude/ensure'; // TODO: リアクションã€Renoteã€è¿”ä¿¡ãªã©ã‚’ã—ãŸãƒŽãƒ¼ãƒˆã¯é™¤å¤–ã™ã‚‹ @@ -11,7 +10,7 @@ export async function injectFeatured(timeline: Note[], user?: User | null) { if (timeline.length < 5) return; if (user) { - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); if (!profile.injectFeaturedNote) return; } diff --git a/src/server/api/common/inject-promo.ts b/src/server/api/common/inject-promo.ts index f694ce6ea06b84d05536aeb90f91fa99034cdc14..2c16ca4cf7c2184287bf8bba3dddee7603af7c23 100644 --- a/src/server/api/common/inject-promo.ts +++ b/src/server/api/common/inject-promo.ts @@ -2,7 +2,6 @@ import rndstr from 'rndstr'; import { Note } from '../../../models/entities/note'; import { User } from '../../../models/entities/user'; import { PromoReads, PromoNotes, Notes, Users } from '../../../models'; -import { ensure } from '../../../prelude/ensure'; export async function injectPromo(timeline: Note[], user?: User | null) { if (timeline.length < 5) return; @@ -23,10 +22,10 @@ export async function injectPromo(timeline: Note[], user?: User | null) { // Pick random promo const promo = promos[Math.floor(Math.random() * promos.length)]; - const note = await Notes.findOne(promo.noteId).then(ensure); + const note = await Notes.findOneOrFail(promo.noteId); // Join - note.user = await Users.findOne(note.userId).then(ensure); + note.user = await Users.findOneOrFail(note.userId); (note as any)._prId_ = rndstr('a-z0-9', 8); diff --git a/src/server/api/endpoints/admin/federation/remove-all-following.ts b/src/server/api/endpoints/admin/federation/remove-all-following.ts index 76497c0dd835515c3a306cd64e5f9c5db8e1f453..e593193552968e8bf599b205dfe5fc9334081fe0 100644 --- a/src/server/api/endpoints/admin/federation/remove-all-following.ts +++ b/src/server/api/endpoints/admin/federation/remove-all-following.ts @@ -2,7 +2,6 @@ import $ from 'cafy'; import define from '../../../define'; import deleteFollowing from '../../../../../services/following/delete'; import { Followings, Users } from '../../../../../models'; -import { ensure } from '../../../../../prelude/ensure'; export const meta = { tags: ['admin'], @@ -23,8 +22,8 @@ export default define(meta, async (ps, me) => { }); const pairs = await Promise.all(followings.map(f => Promise.all([ - Users.findOne(f.followerId).then(ensure), - Users.findOne(f.followeeId).then(ensure) + Users.findOneOrFail(f.followerId), + Users.findOneOrFail(f.followeeId) ]))); for (const pair of pairs) { diff --git a/src/server/api/endpoints/auth/accept.ts b/src/server/api/endpoints/auth/accept.ts index e98242a3c3af5260d4d1bbd34421d5d497a6e612..6d4d31fa1e7709444a8417a2d31afde784eb7446 100644 --- a/src/server/api/endpoints/auth/accept.ts +++ b/src/server/api/endpoints/auth/accept.ts @@ -4,7 +4,6 @@ import define from '../../define'; import { ApiError } from '../../error'; import { AuthSessions, AccessTokens, Apps } from '../../../../models'; import { genId } from '../../../../misc/gen-id'; -import { ensure } from '../../../../prelude/ensure'; import { secureRndstr } from '../../../../misc/secure-rndstr'; export const meta = { @@ -49,7 +48,7 @@ export default define(meta, async (ps, user) => { if (exist == null) { // Lookup app - const app = await Apps.findOne(session.appId).then(ensure); + const app = await Apps.findOneOrFail(session.appId); // Generate Hash const sha256 = crypto.createHash('sha256'); diff --git a/src/server/api/endpoints/auth/session/userkey.ts b/src/server/api/endpoints/auth/session/userkey.ts index 7b474c82954153fcce04d225cd90ae554014983e..68d0c7bdf1f8c4d04f84ba81a048ad6b6b5a8f5c 100644 --- a/src/server/api/endpoints/auth/session/userkey.ts +++ b/src/server/api/endpoints/auth/session/userkey.ts @@ -2,7 +2,6 @@ import $ from 'cafy'; import define from '../../../define'; import { ApiError } from '../../../error'; import { Apps, AuthSessions, AccessTokens, Users } from '../../../../../models'; -import { ensure } from '../../../../../prelude/ensure'; export const meta = { tags: ['auth'], @@ -92,10 +91,10 @@ export default define(meta, async (ps) => { } // Lookup access token - const accessToken = await AccessTokens.findOne({ + const accessToken = await AccessTokens.findOneOrFail({ appId: app.id, userId: session.userId - }).then(ensure); + }); // Delete session AuthSessions.delete(session.id); diff --git a/src/server/api/endpoints/i.ts b/src/server/api/endpoints/i.ts index 3d0c092adb0cbb67989eb291b28d988dab8e9f90..e5b65e09301e5ae3b2eddb331d3f33e939cbfac4 100644 --- a/src/server/api/endpoints/i.ts +++ b/src/server/api/endpoints/i.ts @@ -1,6 +1,5 @@ import define from '../define'; import { RegistryItems, UserProfiles, Users } from '../../../models'; -import { ensure } from '../../../prelude/ensure'; import { genId } from '../../../misc/gen-id'; export const meta = { @@ -25,7 +24,7 @@ export default define(meta, async (ps, user, token) => { const isSecure = token == null; // TODO: ãã®ã†ã¡æ¶ˆã™ - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); for (const [k, v] of Object.entries(profile.clientData)) { await RegistryItems.insert({ id: genId(), diff --git a/src/server/api/endpoints/i/2fa/done.ts b/src/server/api/endpoints/i/2fa/done.ts index 7d35f929e0571795b3006b8d0571cdc4b72b1904..9a74d7675bd8893505e378508a3eff99c82086df 100644 --- a/src/server/api/endpoints/i/2fa/done.ts +++ b/src/server/api/endpoints/i/2fa/done.ts @@ -2,7 +2,6 @@ import $ from 'cafy'; import * as speakeasy from 'speakeasy'; import define from '../../../define'; import { UserProfiles } from '../../../../../models'; -import { ensure } from '../../../../../prelude/ensure'; export const meta = { requireCredential: true as const, @@ -19,7 +18,7 @@ export const meta = { export default define(meta, async (ps, user) => { const token = ps.token.replace(/\s/g, ''); - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); if (profile.twoFactorTempSecret == null) { throw new Error('二段階èªè¨¼ã®è¨å®šãŒé–‹å§‹ã•ã‚Œã¦ã„ã¾ã›ã‚“'); diff --git a/src/server/api/endpoints/i/2fa/key-done.ts b/src/server/api/endpoints/i/2fa/key-done.ts index 8ac165e629fde067f9c0c90bb3239f2ffcf64f6b..4634944ca730995371d76704feb47eccd4c0c71e 100644 --- a/src/server/api/endpoints/i/2fa/key-done.ts +++ b/src/server/api/endpoints/i/2fa/key-done.ts @@ -9,7 +9,6 @@ import { AttestationChallenges, Users } from '../../../../../models'; -import { ensure } from '../../../../../prelude/ensure'; import config from '../../../../../config'; import { procedures, hash } from '../../../2fa'; import { publishMainStream } from '../../../../../services/stream'; @@ -43,7 +42,7 @@ export const meta = { const rpIdHashReal = hash(Buffer.from(config.hostname, 'utf-8')); export default define(meta, async (ps, user) => { - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); // Compare password const same = await bcrypt.compare(ps.password, profile.password!); diff --git a/src/server/api/endpoints/i/2fa/register-key.ts b/src/server/api/endpoints/i/2fa/register-key.ts index e189519a4cfca6d112cefb485f1616ac2e4a772e..d5cc11c7fbf1e840cb2f5d159f0889c2c95ec805 100644 --- a/src/server/api/endpoints/i/2fa/register-key.ts +++ b/src/server/api/endpoints/i/2fa/register-key.ts @@ -2,7 +2,6 @@ import $ from 'cafy'; import * as bcrypt from 'bcryptjs'; import define from '../../../define'; import { UserProfiles, AttestationChallenges } from '../../../../../models'; -import { ensure } from '../../../../../prelude/ensure'; import { promisify } from 'util'; import * as crypto from 'crypto'; import { genId } from '../../../../../misc/gen-id'; @@ -23,7 +22,7 @@ export const meta = { }; export default define(meta, async (ps, user) => { - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); // Compare password const same = await bcrypt.compare(ps.password, profile.password!); diff --git a/src/server/api/endpoints/i/2fa/register.ts b/src/server/api/endpoints/i/2fa/register.ts index 784b276a26cccb3605c4b0013f391bfa54c3e366..a39b2963e9f7976f36629e56c451a458ee82213f 100644 --- a/src/server/api/endpoints/i/2fa/register.ts +++ b/src/server/api/endpoints/i/2fa/register.ts @@ -5,7 +5,6 @@ import * as QRCode from 'qrcode'; import config from '../../../../../config'; import define from '../../../define'; import { UserProfiles } from '../../../../../models'; -import { ensure } from '../../../../../prelude/ensure'; export const meta = { requireCredential: true as const, @@ -20,7 +19,7 @@ export const meta = { }; export default define(meta, async (ps, user) => { - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); // Compare password const same = await bcrypt.compare(ps.password, profile.password!); diff --git a/src/server/api/endpoints/i/2fa/remove-key.ts b/src/server/api/endpoints/i/2fa/remove-key.ts index 3eb92ba19dd855fe9bbcc3e576cc4201cfa1f21d..135f0eb284852a1b4e674e402b59443a70145fde 100644 --- a/src/server/api/endpoints/i/2fa/remove-key.ts +++ b/src/server/api/endpoints/i/2fa/remove-key.ts @@ -2,7 +2,6 @@ import $ from 'cafy'; import * as bcrypt from 'bcryptjs'; import define from '../../../define'; import { UserProfiles, UserSecurityKeys, Users } from '../../../../../models'; -import { ensure } from '../../../../../prelude/ensure'; import { publishMainStream } from '../../../../../services/stream'; export const meta = { @@ -21,7 +20,7 @@ export const meta = { }; export default define(meta, async (ps, user) => { - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); // Compare password const same = await bcrypt.compare(ps.password, profile.password!); diff --git a/src/server/api/endpoints/i/2fa/unregister.ts b/src/server/api/endpoints/i/2fa/unregister.ts index f1287b2dcaccbcaa43e28b9d1503427f3a21bdf9..e809f40c71654523cb4034af2af307f8aa1e1b08 100644 --- a/src/server/api/endpoints/i/2fa/unregister.ts +++ b/src/server/api/endpoints/i/2fa/unregister.ts @@ -2,7 +2,6 @@ import $ from 'cafy'; import * as bcrypt from 'bcryptjs'; import define from '../../../define'; import { UserProfiles } from '../../../../../models'; -import { ensure } from '../../../../../prelude/ensure'; export const meta = { requireCredential: true as const, @@ -17,7 +16,7 @@ export const meta = { }; export default define(meta, async (ps, user) => { - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); // Compare password const same = await bcrypt.compare(ps.password, profile.password!); diff --git a/src/server/api/endpoints/i/change-password.ts b/src/server/api/endpoints/i/change-password.ts index bc2ec3d7b54914153ee362b10a6867ef281f7a17..0a8b86e665d0e244d148fec31d5cceaaea5956d8 100644 --- a/src/server/api/endpoints/i/change-password.ts +++ b/src/server/api/endpoints/i/change-password.ts @@ -2,7 +2,6 @@ import $ from 'cafy'; import * as bcrypt from 'bcryptjs'; import define from '../../define'; import { UserProfiles } from '../../../../models'; -import { ensure } from '../../../../prelude/ensure'; export const meta = { requireCredential: true as const, @@ -21,7 +20,7 @@ export const meta = { }; export default define(meta, async (ps, user) => { - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); // Compare password const same = await bcrypt.compare(ps.currentPassword, profile.password!); diff --git a/src/server/api/endpoints/i/delete-account.ts b/src/server/api/endpoints/i/delete-account.ts index 49a334917034abd12a5263dcb93d78891cfa5f5e..0f04c4c92d9416ec3711dcf1ba8f2668657c26ca 100644 --- a/src/server/api/endpoints/i/delete-account.ts +++ b/src/server/api/endpoints/i/delete-account.ts @@ -2,7 +2,6 @@ import $ from 'cafy'; import * as bcrypt from 'bcryptjs'; import define from '../../define'; import { Users, UserProfiles } from '../../../../models'; -import { ensure } from '../../../../prelude/ensure'; import { doPostSuspend } from '../../../../services/suspend-user'; export const meta = { @@ -18,7 +17,7 @@ export const meta = { }; export default define(meta, async (ps, user) => { - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); // Compare password const same = await bcrypt.compare(ps.password, profile.password!); diff --git a/src/server/api/endpoints/i/regenerate-token.ts b/src/server/api/endpoints/i/regenerate-token.ts index 5d322aa122f40bae3ea7f52ffb8964303fe9fb3b..3596e20197d63c47608c8a532c5ea6f3905de21a 100644 --- a/src/server/api/endpoints/i/regenerate-token.ts +++ b/src/server/api/endpoints/i/regenerate-token.ts @@ -4,7 +4,6 @@ import { publishMainStream } from '../../../../services/stream'; import generateUserToken from '../../common/generate-native-user-token'; import define from '../../define'; import { Users, UserProfiles } from '../../../../models'; -import { ensure } from '../../../../prelude/ensure'; export const meta = { requireCredential: true as const, @@ -19,7 +18,7 @@ export const meta = { }; export default define(meta, async (ps, user) => { - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); // Compare password const same = await bcrypt.compare(ps.password, profile.password!); diff --git a/src/server/api/endpoints/i/update-email.ts b/src/server/api/endpoints/i/update-email.ts index d3d7bace75b8bc93d0fb990c34991b6f75ec3b3e..730918aebeb08e437155b3227042f1e64a0444c3 100644 --- a/src/server/api/endpoints/i/update-email.ts +++ b/src/server/api/endpoints/i/update-email.ts @@ -6,7 +6,6 @@ import config from '../../../../config'; import * as ms from 'ms'; import * as bcrypt from 'bcryptjs'; import { Users, UserProfiles } from '../../../../models'; -import { ensure } from '../../../../prelude/ensure'; import { sendEmail } from '../../../../services/send-email'; import { ApiError } from '../../error'; @@ -40,7 +39,7 @@ export const meta = { }; export default define(meta, async (ps, user) => { - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); // Compare password const same = await bcrypt.compare(ps.password, profile.password!); diff --git a/src/server/api/endpoints/i/update.ts b/src/server/api/endpoints/i/update.ts index bf1796924aeb9f5d6a2e03549cad1ac9f1117d63..3d7f1fa76f2668b5647b8dfd6a2210a5fc592392 100644 --- a/src/server/api/endpoints/i/update.ts +++ b/src/server/api/endpoints/i/update.ts @@ -13,7 +13,6 @@ import { ApiError } from '../../error'; import { Users, DriveFiles, UserProfiles, Pages } from '../../../../models'; import { User } from '../../../../models/entities/user'; import { UserProfile } from '../../../../models/entities/user-profile'; -import { ensure } from '../../../../prelude/ensure'; import { notificationTypes } from '../../../../types'; import { normalizeForSearch } from '../../../../misc/normalize-for-search'; @@ -206,7 +205,7 @@ export default define(meta, async (ps, user, token) => { const updates = {} as Partial<User>; const profileUpdates = {} as Partial<UserProfile>; - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); if (ps.name !== undefined) updates.name = ps.name; if (ps.description !== undefined) profileUpdates.description = ps.description; diff --git a/src/server/api/endpoints/notes/delete.ts b/src/server/api/endpoints/notes/delete.ts index 65565ee3abef26c04d52984b72f71805d29f7703..5afd911ca9020ddf7cffc29da5268376564a8d2f 100644 --- a/src/server/api/endpoints/notes/delete.ts +++ b/src/server/api/endpoints/notes/delete.ts @@ -6,7 +6,6 @@ import * as ms from 'ms'; import { getNote } from '../../common/getters'; import { ApiError } from '../../error'; import { Users } from '../../../../models'; -import { ensure } from '../../../../prelude/ensure'; export const meta = { desc: { @@ -62,5 +61,5 @@ export default define(meta, async (ps, user) => { } // ã“ã®æ“作を行ã†ã®ãŒæŠ•ç¨¿è€…ã¨ã¯é™ã‚‰ãªã„(例ãˆã°ãƒ¢ãƒ‡ãƒ¬ãƒ¼ã‚¿ãƒ¼)ãŸã‚ - await deleteNote(await Users.findOne(note.userId).then(ensure), note); + await deleteNote(await Users.findOneOrFail(note.userId), note); }); diff --git a/src/server/api/endpoints/notes/polls/vote.ts b/src/server/api/endpoints/notes/polls/vote.ts index 1e6ab472cc0c59c12bf87e6ec12776773de9e310..6113d7ea9acf325ec2dc50d7efd0d3139681da47 100644 --- a/src/server/api/endpoints/notes/polls/vote.ts +++ b/src/server/api/endpoints/notes/polls/vote.ts @@ -13,7 +13,6 @@ import { PollVotes, NoteWatchings, Users, Polls } from '../../../../../models'; import { Not } from 'typeorm'; import { IRemoteUser } from '../../../../../models/entities/user'; import { genId } from '../../../../../misc/gen-id'; -import { ensure } from '../../../../../prelude/ensure'; export const meta = { desc: { @@ -87,7 +86,7 @@ export default define(meta, async (ps, user) => { throw new ApiError(meta.errors.noPoll); } - const poll = await Polls.findOne({ noteId: note.id }).then(ensure); + const poll = await Polls.findOneOrFail({ noteId: note.id }); if (poll.expiresAt && poll.expiresAt < createdAt) { throw new ApiError(meta.errors.alreadyExpired); @@ -153,7 +152,7 @@ export default define(meta, async (ps, user) => { // リモート投票ã®å ´åˆãƒªãƒ—ライé€ä¿¡ if (note.userHost != null) { - const pollOwner = await Users.findOne(note.userId).then(ensure) as IRemoteUser; + const pollOwner = await Users.findOneOrFail(note.userId) as IRemoteUser; deliver(user, renderActivity(await renderVote(user, vote, note, poll, pollOwner)), pollOwner.inbox); } diff --git a/src/server/api/endpoints/room/show.ts b/src/server/api/endpoints/room/show.ts index 96248a8c0cf4933536080b1dd7dc8e71ee82bf8e..e8af68956d91e16b75c14e2c91847bb811e699e0 100644 --- a/src/server/api/endpoints/room/show.ts +++ b/src/server/api/endpoints/room/show.ts @@ -3,7 +3,6 @@ import define from '../../define'; import { ApiError } from '../../error'; import { Users, UserProfiles } from '../../../../models'; import { ID } from '../../../../misc/cafy-id'; -import { ensure } from '../../../../prelude/ensure'; import { toPunyNullable } from '../../../../misc/convert-host'; export const meta = { @@ -51,7 +50,7 @@ export default define(meta, async (ps, me) => { throw new ApiError(meta.errors.noSuchUser); } - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); if (profile.room.furnitures == null) { await UserProfiles.update(user.id, { diff --git a/src/server/api/private/signin.ts b/src/server/api/private/signin.ts index 734758d63d3894e9845f0fc574a69a351774adaf..7a5efc6cc9ba42bcc8b91b47c775bb6127590e71 100644 --- a/src/server/api/private/signin.ts +++ b/src/server/api/private/signin.ts @@ -6,7 +6,6 @@ import config from '../../../config'; import { Users, Signins, UserProfiles, UserSecurityKeys, AttestationChallenges } from '../../../models'; import { ILocalUser } from '../../../models/entities/user'; import { genId } from '../../../misc/gen-id'; -import { ensure } from '../../../prelude/ensure'; import { verifyLogin, hash } from '../2fa'; import { randomBytes } from 'crypto'; @@ -47,7 +46,7 @@ export default async (ctx: Koa.Context) => { return; } - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); // Compare password const same = await bcrypt.compare(password, profile.password!); diff --git a/src/server/api/service/discord.ts b/src/server/api/service/discord.ts index 007458066d99172f754b5cb75eac960709bdb8df..fce840cde5e3e7ac3d694947bd622c59bdce5940 100644 --- a/src/server/api/service/discord.ts +++ b/src/server/api/service/discord.ts @@ -10,7 +10,6 @@ import signin from '../common/signin'; import { fetchMeta } from '../../../misc/fetch-meta'; import { Users, UserProfiles } from '../../../models'; import { ILocalUser } from '../../../models/entities/user'; -import { ensure } from '../../../prelude/ensure'; function getUserToken(ctx: Koa.Context) { return ((ctx.headers['cookie'] || '').match(/igi=(\w+)/) || [null, null])[1]; @@ -41,12 +40,12 @@ router.get('/disconnect/discord', async ctx => { return; } - const user = await Users.findOne({ + const user = await Users.findOneOrFail({ host: null, token: userToken - }).then(ensure); + }); - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); delete profile.integrations.discord; @@ -253,12 +252,12 @@ router.get('/dc/cb', async ctx => { return; } - const user = await Users.findOne({ + const user = await Users.findOneOrFail({ host: null, token: userToken - }).then(ensure); + }); - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); await UserProfiles.update(user.id, { integrations: { diff --git a/src/server/api/service/github.ts b/src/server/api/service/github.ts index 663c3cc7545a5be048704a0707952b140803971c..2b10fa02a0364abdd1b46eee7f92862098dc34fb 100644 --- a/src/server/api/service/github.ts +++ b/src/server/api/service/github.ts @@ -10,7 +10,6 @@ import signin from '../common/signin'; import { fetchMeta } from '../../../misc/fetch-meta'; import { Users, UserProfiles } from '../../../models'; import { ILocalUser } from '../../../models/entities/user'; -import { ensure } from '../../../prelude/ensure'; function getUserToken(ctx: Koa.Context) { return ((ctx.headers['cookie'] || '').match(/igi=(\w+)/) || [null, null])[1]; @@ -41,12 +40,12 @@ router.get('/disconnect/github', async ctx => { return; } - const user = await Users.findOne({ + const user = await Users.findOneOrFail({ host: null, token: userToken - }).then(ensure); + }); - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); delete profile.integrations.github; @@ -227,12 +226,12 @@ router.get('/gh/cb', async ctx => { return; } - const user = await Users.findOne({ + const user = await Users.findOneOrFail({ host: null, token: userToken - }).then(ensure); + }); - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); await UserProfiles.update(user.id, { integrations: { diff --git a/src/server/api/service/twitter.ts b/src/server/api/service/twitter.ts index 000eb57c1b5db073d7d3efbbab345a4c068dba11..97e9d3a7fcf19ec4f0b25809384f4cfc14b05701 100644 --- a/src/server/api/service/twitter.ts +++ b/src/server/api/service/twitter.ts @@ -9,7 +9,6 @@ import signin from '../common/signin'; import { fetchMeta } from '../../../misc/fetch-meta'; import { Users, UserProfiles } from '../../../models'; import { ILocalUser } from '../../../models/entities/user'; -import { ensure } from '../../../prelude/ensure'; function getUserToken(ctx: Koa.Context) { return ((ctx.headers['cookie'] || '').match(/igi=(\w+)/) || [null, null])[1]; @@ -40,12 +39,12 @@ router.get('/disconnect/twitter', async ctx => { return; } - const user = await Users.findOne({ + const user = await Users.findOneOrFail({ host: null, token: userToken - }).then(ensure); + }); - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); delete profile.integrations.twitter; @@ -163,12 +162,12 @@ router.get('/tw/cb', async ctx => { const result = await twAuth!.done(JSON.parse(twCtx), verifier); - const user = await Users.findOne({ + const user = await Users.findOneOrFail({ host: null, token: userToken - }).then(ensure); + }); - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); await UserProfiles.update(user.id, { integrations: { diff --git a/src/server/web/feed.ts b/src/server/web/feed.ts index 9c7591d744c0d55305ea78b186e4f16455c31035..6078fbe0f3592369db8fd22e48b062142c191517 100644 --- a/src/server/web/feed.ts +++ b/src/server/web/feed.ts @@ -3,7 +3,6 @@ import config from '../../config'; import { User } from '../../models/entities/user'; import { Notes, DriveFiles, UserProfiles } from '../../models'; import { In } from 'typeorm'; -import { ensure } from '../../prelude/ensure'; export default async function(user: User) { const author = { @@ -11,7 +10,7 @@ export default async function(user: User) { name: user.name || user.username }; - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); const notes = await Notes.find({ where: { diff --git a/src/server/web/index.ts b/src/server/web/index.ts index f3442c61999abb47d5cfcbe8708cfb0ceda8ee0c..8ea7e157519bd8d509d24d7598ef5cf2993cb422 100644 --- a/src/server/web/index.ts +++ b/src/server/web/index.ts @@ -20,7 +20,6 @@ import config from '../../config'; import { Users, Notes, Emojis, UserProfiles, Pages, Channels, Clips } from '../../models'; import parseAcct from '../../misc/acct/parse'; import { getNoteSummary } from '../../misc/get-note-summary'; -import { ensure } from '../../prelude/ensure'; import { getConnection } from 'typeorm'; import redis from '../../db/redis'; import locales = require('../../../locales'); @@ -199,7 +198,7 @@ router.get(['/@:user', '/@:user/:sub'], async (ctx, next) => { }); if (user != null) { - const profile = await UserProfiles.findOne(user.id).then(ensure); + const profile = await UserProfiles.findOneOrFail(user.id); const meta = await fetchMeta(); const me = profile.fields ? profile.fields @@ -242,7 +241,7 @@ router.get('/notes/:note', async ctx => { if (note) { const _note = await Notes.pack(note); - const profile = await UserProfiles.findOne(note.userId).then(ensure); + const profile = await UserProfiles.findOneOrFail(note.userId); const meta = await fetchMeta(); await ctx.render('note', { note: _note, @@ -282,7 +281,7 @@ router.get('/@:user/pages/:page', async ctx => { if (page) { const _page = await Pages.pack(page); - const profile = await UserProfiles.findOne(page.userId).then(ensure); + const profile = await UserProfiles.findOneOrFail(page.userId); const meta = await fetchMeta(); await ctx.render('page', { page: _page, @@ -311,7 +310,7 @@ router.get('/clips/:clip', async ctx => { if (clip) { const _clip = await Clips.pack(clip); - const profile = await UserProfiles.findOne(clip.userId).then(ensure); + const profile = await UserProfiles.findOneOrFail(clip.userId); const meta = await fetchMeta(); await ctx.render('clip', { clip: _clip, diff --git a/src/services/add-note-to-antenna.ts b/src/services/add-note-to-antenna.ts index f11607fd43dab11d03264c37c497c9522697e218..2c893488c33fd6bfb5e2293b8a2476ecd1fa4ad0 100644 --- a/src/services/add-note-to-antenna.ts +++ b/src/services/add-note-to-antenna.ts @@ -3,7 +3,6 @@ import { Note } from '../models/entities/note'; import { AntennaNotes, Mutings, Notes } from '../models'; import { genId } from '../misc/gen-id'; import { isMutedUserRelated } from '../misc/is-muted-user-related'; -import { ensure } from '../prelude/ensure'; import { publishAntennaStream, publishMainStream } from './stream'; import { User } from '../models/entities/user'; @@ -34,10 +33,10 @@ export async function addNoteToAntenna(antenna: Antenna, note: Note, noteUser: U }; if (note.replyId != null) { - _note.reply = await Notes.findOne(note.replyId).then(ensure); + _note.reply = await Notes.findOneOrFail(note.replyId); } if (note.renoteId != null) { - _note.renote = await Notes.findOne(note.renoteId).then(ensure); + _note.renote = await Notes.findOneOrFail(note.renoteId); } if (isMutedUserRelated(_note, new Set<string>(mutings.map(x => x.muteeId)))) { diff --git a/src/services/following/create.ts b/src/services/following/create.ts index c5f130f49ff8d1ef3dfc8f51a76e76b88ea59cae..c0583cdb867fb75e7cc2d06bbc1a466b98988f8c 100644 --- a/src/services/following/create.ts +++ b/src/services/following/create.ts @@ -14,7 +14,6 @@ import { instanceChart, perUserFollowingChart } from '../chart'; import { genId } from '../../misc/gen-id'; import { createNotification } from '../create-notification'; import { isDuplicateKeyValueError } from '../../misc/is-duplicate-key-value-error'; -import { ensure } from '../../prelude/ensure'; const logger = new Logger('following/create'); @@ -130,7 +129,7 @@ export default async function(follower: User, followee: User, requestId?: string if (blocked != null) throw new IdentifiableError('3338392a-f764-498d-8855-db939dcf8c48', 'blocked'); } - const followeeProfile = await UserProfiles.findOne(followee.id).then(ensure); + const followeeProfile = await UserProfiles.findOneOrFail(followee.id); // フォãƒãƒ¼å¯¾è±¡ãŒéµã‚¢ã‚«ã‚¦ãƒ³ãƒˆã§ã‚ã‚‹ or // フォãƒãƒ¯ãƒ¼ãŒBotã§ã‚ã‚Šã€ãƒ•ã‚©ãƒãƒ¼å¯¾è±¡ãŒBotã‹ã‚‰ã®ãƒ•ã‚©ãƒãƒ¼ã«æ…Žé‡ã§ã‚ã‚‹ or diff --git a/src/services/following/requests/accept-all.ts b/src/services/following/requests/accept-all.ts index 70e7448aad1d658dfcc146b3aaea794c954ecf60..da39965349e1a230e11ac5d6992697b5c226cbf0 100644 --- a/src/services/following/requests/accept-all.ts +++ b/src/services/following/requests/accept-all.ts @@ -1,7 +1,6 @@ import accept from './accept'; import { User } from '../../../models/entities/user'; import { FollowRequests, Users } from '../../../models'; -import { ensure } from '../../../prelude/ensure'; /** * 指定ã—ãŸãƒ¦ãƒ¼ã‚¶ãƒ¼å®›ã¦ã®ãƒ•ã‚©ãƒãƒ¼ãƒªã‚¯ã‚¨ã‚¹ãƒˆã‚’ã™ã¹ã¦æ‰¿èª @@ -13,7 +12,7 @@ export default async function(user: User) { }); for (const request of requests) { - const follower = await Users.findOne(request.followerId).then(ensure); + const follower = await Users.findOneOrFail(request.followerId); accept(user, follower); } } diff --git a/src/services/messages/delete.ts b/src/services/messages/delete.ts index 0efff85f397e904d20e3803610598e508d2ad348..c94a7b67db8bf6c4c2bb2fd348a6a2be20869ecb 100644 --- a/src/services/messages/delete.ts +++ b/src/services/messages/delete.ts @@ -1,5 +1,4 @@ import config from '../../config'; -import { ensure } from '../../prelude/ensure'; import { MessagingMessages, Users } from '../../models'; import { MessagingMessage } from '../../models/entities/messaging-message'; import { publishGroupMessagingStream, publishMessagingStream } from '../stream'; @@ -15,8 +14,8 @@ export async function deleteMessage(message: MessagingMessage) { async function postDeleteMessage(message: MessagingMessage) { if (message.recipientId) { - const user = await Users.findOne(message.userId).then(ensure); - const recipient = await Users.findOne(message.recipientId).then(ensure); + const user = await Users.findOneOrFail(message.userId); + const recipient = await Users.findOneOrFail(message.recipientId); if (Users.isLocalUser(user)) publishMessagingStream(message.userId, message.recipientId, 'deleted', message.id); if (Users.isLocalUser(recipient)) publishMessagingStream(message.recipientId, message.userId, 'deleted', message.id); diff --git a/src/services/note/create.ts b/src/services/note/create.ts index 62ec92f2bc2556877d96b2cac0e29362c139374c..563eaac7584c87f1588be50f84ad4a8e00fd73eb 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -26,7 +26,6 @@ import { notesChart, perUserNotesChart, activeUsersChart, instanceChart } from ' import { Poll, IPoll } from '../../models/entities/poll'; import { createNotification } from '../create-notification'; import { isDuplicateKeyValueError } from '../../misc/is-duplicate-key-value-error'; -import { ensure } from '../../prelude/ensure'; import { checkHitAntenna } from '../../misc/check-hit-antenna'; import { checkWordMute } from '../../misc/check-word-mute'; import { addNoteToAntenna } from '../add-note-to-antenna'; @@ -200,7 +199,7 @@ export default async (user: User, data: Option, silent = false) => new Promise<N tags = tags.filter(tag => Array.from(tag || '').length <= 128).splice(0, 32); if (data.reply && (user.id !== data.reply.userId) && !mentionedUsers.some(u => u.id === data.reply!.userId)) { - mentionedUsers.push(await Users.findOne(data.reply.userId).then(ensure)); + mentionedUsers.push(await Users.findOneOrFail(data.reply.userId)); } if (data.visibility == 'specified') { @@ -213,7 +212,7 @@ export default async (user: User, data: Option, silent = false) => new Promise<N } if (data.reply && !data.visibleUsers.some(x => x.id === data.reply!.userId)) { - data.visibleUsers.push(await Users.findOne(data.reply.userId).then(ensure)); + data.visibleUsers.push(await Users.findOneOrFail(data.reply.userId)); } }