2023-07-27 07:31:52 +02:00
|
|
|
/*
|
2024-02-13 16:59:27 +01:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
|
|
import { IdService } from '@/core/IdService.js';
|
2023-09-15 07:28:29 +02:00
|
|
|
import type { UserListsRepository, AntennasRepository } from '@/models/_.js';
|
2022-09-17 20:27:08 +02:00
|
|
|
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
|
|
|
import { AntennaEntityService } from '@/core/entities/AntennaEntityService.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2023-01-12 13:02:26 +01:00
|
|
|
import { RoleService } from '@/core/RoleService.js';
|
2022-02-27 03:07:39 +01:00
|
|
|
import { ApiError } from '../../error.js';
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['antennas'],
|
|
|
|
|
2022-01-18 14:27:10 +01:00
|
|
|
requireCredential: true,
|
2020-01-29 20:37:25 +01: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,
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
kind: 'write:account',
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchUserList: {
|
|
|
|
message: 'No such user list.',
|
|
|
|
code: 'NO_SUCH_USER_LIST',
|
2021-12-09 15:58:30 +01:00
|
|
|
id: '95063e93-a283-4b8b-9aa5-bcdb8df69a7f',
|
2020-02-14 17:03:59 +01:00
|
|
|
},
|
|
|
|
|
2022-12-26 00:50:17 +01:00
|
|
|
tooManyAntennas: {
|
|
|
|
message: 'You cannot create antenna any more.',
|
|
|
|
code: 'TOO_MANY_ANTENNAS',
|
|
|
|
id: 'faf47050-e8b5-438c-913c-db2b1576fde4',
|
|
|
|
},
|
2021-03-06 14:34:11 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 15:58:30 +01:00
|
|
|
ref: 'Antenna',
|
|
|
|
},
|
2022-01-18 14:27:10 +01:00
|
|
|
} as const;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-02-20 05:15:40 +01:00
|
|
|
export const paramDef = {
|
2022-02-19 06:05:32 +01:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
name: { type: 'string', minLength: 1, maxLength: 100 },
|
2023-09-22 09:52:43 +02:00
|
|
|
src: { type: 'string', enum: ['home', 'all', 'users', 'list', 'users_blacklist'] },
|
2022-02-19 06:05:32 +01:00
|
|
|
userListId: { type: 'string', format: 'misskey:id', nullable: true },
|
|
|
|
keywords: { type: 'array', items: {
|
|
|
|
type: 'array', items: {
|
|
|
|
type: 'string',
|
|
|
|
},
|
|
|
|
} },
|
|
|
|
excludeKeywords: { type: 'array', items: {
|
|
|
|
type: 'array', items: {
|
|
|
|
type: 'string',
|
|
|
|
},
|
|
|
|
} },
|
|
|
|
users: { type: 'array', items: {
|
|
|
|
type: 'string',
|
|
|
|
} },
|
|
|
|
caseSensitive: { type: 'boolean' },
|
2023-10-16 08:06:00 +02:00
|
|
|
localOnly: { type: 'boolean' },
|
2024-03-20 23:51:01 +01:00
|
|
|
excludeBots: { type: 'boolean' },
|
2022-02-19 06:05:32 +01:00
|
|
|
withReplies: { type: 'boolean' },
|
|
|
|
withFile: { type: 'boolean' },
|
|
|
|
notify: { type: 'boolean' },
|
|
|
|
},
|
|
|
|
required: ['name', 'src', 'keywords', 'excludeKeywords', 'users', 'caseSensitive', 'withReplies', 'withFile', 'notify'],
|
|
|
|
} as const;
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
@Injectable()
|
2023-08-17 14:20:58 +02:00
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
2022-09-17 20:27:08 +02:00
|
|
|
constructor(
|
|
|
|
@Inject(DI.antennasRepository)
|
|
|
|
private antennasRepository: AntennasRepository,
|
2020-03-04 03:45:33 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
@Inject(DI.userListsRepository)
|
|
|
|
private userListsRepository: UserListsRepository,
|
2020-03-04 03:45:33 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
private antennaEntityService: AntennaEntityService,
|
2023-01-12 13:02:26 +01:00
|
|
|
private roleService: RoleService,
|
2022-09-17 20:27:08 +02:00
|
|
|
private idService: IdService,
|
|
|
|
private globalEventService: GlobalEventService,
|
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
2023-08-21 10:33:04 +02:00
|
|
|
if (ps.keywords.flat().every(x => x === '') && ps.excludeKeywords.flat().every(x => x === '')) {
|
|
|
|
throw new Error('either keywords or excludeKeywords is required.');
|
2023-03-15 10:09:00 +01:00
|
|
|
}
|
|
|
|
|
2022-12-26 00:50:17 +01:00
|
|
|
const currentAntennasCount = await this.antennasRepository.countBy({
|
|
|
|
userId: me.id,
|
|
|
|
});
|
2023-01-15 12:52:53 +01:00
|
|
|
if (currentAntennasCount > (await this.roleService.getUserPolicies(me.id)).antennaLimit) {
|
2022-12-26 00:50:17 +01:00
|
|
|
throw new ApiError(meta.errors.tooManyAntennas);
|
|
|
|
}
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
let userList;
|
|
|
|
|
|
|
|
if (ps.src === 'list' && ps.userListId) {
|
|
|
|
userList = await this.userListsRepository.findOneBy({
|
|
|
|
id: ps.userListId,
|
|
|
|
userId: me.id,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (userList == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchUserList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-20 12:12:38 +01:00
|
|
|
const now = new Date();
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const antenna = await this.antennasRepository.insert({
|
2023-10-16 03:45:22 +02:00
|
|
|
id: this.idService.gen(now.getTime()),
|
2023-03-20 12:12:38 +01:00
|
|
|
lastUsedAt: now,
|
2022-09-17 20:27:08 +02:00
|
|
|
userId: me.id,
|
|
|
|
name: ps.name,
|
|
|
|
src: ps.src,
|
|
|
|
userListId: userList ? userList.id : null,
|
|
|
|
keywords: ps.keywords,
|
|
|
|
excludeKeywords: ps.excludeKeywords,
|
|
|
|
users: ps.users,
|
|
|
|
caseSensitive: ps.caseSensitive,
|
2023-10-16 08:06:00 +02:00
|
|
|
localOnly: ps.localOnly,
|
2024-03-20 23:51:01 +01:00
|
|
|
excludeBots: ps.excludeBots,
|
2022-09-17 20:27:08 +02:00
|
|
|
withReplies: ps.withReplies,
|
|
|
|
withFile: ps.withFile,
|
|
|
|
notify: ps.notify,
|
|
|
|
}).then(x => this.antennasRepository.findOneByOrFail(x.identifiers[0]));
|
|
|
|
|
|
|
|
this.globalEventService.publishInternalEvent('antennaCreated', antenna);
|
|
|
|
|
|
|
|
return await this.antennaEntityService.pack(antenna);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|