mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-12-22 16:30:13 +00:00
refactor: introduce bindThis decorator to bind this automaticaly
This commit is contained in:
parent
e73581f715
commit
bbb49457f9
199 changed files with 969 additions and 96 deletions
|
@ -7,6 +7,7 @@ import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
|
|||
import { RelayService } from '@/core/RelayService.js';
|
||||
import { ApDeliverManagerService } from '@/core/activitypub/ApDeliverManagerService.js';
|
||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class AccountUpdateService {
|
||||
|
@ -24,6 +25,7 @@ export class AccountUpdateService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async publishToFollowers(userId: User['id']) {
|
||||
const user = await this.usersRepository.findOneBy({ id: userId });
|
||||
if (user == null) throw new Error('user not found');
|
||||
|
|
|
@ -12,6 +12,7 @@ const _dirname = dirname(_filename);
|
|||
|
||||
const REQUIRED_CPU_FLAGS = ['avx2', 'fma'];
|
||||
let isSupportedCpu: undefined | boolean = undefined;
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class AiService {
|
||||
|
@ -23,6 +24,7 @@ export class AiService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async detectSensitive(path: string): Promise<nsfw.predictionType[] | null> {
|
||||
try {
|
||||
if (isSupportedCpu === undefined) {
|
||||
|
@ -53,6 +55,7 @@ export class AiService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async getCpuFlags(): Promise<string[]> {
|
||||
const str = await si.cpuFlags();
|
||||
return str.split(/\s+/);
|
||||
|
|
|
@ -13,6 +13,7 @@ import { DI } from '@/di-symbols.js';
|
|||
import type { MutingsRepository, BlockingsRepository, NotesRepository, AntennaNotesRepository, AntennasRepository, UserGroupJoiningsRepository, UserListJoiningsRepository } from '@/models/index.js';
|
||||
import { UtilityService } from '@/core/UtilityService.js';
|
||||
import type { OnApplicationShutdown } from '@nestjs/common';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class AntennaService implements OnApplicationShutdown {
|
||||
|
@ -56,10 +57,12 @@ export class AntennaService implements OnApplicationShutdown {
|
|||
this.redisSubscriber.on('message', this.onRedisMessage);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public onApplicationShutdown(signal?: string | undefined) {
|
||||
this.redisSubscriber.off('message', this.onRedisMessage);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async onRedisMessage(_: string, data: string): Promise<void> {
|
||||
const obj = JSON.parse(data);
|
||||
|
||||
|
@ -81,6 +84,7 @@ export class AntennaService implements OnApplicationShutdown {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async addNoteToAntenna(antenna: Antenna, note: Note, noteUser: { id: User['id']; }): Promise<void> {
|
||||
// 通知しない設定になっているか、自分自身の投稿なら既読にする
|
||||
const read = !antenna.notify || (antenna.userId === noteUser.id);
|
||||
|
@ -133,6 +137,7 @@ export class AntennaService implements OnApplicationShutdown {
|
|||
/**
|
||||
* noteUserFollowers / antennaUserFollowing はどちらか一方が指定されていればよい
|
||||
*/
|
||||
@bindThis
|
||||
public async checkHitAntenna(antenna: Antenna, note: (Note | Packed<'Note'>), noteUser: { id: User['id']; username: string; host: string | null; }, noteUserFollowers?: User['id'][], antennaUserFollowing?: User['id'][]): Promise<boolean> {
|
||||
if (note.visibility === 'specified') return false;
|
||||
|
||||
|
@ -217,6 +222,7 @@ export class AntennaService implements OnApplicationShutdown {
|
|||
return true;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async getAntennas() {
|
||||
if (!this.antennasFetched) {
|
||||
this.antennas = await this.antennasRepository.find();
|
||||
|
|
|
@ -8,6 +8,7 @@ import { DI } from '@/di-symbols.js';
|
|||
* Retry delay (ms) for lock acquisition
|
||||
*/
|
||||
const retryDelay = 100;
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class AppLockService {
|
||||
|
@ -26,14 +27,17 @@ export class AppLockService {
|
|||
* @param timeout Lock timeout (ms), The timeout releases previous lock.
|
||||
* @returns Unlock function
|
||||
*/
|
||||
@bindThis
|
||||
public getApLock(uri: string, timeout = 30 * 1000): Promise<() => void> {
|
||||
return this.lock(`ap-object:${uri}`, timeout);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public getFetchInstanceMetadataLock(host: string, timeout = 30 * 1000): Promise<() => void> {
|
||||
return this.lock(`instance:${host}`, timeout);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public getChartInsertLock(lockKey: string, timeout = 30 * 1000): Promise<() => void> {
|
||||
return this.lock(`chart-insert:${lockKey}`, timeout);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import { DI } from '@/di-symbols.js';
|
|||
import type { UsersRepository } from '@/models/index.js';
|
||||
import type { Config } from '@/config.js';
|
||||
import { HttpRequestService } from '@/core/HttpRequestService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
type CaptchaResponse = {
|
||||
success: boolean;
|
||||
|
@ -19,6 +20,7 @@ export class CaptchaService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async getCaptchaResponse(url: string, secret: string, response: string): Promise<CaptchaResponse> {
|
||||
const params = new URLSearchParams({
|
||||
secret,
|
||||
|
@ -45,6 +47,7 @@ export class CaptchaService {
|
|||
return await res.json() as CaptchaResponse;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async verifyRecaptcha(secret: string, response: string | null | undefined): Promise<void> {
|
||||
if (response == null) {
|
||||
throw 'recaptcha-failed: no response provided';
|
||||
|
@ -60,6 +63,7 @@ export class CaptchaService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async verifyHcaptcha(secret: string, response: string | null | undefined): Promise<void> {
|
||||
if (response == null) {
|
||||
throw 'hcaptcha-failed: no response provided';
|
||||
|
@ -75,6 +79,7 @@ export class CaptchaService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async verifyTurnstile(secret: string, response: string | null | undefined): Promise<void> {
|
||||
if (response == null) {
|
||||
throw 'turnstile-failed: no response provided';
|
||||
|
|
|
@ -7,6 +7,7 @@ import { IdService } from '@/core/IdService.js';
|
|||
import { DI } from '@/di-symbols.js';
|
||||
import { NotificationEntityService } from '@/core/entities/NotificationEntityService.js';
|
||||
import { PushNotificationService } from '@/core/PushNotificationService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class CreateNotificationService {
|
||||
|
@ -30,6 +31,7 @@ export class CreateNotificationService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async createNotification(
|
||||
notifieeId: User['id'],
|
||||
type: Notification['type'],
|
||||
|
@ -90,6 +92,7 @@ export class CreateNotificationService {
|
|||
|
||||
// TODO: locale ファイルをクライアント用とサーバー用で分けたい
|
||||
|
||||
@bindThis
|
||||
private async emailNotificationFollow(userId: User['id'], follower: User) {
|
||||
/*
|
||||
const userProfile = await UserProfiles.findOneByOrFail({ userId: userId });
|
||||
|
@ -101,6 +104,7 @@ export class CreateNotificationService {
|
|||
*/
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async emailNotificationReceiveFollowRequest(userId: User['id'], follower: User) {
|
||||
/*
|
||||
const userProfile = await UserProfiles.findOneByOrFail({ userId: userId });
|
||||
|
|
|
@ -10,6 +10,7 @@ import { UserKeypair } from '@/models/entities/UserKeypair.js';
|
|||
import { UsedUsername } from '@/models/entities/UsedUsername.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import generateNativeUserToken from '@/misc/generate-native-user-token.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class CreateSystemUserService {
|
||||
|
@ -21,6 +22,7 @@ export class CreateSystemUserService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async createSystemUser(username: string): Promise<User> {
|
||||
const password = uuid();
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ type PopulatedEmoji = {
|
|||
name: string;
|
||||
url: string;
|
||||
};
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class CustomEmojiService {
|
||||
|
@ -43,6 +44,7 @@ export class CustomEmojiService {
|
|||
this.cache = new Cache<Emoji | null>(1000 * 60 * 60 * 12);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async add(data: {
|
||||
driveFile: DriveFile;
|
||||
name: string;
|
||||
|
@ -67,6 +69,7 @@ export class CustomEmojiService {
|
|||
return emoji;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private normalizeHost(src: string | undefined, noteUserHost: string | null): string | null {
|
||||
// クエリに使うホスト
|
||||
let host = src === '.' ? null // .はローカルホスト (ここがマッチするのはリアクションのみ)
|
||||
|
@ -79,6 +82,7 @@ export class CustomEmojiService {
|
|||
return host;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private parseEmojiStr(emojiName: string, noteUserHost: string | null) {
|
||||
const match = emojiName.match(/^(\w+)(?:@([\w.-]+))?$/);
|
||||
if (!match) return { name: null, host: null };
|
||||
|
@ -97,6 +101,7 @@ export class CustomEmojiService {
|
|||
* @param noteUserHost ノートやユーザープロフィールの所有者のホスト
|
||||
* @returns 絵文字情報, nullは未マッチを意味する
|
||||
*/
|
||||
@bindThis
|
||||
public async populateEmoji(emojiName: string, noteUserHost: string | null): Promise<PopulatedEmoji | null> {
|
||||
const { name, host } = this.parseEmojiStr(emojiName, noteUserHost);
|
||||
if (name == null) return null;
|
||||
|
@ -123,11 +128,13 @@ export class CustomEmojiService {
|
|||
/**
|
||||
* 複数の添付用絵文字情報を解決する (キャシュ付き, 存在しないものは結果から除外される)
|
||||
*/
|
||||
@bindThis
|
||||
public async populateEmojis(emojiNames: string[], noteUserHost: string | null): Promise<PopulatedEmoji[]> {
|
||||
const emojis = await Promise.all(emojiNames.map(x => this.populateEmoji(x, noteUserHost)));
|
||||
return emojis.filter((x): x is PopulatedEmoji => x != null);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public aggregateNoteEmojis(notes: Note[]) {
|
||||
let emojis: { name: string | null; host: string | null; }[] = [];
|
||||
for (const note of notes) {
|
||||
|
@ -154,6 +161,7 @@ export class CustomEmojiService {
|
|||
/**
|
||||
* 与えられた絵文字のリストをデータベースから取得し、キャッシュに追加します
|
||||
*/
|
||||
@bindThis
|
||||
public async prefetchEmojis(emojis: { name: string; host: string | null; }[]): Promise<void> {
|
||||
const notCachedEmojis = emojis.filter(emoji => this.cache.get(`${emoji.name} ${emoji.host}`) == null);
|
||||
const emojisQuery: any[] = [];
|
||||
|
|
|
@ -4,6 +4,7 @@ import { QueueService } from '@/core/QueueService.js';
|
|||
import { UserSuspendService } from '@/core/UserSuspendService.js';
|
||||
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class DeleteAccountService {
|
||||
|
@ -17,6 +18,7 @@ export class DeleteAccountService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async deleteAccount(user: {
|
||||
id: string;
|
||||
host: string | null;
|
||||
|
|
|
@ -15,6 +15,7 @@ import { LoggerService } from '@/core/LoggerService.js';
|
|||
import type Logger from '@/logger.js';
|
||||
|
||||
const pipeline = util.promisify(stream.pipeline);
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class DownloadService {
|
||||
|
@ -30,6 +31,7 @@ export class DownloadService {
|
|||
this.logger = this.loggerService.getLogger('download');
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async downloadUrl(url: string, path: string): Promise<void> {
|
||||
this.logger.info(`Downloading ${chalk.cyan(url)} ...`);
|
||||
|
||||
|
@ -94,6 +96,7 @@ export class DownloadService {
|
|||
this.logger.succ(`Download finished: ${chalk.cyan(url)}`);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async downloadTextFile(url: string): Promise<string> {
|
||||
// Create temp file
|
||||
const [path, cleanup] = await createTemp();
|
||||
|
@ -112,6 +115,7 @@ export class DownloadService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private isPrivateIp(ip: string): boolean {
|
||||
for (const net of this.config.allowedPrivateNetworks ?? []) {
|
||||
const cidr = new IPCIDR(net);
|
||||
|
|
|
@ -71,6 +71,7 @@ type UploadFromUrlArgs = {
|
|||
requestIp?: string | null;
|
||||
requestHeaders?: Record<string, string> | null;
|
||||
};
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class DriveService {
|
||||
|
@ -122,6 +123,7 @@ export class DriveService {
|
|||
* @param hash Hash for original
|
||||
* @param size Size for original
|
||||
*/
|
||||
@bindThis
|
||||
private async save(file: DriveFile, path: string, name: string, type: string, hash: string, size: number): Promise<DriveFile> {
|
||||
// thunbnail, webpublic を必要なら生成
|
||||
const alts = await this.generateAlts(path, type, !file.uri);
|
||||
|
@ -242,6 +244,7 @@ export class DriveService {
|
|||
* @param type Content-Type for original
|
||||
* @param generateWeb Generate webpublic or not
|
||||
*/
|
||||
@bindThis
|
||||
public async generateAlts(path: string, type: string, generateWeb: boolean) {
|
||||
if (type.startsWith('video/')) {
|
||||
try {
|
||||
|
@ -345,6 +348,7 @@ export class DriveService {
|
|||
/**
|
||||
* Upload to ObjectStorage
|
||||
*/
|
||||
@bindThis
|
||||
private async upload(key: string, stream: fs.ReadStream | Buffer, type: string, filename?: string) {
|
||||
if (type === 'image/apng') type = 'image/png';
|
||||
if (!FILE_TYPE_BROWSERSAFE.includes(type)) type = 'application/octet-stream';
|
||||
|
@ -372,6 +376,7 @@ export class DriveService {
|
|||
if (result) this.registerLogger.debug(`Uploaded: ${result.Bucket}/${result.Key} => ${result.Location}`);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async deleteOldFile(user: IRemoteUser) {
|
||||
const q = this.driveFilesRepository.createQueryBuilder('file')
|
||||
.where('file.userId = :userId', { userId: user.id })
|
||||
|
@ -398,6 +403,7 @@ export class DriveService {
|
|||
* Add file to drive
|
||||
*
|
||||
*/
|
||||
@bindThis
|
||||
public async addFile({
|
||||
user,
|
||||
path,
|
||||
|
@ -601,6 +607,7 @@ export class DriveService {
|
|||
return file;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async deleteFile(file: DriveFile, isExpired = false) {
|
||||
if (file.storedInternal) {
|
||||
this.internalStorageService.del(file.accessKey!);
|
||||
|
@ -627,6 +634,7 @@ export class DriveService {
|
|||
this.deletePostProcess(file, isExpired);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async deleteFileSync(file: DriveFile, isExpired = false) {
|
||||
if (file.storedInternal) {
|
||||
this.internalStorageService.del(file.accessKey!);
|
||||
|
@ -657,6 +665,7 @@ export class DriveService {
|
|||
this.deletePostProcess(file, isExpired);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async deletePostProcess(file: DriveFile, isExpired = false) {
|
||||
// リモートファイル期限切れ削除後は直リンクにする
|
||||
if (isExpired && file.userHost !== null && file.uri != null) {
|
||||
|
@ -683,6 +692,7 @@ export class DriveService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async deleteObjectStorageFile(key: string) {
|
||||
const meta = await this.metaService.fetch();
|
||||
|
||||
|
@ -694,6 +704,7 @@ export class DriveService {
|
|||
}).promise();
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async uploadFromUrl({
|
||||
url,
|
||||
user,
|
||||
|
|
|
@ -7,6 +7,7 @@ import type { Config } from '@/config.js';
|
|||
import type Logger from '@/logger.js';
|
||||
import type { UserProfilesRepository } from '@/models/index.js';
|
||||
import { LoggerService } from '@/core/LoggerService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class EmailService {
|
||||
|
@ -25,6 +26,7 @@ export class EmailService {
|
|||
this.logger = this.loggerService.getLogger('email');
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async sendEmail(to: string, subject: string, html: string, text: string) {
|
||||
const meta = await this.metaService.fetch(true);
|
||||
|
||||
|
@ -141,6 +143,7 @@ export class EmailService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async validateEmailForAccount(emailAddress: string): Promise<{
|
||||
available: boolean;
|
||||
reason: null | 'used' | 'format' | 'disposable' | 'mx' | 'smtp';
|
||||
|
|
|
@ -5,6 +5,7 @@ import { Cache } from '@/misc/cache.js';
|
|||
import { IdService } from '@/core/IdService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { UtilityService } from '@/core/UtilityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class FederatedInstanceService {
|
||||
|
@ -20,6 +21,7 @@ export class FederatedInstanceService {
|
|||
this.cache = new Cache<Instance>(1000 * 60 * 60);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async registerOrFetchInstanceDoc(host: string): Promise<Instance> {
|
||||
host = this.utilityService.toPuny(host);
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ type NodeInfo = {
|
|||
themeColor?: unknown;
|
||||
};
|
||||
};
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class FetchInstanceMetadataService {
|
||||
|
@ -46,6 +47,7 @@ export class FetchInstanceMetadataService {
|
|||
this.logger = this.loggerService.getLogger('metadata', 'cyan');
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async fetchInstanceMetadata(instance: Instance, force = false): Promise<void> {
|
||||
const unlock = await this.appLockService.getFetchInstanceMetadataLock(instance.host);
|
||||
|
||||
|
@ -105,6 +107,7 @@ export class FetchInstanceMetadataService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async fetchNodeinfo(instance: Instance): Promise<NodeInfo> {
|
||||
this.logger.info(`Fetching nodeinfo of ${instance.host} ...`);
|
||||
|
||||
|
@ -148,6 +151,7 @@ export class FetchInstanceMetadataService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async fetchDom(instance: Instance): Promise<DOMWindow['document']> {
|
||||
this.logger.info(`Fetching HTML of ${instance.host} ...`);
|
||||
|
||||
|
@ -161,6 +165,7 @@ export class FetchInstanceMetadataService {
|
|||
return doc;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async fetchManifest(instance: Instance): Promise<Record<string, unknown> | null> {
|
||||
const url = 'https://' + instance.host;
|
||||
|
||||
|
@ -171,6 +176,7 @@ export class FetchInstanceMetadataService {
|
|||
return manifest;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async fetchFaviconUrl(instance: Instance, doc: DOMWindow['document'] | null): Promise<string | null> {
|
||||
const url = 'https://' + instance.host;
|
||||
|
||||
|
@ -198,6 +204,7 @@ export class FetchInstanceMetadataService {
|
|||
return null;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async fetchIconUrl(instance: Instance, doc: DOMWindow['document'] | null, manifest: Record<string, any> | null): Promise<string | null> {
|
||||
if (manifest && manifest.icons && manifest.icons.length > 0 && manifest.icons[0].src) {
|
||||
const url = 'https://' + instance.host;
|
||||
|
@ -226,6 +233,7 @@ export class FetchInstanceMetadataService {
|
|||
return null;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async getThemeColor(info: NodeInfo | null, doc: DOMWindow['document'] | null, manifest: Record<string, any> | null): Promise<string | null> {
|
||||
const themeColor = info?.metadata?.themeColor ?? doc?.querySelector('meta[name="theme-color"]')?.getAttribute('content') ?? manifest?.theme_color;
|
||||
|
||||
|
@ -237,6 +245,7 @@ export class FetchInstanceMetadataService {
|
|||
return null;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async getSiteName(info: NodeInfo | null, doc: DOMWindow['document'] | null, manifest: Record<string, any> | null): Promise<string | null> {
|
||||
if (info && info.metadata) {
|
||||
if (typeof info.metadata.nodeName === 'string') {
|
||||
|
@ -261,6 +270,7 @@ export class FetchInstanceMetadataService {
|
|||
return null;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async getDescription(info: NodeInfo | null, doc: DOMWindow['document'] | null, manifest: Record<string, any> | null): Promise<string | null> {
|
||||
if (info && info.metadata) {
|
||||
if (typeof info.metadata.nodeDescription === 'string') {
|
||||
|
|
|
@ -14,6 +14,7 @@ import sharp from 'sharp';
|
|||
import { encode } from 'blurhash';
|
||||
import { createTempDir } from '@/misc/create-temp.js';
|
||||
import { AiService } from '@/core/AiService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
const pipeline = util.promisify(stream.pipeline);
|
||||
|
||||
|
@ -42,6 +43,7 @@ const TYPE_SVG = {
|
|||
mime: 'image/svg+xml',
|
||||
ext: 'svg',
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class FileInfoService {
|
||||
constructor(
|
||||
|
@ -52,6 +54,7 @@ export class FileInfoService {
|
|||
/**
|
||||
* Get file information
|
||||
*/
|
||||
@bindThis
|
||||
public async getFileInfo(path: string, opts: {
|
||||
skipSensitiveDetection: boolean;
|
||||
sensitiveThreshold?: number;
|
||||
|
@ -135,6 +138,7 @@ export class FileInfoService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async detectSensitivity(source: string, mime: string, sensitiveThreshold: number, sensitiveThresholdForPorn: number, analyzeVideo: boolean): Promise<[sensitive: boolean, porn: boolean]> {
|
||||
let sensitive = false;
|
||||
let porn = false;
|
||||
|
@ -269,6 +273,7 @@ export class FileInfoService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private exists(path: string): Promise<boolean> {
|
||||
return fs.promises.access(path).then(() => true, () => false);
|
||||
}
|
||||
|
@ -276,6 +281,7 @@ export class FileInfoService {
|
|||
/**
|
||||
* Detect MIME Type and extension
|
||||
*/
|
||||
@bindThis
|
||||
public async detectType(path: string): Promise<{
|
||||
mime: string;
|
||||
ext: string | null;
|
||||
|
@ -312,6 +318,7 @@ export class FileInfoService {
|
|||
/**
|
||||
* Check the file is SVG or not
|
||||
*/
|
||||
@bindThis
|
||||
public async checkSvg(path: string) {
|
||||
try {
|
||||
const size = await this.getFileSize(path);
|
||||
|
@ -325,6 +332,7 @@ export class FileInfoService {
|
|||
/**
|
||||
* Get file size
|
||||
*/
|
||||
@bindThis
|
||||
public async getFileSize(path: string): Promise<number> {
|
||||
const getStat = util.promisify(fs.stat);
|
||||
return (await getStat(path)).size;
|
||||
|
@ -333,6 +341,7 @@ export class FileInfoService {
|
|||
/**
|
||||
* Calculate MD5 hash
|
||||
*/
|
||||
@bindThis
|
||||
private async calcHash(path: string): Promise<string> {
|
||||
const hash = crypto.createHash('md5').setEncoding('hex');
|
||||
await pipeline(fs.createReadStream(path), hash);
|
||||
|
@ -342,6 +351,7 @@ export class FileInfoService {
|
|||
/**
|
||||
* Detect dimensions of image
|
||||
*/
|
||||
@bindThis
|
||||
private async detectImageSize(path: string): Promise<{
|
||||
width: number;
|
||||
height: number;
|
||||
|
@ -358,6 +368,7 @@ export class FileInfoService {
|
|||
/**
|
||||
* Calculate average color of image
|
||||
*/
|
||||
@bindThis
|
||||
private getBlurhash(path: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
sharp(path)
|
||||
|
|
|
@ -25,6 +25,7 @@ import type {
|
|||
import type { Packed } from '@/misc/schema.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import type { Config } from '@/config.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class GlobalEventService {
|
||||
|
@ -37,6 +38,7 @@ export class GlobalEventService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private publish(channel: StreamChannels, type: string | null, value?: any): void {
|
||||
const message = type == null ? value : value == null ?
|
||||
{ type: type, body: null } :
|
||||
|
@ -99,6 +101,7 @@ export class GlobalEventService {
|
|||
this.publish(`messagingIndexStream:${userId}`, type, typeof value === 'undefined' ? null : value);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public publishNotesStream(note: Packed<'Note'>): void {
|
||||
this.publish('notesStream', null, note);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import type { Hashtag } from '@/models/entities/Hashtag.js';
|
|||
import HashtagChart from '@/core/chart/charts/hashtag.js';
|
||||
import type { HashtagsRepository, UsersRepository } from '@/models/index.js';
|
||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class HashtagService {
|
||||
|
@ -23,12 +24,14 @@ export class HashtagService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async updateHashtags(user: { id: User['id']; host: User['host']; }, tags: string[]) {
|
||||
for (const tag of tags) {
|
||||
await this.updateHashtag(user, tag);
|
||||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async updateUsertags(user: User, tags: string[]) {
|
||||
for (const tag of tags) {
|
||||
await this.updateHashtag(user, tag, true, true);
|
||||
|
@ -39,6 +42,7 @@ export class HashtagService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async updateHashtag(user: { id: User['id']; host: User['host']; }, tag: string, isUserAttached = false, inc = true) {
|
||||
tag = normalizeForSearch(tag);
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import { Inject, Injectable } from '@nestjs/common';
|
|||
import { DI } from '@/di-symbols.js';
|
||||
import type { Config } from '@/config.js';
|
||||
import { StatusError } from '@/misc/status-error.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import type { Response } from 'node-fetch';
|
||||
import type { URL } from 'node:url';
|
||||
|
||||
|
@ -84,6 +85,7 @@ export class HttpRequestService {
|
|||
* @param url URL
|
||||
* @param bypassProxy Allways bypass proxy
|
||||
*/
|
||||
@bindThis
|
||||
public getAgentByUrl(url: URL, bypassProxy = false): http.Agent | https.Agent {
|
||||
if (bypassProxy || (this.config.proxyBypassHosts || []).includes(url.hostname)) {
|
||||
return url.protocol === 'http:' ? this.http : this.https;
|
||||
|
@ -92,6 +94,7 @@ export class HttpRequestService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async getJson(url: string, accept = 'application/json, */*', timeout = 10000, headers?: Record<string, string>): Promise<unknown> {
|
||||
const res = await this.getResponse({
|
||||
url,
|
||||
|
@ -106,6 +109,7 @@ export class HttpRequestService {
|
|||
return await res.json();
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async getHtml(url: string, accept = 'text/html, */*', timeout = 10000, headers?: Record<string, string>): Promise<string> {
|
||||
const res = await this.getResponse({
|
||||
url,
|
||||
|
@ -120,6 +124,7 @@ export class HttpRequestService {
|
|||
return await res.text();
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async getResponse(args: {
|
||||
url: string,
|
||||
method: string,
|
||||
|
|
|
@ -6,6 +6,7 @@ import { genAid } from '@/misc/id/aid.js';
|
|||
import { genMeid } from '@/misc/id/meid.js';
|
||||
import { genMeidg } from '@/misc/id/meidg.js';
|
||||
import { genObjectId } from '@/misc/id/object-id.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class IdService {
|
||||
|
@ -18,6 +19,7 @@ export class IdService {
|
|||
this.metohd = config.id.toLowerCase();
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public genId(date?: Date): string {
|
||||
if (!date || (date > new Date())) date = new Date();
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ export type IImage = {
|
|||
ext: string | null;
|
||||
type: string;
|
||||
};
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class ImageProcessingService {
|
||||
|
@ -21,10 +22,12 @@ export class ImageProcessingService {
|
|||
* Convert to JPEG
|
||||
* with resize, remove metadata, resolve orientation, stop animation
|
||||
*/
|
||||
@bindThis
|
||||
public async convertToJpeg(path: string, width: number, height: number): Promise<IImage> {
|
||||
return this.convertSharpToJpeg(await sharp(path), width, height);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async convertSharpToJpeg(sharp: sharp.Sharp, width: number, height: number): Promise<IImage> {
|
||||
const data = await sharp
|
||||
.resize(width, height, {
|
||||
|
@ -49,10 +52,12 @@ export class ImageProcessingService {
|
|||
* Convert to WebP
|
||||
* with resize, remove metadata, resolve orientation, stop animation
|
||||
*/
|
||||
@bindThis
|
||||
public async convertToWebp(path: string, width: number, height: number, quality = 85): Promise<IImage> {
|
||||
return this.convertSharpToWebp(await sharp(path), width, height, quality);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async convertSharpToWebp(sharp: sharp.Sharp, width: number, height: number, quality = 85): Promise<IImage> {
|
||||
const data = await sharp
|
||||
.resize(width, height, {
|
||||
|
@ -76,10 +81,12 @@ export class ImageProcessingService {
|
|||
* Convert to PNG
|
||||
* with resize, remove metadata, resolve orientation, stop animation
|
||||
*/
|
||||
@bindThis
|
||||
public async convertToPng(path: string, width: number, height: number): Promise<IImage> {
|
||||
return this.convertSharpToPng(await sharp(path), width, height);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async convertSharpToPng(sharp: sharp.Sharp, width: number, height: number): Promise<IImage> {
|
||||
const data = await sharp
|
||||
.resize(width, height, {
|
||||
|
|
|
@ -7,6 +7,7 @@ import { DI } from '@/di-symbols.js';
|
|||
import { CreateSystemUserService } from '@/core/CreateSystemUserService.js';
|
||||
|
||||
const ACTOR_USERNAME = 'instance.actor' as const;
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class InstanceActorService {
|
||||
|
@ -21,6 +22,7 @@ export class InstanceActorService {
|
|||
this.cache = new Cache<ILocalUser>(Infinity);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async getInstanceActor(): Promise<ILocalUser> {
|
||||
const cached = this.cache.get(null);
|
||||
if (cached) return cached;
|
||||
|
|
|
@ -10,6 +10,7 @@ const _filename = fileURLToPath(import.meta.url);
|
|||
const _dirname = dirname(_filename);
|
||||
|
||||
const path = Path.resolve(_dirname, '../../../../files');
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class InternalStorageService {
|
||||
|
@ -19,26 +20,31 @@ export class InternalStorageService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public resolvePath(key: string) {
|
||||
return Path.resolve(path, key);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public read(key: string) {
|
||||
return fs.createReadStream(this.resolvePath(key));
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public saveFromPath(key: string, srcPath: string) {
|
||||
fs.mkdirSync(path, { recursive: true });
|
||||
fs.copyFileSync(srcPath, this.resolvePath(key));
|
||||
return `${this.config.url}/files/${key}`;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public saveFromBuffer(key: string, data: Buffer) {
|
||||
fs.mkdirSync(path, { recursive: true });
|
||||
fs.writeFileSync(this.resolvePath(key), data);
|
||||
return `${this.config.url}/files/${key}`;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public del(key: string) {
|
||||
fs.unlink(this.resolvePath(key), () => {});
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import * as SyslogPro from 'syslog-pro';
|
|||
import { DI } from '@/di-symbols.js';
|
||||
import type { Config } from '@/config.js';
|
||||
import Logger from '@/logger.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class LoggerService {
|
||||
|
@ -27,6 +28,7 @@ export class LoggerService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public getLogger(domain: string, color?: string | undefined, store?: boolean) {
|
||||
return new Logger(domain, color, store, this.syslogClient);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
|||
import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
|
||||
import { MessagingMessageEntityService } from '@/core/entities/MessagingMessageEntityService.js';
|
||||
import { PushNotificationService } from '@/core/PushNotificationService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class MessagingService {
|
||||
|
@ -46,6 +47,7 @@ export class MessagingService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async createMessage(user: { id: User['id']; host: User['host']; }, recipientUser: CacheableUser | undefined, recipientGroup: UserGroup | undefined, text: string | null | undefined, file: DriveFile | null, uri?: string) {
|
||||
const message = {
|
||||
id: this.idService.genId(),
|
||||
|
@ -140,11 +142,13 @@ export class MessagingService {
|
|||
return messageObj;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async deleteMessage(message: MessagingMessage) {
|
||||
await this.messagingMessagesRepository.delete(message.id);
|
||||
this.postDeleteMessage(message);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async postDeleteMessage(message: MessagingMessage) {
|
||||
if (message.recipientId) {
|
||||
const user = await this.usersRepository.findOneByOrFail({ id: message.userId });
|
||||
|
@ -165,6 +169,7 @@ export class MessagingService {
|
|||
/**
|
||||
* Mark messages as read
|
||||
*/
|
||||
@bindThis
|
||||
public async readUserMessagingMessage(
|
||||
userId: User['id'],
|
||||
otherpartyId: User['id'],
|
||||
|
@ -220,6 +225,7 @@ export class MessagingService {
|
|||
/**
|
||||
* Mark messages as read
|
||||
*/
|
||||
@bindThis
|
||||
public async readGroupMessagingMessage(
|
||||
userId: User['id'],
|
||||
groupId: UserGroup['id'],
|
||||
|
@ -284,6 +290,7 @@ export class MessagingService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async deliverReadActivity(user: { id: User['id']; host: null; }, recipient: IRemoteUser, messages: MessagingMessage | MessagingMessage[]) {
|
||||
messages = toArray(messages).filter(x => x.uri);
|
||||
const contents = messages.map(x => this.apRendererService.renderRead(user, x));
|
||||
|
|
|
@ -5,6 +5,7 @@ import { DI } from '@/di-symbols.js';
|
|||
import { Meta } from '@/models/entities/Meta.js';
|
||||
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
||||
import type { OnApplicationShutdown } from '@nestjs/common';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class MetaService implements OnApplicationShutdown {
|
||||
|
@ -20,7 +21,7 @@ export class MetaService implements OnApplicationShutdown {
|
|||
|
||||
private globalEventService: GlobalEventService,
|
||||
) {
|
||||
this.onMessage = this.onMessage.bind(this);
|
||||
//this.onMessage = this.onMessage.bind(this);
|
||||
|
||||
if (process.env.NODE_ENV !== 'test') {
|
||||
this.intervalId = setInterval(() => {
|
||||
|
@ -34,6 +35,7 @@ export class MetaService implements OnApplicationShutdown {
|
|||
this.redisSubscriber.on('message', this.onMessage);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async onMessage(_: string, data: string): Promise<void> {
|
||||
const obj = JSON.parse(data);
|
||||
|
||||
|
@ -50,6 +52,7 @@ export class MetaService implements OnApplicationShutdown {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async fetch(noCache = false): Promise<Meta> {
|
||||
if (!noCache && this.cache) return this.cache;
|
||||
|
||||
|
@ -84,6 +87,7 @@ export class MetaService implements OnApplicationShutdown {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async update(data: Partial<Meta>): Promise<Meta> {
|
||||
const updated = await this.db.transaction(async transactionalEntityManager => {
|
||||
const metas = await transactionalEntityManager.find(Meta, {
|
||||
|
@ -114,6 +118,7 @@ export class MetaService implements OnApplicationShutdown {
|
|||
return updated;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public onApplicationShutdown(signal?: string | undefined) {
|
||||
clearInterval(this.intervalId);
|
||||
this.redisSubscriber.off('message', this.onMessage);
|
||||
|
|
|
@ -14,6 +14,7 @@ const treeAdapter = TreeAdapter.defaultTreeAdapter;
|
|||
|
||||
const urlRegex = /^https?:\/\/[\w\/:%#@$&?!()\[\]~.,=+\-]+/;
|
||||
const urlRegexFull = /^https?:\/\/[\w\/:%#@$&?!()\[\]~.,=+\-]+$/;
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class MfmService {
|
||||
|
@ -23,6 +24,7 @@ export class MfmService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public fromHtml(html: string, hashtagNames?: string[]): string {
|
||||
// some AP servers like Pixelfed use br tags as well as newlines
|
||||
html = html.replace(/<br\s?\/?>\r?\n/gi, '\n');
|
||||
|
@ -228,6 +230,7 @@ export class MfmService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public toHtml(nodes: mfm.MfmNode[] | null, mentionedRemoteUsers: IMentionedRemoteUsers = []) {
|
||||
if (nodes == null) {
|
||||
return null;
|
||||
|
|
|
@ -3,6 +3,7 @@ import { DI } from '@/di-symbols.js';
|
|||
import type { ModerationLogsRepository } from '@/models/index.js';
|
||||
import type { User } from '@/models/entities/User.js';
|
||||
import { IdService } from '@/core/IdService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class ModerationLogService {
|
||||
|
@ -14,6 +15,7 @@ export class ModerationLogService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async insertModerationLog(moderator: { id: User['id'] }, type: string, info?: Record<string, any>) {
|
||||
await this.moderationLogsRepository.insert({
|
||||
id: this.idService.genId(),
|
||||
|
|
|
@ -64,6 +64,7 @@ class NotificationManager {
|
|||
this.queue = [];
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public push(notifiee: ILocalUser['id'], reason: NotificationType) {
|
||||
// 自分自身へは通知しない
|
||||
if (this.notifier.id === notifiee) return;
|
||||
|
@ -83,6 +84,7 @@ class NotificationManager {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async deliver() {
|
||||
for (const x of this.queue) {
|
||||
// ミュート情報を取得
|
||||
|
@ -130,6 +132,7 @@ type Option = {
|
|||
url?: string | null;
|
||||
app?: App | null;
|
||||
};
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class NoteCreateService {
|
||||
|
@ -188,6 +191,7 @@ export class NoteCreateService {
|
|||
private instanceChart: InstanceChart,
|
||||
) {}
|
||||
|
||||
@bindThis
|
||||
public async create(user: {
|
||||
id: User['id'];
|
||||
username: User['username'];
|
||||
|
@ -307,6 +311,7 @@ export class NoteCreateService {
|
|||
return note;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async insertNote(user: { id: User['id']; host: User['host']; }, data: Option, tags: string[], emojis: string[], mentionedUsers: MinimumUser[]) {
|
||||
const insert = new Note({
|
||||
id: this.idService.genId(data.createdAt!),
|
||||
|
@ -403,6 +408,7 @@ export class NoteCreateService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async postNoteCreated(note: Note, user: {
|
||||
id: User['id'];
|
||||
username: User['username'];
|
||||
|
@ -644,6 +650,7 @@ export class NoteCreateService {
|
|||
this.index(note);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private incRenoteCount(renote: Note) {
|
||||
this.notesRepository.createQueryBuilder().update()
|
||||
.set({
|
||||
|
@ -654,6 +661,7 @@ export class NoteCreateService {
|
|||
.execute();
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async createMentionedEvents(mentionedUsers: MinimumUser[], note: Note, nm: NotificationManager) {
|
||||
for (const u of mentionedUsers.filter(u => this.userEntityService.isLocalUser(u))) {
|
||||
const threadMuted = await this.noteThreadMutingsRepository.findOneBy({
|
||||
|
@ -683,10 +691,12 @@ export class NoteCreateService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private saveReply(reply: Note, note: Note) {
|
||||
this.notesRepository.increment({ id: reply.id }, 'repliesCount', 1);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async renderNoteOrRenoteActivity(data: Option, note: Note) {
|
||||
if (data.localOnly) return null;
|
||||
|
||||
|
@ -697,6 +707,7 @@ export class NoteCreateService {
|
|||
return this.apRendererService.renderActivity(content);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private index(note: Note) {
|
||||
if (note.text == null || this.config.elasticsearch == null) return;
|
||||
/*
|
||||
|
@ -711,6 +722,7 @@ export class NoteCreateService {
|
|||
});*/
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private incNotesCountOfUser(user: { id: User['id']; }) {
|
||||
this.usersRepository.createQueryBuilder().update()
|
||||
.set({
|
||||
|
@ -721,6 +733,7 @@ export class NoteCreateService {
|
|||
.execute();
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async extractMentionedUsers(user: { host: User['host']; }, tokens: mfm.MfmNode[]): Promise<User[]> {
|
||||
if (tokens == null) return [];
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
|
|||
import { ApDeliverManagerService } from '@/core/activitypub/ApDeliverManagerService.js';
|
||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class NoteDeleteService {
|
||||
|
@ -112,6 +113,7 @@ export class NoteDeleteService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async findCascadingNotes(note: Note) {
|
||||
const cascadingNotes: Note[] = [];
|
||||
|
||||
|
@ -134,6 +136,7 @@ export class NoteDeleteService {
|
|||
return cascadingNotes.filter(note => note.userHost === null); // filter out non-local users
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async getMentionedRemoteUsers(note: Note) {
|
||||
const where = [] as any[];
|
||||
|
||||
|
@ -159,6 +162,7 @@ export class NoteDeleteService {
|
|||
}) as IRemoteUser[];
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async deliverToConcerned(user: { id: ILocalUser['id']; host: null; }, note: Note, content: any) {
|
||||
this.apDeliverManagerService.deliverToFollowers(user, content);
|
||||
this.relayService.deliverToRelays(user, content);
|
||||
|
|
|
@ -11,6 +11,7 @@ import type { Config } from '@/config.js';
|
|||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import { ApDeliverManagerService } from '@/core/activitypub/ApDeliverManagerService.js';
|
||||
import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class NotePiningService {
|
||||
|
@ -40,6 +41,7 @@ export class NotePiningService {
|
|||
* @param user
|
||||
* @param noteId
|
||||
*/
|
||||
@bindThis
|
||||
public async addPinned(user: { id: User['id']; host: User['host']; }, noteId: Note['id']) {
|
||||
// Fetch pinee
|
||||
const note = await this.notesRepository.findOneBy({
|
||||
|
@ -79,6 +81,7 @@ export class NotePiningService {
|
|||
* @param user
|
||||
* @param noteId
|
||||
*/
|
||||
@bindThis
|
||||
public async removePinned(user: { id: User['id']; host: User['host']; }, noteId: Note['id']) {
|
||||
// Fetch unpinee
|
||||
const note = await this.notesRepository.findOneBy({
|
||||
|
@ -101,6 +104,7 @@ export class NotePiningService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async deliverPinnedChange(userId: User['id'], noteId: Note['id'], isAddition: boolean) {
|
||||
const user = await this.usersRepository.findOneBy({ id: userId });
|
||||
if (user == null) throw new Error('user not found');
|
||||
|
|
|
@ -11,6 +11,7 @@ import type { UsersRepository, NoteUnreadsRepository, MutingsRepository, NoteThr
|
|||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import { NotificationService } from './NotificationService.js';
|
||||
import { AntennaService } from './AntennaService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class NoteReadService {
|
||||
|
@ -44,6 +45,7 @@ export class NoteReadService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async insertNoteUnread(userId: User['id'], note: Note, params: {
|
||||
// NOTE: isSpecifiedがtrueならisMentionedは必ずfalse
|
||||
isSpecified: boolean;
|
||||
|
@ -94,6 +96,7 @@ export class NoteReadService {
|
|||
}, 2000);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async read(
|
||||
userId: User['id'],
|
||||
notes: (Note | Packed<'Note'>)[],
|
||||
|
|
|
@ -8,6 +8,7 @@ import type { Notification } from '@/models/entities/Notification.js';
|
|||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import { GlobalEventService } from './GlobalEventService.js';
|
||||
import { PushNotificationService } from './PushNotificationService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class NotificationService {
|
||||
|
@ -21,6 +22,7 @@ export class NotificationService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async readNotification(
|
||||
userId: User['id'],
|
||||
notificationIds: Notification['id'][],
|
||||
|
@ -42,6 +44,7 @@ export class NotificationService {
|
|||
else return this.postReadNotifications(userId, notificationIds);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async readNotificationByQuery(
|
||||
userId: User['id'],
|
||||
query: Record<string, any>,
|
||||
|
@ -55,11 +58,13 @@ export class NotificationService {
|
|||
return this.readNotification(userId, notificationIds);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private postReadAllNotifications(userId: User['id']) {
|
||||
this.globalEventService.publishMainStream(userId, 'readAllNotifications');
|
||||
return this.pushNotificationService.pushNotification(userId, 'readAllNotifications', undefined);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private postReadNotifications(userId: User['id'], notificationIds: Notification['id'][]) {
|
||||
this.globalEventService.publishMainStream(userId, 'readNotifications', notificationIds);
|
||||
return this.pushNotificationService.pushNotification(userId, 'readNotifications', { notificationIds });
|
||||
|
|
|
@ -11,6 +11,7 @@ import { CreateNotificationService } from '@/core/CreateNotificationService.js';
|
|||
import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
|
||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import { ApDeliverManagerService } from '@/core/activitypub/ApDeliverManagerService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class PollService {
|
||||
|
@ -40,6 +41,7 @@ export class PollService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async vote(user: CacheableUser, note: Note, choice: number) {
|
||||
const poll = await this.pollsRepository.findOneBy({ noteId: note.id });
|
||||
|
||||
|
@ -99,6 +101,7 @@ export class PollService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async deliverQuestionUpdate(noteId: Note['id']) {
|
||||
const note = await this.notesRepository.findOneBy({ id: noteId });
|
||||
if (note == null) throw new Error('note not found');
|
||||
|
|
|
@ -3,6 +3,7 @@ import type { UsersRepository } from '@/models/index.js';
|
|||
import type { ILocalUser, User } from '@/models/entities/User.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { MetaService } from '@/core/MetaService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class ProxyAccountService {
|
||||
|
@ -14,6 +15,7 @@ export class ProxyAccountService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async fetch(): Promise<ILocalUser | null> {
|
||||
const meta = await this.metaService.fetch();
|
||||
if (meta.proxyAccountId == null) return null;
|
||||
|
|
|
@ -37,6 +37,7 @@ function truncateNotification(notification: Packed<'Notification'>): any {
|
|||
|
||||
return notification;
|
||||
}
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class PushNotificationService {
|
||||
|
|
|
@ -4,6 +4,7 @@ import { DI } from '@/di-symbols.js';
|
|||
import type { User } from '@/models/entities/User.js';
|
||||
import type { UserProfilesRepository, FollowingsRepository, ChannelFollowingsRepository, MutedNotesRepository, BlockingsRepository, NoteThreadMutingsRepository, MutingsRepository } from '@/models/index.js';
|
||||
import type { SelectQueryBuilder } from 'typeorm';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class QueryService {
|
||||
|
@ -59,6 +60,7 @@ export class QueryService {
|
|||
}
|
||||
|
||||
// ここでいうBlockedは被Blockedの意
|
||||
@bindThis
|
||||
public generateBlockedUserQuery(q: SelectQueryBuilder<any>, me: { id: User['id'] }): void {
|
||||
const blockingQuery = this.blockingsRepository.createQueryBuilder('blocking')
|
||||
.select('blocking.blockerId')
|
||||
|
@ -81,6 +83,7 @@ export class QueryService {
|
|||
q.setParameters(blockingQuery.getParameters());
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public generateBlockQueryForUsers(q: SelectQueryBuilder<any>, me: { id: User['id'] }): void {
|
||||
const blockingQuery = this.blockingsRepository.createQueryBuilder('blocking')
|
||||
.select('blocking.blockeeId')
|
||||
|
@ -97,6 +100,7 @@ export class QueryService {
|
|||
q.setParameters(blockedQuery.getParameters());
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public generateChannelQuery(q: SelectQueryBuilder<any>, me?: { id: User['id'] } | null): void {
|
||||
if (me == null) {
|
||||
q.andWhere('note.channelId IS NULL');
|
||||
|
@ -118,6 +122,7 @@ export class QueryService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public generateMutedNoteQuery(q: SelectQueryBuilder<any>, me: { id: User['id'] }): void {
|
||||
const mutedQuery = this.mutedNotesRepository.createQueryBuilder('muted')
|
||||
.select('muted.noteId')
|
||||
|
@ -128,6 +133,7 @@ export class QueryService {
|
|||
q.setParameters(mutedQuery.getParameters());
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public generateMutedNoteThreadQuery(q: SelectQueryBuilder<any>, me: { id: User['id'] }): void {
|
||||
const mutedQuery = this.noteThreadMutingsRepository.createQueryBuilder('threadMuted')
|
||||
.select('threadMuted.threadId')
|
||||
|
@ -142,6 +148,7 @@ export class QueryService {
|
|||
q.setParameters(mutedQuery.getParameters());
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public generateMutedUserQuery(q: SelectQueryBuilder<any>, me: { id: User['id'] }, exclude?: User): void {
|
||||
const mutingQuery = this.mutingsRepository.createQueryBuilder('muting')
|
||||
.select('muting.muteeId')
|
||||
|
@ -186,6 +193,7 @@ export class QueryService {
|
|||
q.setParameters(mutingInstanceQuery.getParameters());
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public generateMutedUserQueryForUsers(q: SelectQueryBuilder<any>, me: { id: User['id'] }): void {
|
||||
const mutingQuery = this.mutingsRepository.createQueryBuilder('muting')
|
||||
.select('muting.muteeId')
|
||||
|
@ -196,6 +204,7 @@ export class QueryService {
|
|||
q.setParameters(mutingQuery.getParameters());
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public generateRepliesQuery(q: SelectQueryBuilder<any>, me?: Pick<User, 'id' | 'showTimelineReplies'> | null): void {
|
||||
if (me == null) {
|
||||
q.andWhere(new Brackets(qb => { qb
|
||||
|
@ -221,6 +230,7 @@ export class QueryService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public generateVisibilityQuery(q: SelectQueryBuilder<any>, me?: { id: User['id'] } | null): void {
|
||||
// This code must always be synchronized with the checks in Notes.isVisibleForMe.
|
||||
if (me == null) {
|
||||
|
|
|
@ -8,6 +8,7 @@ import { DI } from '@/di-symbols.js';
|
|||
import type { DbQueue, DeliverQueue, EndedPollNotificationQueue, InboxQueue, ObjectStorageQueue, SystemQueue, WebhookDeliverQueue } from './QueueModule.js';
|
||||
import type { ThinUser } from '../queue/types.js';
|
||||
import type httpSignature from '@peertube/http-signature';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class QueueService {
|
||||
|
@ -24,6 +25,7 @@ export class QueueService {
|
|||
@Inject('queue:webhookDeliver') public webhookDeliverQueue: WebhookDeliverQueue,
|
||||
) {}
|
||||
|
||||
@bindThis
|
||||
public deliver(user: ThinUser, content: IActivity | null, to: string | null) {
|
||||
if (content == null) return null;
|
||||
if (to == null) return null;
|
||||
|
@ -47,6 +49,7 @@ export class QueueService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public inbox(activity: IActivity, signature: httpSignature.IParsedSignature) {
|
||||
const data = {
|
||||
activity: activity,
|
||||
|
@ -64,6 +67,7 @@ export class QueueService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public createDeleteDriveFilesJob(user: ThinUser) {
|
||||
return this.dbQueue.add('deleteDriveFiles', {
|
||||
user: user,
|
||||
|
@ -73,6 +77,7 @@ export class QueueService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public createExportCustomEmojisJob(user: ThinUser) {
|
||||
return this.dbQueue.add('exportCustomEmojis', {
|
||||
user: user,
|
||||
|
@ -82,6 +87,7 @@ export class QueueService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public createExportNotesJob(user: ThinUser) {
|
||||
return this.dbQueue.add('exportNotes', {
|
||||
user: user,
|
||||
|
@ -91,6 +97,7 @@ export class QueueService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public createExportFollowingJob(user: ThinUser, excludeMuting = false, excludeInactive = false) {
|
||||
return this.dbQueue.add('exportFollowing', {
|
||||
user: user,
|
||||
|
@ -102,6 +109,7 @@ export class QueueService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public createExportMuteJob(user: ThinUser) {
|
||||
return this.dbQueue.add('exportMuting', {
|
||||
user: user,
|
||||
|
@ -111,6 +119,7 @@ export class QueueService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public createExportBlockingJob(user: ThinUser) {
|
||||
return this.dbQueue.add('exportBlocking', {
|
||||
user: user,
|
||||
|
@ -120,6 +129,7 @@ export class QueueService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public createExportUserListsJob(user: ThinUser) {
|
||||
return this.dbQueue.add('exportUserLists', {
|
||||
user: user,
|
||||
|
@ -129,6 +139,7 @@ export class QueueService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public createImportFollowingJob(user: ThinUser, fileId: DriveFile['id']) {
|
||||
return this.dbQueue.add('importFollowing', {
|
||||
user: user,
|
||||
|
@ -139,6 +150,7 @@ export class QueueService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public createImportMutingJob(user: ThinUser, fileId: DriveFile['id']) {
|
||||
return this.dbQueue.add('importMuting', {
|
||||
user: user,
|
||||
|
@ -149,6 +161,7 @@ export class QueueService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public createImportBlockingJob(user: ThinUser, fileId: DriveFile['id']) {
|
||||
return this.dbQueue.add('importBlocking', {
|
||||
user: user,
|
||||
|
@ -159,6 +172,7 @@ export class QueueService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public createImportUserListsJob(user: ThinUser, fileId: DriveFile['id']) {
|
||||
return this.dbQueue.add('importUserLists', {
|
||||
user: user,
|
||||
|
@ -169,6 +183,7 @@ export class QueueService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public createImportCustomEmojisJob(user: ThinUser, fileId: DriveFile['id']) {
|
||||
return this.dbQueue.add('importCustomEmojis', {
|
||||
user: user,
|
||||
|
@ -179,6 +194,7 @@ export class QueueService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public createDeleteAccountJob(user: ThinUser, opts: { soft?: boolean; } = {}) {
|
||||
return this.dbQueue.add('deleteAccount', {
|
||||
user: user,
|
||||
|
@ -189,6 +205,7 @@ export class QueueService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public createDeleteObjectStorageFileJob(key: string) {
|
||||
return this.objectStorageQueue.add('deleteFile', {
|
||||
key: key,
|
||||
|
@ -198,6 +215,7 @@ export class QueueService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public createCleanRemoteFilesJob() {
|
||||
return this.objectStorageQueue.add('cleanRemoteFiles', {}, {
|
||||
removeOnComplete: true,
|
||||
|
@ -205,6 +223,7 @@ export class QueueService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public webhookDeliver(webhook: Webhook, type: typeof webhookEventTypes[number], content: unknown) {
|
||||
const data = {
|
||||
type,
|
||||
|
@ -228,6 +247,7 @@ export class QueueService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public destroy() {
|
||||
this.deliverQueue.once('cleaned', (jobs, status) => {
|
||||
//deliverLogger.succ(`Cleaned ${jobs.length} ${status} jobs`);
|
||||
|
|
|
@ -49,6 +49,7 @@ type DecodedReaction = {
|
|||
*/
|
||||
host?: string | null;
|
||||
};
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class ReactionService {
|
||||
|
@ -81,6 +82,7 @@ export class ReactionService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async create(user: { id: User['id']; host: User['host']; }, note: Note, reaction?: string) {
|
||||
// Check blocking
|
||||
if (note.userId !== user.id) {
|
||||
|
@ -196,6 +198,7 @@ export class ReactionService {
|
|||
//#endregion
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async delete(user: { id: User['id']; host: User['host']; }, note: Note) {
|
||||
// if already unreacted
|
||||
const exist = await this.noteReactionsRepository.findOneBy({
|
||||
|
@ -244,11 +247,13 @@ export class ReactionService {
|
|||
//#endregion
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async getFallbackReaction(): Promise<string> {
|
||||
const meta = await this.metaService.fetch();
|
||||
return meta.useStarForReactionFallback ? '⭐' : '👍';
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public convertLegacyReactions(reactions: Record<string, number>) {
|
||||
const _reactions = {} as Record<string, number>;
|
||||
|
||||
|
@ -279,6 +284,7 @@ export class ReactionService {
|
|||
return _reactions2;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async toDbReaction(reaction?: string | null, reacterHost?: string | null): Promise<string> {
|
||||
if (reaction == null) return await this.getFallbackReaction();
|
||||
|
||||
|
@ -311,6 +317,7 @@ export class ReactionService {
|
|||
return await this.getFallbackReaction();
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public decodeReaction(str: string): DecodedReaction {
|
||||
const custom = str.match(/^:([\w+-]+)(?:@([\w.-]+))?:$/);
|
||||
|
||||
|
@ -332,6 +339,7 @@ export class ReactionService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public convertLegacyReaction(reaction: string): string {
|
||||
reaction = this.decodeReaction(reaction).reaction;
|
||||
if (Object.keys(legacies).includes(reaction)) return legacies[reaction];
|
||||
|
|
|
@ -12,6 +12,7 @@ import { DI } from '@/di-symbols.js';
|
|||
import { deepClone } from '@/misc/clone.js';
|
||||
|
||||
const ACTOR_USERNAME = 'relay.actor' as const;
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class RelayService {
|
||||
|
@ -32,6 +33,7 @@ export class RelayService {
|
|||
this.relaysCache = new Cache<Relay[]>(1000 * 60 * 10);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async getRelayActor(): Promise<ILocalUser> {
|
||||
const user = await this.usersRepository.findOneBy({
|
||||
host: IsNull(),
|
||||
|
@ -44,6 +46,7 @@ export class RelayService {
|
|||
return created as ILocalUser;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async addRelay(inbox: string): Promise<Relay> {
|
||||
const relay = await this.relaysRepository.insert({
|
||||
id: this.idService.genId(),
|
||||
|
@ -59,6 +62,7 @@ export class RelayService {
|
|||
return relay;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async removeRelay(inbox: string): Promise<void> {
|
||||
const relay = await this.relaysRepository.findOneBy({
|
||||
inbox,
|
||||
|
@ -77,11 +81,13 @@ export class RelayService {
|
|||
await this.relaysRepository.delete(relay.id);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async listRelay(): Promise<Relay[]> {
|
||||
const relays = await this.relaysRepository.find();
|
||||
return relays;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async relayAccepted(id: string): Promise<string> {
|
||||
const result = await this.relaysRepository.update(id, {
|
||||
status: 'accepted',
|
||||
|
@ -90,6 +96,7 @@ export class RelayService {
|
|||
return JSON.stringify(result);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async relayRejected(id: string): Promise<string> {
|
||||
const result = await this.relaysRepository.update(id, {
|
||||
status: 'rejected',
|
||||
|
@ -98,6 +105,7 @@ export class RelayService {
|
|||
return JSON.stringify(result);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async deliverToRelays(user: { id: User['id']; host: null; }, activity: any): Promise<void> {
|
||||
if (activity == null) return;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import type Logger from '@/logger.js';
|
||||
import { LoggerService } from '@/core/LoggerService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class RemoteLoggerService {
|
||||
|
|
|
@ -11,6 +11,7 @@ import { UtilityService } from '@/core/UtilityService.js';
|
|||
import { WebfingerService } from '@/core/WebfingerService.js';
|
||||
import { RemoteLoggerService } from '@/core/RemoteLoggerService.js';
|
||||
import { ApPersonService } from '@/core/activitypub/models/ApPersonService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class RemoteUserResolveService {
|
||||
|
@ -31,6 +32,7 @@ export class RemoteUserResolveService {
|
|||
this.logger = this.remoteLoggerService.logger.createSubLogger('resolve-user');
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async resolveUser(username: string, host: string | null): Promise<User> {
|
||||
const usernameLower = username.toLowerCase();
|
||||
|
||||
|
@ -116,6 +118,7 @@ export class RemoteUserResolveService {
|
|||
return user;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async resolveSelf(acctLower: string) {
|
||||
this.logger.info(`WebFinger for ${chalk.yellow(acctLower)}`);
|
||||
const finger = await this.webfingerService.webfinger(acctLower).catch(err => {
|
||||
|
|
|
@ -5,6 +5,7 @@ import { DI } from '@/di-symbols.js';
|
|||
import type { Config } from '@/config.js';
|
||||
import type { Meta } from '@/models/entities/Meta.js';
|
||||
import { HttpRequestService } from '@/core/HttpRequestService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class S3Service {
|
||||
|
@ -16,6 +17,7 @@ export class S3Service {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public getS3(meta: Meta) {
|
||||
const u = meta.objectStorageEndpoint != null
|
||||
? `${meta.objectStorageUseSSL ? 'https://' : 'http://'}${meta.objectStorageEndpoint}`
|
||||
|
|
|
@ -14,6 +14,7 @@ import generateUserToken from '@/misc/generate-native-user-token.js';
|
|||
import UsersChart from './chart/charts/users.js';
|
||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import { UtilityService } from './UtilityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class SignupService {
|
||||
|
@ -37,6 +38,7 @@ export class SignupService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async signup(opts: {
|
||||
username: User['username'];
|
||||
password?: string | null;
|
||||
|
|
|
@ -103,6 +103,7 @@ function PEMString(pemBuffer: Buffer, type = 'CERTIFICATE') {
|
|||
`\n-----END ${type}-----\n`
|
||||
);
|
||||
}
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class TwoFactorAuthenticationService {
|
||||
|
@ -115,6 +116,7 @@ export class TwoFactorAuthenticationService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public hash(data: Buffer) {
|
||||
return crypto
|
||||
.createHash('sha256')
|
||||
|
@ -122,6 +124,7 @@ export class TwoFactorAuthenticationService {
|
|||
.digest();
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public verifySignin({
|
||||
publicKey,
|
||||
authenticatorData,
|
||||
|
@ -159,6 +162,7 @@ export class TwoFactorAuthenticationService {
|
|||
.verify(PEMString(publicKey), signature);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public getProcedures() {
|
||||
return {
|
||||
none: {
|
||||
|
|
|
@ -14,6 +14,7 @@ import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
|||
import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
|
||||
import { LoggerService } from '@/core/LoggerService.js';
|
||||
import { WebhookService } from '@/core/WebhookService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class UserBlockingService {
|
||||
|
@ -50,6 +51,7 @@ export class UserBlockingService {
|
|||
this.logger = this.loggerService.getLogger('user-block');
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async block(blocker: User, blockee: User) {
|
||||
await Promise.all([
|
||||
this.cancelRequest(blocker, blockee),
|
||||
|
@ -76,6 +78,7 @@ export class UserBlockingService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async cancelRequest(follower: User, followee: User) {
|
||||
const request = await this.followRequestsRepository.findOneBy({
|
||||
followeeId: followee.id,
|
||||
|
@ -126,6 +129,7 @@ export class UserBlockingService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async unFollow(follower: User, followee: User) {
|
||||
const following = await this.followingsRepository.findOneBy({
|
||||
followerId: follower.id,
|
||||
|
@ -167,6 +171,7 @@ export class UserBlockingService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async removeFromList(listOwner: User, user: User) {
|
||||
const userLists = await this.userListsRepository.findBy({
|
||||
userId: listOwner.id,
|
||||
|
@ -180,6 +185,7 @@ export class UserBlockingService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async unblock(blocker: CacheableUser, blockee: CacheableUser) {
|
||||
const blocking = await this.blockingsRepository.findOneBy({
|
||||
blockerId: blocker.id,
|
||||
|
|
|
@ -6,6 +6,7 @@ import type { CacheableLocalUser, CacheableUser, ILocalUser } from '@/models/ent
|
|||
import { DI } from '@/di-symbols.js';
|
||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import type { OnApplicationShutdown } from '@nestjs/common';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class UserCacheService implements OnApplicationShutdown {
|
||||
|
@ -23,7 +24,7 @@ export class UserCacheService implements OnApplicationShutdown {
|
|||
|
||||
private userEntityService: UserEntityService,
|
||||
) {
|
||||
this.onMessage = this.onMessage.bind(this);
|
||||
//this.onMessage = this.onMessage.bind(this);
|
||||
|
||||
this.userByIdCache = new Cache<CacheableUser>(Infinity);
|
||||
this.localUserByNativeTokenCache = new Cache<CacheableLocalUser | null>(Infinity);
|
||||
|
@ -33,6 +34,7 @@ export class UserCacheService implements OnApplicationShutdown {
|
|||
this.redisSubscriber.on('message', this.onMessage);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async onMessage(_: string, data: string): Promise<void> {
|
||||
const obj = JSON.parse(data);
|
||||
|
||||
|
@ -68,6 +70,7 @@ export class UserCacheService implements OnApplicationShutdown {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public onApplicationShutdown(signal?: string | undefined) {
|
||||
this.redisSubscriber.off('message', this.onMessage);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ type Remote = IRemoteUser | {
|
|||
inbox: IRemoteUser['inbox'];
|
||||
};
|
||||
type Both = Local | Remote;
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class UserFollowingService {
|
||||
|
@ -66,6 +67,7 @@ export class UserFollowingService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async follow(_follower: { id: User['id'] }, _followee: { id: User['id'] }, requestId?: string): Promise<void> {
|
||||
const [follower, followee] = await Promise.all([
|
||||
this.usersRepository.findOneByOrFail({ id: _follower.id }),
|
||||
|
@ -140,6 +142,7 @@ export class UserFollowingService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async insertFollowingDoc(
|
||||
followee: {
|
||||
id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox']
|
||||
|
@ -253,6 +256,7 @@ export class UserFollowingService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async unfollow(
|
||||
follower: {
|
||||
id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox'];
|
||||
|
@ -305,6 +309,7 @@ export class UserFollowingService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async decrementFollowing(
|
||||
follower: {id: User['id']; host: User['host']; },
|
||||
followee: { id: User['id']; host: User['host']; },
|
||||
|
@ -333,6 +338,7 @@ export class UserFollowingService {
|
|||
this.perUserFollowingChart.update(follower, followee, false);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async createFollowRequest(
|
||||
follower: {
|
||||
id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox'];
|
||||
|
@ -396,6 +402,7 @@ export class UserFollowingService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async cancelFollowRequest(
|
||||
followee: {
|
||||
id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']
|
||||
|
@ -431,6 +438,7 @@ export class UserFollowingService {
|
|||
}).then(packed => this.globalEventServie.publishMainStream(followee.id, 'meUpdated', packed));
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async acceptFollowRequest(
|
||||
followee: {
|
||||
id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox'];
|
||||
|
@ -458,6 +466,7 @@ export class UserFollowingService {
|
|||
}).then(packed => this.globalEventServie.publishMainStream(followee.id, 'meUpdated', packed));
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async acceptAllFollowRequests(
|
||||
user: {
|
||||
id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox'];
|
||||
|
@ -476,6 +485,7 @@ export class UserFollowingService {
|
|||
/**
|
||||
* API following/request/reject
|
||||
*/
|
||||
@bindThis
|
||||
public async rejectFollowRequest(user: Local, follower: Both): Promise<void> {
|
||||
if (this.userEntityService.isRemoteUser(follower)) {
|
||||
this.deliverReject(user, follower);
|
||||
|
@ -491,6 +501,7 @@ export class UserFollowingService {
|
|||
/**
|
||||
* API following/reject
|
||||
*/
|
||||
@bindThis
|
||||
public async rejectFollow(user: Local, follower: Both): Promise<void> {
|
||||
if (this.userEntityService.isRemoteUser(follower)) {
|
||||
this.deliverReject(user, follower);
|
||||
|
@ -506,6 +517,7 @@ export class UserFollowingService {
|
|||
/**
|
||||
* AP Reject/Follow
|
||||
*/
|
||||
@bindThis
|
||||
public async remoteReject(actor: Remote, follower: Local): Promise<void> {
|
||||
await this.removeFollowRequest(actor, follower);
|
||||
await this.removeFollow(actor, follower);
|
||||
|
@ -515,6 +527,7 @@ export class UserFollowingService {
|
|||
/**
|
||||
* Remove follow request record
|
||||
*/
|
||||
@bindThis
|
||||
private async removeFollowRequest(followee: Both, follower: Both): Promise<void> {
|
||||
const request = await this.followRequestsRepository.findOneBy({
|
||||
followeeId: followee.id,
|
||||
|
@ -529,6 +542,7 @@ export class UserFollowingService {
|
|||
/**
|
||||
* Remove follow record
|
||||
*/
|
||||
@bindThis
|
||||
private async removeFollow(followee: Both, follower: Both): Promise<void> {
|
||||
const following = await this.followingsRepository.findOneBy({
|
||||
followeeId: followee.id,
|
||||
|
@ -544,6 +558,7 @@ export class UserFollowingService {
|
|||
/**
|
||||
* Deliver Reject to remote
|
||||
*/
|
||||
@bindThis
|
||||
private async deliverReject(followee: Local, follower: Remote): Promise<void> {
|
||||
const request = await this.followRequestsRepository.findOneBy({
|
||||
followeeId: followee.id,
|
||||
|
@ -557,6 +572,7 @@ export class UserFollowingService {
|
|||
/**
|
||||
* Publish unfollow to local
|
||||
*/
|
||||
@bindThis
|
||||
private async publishUnfollow(followee: Both, follower: Local): Promise<void> {
|
||||
const packedFollowee = await this.userEntityService.pack(followee.id, follower, {
|
||||
detail: true,
|
||||
|
|
|
@ -4,6 +4,7 @@ import type { UserKeypairsRepository } from '@/models/index.js';
|
|||
import { Cache } from '@/misc/cache.js';
|
||||
import type { UserKeypair } from '@/models/entities/UserKeypair.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class UserKeypairStoreService {
|
||||
|
@ -16,6 +17,7 @@ export class UserKeypairStoreService {
|
|||
this.cache = new Cache<UserKeypair>(Infinity);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async getUserKeypair(userId: User['id']): Promise<UserKeypair> {
|
||||
return await this.cache.fetch(userId, () => this.userKeypairsRepository.findOneByOrFail({ userId: userId }));
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import { GlobalEventService } from '@/core/GlobalEventService.js';
|
|||
import { DI } from '@/di-symbols.js';
|
||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import { ProxyAccountService } from '@/core/ProxyAccountService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class UserListService {
|
||||
|
@ -27,6 +28,7 @@ export class UserListService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async push(target: User, list: UserList) {
|
||||
await this.userListJoiningsRepository.insert({
|
||||
id: this.idService.genId(),
|
||||
|
|
|
@ -5,6 +5,7 @@ import { QueueService } from '@/core/QueueService.js';
|
|||
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
||||
import type { User } from '@/models/entities/User.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class UserMutingService {
|
||||
|
@ -21,6 +22,7 @@ export class UserMutingService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async mute(user: User, target: User): Promise<void> {
|
||||
await this.mutingsRepository.insert({
|
||||
id: this.idService.genId(),
|
||||
|
|
|
@ -8,6 +8,7 @@ import { DI } from '@/di-symbols.js';
|
|||
import type { Config } from '@/config.js';
|
||||
import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
|
||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class UserSuspendService {
|
||||
|
@ -28,6 +29,7 @@ export class UserSuspendService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async doPostSuspend(user: { id: User['id']; host: User['host'] }): Promise<void> {
|
||||
this.globalEventService.publishInternalEvent('userChangeSuspendedState', { id: user.id, isSuspended: true });
|
||||
|
||||
|
@ -57,6 +59,7 @@ export class UserSuspendService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async doPostUnsuspend(user: User): Promise<void> {
|
||||
this.globalEventService.publishInternalEvent('userChangeSuspendedState', { id: user.id, isSuspended: false });
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import { toASCII } from 'punycode';
|
|||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import type { Config } from '@/config.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class UtilityService {
|
||||
|
@ -12,24 +13,29 @@ export class UtilityService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public getFullApAccount(username: string, host: string | null): string {
|
||||
return host ? `${username}@${this.toPuny(host)}` : `${username}@${this.toPuny(this.config.host)}`;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public isSelfHost(host: string | null): boolean {
|
||||
if (host == null) return true;
|
||||
return this.toPuny(this.config.host) === this.toPuny(host);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public extractDbHost(uri: string): string {
|
||||
const url = new URL(uri);
|
||||
return this.toPuny(url.hostname);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public toPuny(host: string): string {
|
||||
return toASCII(host.toLowerCase());
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public toPunyNullable(host: string | null | undefined): string | null {
|
||||
if (host == null) return null;
|
||||
return toASCII(host.toLowerCase());
|
||||
|
|
|
@ -5,6 +5,7 @@ import type { Config } from '@/config.js';
|
|||
import { ImageProcessingService } from '@/core/ImageProcessingService.js';
|
||||
import type { IImage } from '@/core/ImageProcessingService.js';
|
||||
import { createTempDir } from '@/misc/create-temp.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class VideoProcessingService {
|
||||
|
@ -16,6 +17,7 @@ export class VideoProcessingService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async generateVideoThumbnail(source: string): Promise<IImage> {
|
||||
const [dir, cleanup] = await createTempDir();
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ type IWebFinger = {
|
|||
links: ILink[];
|
||||
subject: string;
|
||||
};
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class WebfingerService {
|
||||
|
@ -25,12 +26,14 @@ export class WebfingerService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async webfinger(query: string): Promise<IWebFinger> {
|
||||
const url = this.genUrl(query);
|
||||
|
||||
return await this.httpRequestService.getJson(url, 'application/jrd+json, application/json') as IWebFinger;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private genUrl(query: string): string {
|
||||
if (query.match(/^https?:\/\//)) {
|
||||
const u = new URL(query);
|
||||
|
|
|
@ -4,6 +4,7 @@ import type { WebhooksRepository } from '@/models/index.js';
|
|||
import type { Webhook } from '@/models/entities/Webhook.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import type { OnApplicationShutdown } from '@nestjs/common';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class WebhookService implements OnApplicationShutdown {
|
||||
|
@ -17,10 +18,11 @@ export class WebhookService implements OnApplicationShutdown {
|
|||
@Inject(DI.webhooksRepository)
|
||||
private webhooksRepository: WebhooksRepository,
|
||||
) {
|
||||
this.onMessage = this.onMessage.bind(this);
|
||||
//this.onMessage = this.onMessage.bind(this);
|
||||
this.redisSubscriber.on('message', this.onMessage);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async getActiveWebhooks() {
|
||||
if (!this.webhooksFetched) {
|
||||
this.webhooks = await this.webhooksRepository.findBy({
|
||||
|
@ -32,6 +34,7 @@ export class WebhookService implements OnApplicationShutdown {
|
|||
return this.webhooks;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async onMessage(_: string, data: string): Promise<void> {
|
||||
const obj = JSON.parse(data);
|
||||
|
||||
|
@ -64,6 +67,7 @@ export class WebhookService implements OnApplicationShutdown {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public onApplicationShutdown(signal?: string | undefined) {
|
||||
this.redisSubscriber.off('message', this.onMessage);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import promiseLimit from 'promise-limit';
|
|||
import { DI } from '@/di-symbols.js';
|
||||
import type { CacheableRemoteUser, CacheableUser } from '@/models/entities/User.js';
|
||||
import { concat, toArray, toSingle, unique } from '@/misc/prelude/array.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { getApId, getApIds, getApType, isAccept, isActor, isAdd, isAnnounce, isBlock, isCollection, isCollectionOrOrderedCollection, isCreate, isDelete, isFlag, isFollow, isLike, isPost, isRead, isReject, isRemove, isTombstone, isUndo, isUpdate, validActor, validPost } from './type.js';
|
||||
import { ApPersonService } from './models/ApPersonService.js';
|
||||
import type { ApObject } from './type.js';
|
||||
|
@ -24,6 +25,7 @@ export class ApAudienceService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async parseAudience(actor: CacheableRemoteUser, to?: ApObject, cc?: ApObject, resolver?: Resolver): Promise<AudienceInfo> {
|
||||
const toGroups = this.groupingAudience(getApIds(to), actor);
|
||||
const ccGroups = this.groupingAudience(getApIds(cc), actor);
|
||||
|
@ -66,6 +68,7 @@ export class ApAudienceService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private groupingAudience(ids: string[], actor: CacheableRemoteUser) {
|
||||
const groups = {
|
||||
public: [] as string[],
|
||||
|
@ -88,6 +91,7 @@ export class ApAudienceService {
|
|||
return groups;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private isPublic(id: string) {
|
||||
return [
|
||||
'https://www.w3.org/ns/activitystreams#Public',
|
||||
|
@ -96,6 +100,7 @@ export class ApAudienceService {
|
|||
].includes(id);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private isFollowers(id: string, actor: CacheableRemoteUser) {
|
||||
return (
|
||||
id === (actor.followersUri ?? `${actor.uri}/followers`)
|
||||
|
|
|
@ -9,6 +9,7 @@ import type { UserPublickey } from '@/models/entities/UserPublickey.js';
|
|||
import { UserCacheService } from '@/core/UserCacheService.js';
|
||||
import type { Note } from '@/models/entities/Note.js';
|
||||
import type { MessagingMessage } from '@/models/entities/MessagingMessage.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { getApId } from './type.js';
|
||||
import { ApPersonService } from './models/ApPersonService.js';
|
||||
import type { IObject } from './type.js';
|
||||
|
@ -57,6 +58,7 @@ export class ApDbResolverService {
|
|||
this.publicKeyByUserIdCache = new Cache<UserPublickey | null>(Infinity);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public parseUri(value: string | IObject): UriParseResult {
|
||||
const uri = getApId(value);
|
||||
|
||||
|
@ -82,6 +84,7 @@ export class ApDbResolverService {
|
|||
/**
|
||||
* AP Note => Misskey Note in DB
|
||||
*/
|
||||
@bindThis
|
||||
public async getNoteFromApId(value: string | IObject): Promise<Note | null> {
|
||||
const parsed = this.parseUri(value);
|
||||
|
||||
|
@ -98,6 +101,7 @@ export class ApDbResolverService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async getMessageFromApId(value: string | IObject): Promise<MessagingMessage | null> {
|
||||
const parsed = this.parseUri(value);
|
||||
|
||||
|
@ -117,6 +121,7 @@ export class ApDbResolverService {
|
|||
/**
|
||||
* AP Person => Misskey User in DB
|
||||
*/
|
||||
@bindThis
|
||||
public async getUserFromApId(value: string | IObject): Promise<CacheableUser | null> {
|
||||
const parsed = this.parseUri(value);
|
||||
|
||||
|
@ -136,6 +141,7 @@ export class ApDbResolverService {
|
|||
/**
|
||||
* AP KeyId => Misskey User and Key
|
||||
*/
|
||||
@bindThis
|
||||
public async getAuthUserFromKeyId(keyId: string): Promise<{
|
||||
user: CacheableRemoteUser;
|
||||
key: UserPublickey;
|
||||
|
@ -161,6 +167,7 @@ export class ApDbResolverService {
|
|||
/**
|
||||
* AP Actor id => Misskey User and Key
|
||||
*/
|
||||
@bindThis
|
||||
public async getAuthUserFromApId(uri: string): Promise<{
|
||||
user: CacheableRemoteUser;
|
||||
key: UserPublickey | null;
|
||||
|
|
|
@ -6,6 +6,7 @@ import type { Config } from '@/config.js';
|
|||
import type { ILocalUser, IRemoteUser, User } from '@/models/entities/User.js';
|
||||
import { QueueService } from '@/core/QueueService.js';
|
||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
interface IRecipe {
|
||||
type: string;
|
||||
|
@ -48,6 +49,7 @@ export class ApDeliverManagerService {
|
|||
* @param activity Activity
|
||||
* @param from Followee
|
||||
*/
|
||||
@bindThis
|
||||
public async deliverToFollowers(actor: { id: ILocalUser['id']; host: null; }, activity: any) {
|
||||
const manager = new DeliverManager(
|
||||
this.userEntityService,
|
||||
|
@ -65,6 +67,7 @@ export class ApDeliverManagerService {
|
|||
* @param activity Activity
|
||||
* @param to Target user
|
||||
*/
|
||||
@bindThis
|
||||
public async deliverToUser(actor: { id: ILocalUser['id']; host: null; }, activity: any, to: IRemoteUser) {
|
||||
const manager = new DeliverManager(
|
||||
this.userEntityService,
|
||||
|
@ -77,6 +80,7 @@ export class ApDeliverManagerService {
|
|||
await manager.execute();
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public createDeliverManager(actor: { id: User['id']; host: null; }, activity: any) {
|
||||
return new DeliverManager(
|
||||
this.userEntityService,
|
||||
|
@ -114,6 +118,7 @@ class DeliverManager {
|
|||
/**
|
||||
* Add recipe for followers deliver
|
||||
*/
|
||||
@bindThis
|
||||
public addFollowersRecipe() {
|
||||
const deliver = {
|
||||
type: 'Followers',
|
||||
|
@ -126,6 +131,7 @@ class DeliverManager {
|
|||
* Add recipe for direct deliver
|
||||
* @param to To
|
||||
*/
|
||||
@bindThis
|
||||
public addDirectRecipe(to: IRemoteUser) {
|
||||
const recipe = {
|
||||
type: 'Direct',
|
||||
|
@ -139,6 +145,7 @@ class DeliverManager {
|
|||
* Add recipe
|
||||
* @param recipe Recipe
|
||||
*/
|
||||
@bindThis
|
||||
public addRecipe(recipe: IRecipe) {
|
||||
this.recipes.push(recipe);
|
||||
}
|
||||
|
@ -146,6 +153,7 @@ class DeliverManager {
|
|||
/**
|
||||
* Execute delivers
|
||||
*/
|
||||
@bindThis
|
||||
public async execute() {
|
||||
if (!this.userEntityService.isLocalUser(this.actor)) return;
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ import { ApPersonService } from './models/ApPersonService.js';
|
|||
import { ApQuestionService } from './models/ApQuestionService.js';
|
||||
import type { Resolver } from './ApResolverService.js';
|
||||
import type { IAccept, IAdd, IAnnounce, IBlock, ICreate, IDelete, IFlag, IFollow, ILike, IObject, IRead, IReject, IRemove, IUndo, IUpdate } from './type.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class ApInboxService {
|
||||
|
@ -85,6 +86,7 @@ export class ApInboxService {
|
|||
this.logger = this.apLoggerService.logger;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async performActivity(actor: CacheableRemoteUser, activity: IObject) {
|
||||
if (isCollectionOrOrderedCollection(activity)) {
|
||||
const resolver = this.apResolverService.createResolver();
|
||||
|
@ -112,6 +114,7 @@ export class ApInboxService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async performOneActivity(actor: CacheableRemoteUser, activity: IObject): Promise<void> {
|
||||
if (actor.isSuspended) return;
|
||||
|
||||
|
@ -148,6 +151,7 @@ export class ApInboxService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async follow(actor: CacheableRemoteUser, activity: IFollow): Promise<string> {
|
||||
const followee = await this.apDbResolverService.getUserFromApId(activity.object);
|
||||
|
||||
|
@ -163,6 +167,7 @@ export class ApInboxService {
|
|||
return 'ok';
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async like(actor: CacheableRemoteUser, activity: ILike): Promise<string> {
|
||||
const targetUri = getApId(activity.object);
|
||||
|
||||
|
@ -180,6 +185,7 @@ export class ApInboxService {
|
|||
}).then(() => 'ok');
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async read(actor: CacheableRemoteUser, activity: IRead): Promise<string> {
|
||||
const id = await getApId(activity.object);
|
||||
|
||||
|
@ -202,6 +208,7 @@ export class ApInboxService {
|
|||
return `ok: mark as read (${message.userId} => ${message.recipientId} ${message.id})`;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async accept(actor: CacheableRemoteUser, activity: IAccept): Promise<string> {
|
||||
const uri = activity.id ?? activity;
|
||||
|
||||
|
@ -219,6 +226,7 @@ export class ApInboxService {
|
|||
return `skip: Unknown Accept type: ${getApType(object)}`;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async acceptFollow(actor: CacheableRemoteUser, activity: IFollow): Promise<string> {
|
||||
// ※ activityはこっちから投げたフォローリクエストなので、activity.actorは存在するローカルユーザーである必要がある
|
||||
|
||||
|
@ -242,6 +250,7 @@ export class ApInboxService {
|
|||
return 'ok';
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async add(actor: CacheableRemoteUser, activity: IAdd): Promise<void> {
|
||||
if ('actor' in activity && actor.uri !== activity.actor) {
|
||||
throw new Error('invalid actor');
|
||||
|
@ -261,6 +270,7 @@ export class ApInboxService {
|
|||
throw new Error(`unknown target: ${activity.target}`);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async announce(actor: CacheableRemoteUser, activity: IAnnounce): Promise<void> {
|
||||
const uri = getApId(activity);
|
||||
|
||||
|
@ -271,6 +281,7 @@ export class ApInboxService {
|
|||
this.announceNote(actor, activity, targetUri);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async announceNote(actor: CacheableRemoteUser, activity: IAnnounce, targetUri: string): Promise<void> {
|
||||
const uri = getApId(activity);
|
||||
|
||||
|
@ -330,6 +341,7 @@ export class ApInboxService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async block(actor: CacheableRemoteUser, activity: IBlock): Promise<string> {
|
||||
// ※ activity.objectにブロック対象があり、それは存在するローカルユーザーのはず
|
||||
|
||||
|
@ -347,6 +359,7 @@ export class ApInboxService {
|
|||
return 'ok';
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async create(actor: CacheableRemoteUser, activity: ICreate): Promise<void> {
|
||||
const uri = getApId(activity);
|
||||
|
||||
|
@ -382,6 +395,7 @@ export class ApInboxService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async createNote(resolver: Resolver, actor: CacheableRemoteUser, note: IObject, silent = false, activity?: ICreate): Promise<string> {
|
||||
const uri = getApId(note);
|
||||
|
||||
|
@ -416,6 +430,7 @@ export class ApInboxService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async delete(actor: CacheableRemoteUser, activity: IDelete): Promise<string> {
|
||||
if ('actor' in activity && actor.uri !== activity.actor) {
|
||||
throw new Error('invalid actor');
|
||||
|
@ -457,6 +472,7 @@ export class ApInboxService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async deleteActor(actor: CacheableRemoteUser, uri: string): Promise<string> {
|
||||
this.logger.info(`Deleting the Actor: ${uri}`);
|
||||
|
||||
|
@ -478,6 +494,7 @@ export class ApInboxService {
|
|||
return `ok: queued ${job.name} ${job.id}`;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async deleteNote(actor: CacheableRemoteUser, uri: string): Promise<string> {
|
||||
this.logger.info(`Deleting the Note: ${uri}`);
|
||||
|
||||
|
@ -510,6 +527,7 @@ export class ApInboxService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async flag(actor: CacheableRemoteUser, activity: IFlag): Promise<string> {
|
||||
// objectは `(User|Note) | (User|Note)[]` だけど、全パターンDBスキーマと対応させられないので
|
||||
// 対象ユーザーは一番最初のユーザー として あとはコメントとして格納する
|
||||
|
@ -534,6 +552,7 @@ export class ApInboxService {
|
|||
return 'ok';
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async reject(actor: CacheableRemoteUser, activity: IReject): Promise<string> {
|
||||
const uri = activity.id ?? activity;
|
||||
|
||||
|
@ -551,6 +570,7 @@ export class ApInboxService {
|
|||
return `skip: Unknown Reject type: ${getApType(object)}`;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async rejectFollow(actor: CacheableRemoteUser, activity: IFollow): Promise<string> {
|
||||
// ※ activityはこっちから投げたフォローリクエストなので、activity.actorは存在するローカルユーザーである必要がある
|
||||
|
||||
|
@ -574,6 +594,7 @@ export class ApInboxService {
|
|||
return 'ok';
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async remove(actor: CacheableRemoteUser, activity: IRemove): Promise<void> {
|
||||
if ('actor' in activity && actor.uri !== activity.actor) {
|
||||
throw new Error('invalid actor');
|
||||
|
@ -593,6 +614,7 @@ export class ApInboxService {
|
|||
throw new Error(`unknown target: ${activity.target}`);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async undo(actor: CacheableRemoteUser, activity: IUndo): Promise<string> {
|
||||
if ('actor' in activity && actor.uri !== activity.actor) {
|
||||
throw new Error('invalid actor');
|
||||
|
@ -618,6 +640,7 @@ export class ApInboxService {
|
|||
return `skip: unknown object type ${getApType(object)}`;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async undoAccept(actor: CacheableRemoteUser, activity: IAccept): Promise<string> {
|
||||
const follower = await this.apDbResolverService.getUserFromApId(activity.object);
|
||||
if (follower == null) {
|
||||
|
@ -637,6 +660,7 @@ export class ApInboxService {
|
|||
return 'skip: フォローされていない';
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async undoAnnounce(actor: CacheableRemoteUser, activity: IAnnounce): Promise<string> {
|
||||
const uri = getApId(activity);
|
||||
|
||||
|
@ -651,6 +675,7 @@ export class ApInboxService {
|
|||
return 'ok: deleted';
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async undoBlock(actor: CacheableRemoteUser, activity: IBlock): Promise<string> {
|
||||
const blockee = await this.apDbResolverService.getUserFromApId(activity.object);
|
||||
|
||||
|
@ -666,6 +691,7 @@ export class ApInboxService {
|
|||
return 'ok';
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async undoFollow(actor: CacheableRemoteUser, activity: IFollow): Promise<string> {
|
||||
const followee = await this.apDbResolverService.getUserFromApId(activity.object);
|
||||
if (followee == null) {
|
||||
|
@ -699,6 +725,7 @@ export class ApInboxService {
|
|||
return 'skip: リクエストもフォローもされていない';
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async undoLike(actor: CacheableRemoteUser, activity: ILike): Promise<string> {
|
||||
const targetUri = getApId(activity.object);
|
||||
|
||||
|
@ -713,6 +740,7 @@ export class ApInboxService {
|
|||
return 'ok';
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async update(actor: CacheableRemoteUser, activity: IUpdate): Promise<string> {
|
||||
if ('actor' in activity && actor.uri !== activity.actor) {
|
||||
return 'skip: invalid actor';
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import type Logger from '@/logger.js';
|
||||
import { RemoteLoggerService } from '@/core/RemoteLoggerService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class ApLoggerService {
|
||||
|
|
|
@ -6,6 +6,7 @@ import { MfmService } from '@/core/MfmService.js';
|
|||
import type { Note } from '@/models/entities/Note.js';
|
||||
import { extractApHashtagObjects } from './models/tag.js';
|
||||
import type { IObject } from './type.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class ApMfmService {
|
||||
|
@ -17,12 +18,14 @@ export class ApMfmService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public htmlToMfm(html: string, tag?: IObject | IObject[]) {
|
||||
const hashtagNames = extractApHashtagObjects(tag).map(x => x.name).filter((x): x is string => x != null);
|
||||
|
||||
return this.mfmService.fromHtml(html, hashtagNames);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public getNoteHtml(note: Note) {
|
||||
if (!note.text) return '';
|
||||
return this.mfmService.toHtml(mfm.parse(note.text), JSON.parse(note.mentionedRemoteUsers));
|
||||
|
|
|
@ -25,6 +25,7 @@ import { LdSignatureService } from './LdSignatureService.js';
|
|||
import { ApMfmService } from './ApMfmService.js';
|
||||
import type { IActivity, IObject } from './type.js';
|
||||
import type { IIdentifier } from './models/identifier.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class ApRendererService {
|
||||
|
@ -59,6 +60,7 @@ export class ApRendererService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public renderAccept(object: any, user: { id: User['id']; host: null }) {
|
||||
return {
|
||||
type: 'Accept',
|
||||
|
@ -67,6 +69,7 @@ export class ApRendererService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public renderAdd(user: ILocalUser, target: any, object: any) {
|
||||
return {
|
||||
type: 'Add',
|
||||
|
@ -76,6 +79,7 @@ export class ApRendererService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public renderAnnounce(object: any, note: Note) {
|
||||
const attributedTo = `${this.config.url}/users/${note.userId}`;
|
||||
|
||||
|
@ -108,6 +112,7 @@ export class ApRendererService {
|
|||
*
|
||||
* @param block The block to be rendered. The blockee relation must be loaded.
|
||||
*/
|
||||
@bindThis
|
||||
public renderBlock(block: Blocking) {
|
||||
if (block.blockee?.uri == null) {
|
||||
throw new Error('renderBlock: missing blockee uri');
|
||||
|
@ -121,6 +126,7 @@ export class ApRendererService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public renderCreate(object: any, note: Note) {
|
||||
const activity = {
|
||||
id: `${this.config.url}/notes/${note.id}/activity`,
|
||||
|
@ -136,6 +142,7 @@ export class ApRendererService {
|
|||
return activity;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public renderDelete(object: any, user: { id: User['id']; host: null }) {
|
||||
return {
|
||||
type: 'Delete',
|
||||
|
@ -145,6 +152,7 @@ export class ApRendererService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public renderDocument(file: DriveFile) {
|
||||
return {
|
||||
type: 'Document',
|
||||
|
@ -154,6 +162,7 @@ export class ApRendererService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public renderEmoji(emoji: Emoji) {
|
||||
return {
|
||||
id: `${this.config.url}/emojis/${emoji.name}`,
|
||||
|
@ -170,6 +179,7 @@ export class ApRendererService {
|
|||
|
||||
// to anonymise reporters, the reporting actor must be a system user
|
||||
// object has to be a uri or array of uris
|
||||
@bindThis
|
||||
public renderFlag(user: ILocalUser, object: [string], content: string) {
|
||||
return {
|
||||
type: 'Flag',
|
||||
|
@ -179,6 +189,7 @@ export class ApRendererService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public renderFollowRelay(relay: Relay, relayActor: ILocalUser) {
|
||||
const follow = {
|
||||
id: `${this.config.url}/activities/follow-relay/${relay.id}`,
|
||||
|
@ -194,11 +205,13 @@ export class ApRendererService {
|
|||
* Convert (local|remote)(Follower|Followee)ID to URL
|
||||
* @param id Follower|Followee ID
|
||||
*/
|
||||
@bindThis
|
||||
public async renderFollowUser(id: User['id']) {
|
||||
const user = await this.usersRepository.findOneByOrFail({ id: id });
|
||||
return this.userEntityService.isLocalUser(user) ? `${this.config.url}/users/${user.id}` : user.uri;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public renderFollow(
|
||||
follower: { id: User['id']; host: User['host']; uri: User['host'] },
|
||||
followee: { id: User['id']; host: User['host']; uri: User['host'] },
|
||||
|
@ -214,6 +227,7 @@ export class ApRendererService {
|
|||
return follow;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public renderHashtag(tag: string) {
|
||||
return {
|
||||
type: 'Hashtag',
|
||||
|
@ -222,6 +236,7 @@ export class ApRendererService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public renderImage(file: DriveFile) {
|
||||
return {
|
||||
type: 'Image',
|
||||
|
@ -231,6 +246,7 @@ export class ApRendererService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public renderKey(user: ILocalUser, key: UserKeypair, postfix?: string) {
|
||||
return {
|
||||
id: `${this.config.url}/users/${user.id}${postfix ?? '/publickey'}`,
|
||||
|
@ -243,6 +259,7 @@ export class ApRendererService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async renderLike(noteReaction: NoteReaction, note: { uri: string | null }) {
|
||||
const reaction = noteReaction.reaction;
|
||||
|
||||
|
@ -268,6 +285,7 @@ export class ApRendererService {
|
|||
return object;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public renderMention(mention: User) {
|
||||
return {
|
||||
type: 'Mention',
|
||||
|
@ -276,6 +294,7 @@ export class ApRendererService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async renderNote(note: Note, dive = true, isTalk = false): Promise<IObject> {
|
||||
const getPromisedFiles = async (ids: string[]) => {
|
||||
if (!ids || ids.length === 0) return [];
|
||||
|
@ -420,6 +439,7 @@ export class ApRendererService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async renderPerson(user: ILocalUser) {
|
||||
const id = `${this.config.url}/users/${user.id}`;
|
||||
const isSystem = !!user.username.match(/\./);
|
||||
|
@ -496,6 +516,7 @@ export class ApRendererService {
|
|||
return person;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async renderQuestion(user: { id: User['id'] }, note: Note, poll: Poll) {
|
||||
const question = {
|
||||
type: 'Question',
|
||||
|
@ -515,6 +536,7 @@ export class ApRendererService {
|
|||
return question;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public renderRead(user: { id: User['id'] }, message: MessagingMessage) {
|
||||
return {
|
||||
type: 'Read',
|
||||
|
@ -523,6 +545,7 @@ export class ApRendererService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public renderReject(object: any, user: { id: User['id'] }) {
|
||||
return {
|
||||
type: 'Reject',
|
||||
|
@ -531,6 +554,7 @@ export class ApRendererService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public renderRemove(user: { id: User['id'] }, target: any, object: any) {
|
||||
return {
|
||||
type: 'Remove',
|
||||
|
@ -540,6 +564,7 @@ export class ApRendererService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public renderTombstone(id: string) {
|
||||
return {
|
||||
id,
|
||||
|
@ -547,6 +572,7 @@ export class ApRendererService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public renderUndo(object: any, user: { id: User['id'] }) {
|
||||
if (object == null) return null;
|
||||
const id = typeof object.id === 'string' && object.id.startsWith(this.config.url) ? `${object.id}/undo` : undefined;
|
||||
|
@ -560,6 +586,7 @@ export class ApRendererService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public renderUpdate(object: any, user: { id: User['id'] }) {
|
||||
const activity = {
|
||||
id: `${this.config.url}/users/${user.id}#updates/${new Date().getTime()}`,
|
||||
|
@ -573,6 +600,7 @@ export class ApRendererService {
|
|||
return activity;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public renderVote(user: { id: User['id'] }, vote: PollVote, note: Note, poll: Poll, pollOwner: IRemoteUser) {
|
||||
return {
|
||||
id: `${this.config.url}/users/${user.id}#votes/${vote.id}/activity`,
|
||||
|
@ -591,6 +619,7 @@ export class ApRendererService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public renderActivity(x: any): IActivity | null {
|
||||
if (x == null) return null;
|
||||
|
||||
|
@ -632,6 +661,7 @@ export class ApRendererService {
|
|||
}, x);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async attachLdSignature(activity: any, user: { id: User['id']; host: null; }): Promise<IActivity> {
|
||||
const keypair = await this.userKeypairStoreService.getUserKeypair(user.id);
|
||||
|
||||
|
@ -651,6 +681,7 @@ export class ApRendererService {
|
|||
* @param prev URL of prev page (optional)
|
||||
* @param next URL of next page (optional)
|
||||
*/
|
||||
@bindThis
|
||||
public renderOrderedCollectionPage(id: string, totalItems: any, orderedItems: any, partOf: string, prev?: string, next?: string) {
|
||||
const page = {
|
||||
id,
|
||||
|
@ -674,6 +705,7 @@ export class ApRendererService {
|
|||
* @param last URL of last page (optional)
|
||||
* @param orderedItems attached objects (optional)
|
||||
*/
|
||||
@bindThis
|
||||
public renderOrderedCollection(id: string | null, totalItems: any, first?: string, last?: string, orderedItems?: IObject[]) {
|
||||
const page: any = {
|
||||
id,
|
||||
|
@ -688,6 +720,7 @@ export class ApRendererService {
|
|||
return page;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async getEmojis(names: string[]): Promise<Emoji[]> {
|
||||
if (names == null || names.length === 0) return [];
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import type { Config } from '@/config.js';
|
|||
import type { User } from '@/models/entities/User.js';
|
||||
import { UserKeypairStoreService } from '@/core/UserKeypairStoreService.js';
|
||||
import { HttpRequestService } from '@/core/HttpRequestService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
type Request = {
|
||||
url: string;
|
||||
|
@ -36,6 +37,7 @@ export class ApRequestService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private createSignedPost(args: { key: PrivateKey, url: string, body: string, additionalHeaders: Record<string, string> }): Signed {
|
||||
const u = new URL(args.url);
|
||||
const digestHeader = `SHA-256=${crypto.createHash('sha256').update(args.body).digest('base64')}`;
|
||||
|
@ -61,6 +63,7 @@ export class ApRequestService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private createSignedGet(args: { key: PrivateKey, url: string, additionalHeaders: Record<string, string> }): Signed {
|
||||
const u = new URL(args.url);
|
||||
|
||||
|
@ -84,6 +87,7 @@ export class ApRequestService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private signToRequest(request: Request, key: PrivateKey, includeHeaders: string[]): Signed {
|
||||
const signingString = this.genSigningString(request, includeHeaders);
|
||||
const signature = crypto.sign('sha256', Buffer.from(signingString), key.privateKeyPem).toString('base64');
|
||||
|
@ -101,6 +105,7 @@ export class ApRequestService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private genSigningString(request: Request, includeHeaders: string[]): string {
|
||||
request.headers = this.lcObjectKey(request.headers);
|
||||
|
||||
|
@ -117,16 +122,19 @@ export class ApRequestService {
|
|||
return results.join('\n');
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private lcObjectKey(src: Record<string, string>): Record<string, string> {
|
||||
const dst: Record<string, string> = {};
|
||||
for (const key of Object.keys(src).filter(x => x !== '__proto__' && typeof src[x] === 'string')) dst[key.toLowerCase()] = src[key];
|
||||
return dst;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private objectAssignWithLcKey(a: Record<string, string>, b: Record<string, string>): Record<string, string> {
|
||||
return Object.assign(this.lcObjectKey(a), this.lcObjectKey(b));
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async signedPost(user: { id: User['id'] }, url: string, object: any) {
|
||||
const body = JSON.stringify(object);
|
||||
|
||||
|
@ -157,6 +165,7 @@ export class ApRequestService {
|
|||
* @param user http-signature user
|
||||
* @param url URL to fetch
|
||||
*/
|
||||
@bindThis
|
||||
public async signedGet(url: string, user: { id: User['id'] }) {
|
||||
const keypair = await this.userKeypairStoreService.getUserKeypair(user.id);
|
||||
|
||||
|
|
|
@ -7,58 +7,13 @@ import { MetaService } from '@/core/MetaService.js';
|
|||
import { HttpRequestService } from '@/core/HttpRequestService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { UtilityService } from '@/core/UtilityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { isCollectionOrOrderedCollection } from './type.js';
|
||||
import { ApDbResolverService } from './ApDbResolverService.js';
|
||||
import { ApRendererService } from './ApRendererService.js';
|
||||
import { ApRequestService } from './ApRequestService.js';
|
||||
import type { IObject, ICollection, IOrderedCollection } from './type.js';
|
||||
|
||||
@Injectable()
|
||||
export class ApResolverService {
|
||||
constructor(
|
||||
@Inject(DI.config)
|
||||
private config: Config,
|
||||
|
||||
@Inject(DI.usersRepository)
|
||||
private usersRepository: UsersRepository,
|
||||
|
||||
@Inject(DI.notesRepository)
|
||||
private notesRepository: NotesRepository,
|
||||
|
||||
@Inject(DI.pollsRepository)
|
||||
private pollsRepository: PollsRepository,
|
||||
|
||||
@Inject(DI.noteReactionsRepository)
|
||||
private noteReactionsRepository: NoteReactionsRepository,
|
||||
|
||||
private utilityService: UtilityService,
|
||||
private instanceActorService: InstanceActorService,
|
||||
private metaService: MetaService,
|
||||
private apRequestService: ApRequestService,
|
||||
private httpRequestService: HttpRequestService,
|
||||
private apRendererService: ApRendererService,
|
||||
private apDbResolverService: ApDbResolverService,
|
||||
) {
|
||||
}
|
||||
|
||||
public createResolver(): Resolver {
|
||||
return new Resolver(
|
||||
this.config,
|
||||
this.usersRepository,
|
||||
this.notesRepository,
|
||||
this.pollsRepository,
|
||||
this.noteReactionsRepository,
|
||||
this.utilityService,
|
||||
this.instanceActorService,
|
||||
this.metaService,
|
||||
this.apRequestService,
|
||||
this.httpRequestService,
|
||||
this.apRendererService,
|
||||
this.apDbResolverService,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class Resolver {
|
||||
private history: Set<string>;
|
||||
private user?: ILocalUser;
|
||||
|
@ -76,15 +31,17 @@ export class Resolver {
|
|||
private httpRequestService: HttpRequestService,
|
||||
private apRendererService: ApRendererService,
|
||||
private apDbResolverService: ApDbResolverService,
|
||||
private recursionLimit = 100
|
||||
private recursionLimit = 100,
|
||||
) {
|
||||
this.history = new Set();
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public getHistory(): string[] {
|
||||
return Array.from(this.history);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async resolveCollection(value: string | IObject): Promise<ICollection | IOrderedCollection> {
|
||||
const collection = typeof value === 'string'
|
||||
? await this.resolve(value)
|
||||
|
@ -97,6 +54,7 @@ export class Resolver {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async resolve(value: string | IObject): Promise<IObject> {
|
||||
if (value == null) {
|
||||
throw new Error('resolvee is null (or undefined)');
|
||||
|
@ -152,6 +110,7 @@ export class Resolver {
|
|||
return object;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private resolveLocal(url: string): Promise<IObject> {
|
||||
const parsed = this.apDbResolverService.parseUri(url);
|
||||
if (!parsed.local) throw new Error('resolveLocal: not local');
|
||||
|
@ -193,3 +152,50 @@ export class Resolver {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ApResolverService {
|
||||
constructor(
|
||||
@Inject(DI.config)
|
||||
private config: Config,
|
||||
|
||||
@Inject(DI.usersRepository)
|
||||
private usersRepository: UsersRepository,
|
||||
|
||||
@Inject(DI.notesRepository)
|
||||
private notesRepository: NotesRepository,
|
||||
|
||||
@Inject(DI.pollsRepository)
|
||||
private pollsRepository: PollsRepository,
|
||||
|
||||
@Inject(DI.noteReactionsRepository)
|
||||
private noteReactionsRepository: NoteReactionsRepository,
|
||||
|
||||
private utilityService: UtilityService,
|
||||
private instanceActorService: InstanceActorService,
|
||||
private metaService: MetaService,
|
||||
private apRequestService: ApRequestService,
|
||||
private httpRequestService: HttpRequestService,
|
||||
private apRendererService: ApRendererService,
|
||||
private apDbResolverService: ApDbResolverService,
|
||||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public createResolver(): Resolver {
|
||||
return new Resolver(
|
||||
this.config,
|
||||
this.usersRepository,
|
||||
this.notesRepository,
|
||||
this.pollsRepository,
|
||||
this.noteReactionsRepository,
|
||||
this.utilityService,
|
||||
this.instanceActorService,
|
||||
this.metaService,
|
||||
this.apRequestService,
|
||||
this.httpRequestService,
|
||||
this.apRendererService,
|
||||
this.apDbResolverService,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,22 +2,11 @@ import * as crypto from 'node:crypto';
|
|||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import fetch from 'node-fetch';
|
||||
import { HttpRequestService } from '@/core/HttpRequestService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { CONTEXTS } from './misc/contexts.js';
|
||||
|
||||
// RsaSignature2017 based from https://github.com/transmute-industries/RsaSignature2017
|
||||
|
||||
@Injectable()
|
||||
export class LdSignatureService {
|
||||
constructor(
|
||||
private httpRequestService: HttpRequestService,
|
||||
) {
|
||||
}
|
||||
|
||||
public use(): LdSignature {
|
||||
return new LdSignature(this.httpRequestService);
|
||||
}
|
||||
}
|
||||
|
||||
class LdSignature {
|
||||
public debug = false;
|
||||
public preLoad = true;
|
||||
|
@ -28,6 +17,7 @@ class LdSignature {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async signRsaSignature2017(data: any, privateKey: string, creator: string, domain?: string, created?: Date): Promise<any> {
|
||||
const options = {
|
||||
type: 'RsaSignature2017',
|
||||
|
@ -64,6 +54,7 @@ class LdSignature {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async verifyRsaSignature2017(data: any, publicKey: string): Promise<boolean> {
|
||||
const toBeSigned = await this.createVerifyData(data, data.signature);
|
||||
const verifier = crypto.createVerify('sha256');
|
||||
|
@ -71,6 +62,7 @@ class LdSignature {
|
|||
return verifier.verify(publicKey, data.signature.signatureValue, 'base64');
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async createVerifyData(data: any, options: any) {
|
||||
const transformedOptions = {
|
||||
...options,
|
||||
|
@ -90,11 +82,13 @@ class LdSignature {
|
|||
return verifyData;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async normalize(data: any) {
|
||||
const customLoader = this.getLoader();
|
||||
return 42;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private getLoader() {
|
||||
return async (url: string): Promise<any> => {
|
||||
if (!url.match('^https?\:\/\/')) throw `Invalid URL ${url}`;
|
||||
|
@ -120,6 +114,7 @@ class LdSignature {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async fetchDocument(url: string) {
|
||||
const json = await fetch(url, {
|
||||
headers: {
|
||||
|
@ -139,9 +134,23 @@ class LdSignature {
|
|||
return json;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public sha256(data: string): string {
|
||||
const hash = crypto.createHash('sha256');
|
||||
hash.update(data);
|
||||
return hash.digest('hex');
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class LdSignatureService {
|
||||
constructor(
|
||||
private httpRequestService: HttpRequestService,
|
||||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public use(): LdSignature {
|
||||
return new LdSignature(this.httpRequestService);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import { DriveService } from '@/core/DriveService.js';
|
|||
import type Logger from '@/logger.js';
|
||||
import { ApResolverService } from '../ApResolverService.js';
|
||||
import { ApLoggerService } from '../ApLoggerService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class ApImageService {
|
||||
|
@ -34,6 +35,7 @@ export class ApImageService {
|
|||
/**
|
||||
* Imageを作成します。
|
||||
*/
|
||||
@bindThis
|
||||
public async createImage(actor: CacheableRemoteUser, value: any): Promise<DriveFile> {
|
||||
// 投稿者が凍結されていたらスキップ
|
||||
if (actor.isSuspended) {
|
||||
|
@ -81,6 +83,7 @@ export class ApImageService {
|
|||
* Misskeyに対象のImageが登録されていればそれを返し、そうでなければ
|
||||
* リモートサーバーからフェッチしてMisskeyに登録しそれを返します。
|
||||
*/
|
||||
@bindThis
|
||||
public async resolveImage(actor: CacheableRemoteUser, value: any): Promise<DriveFile> {
|
||||
// TODO
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import { isMention } from '../type.js';
|
|||
import { ApResolverService, Resolver } from '../ApResolverService.js';
|
||||
import { ApPersonService } from './ApPersonService.js';
|
||||
import type { IObject, IApMention } from '../type.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class ApMentionService {
|
||||
|
@ -21,6 +22,7 @@ export class ApMentionService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async extractApMentions(tags: IObject | IObject[] | null | undefined, resolver: Resolver) {
|
||||
const hrefs = unique(this.extractApMentionObjects(tags).map(x => x.href as string));
|
||||
|
||||
|
@ -32,6 +34,7 @@ export class ApMentionService {
|
|||
return mentionedUsers;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public extractApMentionObjects(tags: IObject | IObject[] | null | undefined): IApMention[] {
|
||||
if (tags == null) return [];
|
||||
return toArray(tags).filter(isMention);
|
||||
|
|
|
@ -32,6 +32,7 @@ import { ApQuestionService } from './ApQuestionService.js';
|
|||
import { ApImageService } from './ApImageService.js';
|
||||
import type { Resolver } from '../ApResolverService.js';
|
||||
import type { IObject, IPost } from '../type.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class ApNoteService {
|
||||
|
@ -74,6 +75,7 @@ export class ApNoteService {
|
|||
this.logger = this.apLoggerService.logger;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public validateNote(object: any, uri: string) {
|
||||
const expectHost = this.utilityService.extractDbHost(uri);
|
||||
|
||||
|
@ -101,6 +103,7 @@ export class ApNoteService {
|
|||
*
|
||||
* Misskeyに対象のNoteが登録されていればそれを返します。
|
||||
*/
|
||||
@bindThis
|
||||
public async fetchNote(object: string | IObject): Promise<Note | null> {
|
||||
return await this.apDbResolverService.getNoteFromApId(object);
|
||||
}
|
||||
|
@ -108,6 +111,7 @@ export class ApNoteService {
|
|||
/**
|
||||
* Noteを作成します。
|
||||
*/
|
||||
@bindThis
|
||||
public async createNote(value: string | IObject, resolver?: Resolver, silent = false): Promise<Note | null> {
|
||||
if (resolver == null) resolver = this.apResolverService.createResolver();
|
||||
|
||||
|
@ -313,6 +317,7 @@ export class ApNoteService {
|
|||
* Misskeyに対象のNoteが登録されていればそれを返し、そうでなければ
|
||||
* リモートサーバーからフェッチしてMisskeyに登録しそれを返します。
|
||||
*/
|
||||
@bindThis
|
||||
public async resolveNote(value: string | IObject, resolver?: Resolver): Promise<Note | null> {
|
||||
const uri = typeof value === 'string' ? value : value.id;
|
||||
if (uri == null) throw new Error('missing uri');
|
||||
|
@ -345,6 +350,7 @@ export class ApNoteService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async extractEmojis(tags: IObject | IObject[], host: string): Promise<Emoji[]> {
|
||||
host = this.utilityService.toPuny(host);
|
||||
|
||||
|
|
|
@ -72,6 +72,7 @@ function addService(target: { [x: string]: any }, source: IApPropertyValue) {
|
|||
target[source.name.split(':')[2]] = service(id, username);
|
||||
}
|
||||
}
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class ApPersonService implements OnModuleInit {
|
||||
|
@ -161,6 +162,7 @@ export class ApPersonService implements OnModuleInit {
|
|||
* @param x Fetched object
|
||||
* @param uri Fetch target URI
|
||||
*/
|
||||
@bindThis
|
||||
private validateActor(x: IObject, uri: string): IActor {
|
||||
const expectHost = this.utilityService.toPuny(new URL(uri).hostname);
|
||||
|
||||
|
@ -224,6 +226,7 @@ export class ApPersonService implements OnModuleInit {
|
|||
*
|
||||
* Misskeyに対象のPersonが登録されていればそれを返します。
|
||||
*/
|
||||
@bindThis
|
||||
public async fetchPerson(uri: string, resolver?: Resolver): Promise<CacheableUser | null> {
|
||||
if (typeof uri !== 'string') throw new Error('uri is not string');
|
||||
|
||||
|
@ -253,6 +256,7 @@ export class ApPersonService implements OnModuleInit {
|
|||
/**
|
||||
* Personを作成します。
|
||||
*/
|
||||
@bindThis
|
||||
public async createPerson(uri: string, resolver?: Resolver): Promise<User> {
|
||||
if (typeof uri !== 'string') throw new Error('uri is not string');
|
||||
|
||||
|
@ -402,6 +406,7 @@ export class ApPersonService implements OnModuleInit {
|
|||
* @param resolver Resolver
|
||||
* @param hint Hint of Person object (この値が正当なPersonの場合、Remote resolveをせずに更新に利用します)
|
||||
*/
|
||||
@bindThis
|
||||
public async updatePerson(uri: string, resolver?: Resolver | null, hint?: IObject): Promise<void> {
|
||||
if (typeof uri !== 'string') throw new Error('uri is not string');
|
||||
|
||||
|
@ -512,6 +517,7 @@ export class ApPersonService implements OnModuleInit {
|
|||
* Misskeyに対象のPersonが登録されていればそれを返し、そうでなければ
|
||||
* リモートサーバーからフェッチしてMisskeyに登録しそれを返します。
|
||||
*/
|
||||
@bindThis
|
||||
public async resolvePerson(uri: string, resolver?: Resolver): Promise<CacheableUser> {
|
||||
if (typeof uri !== 'string') throw new Error('uri is not string');
|
||||
|
||||
|
@ -528,6 +534,7 @@ export class ApPersonService implements OnModuleInit {
|
|||
return await this.createPerson(uri, resolver);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public analyzeAttachments(attachments: IObject | IObject[] | undefined) {
|
||||
const fields: {
|
||||
name: string,
|
||||
|
@ -551,6 +558,7 @@ export class ApPersonService implements OnModuleInit {
|
|||
return { fields, services };
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async updateFeatured(userId: User['id'], resolver?: Resolver) {
|
||||
const user = await this.usersRepository.findOneByOrFail({ id: userId });
|
||||
if (!this.userEntityService.isRemoteUser(user)) return;
|
||||
|
|
|
@ -9,6 +9,7 @@ import { ApLoggerService } from '../ApLoggerService.js';
|
|||
import { ApResolverService } from '../ApResolverService.js';
|
||||
import type { Resolver } from '../ApResolverService.js';
|
||||
import type { IObject, IQuestion } from '../type.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class ApQuestionService {
|
||||
|
@ -30,6 +31,7 @@ export class ApQuestionService {
|
|||
this.logger = this.apLoggerService.logger;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async extractPollFromQuestion(source: string | IObject, resolver?: Resolver): Promise<IPoll> {
|
||||
if (resolver == null) resolver = this.apResolverService.createResolver();
|
||||
|
||||
|
@ -65,6 +67,7 @@ export class ApQuestionService {
|
|||
* @param uri URI of AP Question object
|
||||
* @returns true if updated
|
||||
*/
|
||||
@bindThis
|
||||
public async updateQuestion(value: any, resolver?: Resolver) {
|
||||
const uri = typeof value === 'string' ? value : value.id;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import type Logger from '@/logger.js';
|
||||
import { LoggerService } from '@/core/LoggerService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class ChartLoggerService {
|
||||
|
|
|
@ -13,6 +13,7 @@ import PerUserFollowingChart from './charts/per-user-following.js';
|
|||
import PerUserDriveChart from './charts/per-user-drive.js';
|
||||
import ApRequestChart from './charts/ap-request.js';
|
||||
import type { OnApplicationShutdown } from '@nestjs/common';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class ChartManagementService implements OnApplicationShutdown {
|
||||
|
@ -49,6 +50,7 @@ export class ChartManagementService implements OnApplicationShutdown {
|
|||
];
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async run() {
|
||||
// 20分おきにメモリ情報をDBに書き込み
|
||||
this.saveIntervalId = setInterval(() => {
|
||||
|
|
|
@ -3,6 +3,7 @@ import { DataSource } from 'typeorm';
|
|||
import { AppLockService } from '@/core/AppLockService.js';
|
||||
import type { User } from '@/models/entities/User.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import Chart from '../core.js';
|
||||
import { ChartLoggerService } from '../ChartLoggerService.js';
|
||||
import { name, schema } from './entities/active-users.js';
|
||||
|
@ -36,6 +37,7 @@ export default class ActiveUsersChart extends Chart<typeof schema> {
|
|||
return {};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async read(user: { id: User['id'], host: null, createdAt: User['createdAt'] }): Promise<void> {
|
||||
await this.commit({
|
||||
'read': [user.id],
|
||||
|
@ -48,6 +50,7 @@ export default class ActiveUsersChart extends Chart<typeof schema> {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async write(user: { id: User['id'], host: null, createdAt: User['createdAt'] }): Promise<void> {
|
||||
await this.commit({
|
||||
'write': [user.id],
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Injectable, Inject } from '@nestjs/common';
|
|||
import { DataSource } from 'typeorm';
|
||||
import { AppLockService } from '@/core/AppLockService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import Chart from '../core.js';
|
||||
import { ChartLoggerService } from '../ChartLoggerService.js';
|
||||
import { name, schema } from './entities/ap-request.js';
|
||||
|
@ -31,18 +32,21 @@ export default class ApRequestChart extends Chart<typeof schema> {
|
|||
return {};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async deliverSucc(): Promise<void> {
|
||||
await this.commit({
|
||||
'deliverSucceeded': 1,
|
||||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async deliverFail(): Promise<void> {
|
||||
await this.commit({
|
||||
'deliverFailed': 1,
|
||||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async inbox(): Promise<void> {
|
||||
await this.commit({
|
||||
'inboxReceived': 1,
|
||||
|
|
|
@ -3,6 +3,7 @@ import { Not, IsNull, DataSource } from 'typeorm';
|
|||
import type { DriveFile } from '@/models/entities/DriveFile.js';
|
||||
import { AppLockService } from '@/core/AppLockService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import Chart from '../core.js';
|
||||
import { ChartLoggerService } from '../ChartLoggerService.js';
|
||||
import { name, schema } from './entities/drive.js';
|
||||
|
@ -32,6 +33,7 @@ export default class DriveChart extends Chart<typeof schema> {
|
|||
return {};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async update(file: DriveFile, isAdditional: boolean): Promise<void> {
|
||||
const fileSizeKb = file.size / 1000;
|
||||
await this.commit(file.userHost === null ? {
|
||||
|
|
|
@ -4,6 +4,7 @@ import type { FollowingsRepository, InstancesRepository } from '@/models/index.j
|
|||
import { AppLockService } from '@/core/AppLockService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { MetaService } from '@/core/MetaService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import Chart from '../core.js';
|
||||
import { ChartLoggerService } from '../ChartLoggerService.js';
|
||||
import { name, schema } from './entities/federation.js';
|
||||
|
@ -107,6 +108,7 @@ export default class FederationChart extends Chart<typeof schema> {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async deliverd(host: string, succeeded: boolean): Promise<void> {
|
||||
await this.commit(succeeded ? {
|
||||
'deliveredInstances': [host],
|
||||
|
@ -115,6 +117,7 @@ export default class FederationChart extends Chart<typeof schema> {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async inbox(host: string): Promise<void> {
|
||||
await this.commit({
|
||||
'inboxInstances': [host],
|
||||
|
|
|
@ -4,6 +4,7 @@ import type { User } from '@/models/entities/User.js';
|
|||
import { AppLockService } from '@/core/AppLockService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import Chart from '../core.js';
|
||||
import { ChartLoggerService } from '../ChartLoggerService.js';
|
||||
import { name, schema } from './entities/hashtag.js';
|
||||
|
@ -34,6 +35,7 @@ export default class HashtagChart extends Chart<typeof schema> {
|
|||
return {};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async update(hashtag: string, user: { id: User['id'], host: User['host'] }): Promise<void> {
|
||||
await this.commit({
|
||||
'local.users': this.userEntityService.isLocalUser(user) ? [user.id] : [],
|
||||
|
|
|
@ -6,6 +6,7 @@ import type { Note } from '@/models/entities/Note.js';
|
|||
import { AppLockService } from '@/core/AppLockService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { UtilityService } from '@/core/UtilityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import Chart from '../core.js';
|
||||
import { ChartLoggerService } from '../ChartLoggerService.js';
|
||||
import { name, schema } from './entities/instance.js';
|
||||
|
@ -68,12 +69,14 @@ export default class InstanceChart extends Chart<typeof schema> {
|
|||
return {};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async requestReceived(host: string): Promise<void> {
|
||||
await this.commit({
|
||||
'requests.received': 1,
|
||||
}, this.utilityService.toPuny(host));
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async requestSent(host: string, isSucceeded: boolean): Promise<void> {
|
||||
await this.commit({
|
||||
'requests.succeeded': isSucceeded ? 1 : 0,
|
||||
|
@ -81,6 +84,7 @@ export default class InstanceChart extends Chart<typeof schema> {
|
|||
}, this.utilityService.toPuny(host));
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async newUser(host: string): Promise<void> {
|
||||
await this.commit({
|
||||
'users.total': 1,
|
||||
|
@ -88,6 +92,7 @@ export default class InstanceChart extends Chart<typeof schema> {
|
|||
}, this.utilityService.toPuny(host));
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async updateNote(host: string, note: Note, isAdditional: boolean): Promise<void> {
|
||||
await this.commit({
|
||||
'notes.total': isAdditional ? 1 : -1,
|
||||
|
@ -100,6 +105,7 @@ export default class InstanceChart extends Chart<typeof schema> {
|
|||
}, this.utilityService.toPuny(host));
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async updateFollowing(host: string, isAdditional: boolean): Promise<void> {
|
||||
await this.commit({
|
||||
'following.total': isAdditional ? 1 : -1,
|
||||
|
@ -108,6 +114,7 @@ export default class InstanceChart extends Chart<typeof schema> {
|
|||
}, this.utilityService.toPuny(host));
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async updateFollowers(host: string, isAdditional: boolean): Promise<void> {
|
||||
await this.commit({
|
||||
'followers.total': isAdditional ? 1 : -1,
|
||||
|
@ -116,6 +123,7 @@ export default class InstanceChart extends Chart<typeof schema> {
|
|||
}, this.utilityService.toPuny(host));
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async updateDrive(file: DriveFile, isAdditional: boolean): Promise<void> {
|
||||
const fileSizeKb = file.size / 1000;
|
||||
await this.commit({
|
||||
|
|
|
@ -4,6 +4,7 @@ import type { NotesRepository } from '@/models/index.js';
|
|||
import type { Note } from '@/models/entities/Note.js';
|
||||
import { AppLockService } from '@/core/AppLockService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import Chart from '../core.js';
|
||||
import { ChartLoggerService } from '../ChartLoggerService.js';
|
||||
import { name, schema } from './entities/notes.js';
|
||||
|
@ -44,6 +45,7 @@ export default class NotesChart extends Chart<typeof schema> {
|
|||
return {};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async update(note: Note, isAdditional: boolean): Promise<void> {
|
||||
const prefix = note.userHost === null ? 'local' : 'remote';
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import type { DriveFile } from '@/models/entities/DriveFile.js';
|
|||
import { AppLockService } from '@/core/AppLockService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import Chart from '../core.js';
|
||||
import { ChartLoggerService } from '../ChartLoggerService.js';
|
||||
import { name, schema } from './entities/per-user-drive.js';
|
||||
|
@ -46,6 +47,7 @@ export default class PerUserDriveChart extends Chart<typeof schema> {
|
|||
return {};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async update(file: DriveFile, isAdditional: boolean): Promise<void> {
|
||||
const fileSizeKb = file.size / 1000;
|
||||
await this.commit({
|
||||
|
|
|
@ -5,6 +5,7 @@ import { AppLockService } from '@/core/AppLockService.js';
|
|||
import { DI } from '@/di-symbols.js';
|
||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import type { FollowingsRepository } from '@/models/index.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import Chart from '../core.js';
|
||||
import { ChartLoggerService } from '../ChartLoggerService.js';
|
||||
import { name, schema } from './entities/per-user-following.js';
|
||||
|
@ -55,6 +56,7 @@ export default class PerUserFollowingChart extends Chart<typeof schema> {
|
|||
return {};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async update(follower: { id: User['id']; host: User['host']; }, followee: { id: User['id']; host: User['host']; }, isFollow: boolean): Promise<void> {
|
||||
const prefixFollower = this.userEntityService.isLocalUser(follower) ? 'local' : 'remote';
|
||||
const prefixFollowee = this.userEntityService.isLocalUser(followee) ? 'local' : 'remote';
|
||||
|
|
|
@ -5,6 +5,7 @@ import type { Note } from '@/models/entities/Note.js';
|
|||
import { AppLockService } from '@/core/AppLockService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import type { NotesRepository } from '@/models/index.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import Chart from '../core.js';
|
||||
import { ChartLoggerService } from '../ChartLoggerService.js';
|
||||
import { name, schema } from './entities/per-user-notes.js';
|
||||
|
@ -43,6 +44,7 @@ export default class PerUserNotesChart extends Chart<typeof schema> {
|
|||
return {};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async update(user: { id: User['id'] }, note: Note, isAdditional: boolean): Promise<void> {
|
||||
await this.commit({
|
||||
'total': isAdditional ? 1 : -1,
|
||||
|
|
|
@ -5,6 +5,7 @@ import type { Note } from '@/models/entities/Note.js';
|
|||
import { AppLockService } from '@/core/AppLockService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import Chart from '../core.js';
|
||||
import { ChartLoggerService } from '../ChartLoggerService.js';
|
||||
import { name, schema } from './entities/per-user-reactions.js';
|
||||
|
@ -35,6 +36,7 @@ export default class PerUserReactionsChart extends Chart<typeof schema> {
|
|||
return {};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async update(user: { id: User['id'], host: User['host'] }, note: Note): Promise<void> {
|
||||
const prefix = this.userEntityService.isLocalUser(user) ? 'local' : 'remote';
|
||||
this.commit({
|
||||
|
|
|
@ -3,6 +3,7 @@ import { DataSource } from 'typeorm';
|
|||
import { AppLockService } from '@/core/AppLockService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import Logger from '@/logger.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import Chart from '../core.js';
|
||||
import { name, schema } from './entities/test-grouped.js';
|
||||
import type { KVs } from '../core.js';
|
||||
|
@ -35,6 +36,7 @@ export default class TestGroupedChart extends Chart<typeof schema> {
|
|||
return {};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async increment(group: string): Promise<void> {
|
||||
if (this.total[group] == null) this.total[group] = 0;
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import { DataSource } from 'typeorm';
|
|||
import { AppLockService } from '@/core/AppLockService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import Logger from '@/logger.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import Chart from '../core.js';
|
||||
import { name, schema } from './entities/test-intersection.js';
|
||||
import type { KVs } from '../core.js';
|
||||
|
@ -31,12 +32,14 @@ export default class TestIntersectionChart extends Chart<typeof schema> {
|
|||
return {};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async addA(key: string): Promise<void> {
|
||||
await this.commit({
|
||||
a: [key],
|
||||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async addB(key: string): Promise<void> {
|
||||
await this.commit({
|
||||
b: [key],
|
||||
|
|
|
@ -3,6 +3,7 @@ import { DataSource } from 'typeorm';
|
|||
import { AppLockService } from '@/core/AppLockService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import Logger from '@/logger.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import Chart from '../core.js';
|
||||
import { name, schema } from './entities/test-unique.js';
|
||||
import type { KVs } from '../core.js';
|
||||
|
@ -31,6 +32,7 @@ export default class TestUniqueChart extends Chart<typeof schema> {
|
|||
return {};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async uniqueIncrement(key: string): Promise<void> {
|
||||
await this.commit({
|
||||
foo: [key],
|
||||
|
|
|
@ -3,6 +3,7 @@ import { DataSource } from 'typeorm';
|
|||
import { AppLockService } from '@/core/AppLockService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import Logger from '@/logger.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import Chart from '../core.js';
|
||||
import { name, schema } from './entities/test.js';
|
||||
import type { KVs } from '../core.js';
|
||||
|
@ -35,6 +36,7 @@ export default class TestChart extends Chart<typeof schema> {
|
|||
return {};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async increment(): Promise<void> {
|
||||
this.total++;
|
||||
|
||||
|
@ -44,6 +46,7 @@ export default class TestChart extends Chart<typeof schema> {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async decrement(): Promise<void> {
|
||||
this.total--;
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import { AppLockService } from '@/core/AppLockService.js';
|
|||
import { DI } from '@/di-symbols.js';
|
||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import type { UsersRepository } from '@/models/index.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import Chart from '../core.js';
|
||||
import { ChartLoggerService } from '../ChartLoggerService.js';
|
||||
import { name, schema } from './entities/users.js';
|
||||
|
@ -46,6 +47,7 @@ export default class UsersChart extends Chart<typeof schema> {
|
|||
return {};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async update(user: { id: User['id'], host: User['host'] }, isAdditional: boolean): Promise<void> {
|
||||
const prefix = this.userEntityService.isLocalUser(user) ? 'local' : 'remote';
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import * as nestedProperty from 'nested-property';
|
|||
import { EntitySchema, LessThan, Between } from 'typeorm';
|
||||
import { dateUTC, isTimeSame, isTimeBefore, subtractTime, addTime } from '@/misc/prelude/time.js';
|
||||
import type Logger from '@/logger.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import type { Repository, DataSource } from 'typeorm';
|
||||
|
||||
const columnPrefix = '___' as const;
|
||||
|
@ -249,6 +250,7 @@ export default abstract class Chart<T extends Schema> {
|
|||
this.repositoryForDay = db.getRepository<{ id: number; group?: string | null; date: number; }>(day);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private convertRawRecord(x: RawRecord<T>): KVs<T> {
|
||||
const kvs = {} as Record<string, number>;
|
||||
for (const k of Object.keys(x).filter((k) => k.startsWith(columnPrefix)) as (keyof Columns<T>)[]) {
|
||||
|
@ -257,6 +259,7 @@ export default abstract class Chart<T extends Schema> {
|
|||
return kvs as KVs<T>;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private getNewLog(latest: KVs<T> | null): KVs<T> {
|
||||
const log = {} as Record<keyof T, number>;
|
||||
for (const [k, v] of Object.entries(this.schema) as ([keyof typeof this['schema'], this['schema'][string]])[]) {
|
||||
|
@ -269,6 +272,7 @@ export default abstract class Chart<T extends Schema> {
|
|||
return log as KVs<T>;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private getLatestLog(group: string | null, span: 'hour' | 'day'): Promise<RawRecord<T> | null> {
|
||||
const repository =
|
||||
span === 'hour' ? this.repositoryForHour :
|
||||
|
@ -288,6 +292,7 @@ export default abstract class Chart<T extends Schema> {
|
|||
/**
|
||||
* 現在(=今のHour or Day)のログをデータベースから探して、あればそれを返し、なければ作成して返します。
|
||||
*/
|
||||
@bindThis
|
||||
private async claimCurrentLog(group: string | null, span: 'hour' | 'day'): Promise<RawRecord<T>> {
|
||||
const [y, m, d, h] = Chart.getCurrentDate();
|
||||
|
||||
|
@ -380,6 +385,7 @@ export default abstract class Chart<T extends Schema> {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async save(): Promise<void> {
|
||||
if (this.buffer.length === 0) {
|
||||
this.logger.info(`${this.name}: Write skipped`);
|
||||
|
@ -498,6 +504,7 @@ export default abstract class Chart<T extends Schema> {
|
|||
update(logHour, logDay))));
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async tick(major: boolean, group: string | null = null): Promise<void> {
|
||||
const data = major ? await this.tickMajor(group) : await this.tickMinor(group);
|
||||
|
||||
|
@ -533,10 +540,12 @@ export default abstract class Chart<T extends Schema> {
|
|||
update(logHour, logDay));
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public resync(group: string | null = null): Promise<void> {
|
||||
return this.tick(true, group);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async clean(): Promise<void> {
|
||||
const current = dateUTC(Chart.getCurrentDate());
|
||||
|
||||
|
@ -572,6 +581,7 @@ export default abstract class Chart<T extends Schema> {
|
|||
]);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async getChartRaw(span: 'hour' | 'day', amount: number, cursor: Date | null, group: string | null = null): Promise<ChartResult<T>> {
|
||||
const [y, m, d, h, _m, _s, _ms] = cursor ? Chart.parseDate(subtractTime(addTime(cursor, 1, span), 1)) : Chart.getCurrentDate();
|
||||
const [y2, m2, d2, h2] = cursor ? Chart.parseDate(addTime(cursor, 1, span)) : [] as never;
|
||||
|
@ -676,6 +686,7 @@ export default abstract class Chart<T extends Schema> {
|
|||
return res;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async getChart(span: 'hour' | 'day', amount: number, cursor: Date | null, group: string | null = null): Promise<Unflatten<ChartResult<T>>> {
|
||||
const result = await this.getChartRaw(span, amount, cursor, group);
|
||||
const object = {};
|
||||
|
|
|
@ -4,6 +4,7 @@ import type { AbuseUserReportsRepository } from '@/models/index.js';
|
|||
import { awaitAll } from '@/misc/prelude/await-all.js';
|
||||
import type { AbuseUserReport } from '@/models/entities/AbuseUserReport.js';
|
||||
import { UserEntityService } from './UserEntityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class AbuseUserReportEntityService {
|
||||
|
@ -15,6 +16,7 @@ export class AbuseUserReportEntityService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async pack(
|
||||
src: AbuseUserReport['id'] | AbuseUserReport,
|
||||
) {
|
||||
|
@ -41,6 +43,7 @@ export class AbuseUserReportEntityService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public packMany(
|
||||
reports: any[],
|
||||
) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import type { AntennaNotesRepository, AntennasRepository, UserGroupJoiningsRepos
|
|||
import { awaitAll } from '@/misc/prelude/await-all.js';
|
||||
import type { Packed } from '@/misc/schema.js';
|
||||
import type { Antenna } from '@/models/entities/Antenna.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class AntennaEntityService {
|
||||
|
@ -19,6 +20,7 @@ export class AntennaEntityService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async pack(
|
||||
src: Antenna['id'] | Antenna,
|
||||
): Promise<Packed<'Antenna'>> {
|
||||
|
|
|
@ -6,6 +6,7 @@ import type { Packed } from '@/misc/schema.js';
|
|||
import type { App } from '@/models/entities/App.js';
|
||||
import type { User } from '@/models/entities/User.js';
|
||||
import { UserEntityService } from './UserEntityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class AppEntityService {
|
||||
|
@ -18,6 +19,7 @@ export class AppEntityService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async pack(
|
||||
src: App['id'] | App,
|
||||
me?: { id: User['id'] } | null | undefined,
|
||||
|
|
|
@ -7,6 +7,7 @@ import type { AuthSession } from '@/models/entities/AuthSession.js';
|
|||
import type { User } from '@/models/entities/User.js';
|
||||
import { UserEntityService } from './UserEntityService.js';
|
||||
import { AppEntityService } from './AppEntityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class AuthSessionEntityService {
|
||||
|
@ -18,6 +19,7 @@ export class AuthSessionEntityService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async pack(
|
||||
src: AuthSession['id'] | AuthSession,
|
||||
me?: { id: User['id'] } | null | undefined,
|
||||
|
|
|
@ -6,6 +6,7 @@ import type { Packed } from '@/misc/schema.js';
|
|||
import type { Blocking } from '@/models/entities/Blocking.js';
|
||||
import type { User } from '@/models/entities/User.js';
|
||||
import { UserEntityService } from './UserEntityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class BlockingEntityService {
|
||||
|
@ -17,6 +18,7 @@ export class BlockingEntityService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async pack(
|
||||
src: Blocking['id'] | Blocking,
|
||||
me?: { id: User['id'] } | null | undefined,
|
||||
|
@ -33,6 +35,7 @@ export class BlockingEntityService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public packMany(
|
||||
blockings: any[],
|
||||
me: { id: User['id'] },
|
||||
|
|
|
@ -8,6 +8,7 @@ import type { User } from '@/models/entities/User.js';
|
|||
import type { Channel } from '@/models/entities/Channel.js';
|
||||
import { UserEntityService } from './UserEntityService.js';
|
||||
import { DriveFileEntityService } from './DriveFileEntityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class ChannelEntityService {
|
||||
|
@ -29,6 +30,7 @@ export class ChannelEntityService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async pack(
|
||||
src: Channel['id'] | Channel,
|
||||
me?: { id: User['id'] } | null | undefined,
|
||||
|
|
|
@ -7,6 +7,7 @@ import type { } from '@/models/entities/Blocking.js';
|
|||
import type { User } from '@/models/entities/User.js';
|
||||
import type { Clip } from '@/models/entities/Clip.js';
|
||||
import { UserEntityService } from './UserEntityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class ClipEntityService {
|
||||
|
@ -18,6 +19,7 @@ export class ClipEntityService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async pack(
|
||||
src: Clip['id'] | Clip,
|
||||
): Promise<Packed<'Clip'>> {
|
||||
|
@ -34,6 +36,7 @@ export class ClipEntityService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public packMany(
|
||||
clips: Clip[],
|
||||
) {
|
||||
|
|
|
@ -19,6 +19,7 @@ type PackOptions = {
|
|||
self?: boolean,
|
||||
withUser?: boolean,
|
||||
};
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class DriveFileEntityService {
|
||||
|
@ -44,6 +45,7 @@ export class DriveFileEntityService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public validateFileName(name: string): boolean {
|
||||
return (
|
||||
(name.trim().length > 0) &&
|
||||
|
@ -54,6 +56,7 @@ export class DriveFileEntityService {
|
|||
);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public getPublicProperties(file: DriveFile): DriveFile['properties'] {
|
||||
if (file.properties.orientation != null) {
|
||||
const properties = deepClone(file.properties);
|
||||
|
@ -67,6 +70,7 @@ export class DriveFileEntityService {
|
|||
return file.properties;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public getPublicUrl(file: DriveFile, thumbnail = false): string | null {
|
||||
// リモートかつメディアプロキシ
|
||||
if (file.uri != null && file.userHost != null && this.config.mediaProxy != null) {
|
||||
|
@ -90,6 +94,7 @@ export class DriveFileEntityService {
|
|||
return thumbnail ? (file.thumbnailUrl ?? (isImage ? (file.webpublicUrl ?? file.url) : null)) : (file.webpublicUrl ?? file.url);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async calcDriveUsageOf(user: User['id'] | { id: User['id'] }): Promise<number> {
|
||||
const id = typeof user === 'object' ? user.id : user;
|
||||
|
||||
|
@ -103,6 +108,7 @@ export class DriveFileEntityService {
|
|||
return parseInt(sum, 10) ?? 0;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async calcDriveUsageOfHost(host: string): Promise<number> {
|
||||
const { sum } = await this.driveFilesRepository
|
||||
.createQueryBuilder('file')
|
||||
|
@ -114,6 +120,7 @@ export class DriveFileEntityService {
|
|||
return parseInt(sum, 10) ?? 0;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async calcDriveUsageOfLocal(): Promise<number> {
|
||||
const { sum } = await this.driveFilesRepository
|
||||
.createQueryBuilder('file')
|
||||
|
@ -125,6 +132,7 @@ export class DriveFileEntityService {
|
|||
return parseInt(sum, 10) ?? 0;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async calcDriveUsageOfRemote(): Promise<number> {
|
||||
const { sum } = await this.driveFilesRepository
|
||||
.createQueryBuilder('file')
|
||||
|
@ -136,6 +144,7 @@ export class DriveFileEntityService {
|
|||
return parseInt(sum, 10) ?? 0;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async pack(
|
||||
src: DriveFile['id'] | DriveFile,
|
||||
options?: PackOptions,
|
||||
|
@ -169,6 +178,7 @@ export class DriveFileEntityService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async packNullable(
|
||||
src: DriveFile['id'] | DriveFile,
|
||||
options?: PackOptions,
|
||||
|
@ -203,6 +213,7 @@ export class DriveFileEntityService {
|
|||
});
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async packMany(
|
||||
files: (DriveFile['id'] | DriveFile)[],
|
||||
options?: PackOptions,
|
||||
|
|
|
@ -7,6 +7,7 @@ import type { } from '@/models/entities/Blocking.js';
|
|||
import type { User } from '@/models/entities/User.js';
|
||||
import type { DriveFolder } from '@/models/entities/DriveFolder.js';
|
||||
import { UserEntityService } from './UserEntityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class DriveFolderEntityService {
|
||||
|
@ -19,6 +20,7 @@ export class DriveFolderEntityService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async pack(
|
||||
src: DriveFolder['id'] | DriveFolder,
|
||||
options?: {
|
||||
|
|
|
@ -7,6 +7,7 @@ import type { } from '@/models/entities/Blocking.js';
|
|||
import type { User } from '@/models/entities/User.js';
|
||||
import type { Emoji } from '@/models/entities/Emoji.js';
|
||||
import { UserEntityService } from './UserEntityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class EmojiEntityService {
|
||||
|
@ -18,6 +19,7 @@ export class EmojiEntityService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async pack(
|
||||
src: Emoji['id'] | Emoji,
|
||||
): Promise<Packed<'Emoji'>> {
|
||||
|
@ -34,6 +36,7 @@ export class EmojiEntityService {
|
|||
};
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public packMany(
|
||||
emojis: any[],
|
||||
) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import type { } from '@/models/entities/Blocking.js';
|
|||
import type { User } from '@/models/entities/User.js';
|
||||
import type { FollowRequest } from '@/models/entities/FollowRequest.js';
|
||||
import { UserEntityService } from './UserEntityService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
@Injectable()
|
||||
export class FollowRequestEntityService {
|
||||
|
@ -18,6 +19,7 @@ export class FollowRequestEntityService {
|
|||
) {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async pack(
|
||||
src: FollowRequest['id'] | FollowRequest,
|
||||
me?: { id: User['id'] } | null | undefined,
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue