refactor: resolve #7139
This commit is contained in:
parent
ebadd7fd3f
commit
91172654e4
|
@ -240,36 +240,6 @@ SQLでは配列のインデックスは**1始まり**。
|
||||||
MongoDBの時とは違い、findOneでレコードを取得する時に対象レコードが存在しない場合 **`undefined`** が返ってくるので注意。
|
MongoDBの時とは違い、findOneでレコードを取得する時に対象レコードが存在しない場合 **`undefined`** が返ってくるので注意。
|
||||||
MongoDBは`null`で返してきてたので、その感覚で`if (x === null)`とか書くとバグる。代わりに`if (x == null)`と書いてください
|
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作成方法
|
### Migration作成方法
|
||||||
```
|
```
|
||||||
npx ts-node ./node_modules/typeorm/cli.js migration:generate -n 変更の名前
|
npx ts-node ./node_modules/typeorm/cli.js migration:generate -n 変更の名前
|
||||||
|
|
|
@ -4,7 +4,6 @@ import { User } from '../models/entities/user';
|
||||||
import { UserListJoinings, UserGroupJoinings } from '../models';
|
import { UserListJoinings, UserGroupJoinings } from '../models';
|
||||||
import parseAcct from './acct/parse';
|
import parseAcct from './acct/parse';
|
||||||
import { getFullApAccount } from './convert-host';
|
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> {
|
export async function checkHitAntenna(antenna: Antenna, note: Note, noteUser: User, followers: User['id'][]): Promise<boolean> {
|
||||||
if (note.visibility === 'specified') return false;
|
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;
|
if (!listUsers.includes(note.userId)) return false;
|
||||||
} else if (antenna.src === 'group') {
|
} 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({
|
const groupUsers = (await UserGroupJoinings.find({
|
||||||
userGroupId: joining.userGroupId
|
userGroupId: joining.userGroupId
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import { fetchMeta } from './fetch-meta';
|
import { fetchMeta } from './fetch-meta';
|
||||||
import { ILocalUser } from '../models/entities/user';
|
import { ILocalUser } from '../models/entities/user';
|
||||||
import { Users } from '../models';
|
import { Users } from '../models';
|
||||||
import { ensure } from '../prelude/ensure';
|
|
||||||
|
|
||||||
export async function fetchProxyAccount(): Promise<ILocalUser | null> {
|
export async function fetchProxyAccount(): Promise<ILocalUser | null> {
|
||||||
const meta = await fetchMeta();
|
const meta = await fetchMeta();
|
||||||
if (meta.proxyAccountId == null) return null;
|
if (meta.proxyAccountId == null) return null;
|
||||||
return await Users.findOne(meta.proxyAccountId).then(ensure) as ILocalUser;
|
return await Users.findOneOrFail(meta.proxyAccountId) as ILocalUser;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { Users } from '..';
|
import { Users } from '..';
|
||||||
import { AbuseUserReport } from '../entities/abuse-user-report';
|
import { AbuseUserReport } from '../entities/abuse-user-report';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { awaitAll } from '../../prelude/await-all';
|
import { awaitAll } from '../../prelude/await-all';
|
||||||
|
|
||||||
@EntityRepository(AbuseUserReport)
|
@EntityRepository(AbuseUserReport)
|
||||||
|
@ -9,7 +8,7 @@ export class AbuseUserReportRepository extends Repository<AbuseUserReport> {
|
||||||
public async pack(
|
public async pack(
|
||||||
src: AbuseUserReport['id'] | AbuseUserReport,
|
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({
|
return await awaitAll({
|
||||||
id: report.id,
|
id: report.id,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { Antenna } from '../entities/antenna';
|
import { Antenna } from '../entities/antenna';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { SchemaType } from '../../misc/schema';
|
import { SchemaType } from '../../misc/schema';
|
||||||
import { AntennaNotes, UserGroupJoinings } from '..';
|
import { AntennaNotes, UserGroupJoinings } from '..';
|
||||||
|
|
||||||
|
@ -11,7 +10,7 @@ export class AntennaRepository extends Repository<Antenna> {
|
||||||
public async pack(
|
public async pack(
|
||||||
src: Antenna['id'] | Antenna,
|
src: Antenna['id'] | Antenna,
|
||||||
): Promise<PackedAntenna> {
|
): 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 hasUnreadNote = (await AntennaNotes.findOne({ antennaId: antenna.id, read: false })) != null;
|
||||||
const userGroupJoining = antenna.userGroupJoiningId ? await UserGroupJoinings.findOne(antenna.userGroupJoiningId) : null;
|
const userGroupJoining = antenna.userGroupJoiningId ? await UserGroupJoinings.findOne(antenna.userGroupJoiningId) : null;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { App } from '../entities/app';
|
import { App } from '../entities/app';
|
||||||
import { AccessTokens } from '..';
|
import { AccessTokens } from '..';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { SchemaType } from '../../misc/schema';
|
import { SchemaType } from '../../misc/schema';
|
||||||
|
|
||||||
export type PackedApp = SchemaType<typeof packedAppSchema>;
|
export type PackedApp = SchemaType<typeof packedAppSchema>;
|
||||||
|
@ -23,7 +22,7 @@ export class AppRepository extends Repository<App> {
|
||||||
includeProfileImageIds: false
|
includeProfileImageIds: false
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
const app = typeof src === 'object' ? src : await this.findOne(src).then(ensure);
|
const app = typeof src === 'object' ? src : await this.findOneOrFail(src);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: app.id,
|
id: app.id,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { Apps } from '..';
|
import { Apps } from '..';
|
||||||
import { AuthSession } from '../entities/auth-session';
|
import { AuthSession } from '../entities/auth-session';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { awaitAll } from '../../prelude/await-all';
|
import { awaitAll } from '../../prelude/await-all';
|
||||||
|
|
||||||
@EntityRepository(AuthSession)
|
@EntityRepository(AuthSession)
|
||||||
|
@ -10,7 +9,7 @@ export class AuthSessionRepository extends Repository<AuthSession> {
|
||||||
src: AuthSession['id'] | AuthSession,
|
src: AuthSession['id'] | AuthSession,
|
||||||
me?: any
|
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({
|
return await awaitAll({
|
||||||
id: session.id,
|
id: session.id,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { Users } from '..';
|
import { Users } from '..';
|
||||||
import { Blocking } from '../entities/blocking';
|
import { Blocking } from '../entities/blocking';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { awaitAll } from '../../prelude/await-all';
|
import { awaitAll } from '../../prelude/await-all';
|
||||||
import { SchemaType } from '../../misc/schema';
|
import { SchemaType } from '../../misc/schema';
|
||||||
|
|
||||||
|
@ -13,7 +12,7 @@ export class BlockingRepository extends Repository<Blocking> {
|
||||||
src: Blocking['id'] | Blocking,
|
src: Blocking['id'] | Blocking,
|
||||||
me?: any
|
me?: any
|
||||||
): Promise<PackedBlocking> {
|
): 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({
|
return await awaitAll({
|
||||||
id: blocking.id,
|
id: blocking.id,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { Channel } from '../entities/channel';
|
import { Channel } from '../entities/channel';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { SchemaType } from '../../misc/schema';
|
import { SchemaType } from '../../misc/schema';
|
||||||
import { DriveFiles, ChannelFollowings, NoteUnreads } from '..';
|
import { DriveFiles, ChannelFollowings, NoteUnreads } from '..';
|
||||||
import { User } from '../entities/user';
|
import { User } from '../entities/user';
|
||||||
|
@ -13,7 +12,7 @@ export class ChannelRepository extends Repository<Channel> {
|
||||||
src: Channel['id'] | Channel,
|
src: Channel['id'] | Channel,
|
||||||
me?: User['id'] | User | null | undefined,
|
me?: User['id'] | User | null | undefined,
|
||||||
): Promise<PackedChannel> {
|
): 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 meId = me ? typeof me === 'string' ? me : me.id : null;
|
||||||
|
|
||||||
const banner = channel.bannerId ? await DriveFiles.findOne(channel.bannerId) : null;
|
const banner = channel.bannerId ? await DriveFiles.findOne(channel.bannerId) : null;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { Clip } from '../entities/clip';
|
import { Clip } from '../entities/clip';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { SchemaType } from '../../misc/schema';
|
import { SchemaType } from '../../misc/schema';
|
||||||
import { Users } from '..';
|
import { Users } from '..';
|
||||||
import { awaitAll } from '../../prelude/await-all';
|
import { awaitAll } from '../../prelude/await-all';
|
||||||
|
@ -12,7 +11,7 @@ export class ClipRepository extends Repository<Clip> {
|
||||||
public async pack(
|
public async pack(
|
||||||
src: Clip['id'] | Clip,
|
src: Clip['id'] | Clip,
|
||||||
): Promise<PackedClip> {
|
): 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({
|
return await awaitAll({
|
||||||
id: clip.id,
|
id: clip.id,
|
||||||
|
|
|
@ -3,7 +3,6 @@ import { DriveFile } from '../entities/drive-file';
|
||||||
import { Users, DriveFolders } from '..';
|
import { Users, DriveFolders } from '..';
|
||||||
import { User } from '../entities/user';
|
import { User } from '../entities/user';
|
||||||
import { toPuny } from '../../misc/convert-host';
|
import { toPuny } from '../../misc/convert-host';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { awaitAll } from '../../prelude/await-all';
|
import { awaitAll } from '../../prelude/await-all';
|
||||||
import { SchemaType } from '../../misc/schema';
|
import { SchemaType } from '../../misc/schema';
|
||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
|
@ -103,7 +102,7 @@ export class DriveFileRepository extends Repository<DriveFile> {
|
||||||
self: false
|
self: false
|
||||||
}, options);
|
}, 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();
|
const meta = await fetchMeta();
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { DriveFolders, DriveFiles } from '..';
|
import { DriveFolders, DriveFiles } from '..';
|
||||||
import { DriveFolder } from '../entities/drive-folder';
|
import { DriveFolder } from '../entities/drive-folder';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { awaitAll } from '../../prelude/await-all';
|
import { awaitAll } from '../../prelude/await-all';
|
||||||
import { SchemaType } from '../../misc/schema';
|
import { SchemaType } from '../../misc/schema';
|
||||||
|
|
||||||
|
@ -26,7 +25,7 @@ export class DriveFolderRepository extends Repository<DriveFolder> {
|
||||||
detail: false
|
detail: false
|
||||||
}, options);
|
}, 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({
|
return await awaitAll({
|
||||||
id: folder.id,
|
id: folder.id,
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { Emoji } from '../entities/emoji';
|
import { Emoji } from '../entities/emoji';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
|
|
||||||
@EntityRepository(Emoji)
|
@EntityRepository(Emoji)
|
||||||
export class EmojiRepository extends Repository<Emoji> {
|
export class EmojiRepository extends Repository<Emoji> {
|
||||||
public async pack(
|
public async pack(
|
||||||
src: Emoji['id'] | Emoji,
|
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 {
|
return {
|
||||||
id: emoji.id,
|
id: emoji.id,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { FollowRequest } from '../entities/follow-request';
|
import { FollowRequest } from '../entities/follow-request';
|
||||||
import { Users } from '..';
|
import { Users } from '..';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
|
|
||||||
@EntityRepository(FollowRequest)
|
@EntityRepository(FollowRequest)
|
||||||
export class FollowRequestRepository extends Repository<FollowRequest> {
|
export class FollowRequestRepository extends Repository<FollowRequest> {
|
||||||
|
@ -9,7 +8,7 @@ export class FollowRequestRepository extends Repository<FollowRequest> {
|
||||||
src: FollowRequest['id'] | FollowRequest,
|
src: FollowRequest['id'] | FollowRequest,
|
||||||
me?: any
|
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 {
|
return {
|
||||||
id: request.id,
|
id: request.id,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { Users } from '..';
|
import { Users } from '..';
|
||||||
import { Following } from '../entities/following';
|
import { Following } from '../entities/following';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { awaitAll } from '../../prelude/await-all';
|
import { awaitAll } from '../../prelude/await-all';
|
||||||
import { SchemaType } from '../../misc/schema';
|
import { SchemaType } from '../../misc/schema';
|
||||||
|
|
||||||
|
@ -57,7 +56,7 @@ export class FollowingRepository extends Repository<Following> {
|
||||||
populateFollower?: boolean;
|
populateFollower?: boolean;
|
||||||
}
|
}
|
||||||
): Promise<PackedFollowing> {
|
): 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 = {};
|
if (opts == null) opts = {};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { Users } from '../../..';
|
import { Users } from '../../..';
|
||||||
import { ReversiGame } from '../../../entities/games/reversi/game';
|
import { ReversiGame } from '../../../entities/games/reversi/game';
|
||||||
import { ensure } from '../../../../prelude/ensure';
|
|
||||||
|
|
||||||
@EntityRepository(ReversiGame)
|
@EntityRepository(ReversiGame)
|
||||||
export class ReversiGameRepository extends Repository<ReversiGame> {
|
export class ReversiGameRepository extends Repository<ReversiGame> {
|
||||||
|
@ -16,7 +15,7 @@ export class ReversiGameRepository extends Repository<ReversiGame> {
|
||||||
detail: true
|
detail: true
|
||||||
}, options);
|
}, 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;
|
const meId = me ? typeof me === 'string' ? me : me.id : null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { ReversiMatching } from '../../../entities/games/reversi/matching';
|
import { ReversiMatching } from '../../../entities/games/reversi/matching';
|
||||||
import { Users } from '../../..';
|
import { Users } from '../../..';
|
||||||
import { ensure } from '../../../../prelude/ensure';
|
|
||||||
import { awaitAll } from '../../../../prelude/await-all';
|
import { awaitAll } from '../../../../prelude/await-all';
|
||||||
|
|
||||||
@EntityRepository(ReversiMatching)
|
@EntityRepository(ReversiMatching)
|
||||||
|
@ -10,7 +9,7 @@ export class ReversiMatchingRepository extends Repository<ReversiMatching> {
|
||||||
src: ReversiMatching['id'] | ReversiMatching,
|
src: ReversiMatching['id'] | ReversiMatching,
|
||||||
me: any
|
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({
|
return await awaitAll({
|
||||||
id: matching.id,
|
id: matching.id,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { MessagingMessage } from '../entities/messaging-message';
|
import { MessagingMessage } from '../entities/messaging-message';
|
||||||
import { Users, DriveFiles, UserGroups } from '..';
|
import { Users, DriveFiles, UserGroups } from '..';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { SchemaType } from '../../misc/schema';
|
import { SchemaType } from '../../misc/schema';
|
||||||
|
|
||||||
export type PackedMessagingMessage = SchemaType<typeof packedMessagingMessageSchema>;
|
export type PackedMessagingMessage = SchemaType<typeof packedMessagingMessageSchema>;
|
||||||
|
@ -25,7 +24,7 @@ export class MessagingMessageRepository extends Repository<MessagingMessage> {
|
||||||
populateGroup: true,
|
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 {
|
return {
|
||||||
id: message.id,
|
id: message.id,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { Users } from '..';
|
import { Users } from '..';
|
||||||
import { ModerationLog } from '../entities/moderation-log';
|
import { ModerationLog } from '../entities/moderation-log';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { awaitAll } from '../../prelude/await-all';
|
import { awaitAll } from '../../prelude/await-all';
|
||||||
|
|
||||||
@EntityRepository(ModerationLog)
|
@EntityRepository(ModerationLog)
|
||||||
|
@ -9,7 +8,7 @@ export class ModerationLogRepository extends Repository<ModerationLog> {
|
||||||
public async pack(
|
public async pack(
|
||||||
src: ModerationLog['id'] | ModerationLog,
|
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({
|
return await awaitAll({
|
||||||
id: log.id,
|
id: log.id,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { Users } from '..';
|
import { Users } from '..';
|
||||||
import { Muting } from '../entities/muting';
|
import { Muting } from '../entities/muting';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { awaitAll } from '../../prelude/await-all';
|
import { awaitAll } from '../../prelude/await-all';
|
||||||
import { SchemaType } from '../../misc/schema';
|
import { SchemaType } from '../../misc/schema';
|
||||||
|
|
||||||
|
@ -13,7 +12,7 @@ export class MutingRepository extends Repository<Muting> {
|
||||||
src: Muting['id'] | Muting,
|
src: Muting['id'] | Muting,
|
||||||
me?: any
|
me?: any
|
||||||
): Promise<PackedMuting> {
|
): 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({
|
return await awaitAll({
|
||||||
id: muting.id,
|
id: muting.id,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { NoteFavorite } from '../entities/note-favorite';
|
import { NoteFavorite } from '../entities/note-favorite';
|
||||||
import { Notes } from '..';
|
import { Notes } from '..';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
|
|
||||||
@EntityRepository(NoteFavorite)
|
@EntityRepository(NoteFavorite)
|
||||||
export class NoteFavoriteRepository extends Repository<NoteFavorite> {
|
export class NoteFavoriteRepository extends Repository<NoteFavorite> {
|
||||||
|
@ -9,7 +8,7 @@ export class NoteFavoriteRepository extends Repository<NoteFavorite> {
|
||||||
src: NoteFavorite['id'] | NoteFavorite,
|
src: NoteFavorite['id'] | NoteFavorite,
|
||||||
me?: any
|
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 {
|
return {
|
||||||
id: favorite.id,
|
id: favorite.id,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { NoteReaction } from '../entities/note-reaction';
|
import { NoteReaction } from '../entities/note-reaction';
|
||||||
import { Users } from '..';
|
import { Users } from '..';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { SchemaType } from '../../misc/schema';
|
import { SchemaType } from '../../misc/schema';
|
||||||
import { convertLegacyReaction } from '../../misc/reaction-lib';
|
import { convertLegacyReaction } from '../../misc/reaction-lib';
|
||||||
|
|
||||||
|
@ -13,7 +12,7 @@ export class NoteReactionRepository extends Repository<NoteReaction> {
|
||||||
src: NoteReaction['id'] | NoteReaction,
|
src: NoteReaction['id'] | NoteReaction,
|
||||||
me?: any
|
me?: any
|
||||||
): Promise<PackedNoteReaction> {
|
): 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 {
|
return {
|
||||||
id: reaction.id,
|
id: reaction.id,
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { EntityRepository, Repository, In } from 'typeorm';
|
||||||
import { Note } from '../entities/note';
|
import { Note } from '../entities/note';
|
||||||
import { User } from '../entities/user';
|
import { User } from '../entities/user';
|
||||||
import { Emojis, Users, PollVotes, DriveFiles, NoteReactions, Followings, Polls, Channels } from '..';
|
import { Emojis, Users, PollVotes, DriveFiles, NoteReactions, Followings, Polls, Channels } from '..';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { SchemaType } from '../../misc/schema';
|
import { SchemaType } from '../../misc/schema';
|
||||||
import { awaitAll } from '../../prelude/await-all';
|
import { awaitAll } from '../../prelude/await-all';
|
||||||
import { convertLegacyReaction, convertLegacyReactions, decodeReaction } from '../../misc/reaction-lib';
|
import { convertLegacyReaction, convertLegacyReactions, decodeReaction } from '../../misc/reaction-lib';
|
||||||
|
@ -92,11 +91,11 @@ export class NoteRepository extends Repository<Note> {
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
const meId = me ? typeof me === 'string' ? me : me.id : null;
|
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;
|
const host = note.userHost;
|
||||||
|
|
||||||
async function populatePoll() {
|
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 => ({
|
const choices = poll.choices.map(c => ({
|
||||||
text: c,
|
text: c,
|
||||||
votes: poll.votes[poll.choices.indexOf(c)],
|
votes: poll.votes[poll.choices.indexOf(c)],
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { Users, Notes, UserGroupInvitations, AccessTokens } from '..';
|
import { Users, Notes, UserGroupInvitations, AccessTokens } from '..';
|
||||||
import { Notification } from '../entities/notification';
|
import { Notification } from '../entities/notification';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { awaitAll } from '../../prelude/await-all';
|
import { awaitAll } from '../../prelude/await-all';
|
||||||
import { SchemaType } from '../../misc/schema';
|
import { SchemaType } from '../../misc/schema';
|
||||||
|
|
||||||
|
@ -12,8 +11,8 @@ export class NotificationRepository extends Repository<Notification> {
|
||||||
public async pack(
|
public async pack(
|
||||||
src: Notification['id'] | Notification,
|
src: Notification['id'] | Notification,
|
||||||
): Promise<PackedNotification> {
|
): Promise<PackedNotification> {
|
||||||
const notification = typeof src === 'object' ? src : await this.findOne(src).then(ensure);
|
const notification = typeof src === 'object' ? src : await this.findOneOrFail(src);
|
||||||
const token = notification.appAccessTokenId ? await AccessTokens.findOne(notification.appAccessTokenId).then(ensure) : null;
|
const token = notification.appAccessTokenId ? await AccessTokens.findOneOrFail(notification.appAccessTokenId) : null;
|
||||||
|
|
||||||
return await awaitAll({
|
return await awaitAll({
|
||||||
id: notification.id,
|
id: notification.id,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { PageLike } from '../entities/page-like';
|
import { PageLike } from '../entities/page-like';
|
||||||
import { Pages } from '..';
|
import { Pages } from '..';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
|
|
||||||
@EntityRepository(PageLike)
|
@EntityRepository(PageLike)
|
||||||
export class PageLikeRepository extends Repository<PageLike> {
|
export class PageLikeRepository extends Repository<PageLike> {
|
||||||
|
@ -9,7 +8,7 @@ export class PageLikeRepository extends Repository<PageLike> {
|
||||||
src: PageLike['id'] | PageLike,
|
src: PageLike['id'] | PageLike,
|
||||||
me?: any
|
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 {
|
return {
|
||||||
id: like.id,
|
id: like.id,
|
||||||
|
|
|
@ -5,7 +5,6 @@ import { Users, DriveFiles, PageLikes } from '..';
|
||||||
import { awaitAll } from '../../prelude/await-all';
|
import { awaitAll } from '../../prelude/await-all';
|
||||||
import { DriveFile } from '../entities/drive-file';
|
import { DriveFile } from '../entities/drive-file';
|
||||||
import { User } from '../entities/user';
|
import { User } from '../entities/user';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
|
|
||||||
export type PackedPage = SchemaType<typeof packedPageSchema>;
|
export type PackedPage = SchemaType<typeof packedPageSchema>;
|
||||||
|
|
||||||
|
@ -16,7 +15,7 @@ export class PageRepository extends Repository<Page> {
|
||||||
me?: User['id'] | User | null | undefined,
|
me?: User['id'] | User | null | undefined,
|
||||||
): Promise<PackedPage> {
|
): Promise<PackedPage> {
|
||||||
const meId = me ? typeof me === 'string' ? me : me.id : null;
|
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 attachedFiles: Promise<DriveFile | undefined>[] = [];
|
||||||
const collectFile = (xs: any[]) => {
|
const collectFile = (xs: any[]) => {
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { UserGroupInvitation } from '../entities/user-group-invitation';
|
import { UserGroupInvitation } from '../entities/user-group-invitation';
|
||||||
import { UserGroups } from '..';
|
import { UserGroups } from '..';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
|
|
||||||
@EntityRepository(UserGroupInvitation)
|
@EntityRepository(UserGroupInvitation)
|
||||||
export class UserGroupInvitationRepository extends Repository<UserGroupInvitation> {
|
export class UserGroupInvitationRepository extends Repository<UserGroupInvitation> {
|
||||||
public async pack(
|
public async pack(
|
||||||
src: UserGroupInvitation['id'] | UserGroupInvitation,
|
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 {
|
return {
|
||||||
id: invitation.id,
|
id: invitation.id,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { UserGroup } from '../entities/user-group';
|
import { UserGroup } from '../entities/user-group';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { UserGroupJoinings } from '..';
|
import { UserGroupJoinings } from '..';
|
||||||
import { SchemaType } from '../../misc/schema';
|
import { SchemaType } from '../../misc/schema';
|
||||||
|
|
||||||
|
@ -11,7 +10,7 @@ export class UserGroupRepository extends Repository<UserGroup> {
|
||||||
public async pack(
|
public async pack(
|
||||||
src: UserGroup['id'] | UserGroup,
|
src: UserGroup['id'] | UserGroup,
|
||||||
): Promise<PackedUserGroup> {
|
): 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({
|
const users = await UserGroupJoinings.find({
|
||||||
userGroupId: userGroup.id
|
userGroupId: userGroup.id
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { UserList } from '../entities/user-list';
|
import { UserList } from '../entities/user-list';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { UserListJoinings } from '..';
|
import { UserListJoinings } from '..';
|
||||||
import { SchemaType } from '../../misc/schema';
|
import { SchemaType } from '../../misc/schema';
|
||||||
|
|
||||||
|
@ -11,7 +10,7 @@ export class UserListRepository extends Repository<UserList> {
|
||||||
public async pack(
|
public async pack(
|
||||||
src: UserList['id'] | UserList,
|
src: UserList['id'] | UserList,
|
||||||
): Promise<PackedUserList> {
|
): 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({
|
const users = await UserListJoinings.find({
|
||||||
userListId: userList.id
|
userListId: userList.id
|
||||||
|
|
|
@ -2,7 +2,6 @@ import $ from 'cafy';
|
||||||
import { EntityRepository, Repository, In, Not } from 'typeorm';
|
import { EntityRepository, Repository, In, Not } from 'typeorm';
|
||||||
import { User, ILocalUser, IRemoteUser } from '../entities/user';
|
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 { 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 config from '../../config';
|
||||||
import { SchemaType } from '../../misc/schema';
|
import { SchemaType } from '../../misc/schema';
|
||||||
import { awaitAll } from '../../prelude/await-all';
|
import { awaitAll } from '../../prelude/await-all';
|
||||||
|
@ -157,7 +156,7 @@ export class UserRepository extends Repository<User> {
|
||||||
includeSecrets: false
|
includeSecrets: false
|
||||||
}, options);
|
}, 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 meId = me ? typeof me === 'string' ? me : me.id : null;
|
||||||
|
|
||||||
const relation = meId && (meId !== user.id) && opts.detail ? await this.getRelation(meId, user.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 },
|
where: { userId: user.id },
|
||||||
order: { id: 'DESC' }
|
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;
|
const falsy = opts.detail ? false : undefined;
|
||||||
|
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
/**
|
|
||||||
* 値が null または undefined の場合はエラーを発生させ、そうでない場合は値をそのまま返します
|
|
||||||
*/
|
|
||||||
export function ensure<T>(x: T): NonNullable<T> {
|
|
||||||
if (x == null) {
|
|
||||||
throw new Error('ぬるぽ');
|
|
||||||
} else {
|
|
||||||
return x!;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -9,7 +9,6 @@ import { Users, Notes, Polls } from '../../../models';
|
||||||
import { MoreThan } from 'typeorm';
|
import { MoreThan } from 'typeorm';
|
||||||
import { Note } from '../../../models/entities/note';
|
import { Note } from '../../../models/entities/note';
|
||||||
import { Poll } from '../../../models/entities/poll';
|
import { Poll } from '../../../models/entities/poll';
|
||||||
import { ensure } from '../../../prelude/ensure';
|
|
||||||
|
|
||||||
const logger = queueLogger.createSubLogger('export-notes');
|
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) {
|
for (const note of notes) {
|
||||||
let poll: Poll | undefined;
|
let poll: Poll | undefined;
|
||||||
if (note.hasPoll) {
|
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));
|
const content = JSON.stringify(serialize(note, poll));
|
||||||
await new Promise((res, rej) => {
|
await new Promise((res, rej) => {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import { MessagingMessage } from '../../models/entities/messaging-message';
|
||||||
import { Notes, Users, UserPublickeys, MessagingMessages } from '../../models';
|
import { Notes, Users, UserPublickeys, MessagingMessages } from '../../models';
|
||||||
import { IObject, getApId } from './type';
|
import { IObject, getApId } from './type';
|
||||||
import { resolvePerson } from './models/person';
|
import { resolvePerson } from './models/person';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import escapeRegexp = require('escape-regexp');
|
import escapeRegexp = require('escape-regexp');
|
||||||
|
|
||||||
export default class DbResolver {
|
export default class DbResolver {
|
||||||
|
@ -99,7 +98,7 @@ export default class DbResolver {
|
||||||
|
|
||||||
if (user == null) return null;
|
if (user == null) return null;
|
||||||
|
|
||||||
const key = await UserPublickeys.findOne(user.id).then(ensure);
|
const key = await UserPublickeys.findOneOrFail(user.id);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
user,
|
user,
|
||||||
|
|
|
@ -5,7 +5,6 @@ import { fetchMeta } from '../../../misc/fetch-meta';
|
||||||
import { apLogger } from '../logger';
|
import { apLogger } from '../logger';
|
||||||
import { DriveFile } from '../../../models/entities/drive-file';
|
import { DriveFile } from '../../../models/entities/drive-file';
|
||||||
import { DriveFiles } from '../../../models';
|
import { DriveFiles } from '../../../models';
|
||||||
import { ensure } from '../../../prelude/ensure';
|
|
||||||
|
|
||||||
const logger = apLogger;
|
const logger = apLogger;
|
||||||
|
|
||||||
|
@ -40,7 +39,7 @@ export async function createImage(actor: IRemoteUser, value: any): Promise<Drive
|
||||||
uri: image.url
|
uri: image.url
|
||||||
});
|
});
|
||||||
|
|
||||||
file = await DriveFiles.findOne(file.id).then(ensure);
|
file = await DriveFiles.findOneOrFail(file.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ import { IObject, getOneApId, getApId, getOneApHrefNullable, validPost, IPost, i
|
||||||
import { Emoji } from '../../../models/entities/emoji';
|
import { Emoji } from '../../../models/entities/emoji';
|
||||||
import { genId } from '../../../misc/gen-id';
|
import { genId } from '../../../misc/gen-id';
|
||||||
import { fetchMeta } from '../../../misc/fetch-meta';
|
import { fetchMeta } from '../../../misc/fetch-meta';
|
||||||
import { ensure } from '../../../prelude/ensure';
|
|
||||||
import { getApLock } from '../../../misc/app-lock';
|
import { getApLock } from '../../../misc/app-lock';
|
||||||
import { createMessage } from '../../../services/messages/create';
|
import { createMessage } from '../../../services/messages/create';
|
||||||
import { parseAudience } from '../audience';
|
import { parseAudience } from '../audience';
|
||||||
|
@ -201,7 +200,7 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s
|
||||||
|
|
||||||
// vote
|
// vote
|
||||||
if (reply && reply.hasPoll) {
|
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> => {
|
const tryCreateVote = async (name: string, index: number): Promise<null> => {
|
||||||
if (poll.expiresAt && Date.now() > new Date(poll.expiresAt).getTime()) {
|
if (poll.expiresAt && Date.now() > new Date(poll.expiresAt).getTime()) {
|
||||||
|
|
|
@ -24,7 +24,6 @@ import { toPuny } from '../../../misc/convert-host';
|
||||||
import { UserProfile } from '../../../models/entities/user-profile';
|
import { UserProfile } from '../../../models/entities/user-profile';
|
||||||
import { validActor } from '../../../remote/activitypub/type';
|
import { validActor } from '../../../remote/activitypub/type';
|
||||||
import { getConnection } from 'typeorm';
|
import { getConnection } from 'typeorm';
|
||||||
import { ensure } from '../../../prelude/ensure';
|
|
||||||
import { toArray } from '../../../prelude/array';
|
import { toArray } from '../../../prelude/array';
|
||||||
import { fetchInstanceMetadata } from '../../../services/fetch-instance-metadata';
|
import { fetchInstanceMetadata } from '../../../services/fetch-instance-metadata';
|
||||||
import { normalizeForSearch } from '../../../misc/normalize-for-search';
|
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']) {
|
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 (!Users.isRemoteUser(user)) return;
|
||||||
if (!user.featured) return;
|
if (!user.featured) return;
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
import config from '../../../config';
|
import config from '../../../config';
|
||||||
import { Users } from '../../../models';
|
import { Users } from '../../../models';
|
||||||
import { User } from '../../../models/entities/user';
|
import { User } from '../../../models/entities/user';
|
||||||
import { ensure } from '../../../prelude/ensure';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert (local|remote)(Follower|Followee)ID to URL
|
* Convert (local|remote)(Follower|Followee)ID to URL
|
||||||
* @param id Follower|Followee ID
|
* @param id Follower|Followee ID
|
||||||
*/
|
*/
|
||||||
export default async function renderFollowUser(id: User['id']): Promise<any> {
|
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;
|
return Users.isLocalUser(user) ? `${config.url}/users/${user.id}` : user.uri;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import { IActivity } from '../type';
|
||||||
import { LdSignature } from '../misc/ld-signature';
|
import { LdSignature } from '../misc/ld-signature';
|
||||||
import { ILocalUser } from '../../../models/entities/user';
|
import { ILocalUser } from '../../../models/entities/user';
|
||||||
import { UserKeypairs } from '../../../models';
|
import { UserKeypairs } from '../../../models';
|
||||||
import { ensure } from '../../../prelude/ensure';
|
|
||||||
|
|
||||||
export const renderActivity = (x: any): IActivity | null => {
|
export const renderActivity = (x: any): IActivity | null => {
|
||||||
if (x == null) return 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> => {
|
export const attachLdSignature = async (activity: any, user: ILocalUser): Promise<IActivity | null> => {
|
||||||
if (activity == null) return null;
|
if (activity == null) return null;
|
||||||
|
|
||||||
const keypair = await UserKeypairs.findOne({
|
const keypair = await UserKeypairs.findOneOrFail({
|
||||||
userId: user.id
|
userId: user.id
|
||||||
}).then(ensure);
|
});
|
||||||
|
|
||||||
const obj = {
|
const obj = {
|
||||||
// as non-standards
|
// as non-standards
|
||||||
|
|
|
@ -10,7 +10,6 @@ import { DriveFiles, Notes, Users, Emojis, Polls } from '../../../models';
|
||||||
import { In } from 'typeorm';
|
import { In } from 'typeorm';
|
||||||
import { Emoji } from '../../../models/entities/emoji';
|
import { Emoji } from '../../../models/entities/emoji';
|
||||||
import { Poll } from '../../../models/entities/poll';
|
import { Poll } from '../../../models/entities/poll';
|
||||||
import { ensure } from '../../../prelude/ensure';
|
|
||||||
|
|
||||||
export default async function renderNote(note: Note, dive = true, isTalk = false): Promise<any> {
|
export default async function renderNote(note: Note, dive = true, isTalk = false): Promise<any> {
|
||||||
const getPromisedFiles = async (ids: string[]) => {
|
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}`;
|
const attributedTo = `${config.url}/users/${user.id}`;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ import renderEmoji from './emoji';
|
||||||
import { IIdentifier } from '../models/identifier';
|
import { IIdentifier } from '../models/identifier';
|
||||||
import renderHashtag from './hashtag';
|
import renderHashtag from './hashtag';
|
||||||
import { DriveFiles, UserProfiles, UserKeypairs } from '../../../models';
|
import { DriveFiles, UserProfiles, UserKeypairs } from '../../../models';
|
||||||
import { ensure } from '../../../prelude/ensure';
|
|
||||||
|
|
||||||
export async function renderPerson(user: ILocalUser) {
|
export async function renderPerson(user: ILocalUser) {
|
||||||
const id = `${config.url}/users/${user.id}`;
|
const id = `${config.url}/users/${user.id}`;
|
||||||
|
@ -18,7 +17,7 @@ export async function renderPerson(user: ILocalUser) {
|
||||||
const [avatar, banner, profile] = await Promise.all([
|
const [avatar, banner, profile] = await Promise.all([
|
||||||
user.avatarId ? DriveFiles.findOne(user.avatarId) : Promise.resolve(undefined),
|
user.avatarId ? DriveFiles.findOne(user.avatarId) : Promise.resolve(undefined),
|
||||||
user.bannerId ? DriveFiles.findOne(user.bannerId) : Promise.resolve(undefined),
|
user.bannerId ? DriveFiles.findOne(user.bannerId) : Promise.resolve(undefined),
|
||||||
UserProfiles.findOne(user.id).then(ensure)
|
UserProfiles.findOneOrFail(user.id)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const attachment: {
|
const attachment: {
|
||||||
|
@ -50,7 +49,7 @@ export async function renderPerson(user: ILocalUser) {
|
||||||
...hashtagTags,
|
...hashtagTags,
|
||||||
];
|
];
|
||||||
|
|
||||||
const keypair = await UserKeypairs.findOne(user.id).then(ensure);
|
const keypair = await UserKeypairs.findOneOrFail(user.id);
|
||||||
|
|
||||||
const person = {
|
const person = {
|
||||||
type: isSystem ? 'Application' : user.isBot ? 'Service' : 'Person',
|
type: isSystem ? 'Application' : user.isBot ? 'Service' : 'Person',
|
||||||
|
|
|
@ -6,7 +6,6 @@ import * as crypto from 'crypto';
|
||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
import { ILocalUser } from '../../models/entities/user';
|
import { ILocalUser } from '../../models/entities/user';
|
||||||
import { UserKeypairs } from '../../models';
|
import { UserKeypairs } from '../../models';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { getAgentByUrl } from '../../misc/fetch';
|
import { getAgentByUrl } from '../../misc/fetch';
|
||||||
import { URL } from 'url';
|
import { URL } from 'url';
|
||||||
import got from 'got';
|
import got from 'got';
|
||||||
|
@ -23,9 +22,9 @@ export default async (user: ILocalUser, url: string, object: any) => {
|
||||||
sha256.update(data);
|
sha256.update(data);
|
||||||
const hash = sha256.digest('base64');
|
const hash = sha256.digest('base64');
|
||||||
|
|
||||||
const keypair = await UserKeypairs.findOne({
|
const keypair = await UserKeypairs.findOneOrFail({
|
||||||
userId: user.id
|
userId: user.id
|
||||||
}).then(ensure);
|
});
|
||||||
|
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
const req = https.request({
|
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) {
|
export async function signedGet(url: string, user: ILocalUser) {
|
||||||
const timeout = 10 * 1000;
|
const timeout = 10 * 1000;
|
||||||
|
|
||||||
const keypair = await UserKeypairs.findOne({
|
const keypair = await UserKeypairs.findOneOrFail({
|
||||||
userId: user.id
|
userId: user.id
|
||||||
}).then(ensure);
|
});
|
||||||
|
|
||||||
const req = got.get<any>(url, {
|
const req = got.get<any>(url, {
|
||||||
headers: {
|
headers: {
|
||||||
|
|
|
@ -16,7 +16,6 @@ import { isSelfHost } from '../misc/convert-host';
|
||||||
import { Notes, Users, Emojis, UserKeypairs, NoteReactions } from '../models';
|
import { Notes, Users, Emojis, UserKeypairs, NoteReactions } from '../models';
|
||||||
import { ILocalUser, User } from '../models/entities/user';
|
import { ILocalUser, User } from '../models/entities/user';
|
||||||
import { In } from 'typeorm';
|
import { In } from 'typeorm';
|
||||||
import { ensure } from '../prelude/ensure';
|
|
||||||
import { renderLike } from '../remote/activitypub/renderer/like';
|
import { renderLike } from '../remote/activitypub/renderer/like';
|
||||||
|
|
||||||
// Init router
|
// Init router
|
||||||
|
@ -136,7 +135,7 @@ router.get('/users/:user/publickey', async ctx => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const keypair = await UserKeypairs.findOne(user.id).then(ensure);
|
const keypair = await UserKeypairs.findOneOrFail(user.id);
|
||||||
|
|
||||||
if (Users.isLocalUser(user)) {
|
if (Users.isLocalUser(user)) {
|
||||||
ctx.body = renderActivity(renderKey(user, keypair));
|
ctx.body = renderActivity(renderKey(user, keypair));
|
||||||
|
|
|
@ -5,7 +5,6 @@ import renderOrderedCollection from '../../remote/activitypub/renderer/ordered-c
|
||||||
import { setResponseType } from '../activitypub';
|
import { setResponseType } from '../activitypub';
|
||||||
import renderNote from '../../remote/activitypub/renderer/note';
|
import renderNote from '../../remote/activitypub/renderer/note';
|
||||||
import { Users, Notes, UserNotePinings } from '../../models';
|
import { Users, Notes, UserNotePinings } from '../../models';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
|
|
||||||
export default async (ctx: Router.RouterContext) => {
|
export default async (ctx: Router.RouterContext) => {
|
||||||
const userId = ctx.params.user;
|
const userId = ctx.params.user;
|
||||||
|
@ -27,7 +26,7 @@ export default async (ctx: Router.RouterContext) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const pinnedNotes = await Promise.all(pinings.map(pining =>
|
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)));
|
const renderedNotes = await Promise.all(pinnedNotes.map(note => renderNote(note)));
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ import { Users, Notes } from '../../models';
|
||||||
import { makePaginationQuery } from '../api/common/make-pagination-query';
|
import { makePaginationQuery } from '../api/common/make-pagination-query';
|
||||||
import { Brackets } from 'typeorm';
|
import { Brackets } from 'typeorm';
|
||||||
import { Note } from '../../models/entities/note';
|
import { Note } from '../../models/entities/note';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
|
|
||||||
export default async (ctx: Router.RouterContext) => {
|
export default async (ctx: Router.RouterContext) => {
|
||||||
const userId = ctx.params.user;
|
const userId = ctx.params.user;
|
||||||
|
@ -101,7 +100,7 @@ export default async (ctx: Router.RouterContext) => {
|
||||||
*/
|
*/
|
||||||
export async function packActivity(note: Note): Promise<any> {
|
export async function packActivity(note: Note): Promise<any> {
|
||||||
if (note.renoteId && note.text == null && !note.hasPoll && (note.fileIds == null || note.fileIds.length === 0)) {
|
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);
|
return renderAnnounce(renote.uri ? renote.uri : `${config.url}/notes/${renote.id}`, note);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import isNativeToken from './common/is-native-token';
|
import isNativeToken from './common/is-native-token';
|
||||||
import { User } from '../../models/entities/user';
|
import { User } from '../../models/entities/user';
|
||||||
import { Users, AccessTokens, Apps } from '../../models';
|
import { Users, AccessTokens, Apps } from '../../models';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { AccessToken } from '../../models/entities/access-token';
|
import { AccessToken } from '../../models/entities/access-token';
|
||||||
|
|
||||||
export default async (token: string): Promise<[User | null | undefined, AccessToken | null | undefined]> => {
|
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) {
|
if (accessToken.appId) {
|
||||||
const app = await Apps
|
const app = await Apps
|
||||||
.findOne(accessToken.appId).then(ensure);
|
.findOneOrFail(accessToken.appId);
|
||||||
|
|
||||||
return [user, {
|
return [user, {
|
||||||
id: accessToken.id,
|
id: accessToken.id,
|
||||||
|
|
|
@ -3,7 +3,6 @@ import { Note } from '../../../models/entities/note';
|
||||||
import { User } from '../../../models/entities/user';
|
import { User } from '../../../models/entities/user';
|
||||||
import { Notes, UserProfiles, NoteReactions } from '../../../models';
|
import { Notes, UserProfiles, NoteReactions } from '../../../models';
|
||||||
import { generateMutedUserQuery } from './generate-muted-user-query';
|
import { generateMutedUserQuery } from './generate-muted-user-query';
|
||||||
import { ensure } from '../../../prelude/ensure';
|
|
||||||
|
|
||||||
// TODO: リアクション、Renote、返信などをしたノートは除外する
|
// TODO: リアクション、Renote、返信などをしたノートは除外する
|
||||||
|
|
||||||
|
@ -11,7 +10,7 @@ export async function injectFeatured(timeline: Note[], user?: User | null) {
|
||||||
if (timeline.length < 5) return;
|
if (timeline.length < 5) return;
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
const profile = await UserProfiles.findOne(user.id).then(ensure);
|
const profile = await UserProfiles.findOneOrFail(user.id);
|
||||||
if (!profile.injectFeaturedNote) return;
|
if (!profile.injectFeaturedNote) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ import rndstr from 'rndstr';
|
||||||
import { Note } from '../../../models/entities/note';
|
import { Note } from '../../../models/entities/note';
|
||||||
import { User } from '../../../models/entities/user';
|
import { User } from '../../../models/entities/user';
|
||||||
import { PromoReads, PromoNotes, Notes, Users } from '../../../models';
|
import { PromoReads, PromoNotes, Notes, Users } from '../../../models';
|
||||||
import { ensure } from '../../../prelude/ensure';
|
|
||||||
|
|
||||||
export async function injectPromo(timeline: Note[], user?: User | null) {
|
export async function injectPromo(timeline: Note[], user?: User | null) {
|
||||||
if (timeline.length < 5) return;
|
if (timeline.length < 5) return;
|
||||||
|
@ -23,10 +22,10 @@ export async function injectPromo(timeline: Note[], user?: User | null) {
|
||||||
// Pick random promo
|
// Pick random promo
|
||||||
const promo = promos[Math.floor(Math.random() * promos.length)];
|
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
|
// 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);
|
(note as any)._prId_ = rndstr('a-z0-9', 8);
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ import $ from 'cafy';
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import deleteFollowing from '../../../../../services/following/delete';
|
import deleteFollowing from '../../../../../services/following/delete';
|
||||||
import { Followings, Users } from '../../../../../models';
|
import { Followings, Users } from '../../../../../models';
|
||||||
import { ensure } from '../../../../../prelude/ensure';
|
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ['admin'],
|
tags: ['admin'],
|
||||||
|
@ -23,8 +22,8 @@ export default define(meta, async (ps, me) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const pairs = await Promise.all(followings.map(f => Promise.all([
|
const pairs = await Promise.all(followings.map(f => Promise.all([
|
||||||
Users.findOne(f.followerId).then(ensure),
|
Users.findOneOrFail(f.followerId),
|
||||||
Users.findOne(f.followeeId).then(ensure)
|
Users.findOneOrFail(f.followeeId)
|
||||||
])));
|
])));
|
||||||
|
|
||||||
for (const pair of pairs) {
|
for (const pair of pairs) {
|
||||||
|
|
|
@ -4,7 +4,6 @@ import define from '../../define';
|
||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
import { AuthSessions, AccessTokens, Apps } from '../../../../models';
|
import { AuthSessions, AccessTokens, Apps } from '../../../../models';
|
||||||
import { genId } from '../../../../misc/gen-id';
|
import { genId } from '../../../../misc/gen-id';
|
||||||
import { ensure } from '../../../../prelude/ensure';
|
|
||||||
import { secureRndstr } from '../../../../misc/secure-rndstr';
|
import { secureRndstr } from '../../../../misc/secure-rndstr';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
|
@ -49,7 +48,7 @@ export default define(meta, async (ps, user) => {
|
||||||
|
|
||||||
if (exist == null) {
|
if (exist == null) {
|
||||||
// Lookup app
|
// Lookup app
|
||||||
const app = await Apps.findOne(session.appId).then(ensure);
|
const app = await Apps.findOneOrFail(session.appId);
|
||||||
|
|
||||||
// Generate Hash
|
// Generate Hash
|
||||||
const sha256 = crypto.createHash('sha256');
|
const sha256 = crypto.createHash('sha256');
|
||||||
|
|
|
@ -2,7 +2,6 @@ import $ from 'cafy';
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import { ApiError } from '../../../error';
|
import { ApiError } from '../../../error';
|
||||||
import { Apps, AuthSessions, AccessTokens, Users } from '../../../../../models';
|
import { Apps, AuthSessions, AccessTokens, Users } from '../../../../../models';
|
||||||
import { ensure } from '../../../../../prelude/ensure';
|
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ['auth'],
|
tags: ['auth'],
|
||||||
|
@ -92,10 +91,10 @@ export default define(meta, async (ps) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lookup access token
|
// Lookup access token
|
||||||
const accessToken = await AccessTokens.findOne({
|
const accessToken = await AccessTokens.findOneOrFail({
|
||||||
appId: app.id,
|
appId: app.id,
|
||||||
userId: session.userId
|
userId: session.userId
|
||||||
}).then(ensure);
|
});
|
||||||
|
|
||||||
// Delete session
|
// Delete session
|
||||||
AuthSessions.delete(session.id);
|
AuthSessions.delete(session.id);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import define from '../define';
|
import define from '../define';
|
||||||
import { RegistryItems, UserProfiles, Users } from '../../../models';
|
import { RegistryItems, UserProfiles, Users } from '../../../models';
|
||||||
import { ensure } from '../../../prelude/ensure';
|
|
||||||
import { genId } from '../../../misc/gen-id';
|
import { genId } from '../../../misc/gen-id';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
|
@ -25,7 +24,7 @@ export default define(meta, async (ps, user, token) => {
|
||||||
const isSecure = token == null;
|
const isSecure = token == null;
|
||||||
|
|
||||||
// TODO: そのうち消す
|
// 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)) {
|
for (const [k, v] of Object.entries(profile.clientData)) {
|
||||||
await RegistryItems.insert({
|
await RegistryItems.insert({
|
||||||
id: genId(),
|
id: genId(),
|
||||||
|
|
|
@ -2,7 +2,6 @@ import $ from 'cafy';
|
||||||
import * as speakeasy from 'speakeasy';
|
import * as speakeasy from 'speakeasy';
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import { UserProfiles } from '../../../../../models';
|
import { UserProfiles } from '../../../../../models';
|
||||||
import { ensure } from '../../../../../prelude/ensure';
|
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
requireCredential: true as const,
|
requireCredential: true as const,
|
||||||
|
@ -19,7 +18,7 @@ export const meta = {
|
||||||
export default define(meta, async (ps, user) => {
|
export default define(meta, async (ps, user) => {
|
||||||
const token = ps.token.replace(/\s/g, '');
|
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) {
|
if (profile.twoFactorTempSecret == null) {
|
||||||
throw new Error('二段階認証の設定が開始されていません');
|
throw new Error('二段階認証の設定が開始されていません');
|
||||||
|
|
|
@ -9,7 +9,6 @@ import {
|
||||||
AttestationChallenges,
|
AttestationChallenges,
|
||||||
Users
|
Users
|
||||||
} from '../../../../../models';
|
} from '../../../../../models';
|
||||||
import { ensure } from '../../../../../prelude/ensure';
|
|
||||||
import config from '../../../../../config';
|
import config from '../../../../../config';
|
||||||
import { procedures, hash } from '../../../2fa';
|
import { procedures, hash } from '../../../2fa';
|
||||||
import { publishMainStream } from '../../../../../services/stream';
|
import { publishMainStream } from '../../../../../services/stream';
|
||||||
|
@ -43,7 +42,7 @@ export const meta = {
|
||||||
const rpIdHashReal = hash(Buffer.from(config.hostname, 'utf-8'));
|
const rpIdHashReal = hash(Buffer.from(config.hostname, 'utf-8'));
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
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
|
// Compare password
|
||||||
const same = await bcrypt.compare(ps.password, profile.password!);
|
const same = await bcrypt.compare(ps.password, profile.password!);
|
||||||
|
|
|
@ -2,7 +2,6 @@ import $ from 'cafy';
|
||||||
import * as bcrypt from 'bcryptjs';
|
import * as bcrypt from 'bcryptjs';
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import { UserProfiles, AttestationChallenges } from '../../../../../models';
|
import { UserProfiles, AttestationChallenges } from '../../../../../models';
|
||||||
import { ensure } from '../../../../../prelude/ensure';
|
|
||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
import * as crypto from 'crypto';
|
import * as crypto from 'crypto';
|
||||||
import { genId } from '../../../../../misc/gen-id';
|
import { genId } from '../../../../../misc/gen-id';
|
||||||
|
@ -23,7 +22,7 @@ export const meta = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
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
|
// Compare password
|
||||||
const same = await bcrypt.compare(ps.password, profile.password!);
|
const same = await bcrypt.compare(ps.password, profile.password!);
|
||||||
|
|
|
@ -5,7 +5,6 @@ import * as QRCode from 'qrcode';
|
||||||
import config from '../../../../../config';
|
import config from '../../../../../config';
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import { UserProfiles } from '../../../../../models';
|
import { UserProfiles } from '../../../../../models';
|
||||||
import { ensure } from '../../../../../prelude/ensure';
|
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
requireCredential: true as const,
|
requireCredential: true as const,
|
||||||
|
@ -20,7 +19,7 @@ export const meta = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
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
|
// Compare password
|
||||||
const same = await bcrypt.compare(ps.password, profile.password!);
|
const same = await bcrypt.compare(ps.password, profile.password!);
|
||||||
|
|
|
@ -2,7 +2,6 @@ import $ from 'cafy';
|
||||||
import * as bcrypt from 'bcryptjs';
|
import * as bcrypt from 'bcryptjs';
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import { UserProfiles, UserSecurityKeys, Users } from '../../../../../models';
|
import { UserProfiles, UserSecurityKeys, Users } from '../../../../../models';
|
||||||
import { ensure } from '../../../../../prelude/ensure';
|
|
||||||
import { publishMainStream } from '../../../../../services/stream';
|
import { publishMainStream } from '../../../../../services/stream';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
|
@ -21,7 +20,7 @@ export const meta = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
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
|
// Compare password
|
||||||
const same = await bcrypt.compare(ps.password, profile.password!);
|
const same = await bcrypt.compare(ps.password, profile.password!);
|
||||||
|
|
|
@ -2,7 +2,6 @@ import $ from 'cafy';
|
||||||
import * as bcrypt from 'bcryptjs';
|
import * as bcrypt from 'bcryptjs';
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import { UserProfiles } from '../../../../../models';
|
import { UserProfiles } from '../../../../../models';
|
||||||
import { ensure } from '../../../../../prelude/ensure';
|
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
requireCredential: true as const,
|
requireCredential: true as const,
|
||||||
|
@ -17,7 +16,7 @@ export const meta = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
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
|
// Compare password
|
||||||
const same = await bcrypt.compare(ps.password, profile.password!);
|
const same = await bcrypt.compare(ps.password, profile.password!);
|
||||||
|
|
|
@ -2,7 +2,6 @@ import $ from 'cafy';
|
||||||
import * as bcrypt from 'bcryptjs';
|
import * as bcrypt from 'bcryptjs';
|
||||||
import define from '../../define';
|
import define from '../../define';
|
||||||
import { UserProfiles } from '../../../../models';
|
import { UserProfiles } from '../../../../models';
|
||||||
import { ensure } from '../../../../prelude/ensure';
|
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
requireCredential: true as const,
|
requireCredential: true as const,
|
||||||
|
@ -21,7 +20,7 @@ export const meta = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
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
|
// Compare password
|
||||||
const same = await bcrypt.compare(ps.currentPassword, profile.password!);
|
const same = await bcrypt.compare(ps.currentPassword, profile.password!);
|
||||||
|
|
|
@ -2,7 +2,6 @@ import $ from 'cafy';
|
||||||
import * as bcrypt from 'bcryptjs';
|
import * as bcrypt from 'bcryptjs';
|
||||||
import define from '../../define';
|
import define from '../../define';
|
||||||
import { Users, UserProfiles } from '../../../../models';
|
import { Users, UserProfiles } from '../../../../models';
|
||||||
import { ensure } from '../../../../prelude/ensure';
|
|
||||||
import { doPostSuspend } from '../../../../services/suspend-user';
|
import { doPostSuspend } from '../../../../services/suspend-user';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
|
@ -18,7 +17,7 @@ export const meta = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
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
|
// Compare password
|
||||||
const same = await bcrypt.compare(ps.password, profile.password!);
|
const same = await bcrypt.compare(ps.password, profile.password!);
|
||||||
|
|
|
@ -4,7 +4,6 @@ import { publishMainStream } from '../../../../services/stream';
|
||||||
import generateUserToken from '../../common/generate-native-user-token';
|
import generateUserToken from '../../common/generate-native-user-token';
|
||||||
import define from '../../define';
|
import define from '../../define';
|
||||||
import { Users, UserProfiles } from '../../../../models';
|
import { Users, UserProfiles } from '../../../../models';
|
||||||
import { ensure } from '../../../../prelude/ensure';
|
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
requireCredential: true as const,
|
requireCredential: true as const,
|
||||||
|
@ -19,7 +18,7 @@ export const meta = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
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
|
// Compare password
|
||||||
const same = await bcrypt.compare(ps.password, profile.password!);
|
const same = await bcrypt.compare(ps.password, profile.password!);
|
||||||
|
|
|
@ -6,7 +6,6 @@ import config from '../../../../config';
|
||||||
import * as ms from 'ms';
|
import * as ms from 'ms';
|
||||||
import * as bcrypt from 'bcryptjs';
|
import * as bcrypt from 'bcryptjs';
|
||||||
import { Users, UserProfiles } from '../../../../models';
|
import { Users, UserProfiles } from '../../../../models';
|
||||||
import { ensure } from '../../../../prelude/ensure';
|
|
||||||
import { sendEmail } from '../../../../services/send-email';
|
import { sendEmail } from '../../../../services/send-email';
|
||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
|
|
||||||
|
@ -40,7 +39,7 @@ export const meta = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default define(meta, async (ps, user) => {
|
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
|
// Compare password
|
||||||
const same = await bcrypt.compare(ps.password, profile.password!);
|
const same = await bcrypt.compare(ps.password, profile.password!);
|
||||||
|
|
|
@ -13,7 +13,6 @@ import { ApiError } from '../../error';
|
||||||
import { Users, DriveFiles, UserProfiles, Pages } from '../../../../models';
|
import { Users, DriveFiles, UserProfiles, Pages } from '../../../../models';
|
||||||
import { User } from '../../../../models/entities/user';
|
import { User } from '../../../../models/entities/user';
|
||||||
import { UserProfile } from '../../../../models/entities/user-profile';
|
import { UserProfile } from '../../../../models/entities/user-profile';
|
||||||
import { ensure } from '../../../../prelude/ensure';
|
|
||||||
import { notificationTypes } from '../../../../types';
|
import { notificationTypes } from '../../../../types';
|
||||||
import { normalizeForSearch } from '../../../../misc/normalize-for-search';
|
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 updates = {} as Partial<User>;
|
||||||
const profileUpdates = {} as Partial<UserProfile>;
|
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.name !== undefined) updates.name = ps.name;
|
||||||
if (ps.description !== undefined) profileUpdates.description = ps.description;
|
if (ps.description !== undefined) profileUpdates.description = ps.description;
|
||||||
|
|
|
@ -6,7 +6,6 @@ import * as ms from 'ms';
|
||||||
import { getNote } from '../../common/getters';
|
import { getNote } from '../../common/getters';
|
||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
import { Users } from '../../../../models';
|
import { Users } from '../../../../models';
|
||||||
import { ensure } from '../../../../prelude/ensure';
|
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
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);
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,7 +13,6 @@ import { PollVotes, NoteWatchings, Users, Polls } from '../../../../../models';
|
||||||
import { Not } from 'typeorm';
|
import { Not } from 'typeorm';
|
||||||
import { IRemoteUser } from '../../../../../models/entities/user';
|
import { IRemoteUser } from '../../../../../models/entities/user';
|
||||||
import { genId } from '../../../../../misc/gen-id';
|
import { genId } from '../../../../../misc/gen-id';
|
||||||
import { ensure } from '../../../../../prelude/ensure';
|
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
|
@ -87,7 +86,7 @@ export default define(meta, async (ps, user) => {
|
||||||
throw new ApiError(meta.errors.noPoll);
|
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) {
|
if (poll.expiresAt && poll.expiresAt < createdAt) {
|
||||||
throw new ApiError(meta.errors.alreadyExpired);
|
throw new ApiError(meta.errors.alreadyExpired);
|
||||||
|
@ -153,7 +152,7 @@ export default define(meta, async (ps, user) => {
|
||||||
|
|
||||||
// リモート投票の場合リプライ送信
|
// リモート投票の場合リプライ送信
|
||||||
if (note.userHost != null) {
|
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);
|
deliver(user, renderActivity(await renderVote(user, vote, note, poll, pollOwner)), pollOwner.inbox);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ import define from '../../define';
|
||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
import { Users, UserProfiles } from '../../../../models';
|
import { Users, UserProfiles } from '../../../../models';
|
||||||
import { ID } from '../../../../misc/cafy-id';
|
import { ID } from '../../../../misc/cafy-id';
|
||||||
import { ensure } from '../../../../prelude/ensure';
|
|
||||||
import { toPunyNullable } from '../../../../misc/convert-host';
|
import { toPunyNullable } from '../../../../misc/convert-host';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
|
@ -51,7 +50,7 @@ export default define(meta, async (ps, me) => {
|
||||||
throw new ApiError(meta.errors.noSuchUser);
|
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) {
|
if (profile.room.furnitures == null) {
|
||||||
await UserProfiles.update(user.id, {
|
await UserProfiles.update(user.id, {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import config from '../../../config';
|
||||||
import { Users, Signins, UserProfiles, UserSecurityKeys, AttestationChallenges } from '../../../models';
|
import { Users, Signins, UserProfiles, UserSecurityKeys, AttestationChallenges } from '../../../models';
|
||||||
import { ILocalUser } from '../../../models/entities/user';
|
import { ILocalUser } from '../../../models/entities/user';
|
||||||
import { genId } from '../../../misc/gen-id';
|
import { genId } from '../../../misc/gen-id';
|
||||||
import { ensure } from '../../../prelude/ensure';
|
|
||||||
import { verifyLogin, hash } from '../2fa';
|
import { verifyLogin, hash } from '../2fa';
|
||||||
import { randomBytes } from 'crypto';
|
import { randomBytes } from 'crypto';
|
||||||
|
|
||||||
|
@ -47,7 +46,7 @@ export default async (ctx: Koa.Context) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const profile = await UserProfiles.findOne(user.id).then(ensure);
|
const profile = await UserProfiles.findOneOrFail(user.id);
|
||||||
|
|
||||||
// Compare password
|
// Compare password
|
||||||
const same = await bcrypt.compare(password, profile.password!);
|
const same = await bcrypt.compare(password, profile.password!);
|
||||||
|
|
|
@ -10,7 +10,6 @@ import signin from '../common/signin';
|
||||||
import { fetchMeta } from '../../../misc/fetch-meta';
|
import { fetchMeta } from '../../../misc/fetch-meta';
|
||||||
import { Users, UserProfiles } from '../../../models';
|
import { Users, UserProfiles } from '../../../models';
|
||||||
import { ILocalUser } from '../../../models/entities/user';
|
import { ILocalUser } from '../../../models/entities/user';
|
||||||
import { ensure } from '../../../prelude/ensure';
|
|
||||||
|
|
||||||
function getUserToken(ctx: Koa.Context) {
|
function getUserToken(ctx: Koa.Context) {
|
||||||
return ((ctx.headers['cookie'] || '').match(/igi=(\w+)/) || [null, null])[1];
|
return ((ctx.headers['cookie'] || '').match(/igi=(\w+)/) || [null, null])[1];
|
||||||
|
@ -41,12 +40,12 @@ router.get('/disconnect/discord', async ctx => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await Users.findOne({
|
const user = await Users.findOneOrFail({
|
||||||
host: null,
|
host: null,
|
||||||
token: userToken
|
token: userToken
|
||||||
}).then(ensure);
|
});
|
||||||
|
|
||||||
const profile = await UserProfiles.findOne(user.id).then(ensure);
|
const profile = await UserProfiles.findOneOrFail(user.id);
|
||||||
|
|
||||||
delete profile.integrations.discord;
|
delete profile.integrations.discord;
|
||||||
|
|
||||||
|
@ -253,12 +252,12 @@ router.get('/dc/cb', async ctx => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await Users.findOne({
|
const user = await Users.findOneOrFail({
|
||||||
host: null,
|
host: null,
|
||||||
token: userToken
|
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, {
|
await UserProfiles.update(user.id, {
|
||||||
integrations: {
|
integrations: {
|
||||||
|
|
|
@ -10,7 +10,6 @@ import signin from '../common/signin';
|
||||||
import { fetchMeta } from '../../../misc/fetch-meta';
|
import { fetchMeta } from '../../../misc/fetch-meta';
|
||||||
import { Users, UserProfiles } from '../../../models';
|
import { Users, UserProfiles } from '../../../models';
|
||||||
import { ILocalUser } from '../../../models/entities/user';
|
import { ILocalUser } from '../../../models/entities/user';
|
||||||
import { ensure } from '../../../prelude/ensure';
|
|
||||||
|
|
||||||
function getUserToken(ctx: Koa.Context) {
|
function getUserToken(ctx: Koa.Context) {
|
||||||
return ((ctx.headers['cookie'] || '').match(/igi=(\w+)/) || [null, null])[1];
|
return ((ctx.headers['cookie'] || '').match(/igi=(\w+)/) || [null, null])[1];
|
||||||
|
@ -41,12 +40,12 @@ router.get('/disconnect/github', async ctx => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await Users.findOne({
|
const user = await Users.findOneOrFail({
|
||||||
host: null,
|
host: null,
|
||||||
token: userToken
|
token: userToken
|
||||||
}).then(ensure);
|
});
|
||||||
|
|
||||||
const profile = await UserProfiles.findOne(user.id).then(ensure);
|
const profile = await UserProfiles.findOneOrFail(user.id);
|
||||||
|
|
||||||
delete profile.integrations.github;
|
delete profile.integrations.github;
|
||||||
|
|
||||||
|
@ -227,12 +226,12 @@ router.get('/gh/cb', async ctx => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await Users.findOne({
|
const user = await Users.findOneOrFail({
|
||||||
host: null,
|
host: null,
|
||||||
token: userToken
|
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, {
|
await UserProfiles.update(user.id, {
|
||||||
integrations: {
|
integrations: {
|
||||||
|
|
|
@ -9,7 +9,6 @@ import signin from '../common/signin';
|
||||||
import { fetchMeta } from '../../../misc/fetch-meta';
|
import { fetchMeta } from '../../../misc/fetch-meta';
|
||||||
import { Users, UserProfiles } from '../../../models';
|
import { Users, UserProfiles } from '../../../models';
|
||||||
import { ILocalUser } from '../../../models/entities/user';
|
import { ILocalUser } from '../../../models/entities/user';
|
||||||
import { ensure } from '../../../prelude/ensure';
|
|
||||||
|
|
||||||
function getUserToken(ctx: Koa.Context) {
|
function getUserToken(ctx: Koa.Context) {
|
||||||
return ((ctx.headers['cookie'] || '').match(/igi=(\w+)/) || [null, null])[1];
|
return ((ctx.headers['cookie'] || '').match(/igi=(\w+)/) || [null, null])[1];
|
||||||
|
@ -40,12 +39,12 @@ router.get('/disconnect/twitter', async ctx => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await Users.findOne({
|
const user = await Users.findOneOrFail({
|
||||||
host: null,
|
host: null,
|
||||||
token: userToken
|
token: userToken
|
||||||
}).then(ensure);
|
});
|
||||||
|
|
||||||
const profile = await UserProfiles.findOne(user.id).then(ensure);
|
const profile = await UserProfiles.findOneOrFail(user.id);
|
||||||
|
|
||||||
delete profile.integrations.twitter;
|
delete profile.integrations.twitter;
|
||||||
|
|
||||||
|
@ -163,12 +162,12 @@ router.get('/tw/cb', async ctx => {
|
||||||
|
|
||||||
const result = await twAuth!.done(JSON.parse(twCtx), verifier);
|
const result = await twAuth!.done(JSON.parse(twCtx), verifier);
|
||||||
|
|
||||||
const user = await Users.findOne({
|
const user = await Users.findOneOrFail({
|
||||||
host: null,
|
host: null,
|
||||||
token: userToken
|
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, {
|
await UserProfiles.update(user.id, {
|
||||||
integrations: {
|
integrations: {
|
||||||
|
|
|
@ -3,7 +3,6 @@ import config from '../../config';
|
||||||
import { User } from '../../models/entities/user';
|
import { User } from '../../models/entities/user';
|
||||||
import { Notes, DriveFiles, UserProfiles } from '../../models';
|
import { Notes, DriveFiles, UserProfiles } from '../../models';
|
||||||
import { In } from 'typeorm';
|
import { In } from 'typeorm';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
|
|
||||||
export default async function(user: User) {
|
export default async function(user: User) {
|
||||||
const author = {
|
const author = {
|
||||||
|
@ -11,7 +10,7 @@ export default async function(user: User) {
|
||||||
name: user.name || user.username
|
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({
|
const notes = await Notes.find({
|
||||||
where: {
|
where: {
|
||||||
|
|
|
@ -20,7 +20,6 @@ import config from '../../config';
|
||||||
import { Users, Notes, Emojis, UserProfiles, Pages, Channels, Clips } from '../../models';
|
import { Users, Notes, Emojis, UserProfiles, Pages, Channels, Clips } from '../../models';
|
||||||
import parseAcct from '../../misc/acct/parse';
|
import parseAcct from '../../misc/acct/parse';
|
||||||
import { getNoteSummary } from '../../misc/get-note-summary';
|
import { getNoteSummary } from '../../misc/get-note-summary';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { getConnection } from 'typeorm';
|
import { getConnection } from 'typeorm';
|
||||||
import redis from '../../db/redis';
|
import redis from '../../db/redis';
|
||||||
import locales = require('../../../locales');
|
import locales = require('../../../locales');
|
||||||
|
@ -199,7 +198,7 @@ router.get(['/@:user', '/@:user/:sub'], async (ctx, next) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
const profile = await UserProfiles.findOne(user.id).then(ensure);
|
const profile = await UserProfiles.findOneOrFail(user.id);
|
||||||
const meta = await fetchMeta();
|
const meta = await fetchMeta();
|
||||||
const me = profile.fields
|
const me = profile.fields
|
||||||
? profile.fields
|
? profile.fields
|
||||||
|
@ -242,7 +241,7 @@ router.get('/notes/:note', async ctx => {
|
||||||
|
|
||||||
if (note) {
|
if (note) {
|
||||||
const _note = await Notes.pack(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();
|
const meta = await fetchMeta();
|
||||||
await ctx.render('note', {
|
await ctx.render('note', {
|
||||||
note: _note,
|
note: _note,
|
||||||
|
@ -282,7 +281,7 @@ router.get('/@:user/pages/:page', async ctx => {
|
||||||
|
|
||||||
if (page) {
|
if (page) {
|
||||||
const _page = await Pages.pack(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();
|
const meta = await fetchMeta();
|
||||||
await ctx.render('page', {
|
await ctx.render('page', {
|
||||||
page: _page,
|
page: _page,
|
||||||
|
@ -311,7 +310,7 @@ router.get('/clips/:clip', async ctx => {
|
||||||
|
|
||||||
if (clip) {
|
if (clip) {
|
||||||
const _clip = await Clips.pack(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();
|
const meta = await fetchMeta();
|
||||||
await ctx.render('clip', {
|
await ctx.render('clip', {
|
||||||
clip: _clip,
|
clip: _clip,
|
||||||
|
|
|
@ -3,7 +3,6 @@ import { Note } from '../models/entities/note';
|
||||||
import { AntennaNotes, Mutings, Notes } from '../models';
|
import { AntennaNotes, Mutings, Notes } from '../models';
|
||||||
import { genId } from '../misc/gen-id';
|
import { genId } from '../misc/gen-id';
|
||||||
import { isMutedUserRelated } from '../misc/is-muted-user-related';
|
import { isMutedUserRelated } from '../misc/is-muted-user-related';
|
||||||
import { ensure } from '../prelude/ensure';
|
|
||||||
import { publishAntennaStream, publishMainStream } from './stream';
|
import { publishAntennaStream, publishMainStream } from './stream';
|
||||||
import { User } from '../models/entities/user';
|
import { User } from '../models/entities/user';
|
||||||
|
|
||||||
|
@ -34,10 +33,10 @@ export async function addNoteToAntenna(antenna: Antenna, note: Note, noteUser: U
|
||||||
};
|
};
|
||||||
|
|
||||||
if (note.replyId != null) {
|
if (note.replyId != null) {
|
||||||
_note.reply = await Notes.findOne(note.replyId).then(ensure);
|
_note.reply = await Notes.findOneOrFail(note.replyId);
|
||||||
}
|
}
|
||||||
if (note.renoteId != null) {
|
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)))) {
|
if (isMutedUserRelated(_note, new Set<string>(mutings.map(x => x.muteeId)))) {
|
||||||
|
|
|
@ -14,7 +14,6 @@ import { instanceChart, perUserFollowingChart } from '../chart';
|
||||||
import { genId } from '../../misc/gen-id';
|
import { genId } from '../../misc/gen-id';
|
||||||
import { createNotification } from '../create-notification';
|
import { createNotification } from '../create-notification';
|
||||||
import { isDuplicateKeyValueError } from '../../misc/is-duplicate-key-value-error';
|
import { isDuplicateKeyValueError } from '../../misc/is-duplicate-key-value-error';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
|
|
||||||
const logger = new Logger('following/create');
|
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');
|
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
|
// フォロー対象が鍵アカウントである or
|
||||||
// フォロワーがBotであり、フォロー対象がBotからのフォローに慎重である or
|
// フォロワーがBotであり、フォロー対象がBotからのフォローに慎重である or
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import accept from './accept';
|
import accept from './accept';
|
||||||
import { User } from '../../../models/entities/user';
|
import { User } from '../../../models/entities/user';
|
||||||
import { FollowRequests, Users } from '../../../models';
|
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) {
|
for (const request of requests) {
|
||||||
const follower = await Users.findOne(request.followerId).then(ensure);
|
const follower = await Users.findOneOrFail(request.followerId);
|
||||||
accept(user, follower);
|
accept(user, follower);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { MessagingMessages, Users } from '../../models';
|
import { MessagingMessages, Users } from '../../models';
|
||||||
import { MessagingMessage } from '../../models/entities/messaging-message';
|
import { MessagingMessage } from '../../models/entities/messaging-message';
|
||||||
import { publishGroupMessagingStream, publishMessagingStream } from '../stream';
|
import { publishGroupMessagingStream, publishMessagingStream } from '../stream';
|
||||||
|
@ -15,8 +14,8 @@ export async function deleteMessage(message: MessagingMessage) {
|
||||||
|
|
||||||
async function postDeleteMessage(message: MessagingMessage) {
|
async function postDeleteMessage(message: MessagingMessage) {
|
||||||
if (message.recipientId) {
|
if (message.recipientId) {
|
||||||
const user = await Users.findOne(message.userId).then(ensure);
|
const user = await Users.findOneOrFail(message.userId);
|
||||||
const recipient = await Users.findOne(message.recipientId).then(ensure);
|
const recipient = await Users.findOneOrFail(message.recipientId);
|
||||||
|
|
||||||
if (Users.isLocalUser(user)) publishMessagingStream(message.userId, message.recipientId, 'deleted', message.id);
|
if (Users.isLocalUser(user)) publishMessagingStream(message.userId, message.recipientId, 'deleted', message.id);
|
||||||
if (Users.isLocalUser(recipient)) publishMessagingStream(message.recipientId, message.userId, 'deleted', message.id);
|
if (Users.isLocalUser(recipient)) publishMessagingStream(message.recipientId, message.userId, 'deleted', message.id);
|
||||||
|
|
|
@ -26,7 +26,6 @@ import { notesChart, perUserNotesChart, activeUsersChart, instanceChart } from '
|
||||||
import { Poll, IPoll } from '../../models/entities/poll';
|
import { Poll, IPoll } from '../../models/entities/poll';
|
||||||
import { createNotification } from '../create-notification';
|
import { createNotification } from '../create-notification';
|
||||||
import { isDuplicateKeyValueError } from '../../misc/is-duplicate-key-value-error';
|
import { isDuplicateKeyValueError } from '../../misc/is-duplicate-key-value-error';
|
||||||
import { ensure } from '../../prelude/ensure';
|
|
||||||
import { checkHitAntenna } from '../../misc/check-hit-antenna';
|
import { checkHitAntenna } from '../../misc/check-hit-antenna';
|
||||||
import { checkWordMute } from '../../misc/check-word-mute';
|
import { checkWordMute } from '../../misc/check-word-mute';
|
||||||
import { addNoteToAntenna } from '../add-note-to-antenna';
|
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);
|
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)) {
|
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') {
|
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)) {
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue