2023-02-09 03:46:01 +02:00
|
|
|
|
import { IncomingMessage } from 'node:http';
|
2022-09-17 21:27:08 +03:00
|
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
2022-12-03 12:42:05 +02:00
|
|
|
|
import fastifyAccepts from '@fastify/accepts';
|
2022-09-17 21:27:08 +03:00
|
|
|
|
import httpSignature from '@peertube/http-signature';
|
|
|
|
|
import { Brackets, In, IsNull, LessThan, Not } from 'typeorm';
|
2022-12-03 12:42:05 +02:00
|
|
|
|
import accepts from 'accepts';
|
2022-12-23 01:50:58 +02:00
|
|
|
|
import vary from 'vary';
|
2022-09-17 21:27:08 +03:00
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2023-04-12 14:22:50 +03:00
|
|
|
|
import type { FollowingsRepository, NotesRepository, EmojisRepository, NoteReactionsRepository, UserProfilesRepository, UserNotePiningsRepository, UsersRepository, FollowRequestsRepository } from '@/models/index.js';
|
2022-09-17 21:27:08 +03:00
|
|
|
|
import * as url from '@/misc/prelude/url.js';
|
2022-09-20 23:33:11 +03:00
|
|
|
|
import type { Config } from '@/config.js';
|
2022-12-04 03:16:03 +02:00
|
|
|
|
import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
|
2022-09-17 21:27:08 +03:00
|
|
|
|
import { QueueService } from '@/core/QueueService.js';
|
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 18:09:29 +03:00
|
|
|
|
import type { LocalUser, RemoteUser, User } from '@/models/entities/User.js';
|
2023-04-05 06:10:40 +03:00
|
|
|
|
import { UserKeypairService } from '@/core/UserKeypairService.js';
|
2022-09-17 21:27:08 +03:00
|
|
|
|
import type { Following } from '@/models/entities/Following.js';
|
|
|
|
|
import { countIf } from '@/misc/prelude/array.js';
|
|
|
|
|
import type { Note } from '@/models/entities/Note.js';
|
|
|
|
|
import { QueryService } from '@/core/QueryService.js';
|
|
|
|
|
import { UtilityService } from '@/core/UtilityService.js';
|
|
|
|
|
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
2022-12-04 08:03:09 +02:00
|
|
|
|
import { bindThis } from '@/decorators.js';
|
2023-02-09 03:46:01 +02:00
|
|
|
|
import { IActivity } from '@/core/activitypub/type.js';
|
2022-12-13 17:01:45 +02:00
|
|
|
|
import type { FastifyInstance, FastifyRequest, FastifyReply, FastifyPluginOptions } from 'fastify';
|
2022-09-17 21:27:08 +03:00
|
|
|
|
import type { FindOptionsWhere } from 'typeorm';
|
|
|
|
|
|
|
|
|
|
const ACTIVITY_JSON = 'application/activity+json; charset=utf-8';
|
|
|
|
|
const LD_JSON = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"; charset=utf-8';
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class ActivityPubServerService {
|
|
|
|
|
constructor(
|
|
|
|
|
@Inject(DI.config)
|
|
|
|
|
private config: Config,
|
|
|
|
|
|
|
|
|
|
@Inject(DI.usersRepository)
|
|
|
|
|
private usersRepository: UsersRepository,
|
|
|
|
|
|
|
|
|
|
@Inject(DI.userProfilesRepository)
|
|
|
|
|
private userProfilesRepository: UserProfilesRepository,
|
|
|
|
|
|
|
|
|
|
@Inject(DI.notesRepository)
|
|
|
|
|
private notesRepository: NotesRepository,
|
|
|
|
|
|
|
|
|
|
@Inject(DI.noteReactionsRepository)
|
|
|
|
|
private noteReactionsRepository: NoteReactionsRepository,
|
|
|
|
|
|
|
|
|
|
@Inject(DI.emojisRepository)
|
|
|
|
|
private emojisRepository: EmojisRepository,
|
|
|
|
|
|
|
|
|
|
@Inject(DI.userNotePiningsRepository)
|
|
|
|
|
private userNotePiningsRepository: UserNotePiningsRepository,
|
|
|
|
|
|
|
|
|
|
@Inject(DI.followingsRepository)
|
|
|
|
|
private followingsRepository: FollowingsRepository,
|
|
|
|
|
|
2023-04-12 14:22:50 +03:00
|
|
|
|
@Inject(DI.followRequestsRepository)
|
|
|
|
|
private followRequestsRepository: FollowRequestsRepository,
|
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
|
private utilityService: UtilityService,
|
|
|
|
|
private userEntityService: UserEntityService,
|
|
|
|
|
private apRendererService: ApRendererService,
|
|
|
|
|
private queueService: QueueService,
|
2023-04-05 06:10:40 +03:00
|
|
|
|
private userKeypairService: UserKeypairService,
|
2022-09-17 21:27:08 +03:00
|
|
|
|
private queryService: QueryService,
|
|
|
|
|
) {
|
2022-12-04 08:03:09 +02:00
|
|
|
|
//this.createServer = this.createServer.bind(this);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 08:03:09 +02:00
|
|
|
|
@bindThis
|
2022-12-03 12:42:05 +02:00
|
|
|
|
private setResponseType(request: FastifyRequest, reply: FastifyReply): void {
|
|
|
|
|
const accept = request.accepts().type([ACTIVITY_JSON, LD_JSON]);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
if (accept === LD_JSON) {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.type(LD_JSON);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
} else {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.type(ACTIVITY_JSON);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Pack Create<Note> or Announce Activity
|
|
|
|
|
* @param note Note
|
|
|
|
|
*/
|
2022-12-04 08:03:09 +02:00
|
|
|
|
@bindThis
|
2022-09-18 21:11:50 +03:00
|
|
|
|
private async packActivity(note: Note): Promise<any> {
|
2022-09-17 21:27:08 +03:00
|
|
|
|
if (note.renoteId && note.text == null && !note.hasPoll && (note.fileIds == null || note.fileIds.length === 0)) {
|
2022-09-23 00:21:31 +03:00
|
|
|
|
const renote = await this.notesRepository.findOneByOrFail({ id: note.renoteId });
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return this.apRendererService.renderAnnounce(renote.uri ? renote.uri : `${this.config.url}/notes/${renote.id}`, note);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this.apRendererService.renderCreate(await this.apRendererService.renderNote(note, false), note);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 08:03:09 +02:00
|
|
|
|
@bindThis
|
2022-12-03 12:42:05 +02:00
|
|
|
|
private inbox(request: FastifyRequest, reply: FastifyReply) {
|
2022-12-25 07:53:50 +02:00
|
|
|
|
let signature;
|
2022-09-17 21:27:08 +03:00
|
|
|
|
|
|
|
|
|
try {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
signature = httpSignature.parseRequest(request.raw, { 'headers': [] });
|
2022-09-17 21:27:08 +03:00
|
|
|
|
} catch (e) {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(401);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-09 03:46:01 +02:00
|
|
|
|
// TODO: request.bodyのバリデーション?
|
|
|
|
|
this.queueService.inbox(request.body as IActivity, signature);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(202);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 08:03:09 +02:00
|
|
|
|
@bindThis
|
2022-12-03 12:42:05 +02:00
|
|
|
|
private async followers(
|
|
|
|
|
request: FastifyRequest<{ Params: { user: string; }; Querystring: { cursor?: string; page?: string; }; }>,
|
|
|
|
|
reply: FastifyReply,
|
|
|
|
|
) {
|
|
|
|
|
const userId = request.params.user;
|
2022-09-17 21:27:08 +03:00
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
const cursor = request.query.cursor;
|
2022-09-17 21:27:08 +03:00
|
|
|
|
if (cursor != null && typeof cursor !== 'string') {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(400);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
const page = request.query.page === 'true';
|
2022-09-17 21:27:08 +03:00
|
|
|
|
|
|
|
|
|
const user = await this.usersRepository.findOneBy({
|
|
|
|
|
id: userId,
|
|
|
|
|
host: IsNull(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (user == null) {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(404);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//#region Check ff visibility
|
|
|
|
|
const profile = await this.userProfilesRepository.findOneByOrFail({ userId: user.id });
|
|
|
|
|
|
|
|
|
|
if (profile.ffVisibility === 'private') {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(403);
|
|
|
|
|
reply.header('Cache-Control', 'public, max-age=30');
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
} else if (profile.ffVisibility === 'followers') {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(403);
|
|
|
|
|
reply.header('Cache-Control', 'public, max-age=30');
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
|
|
const limit = 10;
|
|
|
|
|
const partOf = `${this.config.url}/users/${userId}/followers`;
|
|
|
|
|
|
|
|
|
|
if (page) {
|
|
|
|
|
const query = {
|
|
|
|
|
followeeId: user.id,
|
|
|
|
|
} as FindOptionsWhere<Following>;
|
|
|
|
|
|
|
|
|
|
// カーソルが指定されている場合
|
|
|
|
|
if (cursor) {
|
|
|
|
|
query.id = LessThan(cursor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get followers
|
|
|
|
|
const followings = await this.followingsRepository.find({
|
|
|
|
|
where: query,
|
|
|
|
|
take: limit + 1,
|
|
|
|
|
order: { id: -1 },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 「次のページ」があるかどうか
|
|
|
|
|
const inStock = followings.length === limit + 1;
|
|
|
|
|
if (inStock) followings.pop();
|
|
|
|
|
|
|
|
|
|
const renderedFollowers = await Promise.all(followings.map(following => this.apRendererService.renderFollowUser(following.followerId)));
|
|
|
|
|
const rendered = this.apRendererService.renderOrderedCollectionPage(
|
|
|
|
|
`${partOf}?${url.query({
|
|
|
|
|
page: 'true',
|
|
|
|
|
cursor,
|
|
|
|
|
})}`,
|
|
|
|
|
user.followersCount, renderedFollowers, partOf,
|
|
|
|
|
undefined,
|
|
|
|
|
inStock ? `${partOf}?${url.query({
|
|
|
|
|
page: 'true',
|
|
|
|
|
cursor: followings[followings.length - 1].id,
|
|
|
|
|
})}` : undefined,
|
|
|
|
|
);
|
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
this.setResponseType(request, reply);
|
2023-02-12 11:47:30 +02:00
|
|
|
|
return (this.apRendererService.addContext(rendered));
|
2022-09-17 21:27:08 +03:00
|
|
|
|
} else {
|
|
|
|
|
// index page
|
|
|
|
|
const rendered = this.apRendererService.renderOrderedCollection(partOf, user.followersCount, `${partOf}?page=true`);
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.header('Cache-Control', 'public, max-age=180');
|
|
|
|
|
this.setResponseType(request, reply);
|
2023-02-12 11:47:30 +02:00
|
|
|
|
return (this.apRendererService.addContext(rendered));
|
2022-09-17 21:27:08 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 08:03:09 +02:00
|
|
|
|
@bindThis
|
2022-12-03 12:42:05 +02:00
|
|
|
|
private async following(
|
|
|
|
|
request: FastifyRequest<{ Params: { user: string; }; Querystring: { cursor?: string; page?: string; }; }>,
|
|
|
|
|
reply: FastifyReply,
|
|
|
|
|
) {
|
|
|
|
|
const userId = request.params.user;
|
2022-09-17 21:27:08 +03:00
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
const cursor = request.query.cursor;
|
2022-09-17 21:27:08 +03:00
|
|
|
|
if (cursor != null && typeof cursor !== 'string') {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(400);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
const page = request.query.page === 'true';
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
|
const user = await this.usersRepository.findOneBy({
|
|
|
|
|
id: userId,
|
|
|
|
|
host: IsNull(),
|
|
|
|
|
});
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
|
if (user == null) {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(404);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
|
//#region Check ff visibility
|
|
|
|
|
const profile = await this.userProfilesRepository.findOneByOrFail({ userId: user.id });
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
|
if (profile.ffVisibility === 'private') {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(403);
|
|
|
|
|
reply.header('Cache-Control', 'public, max-age=30');
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
} else if (profile.ffVisibility === 'followers') {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(403);
|
|
|
|
|
reply.header('Cache-Control', 'public, max-age=30');
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//#endregion
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
|
const limit = 10;
|
|
|
|
|
const partOf = `${this.config.url}/users/${userId}/following`;
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
|
if (page) {
|
|
|
|
|
const query = {
|
|
|
|
|
followerId: user.id,
|
|
|
|
|
} as FindOptionsWhere<Following>;
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
|
// カーソルが指定されている場合
|
|
|
|
|
if (cursor) {
|
|
|
|
|
query.id = LessThan(cursor);
|
|
|
|
|
}
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
|
// Get followings
|
|
|
|
|
const followings = await this.followingsRepository.find({
|
|
|
|
|
where: query,
|
|
|
|
|
take: limit + 1,
|
|
|
|
|
order: { id: -1 },
|
|
|
|
|
});
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
|
// 「次のページ」があるかどうか
|
|
|
|
|
const inStock = followings.length === limit + 1;
|
|
|
|
|
if (inStock) followings.pop();
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
|
const renderedFollowees = await Promise.all(followings.map(following => this.apRendererService.renderFollowUser(following.followeeId)));
|
|
|
|
|
const rendered = this.apRendererService.renderOrderedCollectionPage(
|
|
|
|
|
`${partOf}?${url.query({
|
|
|
|
|
page: 'true',
|
|
|
|
|
cursor,
|
|
|
|
|
})}`,
|
|
|
|
|
user.followingCount, renderedFollowees, partOf,
|
|
|
|
|
undefined,
|
|
|
|
|
inStock ? `${partOf}?${url.query({
|
|
|
|
|
page: 'true',
|
|
|
|
|
cursor: followings[followings.length - 1].id,
|
|
|
|
|
})}` : undefined,
|
|
|
|
|
);
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
this.setResponseType(request, reply);
|
2023-02-12 11:47:30 +02:00
|
|
|
|
return (this.apRendererService.addContext(rendered));
|
2022-09-17 21:27:08 +03:00
|
|
|
|
} else {
|
|
|
|
|
// index page
|
|
|
|
|
const rendered = this.apRendererService.renderOrderedCollection(partOf, user.followingCount, `${partOf}?page=true`);
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.header('Cache-Control', 'public, max-age=180');
|
|
|
|
|
this.setResponseType(request, reply);
|
2023-02-12 11:47:30 +02:00
|
|
|
|
return (this.apRendererService.addContext(rendered));
|
2022-09-17 21:27:08 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 08:03:09 +02:00
|
|
|
|
@bindThis
|
2022-12-03 12:42:05 +02:00
|
|
|
|
private async featured(request: FastifyRequest<{ Params: { user: string; }; }>, reply: FastifyReply) {
|
|
|
|
|
const userId = request.params.user;
|
2022-09-17 21:27:08 +03:00
|
|
|
|
|
|
|
|
|
const user = await this.usersRepository.findOneBy({
|
|
|
|
|
id: userId,
|
|
|
|
|
host: IsNull(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (user == null) {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(404);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const pinings = await this.userNotePiningsRepository.find({
|
|
|
|
|
where: { userId: user.id },
|
|
|
|
|
order: { id: 'DESC' },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const pinnedNotes = await Promise.all(pinings.map(pining =>
|
|
|
|
|
this.notesRepository.findOneByOrFail({ id: pining.noteId })));
|
|
|
|
|
|
|
|
|
|
const renderedNotes = await Promise.all(pinnedNotes.map(note => this.apRendererService.renderNote(note)));
|
|
|
|
|
|
|
|
|
|
const rendered = this.apRendererService.renderOrderedCollection(
|
|
|
|
|
`${this.config.url}/users/${userId}/collections/featured`,
|
|
|
|
|
renderedNotes.length, undefined, undefined, renderedNotes,
|
|
|
|
|
);
|
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.header('Cache-Control', 'public, max-age=180');
|
|
|
|
|
this.setResponseType(request, reply);
|
2023-02-12 11:47:30 +02:00
|
|
|
|
return (this.apRendererService.addContext(rendered));
|
2022-09-17 21:27:08 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 08:03:09 +02:00
|
|
|
|
@bindThis
|
2022-12-03 12:42:05 +02:00
|
|
|
|
private async outbox(
|
|
|
|
|
request: FastifyRequest<{
|
|
|
|
|
Params: { user: string; };
|
|
|
|
|
Querystring: { since_id?: string; until_id?: string; page?: string; };
|
|
|
|
|
}>,
|
|
|
|
|
reply: FastifyReply,
|
|
|
|
|
) {
|
|
|
|
|
const userId = request.params.user;
|
2022-09-17 21:27:08 +03:00
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
const sinceId = request.query.since_id;
|
2022-09-17 21:27:08 +03:00
|
|
|
|
if (sinceId != null && typeof sinceId !== 'string') {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(400);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
const untilId = request.query.until_id;
|
2022-09-17 21:27:08 +03:00
|
|
|
|
if (untilId != null && typeof untilId !== 'string') {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(400);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
const page = request.query.page === 'true';
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
|
if (countIf(x => x != null, [sinceId, untilId]) > 1) {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(400);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
|
const user = await this.usersRepository.findOneBy({
|
|
|
|
|
id: userId,
|
|
|
|
|
host: IsNull(),
|
|
|
|
|
});
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
|
if (user == null) {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(404);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
|
const limit = 20;
|
|
|
|
|
const partOf = `${this.config.url}/users/${userId}/outbox`;
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
|
if (page) {
|
|
|
|
|
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), sinceId, untilId)
|
|
|
|
|
.andWhere('note.userId = :userId', { userId: user.id })
|
|
|
|
|
.andWhere(new Brackets(qb => { qb
|
|
|
|
|
.where('note.visibility = \'public\'')
|
|
|
|
|
.orWhere('note.visibility = \'home\'');
|
|
|
|
|
}))
|
|
|
|
|
.andWhere('note.localOnly = FALSE');
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
|
const notes = await query.take(limit).getMany();
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
|
if (sinceId) notes.reverse();
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-09-18 21:11:50 +03:00
|
|
|
|
const activities = await Promise.all(notes.map(note => this.packActivity(note)));
|
2022-09-17 21:27:08 +03:00
|
|
|
|
const rendered = this.apRendererService.renderOrderedCollectionPage(
|
|
|
|
|
`${partOf}?${url.query({
|
|
|
|
|
page: 'true',
|
|
|
|
|
since_id: sinceId,
|
|
|
|
|
until_id: untilId,
|
|
|
|
|
})}`,
|
|
|
|
|
user.notesCount, activities, partOf,
|
|
|
|
|
notes.length ? `${partOf}?${url.query({
|
|
|
|
|
page: 'true',
|
|
|
|
|
since_id: notes[0].id,
|
|
|
|
|
})}` : undefined,
|
|
|
|
|
notes.length ? `${partOf}?${url.query({
|
|
|
|
|
page: 'true',
|
|
|
|
|
until_id: notes[notes.length - 1].id,
|
|
|
|
|
})}` : undefined,
|
|
|
|
|
);
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
this.setResponseType(request, reply);
|
2023-02-12 11:47:30 +02:00
|
|
|
|
return (this.apRendererService.addContext(rendered));
|
2022-09-17 21:27:08 +03:00
|
|
|
|
} else {
|
|
|
|
|
// index page
|
|
|
|
|
const rendered = this.apRendererService.renderOrderedCollection(partOf, user.notesCount,
|
|
|
|
|
`${partOf}?page=true`,
|
|
|
|
|
`${partOf}?page=true&since_id=000000000000000000000000`,
|
|
|
|
|
);
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.header('Cache-Control', 'public, max-age=180');
|
|
|
|
|
this.setResponseType(request, reply);
|
2023-02-12 11:47:30 +02:00
|
|
|
|
return (this.apRendererService.addContext(rendered));
|
2022-09-17 21:27:08 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 08:03:09 +02:00
|
|
|
|
@bindThis
|
2022-12-03 12:42:05 +02:00
|
|
|
|
private async userInfo(request: FastifyRequest, reply: FastifyReply, user: User | null) {
|
2022-09-17 21:27:08 +03:00
|
|
|
|
if (user == null) {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(404);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.header('Cache-Control', 'public, max-age=180');
|
|
|
|
|
this.setResponseType(request, reply);
|
2023-02-13 08:50:22 +02:00
|
|
|
|
return (this.apRendererService.addContext(await this.apRendererService.renderPerson(user as LocalUser)));
|
2022-09-17 21:27:08 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 08:03:09 +02:00
|
|
|
|
@bindThis
|
2022-12-03 12:42:05 +02:00
|
|
|
|
public createServer(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) {
|
2023-02-09 03:46:01 +02:00
|
|
|
|
// addConstraintStrategy の型定義がおかしいため
|
|
|
|
|
(fastify.addConstraintStrategy as any)({
|
2022-12-03 12:42:05 +02:00
|
|
|
|
name: 'apOrHtml',
|
|
|
|
|
storage() {
|
2023-02-09 03:46:01 +02:00
|
|
|
|
const store = {} as any;
|
2022-12-03 12:42:05 +02:00
|
|
|
|
return {
|
2023-02-09 03:46:01 +02:00
|
|
|
|
get(key: string) {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
return store[key] ?? null;
|
|
|
|
|
},
|
2023-02-09 03:46:01 +02:00
|
|
|
|
set(key: string, value: any) {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
store[key] = value;
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
},
|
2023-02-09 03:46:01 +02:00
|
|
|
|
deriveConstraint(request: IncomingMessage) {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
const accepted = accepts(request).type(['html', ACTIVITY_JSON, LD_JSON]);
|
|
|
|
|
const isAp = typeof accepted === 'string' && !accepted.match(/html/);
|
|
|
|
|
return isAp ? 'ap' : 'html';
|
|
|
|
|
},
|
|
|
|
|
});
|
2022-09-17 21:27:08 +03:00
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
fastify.register(fastifyAccepts);
|
2022-12-06 02:21:36 +02:00
|
|
|
|
fastify.addContentTypeParser('application/activity+json', { parseAs: 'string' }, fastify.getDefaultJsonParser('ignore', 'ignore'));
|
|
|
|
|
fastify.addContentTypeParser('application/ld+json', { parseAs: 'string' }, fastify.getDefaultJsonParser('ignore', 'ignore'));
|
2022-09-17 21:27:08 +03:00
|
|
|
|
|
2023-02-12 01:22:42 +02:00
|
|
|
|
fastify.addHook('onRequest', (request, reply, done) => {
|
|
|
|
|
reply.header('Access-Control-Allow-Headers', 'Accept');
|
|
|
|
|
reply.header('Access-Control-Allow-Methods', 'GET, OPTIONS');
|
|
|
|
|
reply.header('Access-Control-Allow-Origin', '*');
|
|
|
|
|
reply.header('Access-Control-Expose-Headers', 'Vary');
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
//#region Routing
|
2022-12-25 07:56:59 +02:00
|
|
|
|
// inbox (limit: 64kb)
|
|
|
|
|
fastify.post('/inbox', { bodyLimit: 1024 * 64 }, async (request, reply) => await this.inbox(request, reply));
|
|
|
|
|
fastify.post('/users/:user/inbox', { bodyLimit: 1024 * 64 }, async (request, reply) => await this.inbox(request, reply));
|
2022-09-17 21:27:08 +03:00
|
|
|
|
|
|
|
|
|
// note
|
2022-12-03 12:42:05 +02:00
|
|
|
|
fastify.get<{ Params: { note: string; } }>('/notes/:note', { constraints: { apOrHtml: 'ap' } }, async (request, reply) => {
|
2022-12-23 01:50:58 +02:00
|
|
|
|
vary(reply.raw, 'Accept');
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
|
const note = await this.notesRepository.findOneBy({
|
2022-12-03 12:42:05 +02:00
|
|
|
|
id: request.params.note,
|
2022-12-04 03:32:12 +02:00
|
|
|
|
visibility: In(['public', 'home']),
|
2022-09-17 21:27:08 +03:00
|
|
|
|
localOnly: false,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (note == null) {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(404);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// リモートだったらリダイレクト
|
|
|
|
|
if (note.userHost != null) {
|
|
|
|
|
if (note.uri == null || this.utilityService.isSelfHost(note.userHost)) {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(500);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.redirect(note.uri);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.header('Cache-Control', 'public, max-age=180');
|
|
|
|
|
this.setResponseType(request, reply);
|
2023-02-12 11:47:30 +02:00
|
|
|
|
return this.apRendererService.addContext(await this.apRendererService.renderNote(note, false));
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// note activity
|
2022-12-03 12:42:05 +02:00
|
|
|
|
fastify.get<{ Params: { note: string; } }>('/notes/:note/activity', async (request, reply) => {
|
2022-12-23 01:50:58 +02:00
|
|
|
|
vary(reply.raw, 'Accept');
|
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
|
const note = await this.notesRepository.findOneBy({
|
2022-12-03 12:42:05 +02:00
|
|
|
|
id: request.params.note,
|
2022-09-17 21:27:08 +03:00
|
|
|
|
userHost: IsNull(),
|
2022-12-04 03:32:12 +02:00
|
|
|
|
visibility: In(['public', 'home']),
|
2022-09-17 21:27:08 +03:00
|
|
|
|
localOnly: false,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (note == null) {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(404);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.header('Cache-Control', 'public, max-age=180');
|
|
|
|
|
this.setResponseType(request, reply);
|
2023-02-12 11:47:30 +02:00
|
|
|
|
return (this.apRendererService.addContext(await this.packActivity(note)));
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// outbox
|
2022-12-03 12:42:05 +02:00
|
|
|
|
fastify.get<{
|
|
|
|
|
Params: { user: string; };
|
|
|
|
|
Querystring: { since_id?: string; until_id?: string; page?: string; };
|
|
|
|
|
}>('/users/:user/outbox', async (request, reply) => await this.outbox(request, reply));
|
2022-09-17 21:27:08 +03:00
|
|
|
|
|
|
|
|
|
// followers
|
2022-12-03 12:42:05 +02:00
|
|
|
|
fastify.get<{
|
|
|
|
|
Params: { user: string; };
|
|
|
|
|
Querystring: { cursor?: string; page?: string; };
|
|
|
|
|
}>('/users/:user/followers', async (request, reply) => await this.followers(request, reply));
|
2022-09-17 21:27:08 +03:00
|
|
|
|
|
|
|
|
|
// following
|
2022-12-03 12:42:05 +02:00
|
|
|
|
fastify.get<{
|
|
|
|
|
Params: { user: string; };
|
|
|
|
|
Querystring: { cursor?: string; page?: string; };
|
|
|
|
|
}>('/users/:user/following', async (request, reply) => await this.following(request, reply));
|
2022-09-17 21:27:08 +03:00
|
|
|
|
|
|
|
|
|
// featured
|
2022-12-03 12:42:05 +02:00
|
|
|
|
fastify.get<{ Params: { user: string; }; }>('/users/:user/collections/featured', async (request, reply) => await this.featured(request, reply));
|
2022-09-17 21:27:08 +03:00
|
|
|
|
|
|
|
|
|
// publickey
|
2022-12-03 12:42:05 +02:00
|
|
|
|
fastify.get<{ Params: { user: string; } }>('/users/:user/publickey', async (request, reply) => {
|
|
|
|
|
const userId = request.params.user;
|
2022-09-17 21:27:08 +03:00
|
|
|
|
|
|
|
|
|
const user = await this.usersRepository.findOneBy({
|
|
|
|
|
id: userId,
|
|
|
|
|
host: IsNull(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (user == null) {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(404);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 06:10:40 +03:00
|
|
|
|
const keypair = await this.userKeypairService.getUserKeypair(user.id);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
|
|
|
|
|
if (this.userEntityService.isLocalUser(user)) {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.header('Cache-Control', 'public, max-age=180');
|
|
|
|
|
this.setResponseType(request, reply);
|
2023-02-12 11:47:30 +02:00
|
|
|
|
return (this.apRendererService.addContext(this.apRendererService.renderKey(user, keypair)));
|
2022-09-17 21:27:08 +03:00
|
|
|
|
} else {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(400);
|
2023-02-09 04:02:37 +02:00
|
|
|
|
return;
|
2022-09-17 21:27:08 +03:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
fastify.get<{ Params: { user: string; } }>('/users/:user', { constraints: { apOrHtml: 'ap' } }, async (request, reply) => {
|
|
|
|
|
const userId = request.params.user;
|
2022-09-17 21:27:08 +03:00
|
|
|
|
|
|
|
|
|
const user = await this.usersRepository.findOneBy({
|
|
|
|
|
id: userId,
|
|
|
|
|
host: IsNull(),
|
|
|
|
|
isSuspended: false,
|
|
|
|
|
});
|
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
return await this.userInfo(request, reply, user);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
fastify.get<{ Params: { user: string; } }>('/@:user', { constraints: { apOrHtml: 'ap' } }, async (request, reply) => {
|
2022-09-17 21:27:08 +03:00
|
|
|
|
const user = await this.usersRepository.findOneBy({
|
2022-12-03 12:42:05 +02:00
|
|
|
|
usernameLower: request.params.user.toLowerCase(),
|
2022-09-17 21:27:08 +03:00
|
|
|
|
host: IsNull(),
|
|
|
|
|
isSuspended: false,
|
|
|
|
|
});
|
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
return await this.userInfo(request, reply, user);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
|
|
// emoji
|
2022-12-03 12:42:05 +02:00
|
|
|
|
fastify.get<{ Params: { emoji: string; } }>('/emojis/:emoji', async (request, reply) => {
|
2022-09-17 21:27:08 +03:00
|
|
|
|
const emoji = await this.emojisRepository.findOneBy({
|
|
|
|
|
host: IsNull(),
|
2022-12-03 12:42:05 +02:00
|
|
|
|
name: request.params.emoji,
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
|
|
|
|
|
2023-05-18 12:48:35 +03:00
|
|
|
|
if (emoji == null || emoji.localOnly) {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(404);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.header('Cache-Control', 'public, max-age=180');
|
|
|
|
|
this.setResponseType(request, reply);
|
2023-02-12 11:47:30 +02:00
|
|
|
|
return (this.apRendererService.addContext(await this.apRendererService.renderEmoji(emoji)));
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// like
|
2022-12-03 12:42:05 +02:00
|
|
|
|
fastify.get<{ Params: { like: string; } }>('/likes/:like', async (request, reply) => {
|
|
|
|
|
const reaction = await this.noteReactionsRepository.findOneBy({ id: request.params.like });
|
2022-09-17 21:27:08 +03:00
|
|
|
|
|
|
|
|
|
if (reaction == null) {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(404);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const note = await this.notesRepository.findOneBy({ id: reaction.noteId });
|
|
|
|
|
|
|
|
|
|
if (note == null) {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(404);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.header('Cache-Control', 'public, max-age=180');
|
|
|
|
|
this.setResponseType(request, reply);
|
2023-02-12 11:47:30 +02:00
|
|
|
|
return (this.apRendererService.addContext(await this.apRendererService.renderLike(reaction, note)));
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// follow
|
2022-12-03 12:42:05 +02:00
|
|
|
|
fastify.get<{ Params: { follower: string; followee: string; } }>('/follows/:follower/:followee', async (request, reply) => {
|
2022-09-17 21:27:08 +03:00
|
|
|
|
// This may be used before the follow is completed, so we do not
|
|
|
|
|
// check if the following exists.
|
|
|
|
|
|
|
|
|
|
const [follower, followee] = await Promise.all([
|
|
|
|
|
this.usersRepository.findOneBy({
|
2022-12-03 12:42:05 +02:00
|
|
|
|
id: request.params.follower,
|
2022-09-17 21:27:08 +03:00
|
|
|
|
host: IsNull(),
|
|
|
|
|
}),
|
|
|
|
|
this.usersRepository.findOneBy({
|
2022-12-03 12:42:05 +02:00
|
|
|
|
id: request.params.followee,
|
2022-09-17 21:27:08 +03:00
|
|
|
|
host: Not(IsNull()),
|
|
|
|
|
}),
|
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 18:09:29 +03:00
|
|
|
|
]) as [LocalUser | RemoteUser | null, LocalUser | RemoteUser | null];
|
2022-09-17 21:27:08 +03:00
|
|
|
|
|
|
|
|
|
if (follower == null || followee == null) {
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.code(404);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
reply.header('Cache-Control', 'public, max-age=180');
|
|
|
|
|
this.setResponseType(request, reply);
|
2023-02-12 11:47:30 +02:00
|
|
|
|
return (this.apRendererService.addContext(this.apRendererService.renderFollow(follower, followee)));
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
|
|
|
|
|
2023-04-12 14:22:50 +03:00
|
|
|
|
// follow
|
|
|
|
|
fastify.get<{ Params: { followRequestId: string ; } }>('/follows/:followRequestId', async (request, reply) => {
|
|
|
|
|
// This may be used before the follow is completed, so we do not
|
|
|
|
|
// check if the following exists and only check if the follow request exists.
|
|
|
|
|
|
|
|
|
|
const followRequest = await this.followRequestsRepository.findOneBy({
|
|
|
|
|
id: request.params.followRequestId,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (followRequest == null) {
|
|
|
|
|
reply.code(404);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const [follower, followee] = await Promise.all([
|
|
|
|
|
this.usersRepository.findOneBy({
|
|
|
|
|
id: followRequest.followerId,
|
|
|
|
|
host: IsNull(),
|
|
|
|
|
}),
|
|
|
|
|
this.usersRepository.findOneBy({
|
|
|
|
|
id: followRequest.followeeId,
|
|
|
|
|
host: Not(IsNull()),
|
|
|
|
|
}),
|
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 18:09:29 +03:00
|
|
|
|
]) as [LocalUser | RemoteUser | null, LocalUser | RemoteUser | null];
|
2023-04-12 14:22:50 +03:00
|
|
|
|
|
|
|
|
|
if (follower == null || followee == null) {
|
|
|
|
|
reply.code(404);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reply.header('Cache-Control', 'public, max-age=180');
|
|
|
|
|
this.setResponseType(request, reply);
|
|
|
|
|
return (this.apRendererService.addContext(this.apRendererService.renderFollow(follower, followee)));
|
|
|
|
|
});
|
|
|
|
|
|
2022-12-03 12:42:05 +02:00
|
|
|
|
done();
|
2022-09-17 21:27:08 +03:00
|
|
|
|
}
|
|
|
|
|
}
|