2021-11-12 11:47:04 +01:00
|
|
|
import ms from 'ms';
|
2022-04-17 13:51:59 +02:00
|
|
|
import { In } from 'typeorm';
|
2022-09-17 20:27:08 +02:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import type { User } from '@/models/entities/User.js';
|
2022-09-20 22:33:11 +02:00
|
|
|
import type { UsersRepository, NotesRepository, BlockingsRepository, DriveFilesRepository, ChannelsRepository } from '@/models/index.js';
|
2022-09-17 20:27:08 +02:00
|
|
|
import type { DriveFile } from '@/models/entities/DriveFile.js';
|
|
|
|
import type { Note } from '@/models/entities/Note.js';
|
|
|
|
import type { Channel } from '@/models/entities/Channel.js';
|
2022-02-27 03:07:39 +01:00
|
|
|
import { MAX_NOTE_TEXT_LENGTH } from '@/const.js';
|
2022-09-17 20:27:08 +02:00
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
|
|
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
|
|
|
import { NoteCreateService } from '@/core/NoteCreateService.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2022-04-17 13:51:59 +02:00
|
|
|
import { ApiError } from '../../error.js';
|
2018-07-05 15:35:35 +02:00
|
|
|
|
|
|
|
export const meta = {
|
2019-02-23 03:20:58 +01:00
|
|
|
tags: ['notes'],
|
|
|
|
|
2022-01-18 14:27:10 +01:00
|
|
|
requireCredential: true,
|
2018-07-15 20:25:35 +02:00
|
|
|
|
enhance: account migration (#10592)
* copy block and mute then create follow and unfollow jobs
* copy block and mute and update lists when detecting an account has moved
* no need to care promise orders
* refactor updating actor and target
* automatically accept if a locked account had accepted an old account
* fix exception format
* prevent the old account from calling some endpoints
* do not unfollow when moving
* adjust following and follower counts
* check movedToUri when receiving a follow request
* skip if no need to adjust
* Revert "disable account migration"
This reverts commit 2321214c98591bcfe1385c1ab5bf0ff7b471ae1d.
* fix translation specifier
* fix checking alsoKnownAs and uri
* fix updating account
* fix refollowing locked account
* decrease followersCount if followed by the old account
* adjust following and followers counts when unfollowing
* fix copying mutings
* prohibit moved account from moving again
* fix move service
* allow app creation after moving
* fix lint
* remove unnecessary field
* fix cache update
* add e2e test
* add e2e test of accepting the new account automatically
* force follow if any error happens
* remove unnecessary joins
* use Array.map instead of for const of
* ユーザーリストの移行は追加のみを行う
* nanka iroiro
* fix misskey-js?
* :v:
* 移行を行ったアカウントからのフォローリクエストの自動許可を調整
* newUriを外に出す
* newUriを外に出す2
* clean up
* fix newUri
* prevent moving if the destination account has already moved
* set alsoKnownAs via /i/update
* fix database initialization
* add return type
* prohibit updating alsoKnownAs after moving
* skip to add to alsoKnownAs if toUrl is known
* skip adding to the list if it already has
* use Acct.parse instead
* rename error code
* :art:
* 制限を5から10に緩和
* movedTo(Uri), alsoKnownAsはユーザーidを返すように
* test api res
* fix
* 元アカウントはミュートし続ける
* :art:
* unfollow
* fix
* getUserUriをUserEntityServiceに
* ?
* job!
* :art:
* instance => server
* accountMovedShort, forbiddenBecauseYouAreMigrated
* accountMovedShort
* fix test
* import, pin禁止
* 実績を凍結する
* clean up
* :v:
* change message
* ブロック, フォロー, ミュート, リストのインポートファイルの制限を32MiBに
* Revert "ブロック, フォロー, ミュート, リストのインポートファイルの制限を32MiBに"
This reverts commit 3bd7be35d8aa455cb01ae58f8172a71a50485db1.
* validateAlsoKnownAs
* 移行後2時間以内はインポート可能なファイルサイズを拡大
* clean up
* どうせactorをupdatePersonで更新するならupdatePersonしか移行処理を発行しないことにする
* handle error?
* リモートからの移行処理の条件を是正
* log, port
* fix
* fix
* enhance(dev): non-production環境でhttpサーバー間でもユーザー、ノートの連合が可能なように
* refactor (use checkHttps)
* MISSKEY_WEBFINGER_USE_HTTP
* Environment Variable readme
* NEVER USE IN PRODUCTION
* fix punyHost
* fix indent
* fix
* experimental
---------
Co-authored-by: tamaina <tamaina@hotmail.co.jp>
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2023-04-29 17:09:29 +02:00
|
|
|
prohibitMoved: true,
|
|
|
|
|
2018-07-15 20:25:35 +02:00
|
|
|
limit: {
|
|
|
|
duration: ms('1hour'),
|
2021-12-09 15:58:30 +01:00
|
|
|
max: 300,
|
2018-07-15 20:25:35 +02:00
|
|
|
},
|
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
kind: 'write:notes',
|
2018-07-15 20:25:35 +02:00
|
|
|
|
2018-07-05 16:47:36 +02:00
|
|
|
res: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2019-02-24 01:45:27 +01:00
|
|
|
properties: {
|
2018-07-05 16:47:36 +02:00
|
|
|
createdNote: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2019-04-23 15:35:26 +02:00
|
|
|
ref: 'Note',
|
2021-12-09 15:58:30 +01:00
|
|
|
},
|
|
|
|
},
|
2019-02-22 03:46:58 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchRenoteTarget: {
|
|
|
|
message: 'No such renote target.',
|
|
|
|
code: 'NO_SUCH_RENOTE_TARGET',
|
2021-12-09 15:58:30 +01:00
|
|
|
id: 'b5c90186-4ab0-49c8-9bba-a1f76c282ba4',
|
2019-02-22 03:46:58 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
cannotReRenote: {
|
|
|
|
message: 'You can not Renote a pure Renote.',
|
|
|
|
code: 'CANNOT_RENOTE_TO_A_PURE_RENOTE',
|
2021-12-09 15:58:30 +01:00
|
|
|
id: 'fd4cc33e-2a37-48dd-99cc-9b806eb2031a',
|
2019-02-22 03:46:58 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
noSuchReplyTarget: {
|
|
|
|
message: 'No such reply target.',
|
|
|
|
code: 'NO_SUCH_REPLY_TARGET',
|
2021-12-09 15:58:30 +01:00
|
|
|
id: '749ee0f6-d3da-459a-bf02-282e2da4292c',
|
2019-02-22 03:46:58 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
cannotReplyToPureRenote: {
|
|
|
|
message: 'You can not reply to a pure Renote.',
|
|
|
|
code: 'CANNOT_REPLY_TO_A_PURE_RENOTE',
|
2021-12-09 15:58:30 +01:00
|
|
|
id: '3ac74a84-8fd5-4bb0-870f-01804f82ce15',
|
2019-02-22 03:46:58 +01:00
|
|
|
},
|
|
|
|
|
2019-03-06 14:55:47 +01:00
|
|
|
cannotCreateAlreadyExpiredPoll: {
|
|
|
|
message: 'Poll is already expired.',
|
|
|
|
code: 'CANNOT_CREATE_ALREADY_EXPIRED_POLL',
|
2021-12-09 15:58:30 +01:00
|
|
|
id: '04da457d-b083-4055-9082-955525eda5a5',
|
2020-08-18 15:44:21 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
noSuchChannel: {
|
|
|
|
message: 'No such channel.',
|
|
|
|
code: 'NO_SUCH_CHANNEL',
|
2021-12-09 15:58:30 +01:00
|
|
|
id: 'b1653923-5453-4edc-b786-7c4f39bb0bbb',
|
2020-08-18 15:44:21 +02:00
|
|
|
},
|
2021-08-17 14:48:59 +02:00
|
|
|
|
|
|
|
youHaveBeenBlocked: {
|
|
|
|
message: 'You have been blocked by this user.',
|
|
|
|
code: 'YOU_HAVE_BEEN_BLOCKED',
|
2021-12-09 15:58:30 +01:00
|
|
|
id: 'b390d7e1-8a5e-46ed-b625-06271cafd3d3',
|
2021-08-17 14:48:59 +02:00
|
|
|
},
|
2023-02-24 08:32:01 +01:00
|
|
|
|
|
|
|
noSuchFile: {
|
|
|
|
message: 'Some files are not found.',
|
|
|
|
code: 'NO_SUCH_FILE',
|
|
|
|
id: 'b6992544-63e7-67f0-fa7f-32444b1b5306',
|
|
|
|
},
|
2021-12-09 15:58:30 +01:00
|
|
|
},
|
2022-01-18 14:27:10 +01:00
|
|
|
} as const;
|
2018-04-07 19:30:37 +02:00
|
|
|
|
2022-02-20 05:15:40 +01:00
|
|
|
export const paramDef = {
|
2022-02-19 06:05:32 +01:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
2022-04-17 13:51:59 +02:00
|
|
|
visibility: { type: 'string', enum: ['public', 'home', 'followers', 'specified'], default: 'public' },
|
2022-02-19 06:05:32 +01:00
|
|
|
visibleUserIds: { type: 'array', uniqueItems: true, items: {
|
|
|
|
type: 'string', format: 'misskey:id',
|
|
|
|
} },
|
|
|
|
cw: { type: 'string', nullable: true, maxLength: 100 },
|
|
|
|
localOnly: { type: 'boolean', default: false },
|
2023-05-19 02:43:38 +02:00
|
|
|
reactionAcceptance: { type: 'string', nullable: true, enum: [null, 'likeOnly', 'likeOnlyForRemote', 'nonSensitiveOnly', 'nonSensitiveOnlyForLocalLikeOnlyForRemote'], default: null },
|
2022-02-19 06:05:32 +01:00
|
|
|
noExtractMentions: { type: 'boolean', default: false },
|
|
|
|
noExtractHashtags: { type: 'boolean', default: false },
|
|
|
|
noExtractEmojis: { type: 'boolean', default: false },
|
|
|
|
replyId: { type: 'string', format: 'misskey:id', nullable: true },
|
2023-02-26 03:28:05 +01:00
|
|
|
renoteId: { type: 'string', format: 'misskey:id', nullable: true },
|
2022-02-19 06:05:32 +01:00
|
|
|
channelId: { type: 'string', format: 'misskey:id', nullable: true },
|
2023-02-26 03:28:05 +01:00
|
|
|
|
|
|
|
// anyOf内にバリデーションを書いても最初の一つしかチェックされない
|
|
|
|
// See https://github.com/misskey-dev/misskey/pull/10082
|
|
|
|
text: {
|
|
|
|
type: 'string',
|
|
|
|
minLength: 1,
|
|
|
|
maxLength: MAX_NOTE_TEXT_LENGTH,
|
2023-03-08 00:56:47 +01:00
|
|
|
nullable: false,
|
2022-04-03 06:57:26 +02:00
|
|
|
},
|
2023-02-26 03:28:05 +01:00
|
|
|
fileIds: {
|
|
|
|
type: 'array',
|
|
|
|
uniqueItems: true,
|
|
|
|
minItems: 1,
|
|
|
|
maxItems: 16,
|
|
|
|
items: { type: 'string', format: 'misskey:id' },
|
2022-04-03 06:57:26 +02:00
|
|
|
},
|
2023-02-26 03:28:05 +01:00
|
|
|
mediaIds: {
|
|
|
|
type: 'array',
|
|
|
|
uniqueItems: true,
|
|
|
|
minItems: 1,
|
|
|
|
maxItems: 16,
|
|
|
|
items: { type: 'string', format: 'misskey:id' },
|
|
|
|
},
|
|
|
|
poll: {
|
|
|
|
type: 'object',
|
|
|
|
nullable: true,
|
2023-02-01 12:04:01 +01:00
|
|
|
properties: {
|
2023-02-26 03:28:05 +01:00
|
|
|
choices: {
|
2023-02-01 12:04:01 +01:00
|
|
|
type: 'array',
|
|
|
|
uniqueItems: true,
|
2023-02-26 03:28:05 +01:00
|
|
|
minItems: 2,
|
|
|
|
maxItems: 10,
|
|
|
|
items: { type: 'string', minLength: 1, maxLength: 50 },
|
2023-02-01 12:04:01 +01:00
|
|
|
},
|
2023-02-26 03:28:05 +01:00
|
|
|
multiple: { type: 'boolean' },
|
|
|
|
expiresAt: { type: 'integer', nullable: true },
|
|
|
|
expiredAfter: { type: 'integer', nullable: true, minimum: 1 },
|
2022-04-03 06:57:26 +02:00
|
|
|
},
|
2023-02-26 03:28:05 +01:00
|
|
|
required: ['choices'],
|
2022-04-03 06:57:26 +02:00
|
|
|
},
|
2023-02-26 03:28:05 +01:00
|
|
|
},
|
|
|
|
// (re)note with text, files and poll are optional
|
|
|
|
anyOf: [
|
|
|
|
{ required: ['text'] },
|
2023-02-26 12:10:24 +01:00
|
|
|
{ required: ['renoteId'] },
|
2023-02-26 03:28:05 +01:00
|
|
|
{ required: ['fileIds'] },
|
|
|
|
{ required: ['mediaIds'] },
|
|
|
|
{ required: ['poll'] },
|
2022-04-03 06:57:26 +02:00
|
|
|
],
|
2022-02-19 06:05:32 +01:00
|
|
|
} as const;
|
|
|
|
|
2022-01-02 18:12:50 +01:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-09-17 20:27:08 +02:00
|
|
|
@Injectable()
|
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.usersRepository)
|
|
|
|
private usersRepository: UsersRepository,
|
2018-04-28 21:30:51 +02:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
@Inject(DI.notesRepository)
|
|
|
|
private notesRepository: NotesRepository,
|
2018-04-07 19:30:37 +02:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
@Inject(DI.blockingsRepository)
|
|
|
|
private blockingsRepository: BlockingsRepository,
|
2018-04-07 19:30:37 +02:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
@Inject(DI.driveFilesRepository)
|
|
|
|
private driveFilesRepository: DriveFilesRepository,
|
2021-08-17 14:48:59 +02:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
@Inject(DI.channelsRepository)
|
|
|
|
private channelsRepository: ChannelsRepository,
|
|
|
|
|
|
|
|
private noteEntityService: NoteEntityService,
|
|
|
|
private noteCreateService: NoteCreateService,
|
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
let visibleUsers: User[] = [];
|
|
|
|
if (ps.visibleUserIds) {
|
|
|
|
visibleUsers = await this.usersRepository.findBy({
|
|
|
|
id: In(ps.visibleUserIds),
|
|
|
|
});
|
2021-08-17 14:48:59 +02:00
|
|
|
}
|
2018-04-07 19:30:37 +02:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
let files: DriveFile[] = [];
|
|
|
|
const fileIds = ps.fileIds != null ? ps.fileIds : ps.mediaIds != null ? ps.mediaIds : null;
|
|
|
|
if (fileIds != null) {
|
|
|
|
files = await this.driveFilesRepository.createQueryBuilder('file')
|
|
|
|
.where('file.userId = :userId AND file.id IN (:...fileIds)', {
|
|
|
|
userId: me.id,
|
|
|
|
fileIds,
|
|
|
|
})
|
|
|
|
.orderBy('array_position(ARRAY[:...fileIds], "id"::text)')
|
|
|
|
.setParameters({ fileIds })
|
|
|
|
.getMany();
|
2023-02-24 08:32:01 +01:00
|
|
|
|
|
|
|
if (files.length !== fileIds.length) {
|
|
|
|
throw new ApiError(meta.errors.noSuchFile);
|
|
|
|
}
|
2022-09-17 20:27:08 +02:00
|
|
|
}
|
2018-04-07 19:30:37 +02:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
let renote: Note | null = null;
|
|
|
|
if (ps.renoteId != null) {
|
|
|
|
// Fetch renote to note
|
|
|
|
renote = await this.notesRepository.findOneBy({ id: ps.renoteId });
|
2021-08-17 14:48:59 +02:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
if (renote == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchRenoteTarget);
|
|
|
|
} else if (renote.renoteId && !renote.text && !renote.fileIds && !renote.hasPoll) {
|
|
|
|
throw new ApiError(meta.errors.cannotReRenote);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check blocking
|
|
|
|
if (renote.userId !== me.id) {
|
|
|
|
const block = await this.blockingsRepository.findOneBy({
|
|
|
|
blockerId: renote.userId,
|
|
|
|
blockeeId: me.id,
|
|
|
|
});
|
|
|
|
if (block) {
|
|
|
|
throw new ApiError(meta.errors.youHaveBeenBlocked);
|
|
|
|
}
|
|
|
|
}
|
2021-08-17 14:48:59 +02:00
|
|
|
}
|
2018-04-07 19:30:37 +02:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
let reply: Note | null = null;
|
|
|
|
if (ps.replyId != null) {
|
|
|
|
// Fetch reply
|
|
|
|
reply = await this.notesRepository.findOneBy({ id: ps.replyId });
|
|
|
|
|
|
|
|
if (reply == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchReplyTarget);
|
|
|
|
} else if (reply.renoteId && !reply.text && !reply.fileIds && !reply.hasPoll) {
|
|
|
|
throw new ApiError(meta.errors.cannotReplyToPureRenote);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check blocking
|
|
|
|
if (reply.userId !== me.id) {
|
|
|
|
const block = await this.blockingsRepository.findOneBy({
|
|
|
|
blockerId: reply.userId,
|
|
|
|
blockeeId: me.id,
|
|
|
|
});
|
|
|
|
if (block) {
|
|
|
|
throw new ApiError(meta.errors.youHaveBeenBlocked);
|
|
|
|
}
|
|
|
|
}
|
2021-11-13 11:10:14 +01:00
|
|
|
}
|
2018-04-07 19:30:37 +02:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
if (ps.poll) {
|
|
|
|
if (typeof ps.poll.expiresAt === 'number') {
|
|
|
|
if (ps.poll.expiresAt < Date.now()) {
|
|
|
|
throw new ApiError(meta.errors.cannotCreateAlreadyExpiredPoll);
|
|
|
|
}
|
|
|
|
} else if (typeof ps.poll.expiredAfter === 'number') {
|
|
|
|
ps.poll.expiresAt = Date.now() + ps.poll.expiredAfter;
|
|
|
|
}
|
|
|
|
}
|
2020-08-18 15:44:21 +02:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
let channel: Channel | null = null;
|
|
|
|
if (ps.channelId != null) {
|
2023-05-06 01:15:17 +02:00
|
|
|
channel = await this.channelsRepository.findOneBy({ id: ps.channelId, isArchived: false });
|
2020-08-18 15:44:21 +02:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
if (channel == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchChannel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 投稿を作成
|
|
|
|
const note = await this.noteCreateService.create(me, {
|
|
|
|
createdAt: new Date(),
|
|
|
|
files: files,
|
|
|
|
poll: ps.poll ? {
|
|
|
|
choices: ps.poll.choices,
|
2023-02-17 02:56:59 +01:00
|
|
|
multiple: ps.poll.multiple ?? false,
|
2022-09-17 20:27:08 +02:00
|
|
|
expiresAt: ps.poll.expiresAt ? new Date(ps.poll.expiresAt) : null,
|
|
|
|
} : undefined,
|
|
|
|
text: ps.text ?? undefined,
|
|
|
|
reply,
|
|
|
|
renote,
|
|
|
|
cw: ps.cw,
|
|
|
|
localOnly: ps.localOnly,
|
2023-03-08 00:56:47 +01:00
|
|
|
reactionAcceptance: ps.reactionAcceptance,
|
2022-09-17 20:27:08 +02:00
|
|
|
visibility: ps.visibility,
|
|
|
|
visibleUsers,
|
|
|
|
channel,
|
|
|
|
apMentions: ps.noExtractMentions ? [] : undefined,
|
|
|
|
apHashtags: ps.noExtractHashtags ? [] : undefined,
|
|
|
|
apEmojis: ps.noExtractEmojis ? [] : undefined,
|
|
|
|
});
|
2019-02-22 03:46:58 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
return {
|
|
|
|
createdNote: await this.noteEntityService.pack(note, me),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|