refactor: introduce bindThis decorator to bind this automaticaly

This commit is contained in:
syuilo
2022-12-04 15:03:09 +09:00
parent e73581f715
commit bbb49457f9
199 changed files with 969 additions and 96 deletions

View File

@ -18,6 +18,7 @@ import type { Note } from '@/models/entities/Note.js';
import { QueryService } from '@/core/QueryService.js';
import { UtilityService } from '@/core/UtilityService.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { bindThis } from '@/decorators.js';
import type { FindOptionsWhere } from 'typeorm';
const ACTIVITY_JSON = 'application/activity+json; charset=utf-8';
@ -57,9 +58,10 @@ export class ActivityPubServerService {
private userKeypairStoreService: UserKeypairStoreService,
private queryService: QueryService,
) {
this.createServer = this.createServer.bind(this);
//this.createServer = this.createServer.bind(this);
}
@bindThis
private setResponseType(request: FastifyRequest, reply: FastifyReply): void {
const accept = request.accepts().type([ACTIVITY_JSON, LD_JSON]);
if (accept === LD_JSON) {
@ -73,6 +75,7 @@ export class ActivityPubServerService {
* Pack Create<Note> or Announce Activity
* @param note Note
*/
@bindThis
private async packActivity(note: Note): Promise<any> {
if (note.renoteId && note.text == null && !note.hasPoll && (note.fileIds == null || note.fileIds.length === 0)) {
const renote = await this.notesRepository.findOneByOrFail({ id: note.renoteId });
@ -82,6 +85,7 @@ export class ActivityPubServerService {
return this.apRendererService.renderCreate(await this.apRendererService.renderNote(note, false), note);
}
@bindThis
private inbox(request: FastifyRequest, reply: FastifyReply) {
let signature;
@ -97,6 +101,7 @@ export class ActivityPubServerService {
reply.code(202);
}
@bindThis
private async followers(
request: FastifyRequest<{ Params: { user: string; }; Querystring: { cursor?: string; page?: string; }; }>,
reply: FastifyReply,
@ -184,6 +189,7 @@ export class ActivityPubServerService {
}
}
@bindThis
private async following(
request: FastifyRequest<{ Params: { user: string; }; Querystring: { cursor?: string; page?: string; }; }>,
reply: FastifyReply,
@ -271,6 +277,7 @@ export class ActivityPubServerService {
}
}
@bindThis
private async featured(request: FastifyRequest<{ Params: { user: string; }; }>, reply: FastifyReply) {
const userId = request.params.user;
@ -304,6 +311,7 @@ export class ActivityPubServerService {
return (this.apRendererService.renderActivity(rendered));
}
@bindThis
private async outbox(
request: FastifyRequest<{
Params: { user: string; };
@ -390,6 +398,7 @@ export class ActivityPubServerService {
}
}
@bindThis
private async userInfo(request: FastifyRequest, reply: FastifyReply, user: User | null) {
if (user == null) {
reply.code(404);
@ -401,6 +410,7 @@ export class ActivityPubServerService {
return (this.apRendererService.renderActivity(await this.apRendererService.renderPerson(user as ILocalUser)));
}
@bindThis
public createServer(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) {
fastify.addConstraintStrategy({
name: 'apOrHtml',

View File

@ -19,6 +19,7 @@ import { InternalStorageService } from '@/core/InternalStorageService.js';
import { contentDisposition } from '@/misc/content-disposition.js';
import { FileInfoService } from '@/core/FileInfoService.js';
import { LoggerService } from '@/core/LoggerService.js';
import { bindThis } from '@/decorators.js';
const _filename = fileURLToPath(import.meta.url);
const _dirname = dirname(_filename);
@ -45,9 +46,10 @@ export class FileServerService {
) {
this.logger = this.loggerService.getLogger('server', 'gray', false);
this.createServer = this.createServer.bind(this);
//this.createServer = this.createServer.bind(this);
}
@bindThis
public commonReadableHandlerGenerator(reply: FastifyReply) {
return (err: Error): void => {
this.logger.error(err);
@ -56,6 +58,7 @@ export class FileServerService {
};
}
@bindThis
public createServer(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) {
fastify.addHook('onRequest', (request, reply, done) => {
reply.header('Content-Security-Policy', 'default-src \'none\'; img-src \'self\'; media-src \'self\'; style-src \'unsafe-inline\'');
@ -80,6 +83,7 @@ export class FileServerService {
done();
}
@bindThis
private async sendDriveFile(request: FastifyRequest<{ Params: { key: string; } }>, reply: FastifyReply) {
const key = request.params.key;

View File

@ -14,6 +14,7 @@ import { StatusError } from '@/misc/status-error.js';
import type Logger from '@/logger.js';
import { FileInfoService } from '@/core/FileInfoService.js';
import { LoggerService } from '@/core/LoggerService.js';
import { bindThis } from '@/decorators.js';
@Injectable()
export class MediaProxyServerService {
@ -30,9 +31,10 @@ export class MediaProxyServerService {
) {
this.logger = this.loggerService.getLogger('server', 'gray', false);
this.createServer = this.createServer.bind(this);
//this.createServer = this.createServer.bind(this);
}
@bindThis
public createServer(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) {
fastify.addHook('onRequest', (request, reply, done) => {
reply.header('Content-Security-Policy', 'default-src \'none\'; img-src \'self\'; media-src \'self\'; style-src \'unsafe-inline\'');
@ -47,6 +49,7 @@ export class MediaProxyServerService {
done();
}
@bindThis
private async handler(request: FastifyRequest<{ Params: { url: string; }; Querystring: { url?: string; }; }>, reply: FastifyReply) {
const url = 'url' in request.query ? request.query.url : 'https://' + request.params.url;

View File

@ -8,6 +8,7 @@ import { MetaService } from '@/core/MetaService.js';
import { MAX_NOTE_TEXT_LENGTH } from '@/const.js';
import { Cache } from '@/misc/cache.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { bindThis } from '@/decorators.js';
const nodeinfo2_1path = '/nodeinfo/2.1';
const nodeinfo2_0path = '/nodeinfo/2.0';
@ -27,9 +28,10 @@ export class NodeinfoServerService {
private userEntityService: UserEntityService,
private metaService: MetaService,
) {
this.createServer = this.createServer.bind(this);
//this.createServer = this.createServer.bind(this);
}
@bindThis
public getLinks() {
return [/* (awaiting release) {
rel: 'http://nodeinfo.diaspora.software/ns/schema/2.1',
@ -40,6 +42,7 @@ export class NodeinfoServerService {
}];
}
@bindThis
public createServer(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) {
const nodeinfo2 = async () => {
const now = Date.now();

View File

@ -23,6 +23,7 @@ import { WellKnownServerService } from './WellKnownServerService.js';
import { MediaProxyServerService } from './MediaProxyServerService.js';
import { FileServerService } from './FileServerService.js';
import { ClientServerService } from './web/ClientServerService.js';
import { bindThis } from '@/decorators.js';
@Injectable()
export class ServerService {
@ -53,6 +54,7 @@ export class ServerService {
this.logger = this.loggerService.getLogger('server', 'gray', false);
}
@bindThis
public launch() {
const fastify = Fastify({
trustProxy: true,

View File

@ -10,6 +10,7 @@ import type { User } from '@/models/entities/User.js';
import * as Acct from '@/misc/acct.js';
import { NodeinfoServerService } from './NodeinfoServerService.js';
import type { FindOptionsWhere } from 'typeorm';
import { bindThis } from '@/decorators.js';
@Injectable()
export class WellKnownServerService {
@ -22,9 +23,10 @@ export class WellKnownServerService {
private nodeinfoServerService: NodeinfoServerService,
) {
this.createServer = this.createServer.bind(this);
//this.createServer = this.createServer.bind(this);
}
@bindThis
public createServer(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) {
const XRD = (...x: { element: string, value?: string, attributes?: Record<string, string> }[]) =>
`<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">${x.map(({ element, value, attributes }) =>

View File

@ -12,6 +12,7 @@ import type Logger from '@/logger.js';
import type { UserIpsRepository } from '@/models/index.js';
import { MetaService } from '@/core/MetaService.js';
import { createTemp } from '@/misc/create-temp.js';
import { bindThis } from '@/decorators.js';
import { ApiError } from './error.js';
import { RateLimiterService } from './RateLimiterService.js';
import { ApiLoggerService } from './ApiLoggerService.js';
@ -50,6 +51,7 @@ export class ApiCallService implements OnApplicationShutdown {
}, 1000 * 60 * 60);
}
@bindThis
public handleRequest(
endpoint: IEndpoint & { exec: any },
request: FastifyRequest<{ Body: Record<string, unknown>, Querystring: Record<string, unknown> }>,
@ -90,6 +92,7 @@ export class ApiCallService implements OnApplicationShutdown {
});
}
@bindThis
public async handleMultipartRequest(
endpoint: IEndpoint & { exec: any },
request: FastifyRequest<{ Body: Record<string, unknown>, Querystring: Record<string, unknown> }>,
@ -140,6 +143,7 @@ export class ApiCallService implements OnApplicationShutdown {
});
}
@bindThis
private send(reply: FastifyReply, x?: any, y?: ApiError) {
if (x == null) {
reply.code(204);
@ -160,6 +164,7 @@ export class ApiCallService implements OnApplicationShutdown {
}
}
@bindThis
private async logIp(request: FastifyRequest, user: ILocalUser) {
const meta = await this.metaService.fetch();
if (!meta.enableIpLogging) return;
@ -183,6 +188,7 @@ export class ApiCallService implements OnApplicationShutdown {
}
}
@bindThis
private async call(
ep: IEndpoint & { exec: any },
user: CacheableLocalUser | null | undefined,
@ -315,6 +321,7 @@ export class ApiCallService implements OnApplicationShutdown {
});
}
@bindThis
public onApplicationShutdown(signal?: string | undefined) {
clearInterval(this.userIpHistoriesClearIntervalId);
}

View File

@ -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 ApiLoggerService {

View File

@ -14,6 +14,7 @@ import { SigninApiService } from './SigninApiService.js';
import { GithubServerService } from './integration/GithubServerService.js';
import { DiscordServerService } from './integration/DiscordServerService.js';
import { TwitterServerService } from './integration/TwitterServerService.js';
import { bindThis } from '@/decorators.js';
@Injectable()
export class ApiServerService {
@ -40,9 +41,10 @@ export class ApiServerService {
private discordServerService: DiscordServerService,
private twitterServerService: TwitterServerService,
) {
this.createServer = this.createServer.bind(this);
//this.createServer = this.createServer.bind(this);
}
@bindThis
public createServer(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) {
fastify.register(cors, {
origin: '*',

View File

@ -7,6 +7,7 @@ import { Cache } from '@/misc/cache.js';
import type { App } from '@/models/entities/App.js';
import { UserCacheService } from '@/core/UserCacheService.js';
import isNativeToken from '@/misc/is-native-token.js';
import { bindThis } from '@/decorators.js';
export class AuthenticationError extends Error {
constructor(message: string) {
@ -34,6 +35,7 @@ export class AuthenticateService {
this.appCache = new Cache<App>(Infinity);
}
@bindThis
public async authenticate(token: string | null | undefined): Promise<[CacheableLocalUser | null | undefined, AccessToken | null | undefined]> {
if (token == null) {
return [null, null];

View File

@ -5,6 +5,7 @@ import { IdentifiableError } from '@/misc/identifiable-error.js';
import type { User } from '@/models/entities/User.js';
import type { Note } from '@/models/entities/Note.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { bindThis } from '@/decorators.js';
@Injectable()
export class GetterService {
@ -22,6 +23,7 @@ export class GetterService {
/**
* Get note for API processing
*/
@bindThis
public async getNote(noteId: Note['id']) {
const note = await this.notesRepository.findOneBy({ id: noteId });
@ -35,6 +37,7 @@ export class GetterService {
/**
* Get user for API processing
*/
@bindThis
public async getUser(userId: User['id']) {
const user = await this.usersRepository.findOneBy({ id: userId });
@ -48,6 +51,7 @@ export class GetterService {
/**
* Get remote user for API processing
*/
@bindThis
public async getRemoteUser(userId: User['id']) {
const user = await this.getUser(userId);
@ -61,6 +65,7 @@ export class GetterService {
/**
* Get local user for API processing
*/
@bindThis
public async getLocalUser(userId: User['id']) {
const user = await this.getUser(userId);

View File

@ -5,6 +5,7 @@ import { DI } from '@/di-symbols.js';
import type Logger from '@/logger.js';
import { LoggerService } from '@/core/LoggerService.js';
import type { IEndpointMeta } from './endpoints.js';
import { bindThis } from '@/decorators.js';
@Injectable()
export class RateLimiterService {
@ -19,6 +20,7 @@ export class RateLimiterService {
this.logger = this.loggerService.getLogger('limiter');
}
@bindThis
public limit(limitation: IEndpointMeta['limit'] & { key: NonNullable<string> }, actor: string) {
return new Promise<void>((ok, reject) => {
if (process.env.NODE_ENV === 'test') ok();

View File

@ -13,6 +13,7 @@ import { IdService } from '@/core/IdService.js';
import { TwoFactorAuthenticationService } from '@/core/TwoFactorAuthenticationService.js';
import { RateLimiterService } from './RateLimiterService.js';
import { SigninService } from './SigninService.js';
import { bindThis } from '@/decorators.js';
@Injectable()
export class SigninApiService {
@ -42,6 +43,7 @@ export class SigninApiService {
) {
}
@bindThis
public async signin(
request: FastifyRequest<{
Body: {

View File

@ -7,6 +7,7 @@ import { IdService } from '@/core/IdService.js';
import type { ILocalUser } from '@/models/entities/User.js';
import { GlobalEventService } from '@/core/GlobalEventService.js';
import { SigninEntityService } from '@/core/entities/SigninEntityService.js';
import { bindThis } from '@/decorators.js';
@Injectable()
export class SigninService {
@ -23,6 +24,7 @@ export class SigninService {
) {
}
@bindThis
public signin(request: FastifyRequest, reply: FastifyReply, user: ILocalUser, redirect = false) {
setImmediate(async () => {
// Append signin history

View File

@ -14,6 +14,7 @@ import { EmailService } from '@/core/EmailService.js';
import { ILocalUser } from '@/models/entities/User.js';
import { FastifyReplyError } from '@/misc/fastify-reply-error.js';
import { SigninService } from './SigninService.js';
import { bindThis } from '@/decorators.js';
@Injectable()
export class SignupApiService {
@ -43,6 +44,7 @@ export class SignupApiService {
) {
}
@bindThis
public async signup(
request: FastifyRequest<{
Body: {
@ -165,6 +167,7 @@ export class SignupApiService {
}
}
@bindThis
public async signupPending(request: FastifyRequest<{ Body: { code: string; } }>, reply: FastifyReply) {
const body = request.body;

View File

@ -13,6 +13,7 @@ import MainStreamConnection from './stream/index.js';
import { ChannelsService } from './stream/ChannelsService.js';
import type { ParsedUrlQuery } from 'querystring';
import type * as http from 'node:http';
import { bindThis } from '@/decorators.js';
@Injectable()
export class StreamingApiServerService {
@ -49,6 +50,7 @@ export class StreamingApiServerService {
) {
}
@bindThis
public attachStreamingApi(server: http.Server) {
// Init websocket server
const ws = new websocket.server({

View File

@ -8,6 +8,7 @@ import { UserSuspendService } from '@/core/UserSuspendService.js';
import { UserFollowingService } from '@/core/UserFollowingService.js';
import { DI } from '@/di-symbols.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { bindThis } from '@/decorators.js';
export const meta = {
tags: ['admin'],
@ -79,6 +80,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
});
}
@bindThis
private async unFollowAll(follower: User) {
const followings = await this.followingsRepository.findBy({
followerId: follower.id,
@ -97,6 +99,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
}
}
@bindThis
private async readAllNotify(notifier: User) {
await this.notificationsRepository.update({
notifierId: notifier.id,

View File

@ -15,6 +15,7 @@ import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { UtilityService } from '@/core/UtilityService.js';
import { DI } from '@/di-symbols.js';
import { bindThis } from '@/decorators.js';
import { ApiError } from '../../error.js';
export const meta = {
@ -112,6 +113,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
/***
* URIからUserかNoteを解決する
*/
@bindThis
private async fetchAny(uri: string, me: CacheableLocalUser | null | undefined): Promise<SchemaType<typeof meta['res']> | null> {
// ブロックしてたら中断
const fetchedMeta = await this.metaService.fetch();
@ -144,6 +146,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
);
}
@bindThis
private async mergePack(me: CacheableLocalUser | null | undefined, user: User | null | undefined, note: Note | null | undefined): Promise<SchemaType<typeof meta.res> | null> {
if (user != null) {
return {

View File

@ -14,6 +14,7 @@ import { MetaService } from '@/core/MetaService.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { FastifyReplyError } from '@/misc/fastify-reply-error.js';
import { SigninService } from '../SigninService.js';
import { bindThis } from '@/decorators.js';
@Injectable()
export class DiscordServerService {
@ -36,9 +37,10 @@ export class DiscordServerService {
private metaService: MetaService,
private signinService: SigninService,
) {
this.create = this.create.bind(this);
//this.create = this.create.bind(this);
}
@bindThis
public create(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) {
fastify.get('/disconnect/discord', async (request, reply) => {
if (!this.compareOrigin(request)) {
@ -288,10 +290,12 @@ export class DiscordServerService {
done();
}
@bindThis
private getUserToken(request: FastifyRequest): string | null {
return ((request.headers['cookie'] ?? '').match(/igi=(\w+)/) ?? [null, null])[1];
}
@bindThis
private compareOrigin(request: FastifyRequest): boolean {
function normalizeUrl(url?: string): string {
return url ? url.endsWith('/') ? url.substr(0, url.length - 1) : url : '';

View File

@ -14,6 +14,7 @@ import { MetaService } from '@/core/MetaService.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { FastifyReplyError } from '@/misc/fastify-reply-error.js';
import { SigninService } from '../SigninService.js';
import { bindThis } from '@/decorators.js';
@Injectable()
export class GithubServerService {
@ -36,9 +37,10 @@ export class GithubServerService {
private metaService: MetaService,
private signinService: SigninService,
) {
this.create = this.create.bind(this);
//this.create = this.create.bind(this);
}
@bindThis
public create(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) {
fastify.get('/disconnect/github', async (request, reply) => {
if (!this.compareOrigin(request)) {
@ -260,10 +262,12 @@ export class GithubServerService {
done();
}
@bindThis
private getUserToken(request: FastifyRequest): string | null {
return ((request.headers['cookie'] ?? '').match(/igi=(\w+)/) ?? [null, null])[1];
}
@bindThis
private compareOrigin(request: FastifyRequest): boolean {
function normalizeUrl(url?: string): string {
return url ? url.endsWith('/') ? url.substr(0, url.length - 1) : url : '';

View File

@ -14,6 +14,7 @@ import { MetaService } from '@/core/MetaService.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { FastifyReplyError } from '@/misc/fastify-reply-error.js';
import { SigninService } from '../SigninService.js';
import { bindThis } from '@/decorators.js';
@Injectable()
export class TwitterServerService {
@ -36,9 +37,10 @@ export class TwitterServerService {
private metaService: MetaService,
private signinService: SigninService,
) {
this.create = this.create.bind(this);
//this.create = this.create.bind(this);
}
@bindThis
public create(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) {
fastify.get('/disconnect/twitter', async (request, reply) => {
if (!this.compareOrigin(request)) {
@ -205,10 +207,12 @@ export class TwitterServerService {
done();
}
@bindThis
private getUserToken(request: FastifyRequest): string | null {
return ((request.headers['cookie'] ?? '').match(/igi=(\w+)/) ?? [null, null])[1];
}
@bindThis
private compareOrigin(request: FastifyRequest): boolean {
function normalizeUrl(url?: string): string {
return url ? url.endsWith('/') ? url.substr(0, url.length - 1) : url : '';

View File

@ -15,6 +15,7 @@ import { MessagingChannelService } from './channels/messaging.js';
import { MessagingIndexChannelService } from './channels/messaging-index.js';
import { DriveChannelService } from './channels/drive.js';
import { HashtagChannelService } from './channels/hashtag.js';
import { bindThis } from '@/decorators.js';
@Injectable()
export class ChannelsService {
@ -37,6 +38,7 @@ export class ChannelsService {
) {
}
@bindThis
public getChannelService(name: string) {
switch (name) {
case 'main': return this.mainChannelService;

View File

@ -1,3 +1,4 @@
import { bindThis } from '@/decorators.js';
import type Connection from '.';
/**
@ -43,6 +44,7 @@ export default abstract class Channel {
this.connection = connection;
}
@bindThis
public send(typeOrPayload: any, payload?: any) {
const type = payload === undefined ? typeOrPayload.type : typeOrPayload;
const body = payload === undefined ? typeOrPayload.body : payload;

View File

@ -1,4 +1,5 @@
import { Inject, Injectable } from '@nestjs/common';
import { bindThis } from '@/decorators.js';
import Channel from '../channel.js';
class AdminChannel extends Channel {
@ -6,6 +7,7 @@ class AdminChannel extends Channel {
public static shouldShare = true;
public static requireCredential = true;
@bindThis
public async init(params: any) {
// Subscribe admin stream
this.subscriber.on(`adminStream:${this.user!.id}`, data => {
@ -23,6 +25,7 @@ export class AdminChannelService {
) {
}
@bindThis
public create(id: string, connection: Channel['connection']): AdminChannel {
return new AdminChannel(
id,

View File

@ -2,6 +2,7 @@ import { Inject, Injectable } from '@nestjs/common';
import type { NotesRepository } from '@/models/index.js';
import { isUserRelated } from '@/misc/is-user-related.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { bindThis } from '@/decorators.js';
import Channel from '../channel.js';
import type { StreamMessages } from '../types.js';
@ -18,9 +19,10 @@ class AntennaChannel extends Channel {
connection: Channel['connection'],
) {
super(id, connection);
this.onEvent = this.onEvent.bind(this);
//this.onEvent = this.onEvent.bind(this);
}
@bindThis
public async init(params: any) {
this.antennaId = params.antennaId as string;
@ -28,6 +30,7 @@ class AntennaChannel extends Channel {
this.subscriber.on(`antennaStream:${this.antennaId}`, this.onEvent);
}
@bindThis
private async onEvent(data: StreamMessages['antenna']['payload']) {
if (data.type === 'note') {
const note = await this.noteEntityService.pack(data.body.id, this.user, { detail: true });
@ -45,6 +48,7 @@ class AntennaChannel extends Channel {
}
}
@bindThis
public dispose() {
// Unsubscribe events
this.subscriber.off(`antennaStream:${this.antennaId}`, this.onEvent);
@ -61,6 +65,7 @@ export class AntennaChannelService {
) {
}
@bindThis
public create(id: string, connection: Channel['connection']): AntennaChannel {
return new AntennaChannel(
this.noteEntityService,

View File

@ -5,6 +5,7 @@ import type { User } from '@/models/entities/User.js';
import type { Packed } from '@/misc/schema.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { bindThis } from '@/decorators.js';
import Channel from '../channel.js';
import type { StreamMessages } from '../types.js';
@ -24,10 +25,11 @@ class ChannelChannel extends Channel {
connection: Channel['connection'],
) {
super(id, connection);
this.onNote = this.onNote.bind(this);
this.emitTypers = this.emitTypers.bind(this);
//this.onNote = this.onNote.bind(this);
//this.emitTypers = this.emitTypers.bind(this);
}
@bindThis
public async init(params: any) {
this.channelId = params.channelId as string;
@ -37,6 +39,7 @@ class ChannelChannel extends Channel {
this.emitTypersIntervalId = setInterval(this.emitTypers, 5000);
}
@bindThis
private async onNote(note: Packed<'Note'>) {
if (note.channelId !== this.channelId) return;
@ -63,6 +66,7 @@ class ChannelChannel extends Channel {
this.send('note', note);
}
@bindThis
private onEvent(data: StreamMessages['channel']['payload']) {
if (data.type === 'typing') {
const id = data.body;
@ -74,6 +78,7 @@ class ChannelChannel extends Channel {
}
}
@bindThis
private async emitTypers() {
const now = new Date();
@ -90,6 +95,7 @@ class ChannelChannel extends Channel {
});
}
@bindThis
public dispose() {
// Unsubscribe events
this.subscriber.off('notesStream', this.onNote);
@ -110,6 +116,7 @@ export class ChannelChannelService {
) {
}
@bindThis
public create(id: string, connection: Channel['connection']): ChannelChannel {
return new ChannelChannel(
this.noteEntityService,

View File

@ -1,4 +1,5 @@
import { Inject, Injectable } from '@nestjs/common';
import { bindThis } from '@/decorators.js';
import Channel from '../channel.js';
class DriveChannel extends Channel {
@ -6,6 +7,7 @@ class DriveChannel extends Channel {
public static shouldShare = true;
public static requireCredential = true;
@bindThis
public async init(params: any) {
// Subscribe drive stream
this.subscriber.on(`driveStream:${this.user!.id}`, data => {
@ -23,6 +25,7 @@ export class DriveChannelService {
) {
}
@bindThis
public create(id: string, connection: Channel['connection']): DriveChannel {
return new DriveChannel(
id,

View File

@ -6,6 +6,7 @@ import { isUserRelated } from '@/misc/is-user-related.js';
import type { Packed } from '@/misc/schema.js';
import { MetaService } from '@/core/MetaService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { bindThis } from '@/decorators.js';
import Channel from '../channel.js';
class GlobalTimelineChannel extends Channel {
@ -21,9 +22,10 @@ class GlobalTimelineChannel extends Channel {
connection: Channel['connection'],
) {
super(id, connection);
this.onNote = this.onNote.bind(this);
//this.onNote = this.onNote.bind(this);
}
@bindThis
public async init(params: any) {
const meta = await this.metaService.fetch();
if (meta.disableGlobalTimeline) {
@ -34,6 +36,7 @@ class GlobalTimelineChannel extends Channel {
this.subscriber.on('notesStream', this.onNote);
}
@bindThis
private async onNote(note: Packed<'Note'>) {
if (note.visibility !== 'public') return;
if (note.channelId != null) return;
@ -78,6 +81,7 @@ class GlobalTimelineChannel extends Channel {
this.send('note', note);
}
@bindThis
public dispose() {
// Unsubscribe events
this.subscriber.off('notesStream', this.onNote);
@ -95,6 +99,7 @@ export class GlobalTimelineChannelService {
) {
}
@bindThis
public create(id: string, connection: Channel['connection']): GlobalTimelineChannel {
return new GlobalTimelineChannel(
this.metaService,

View File

@ -4,6 +4,7 @@ import { normalizeForSearch } from '@/misc/normalize-for-search.js';
import { isUserRelated } from '@/misc/is-user-related.js';
import type { Packed } from '@/misc/schema.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { bindThis } from '@/decorators.js';
import Channel from '../channel.js';
class HashtagChannel extends Channel {
@ -19,9 +20,10 @@ class HashtagChannel extends Channel {
connection: Channel['connection'],
) {
super(id, connection);
this.onNote = this.onNote.bind(this);
//this.onNote = this.onNote.bind(this);
}
@bindThis
public async init(params: any) {
this.q = params.q;
@ -31,6 +33,7 @@ class HashtagChannel extends Channel {
this.subscriber.on('notesStream', this.onNote);
}
@bindThis
private async onNote(note: Packed<'Note'>) {
const noteTags = note.tags ? note.tags.map((t: string) => t.toLowerCase()) : [];
const matched = this.q.some(tags => tags.every(tag => noteTags.includes(normalizeForSearch(tag))));
@ -53,6 +56,7 @@ class HashtagChannel extends Channel {
this.send('note', note);
}
@bindThis
public dispose() {
// Unsubscribe events
this.subscriber.off('notesStream', this.onNote);
@ -69,6 +73,7 @@ export class HashtagChannelService {
) {
}
@bindThis
public create(id: string, connection: Channel['connection']): HashtagChannel {
return new HashtagChannel(
this.noteEntityService,

View File

@ -5,6 +5,7 @@ import { isUserRelated } from '@/misc/is-user-related.js';
import { isInstanceMuted } from '@/misc/is-instance-muted.js';
import type { Packed } from '@/misc/schema.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { bindThis } from '@/decorators.js';
import Channel from '../channel.js';
class HomeTimelineChannel extends Channel {
@ -19,14 +20,16 @@ class HomeTimelineChannel extends Channel {
connection: Channel['connection'],
) {
super(id, connection);
this.onNote = this.onNote.bind(this);
//this.onNote = this.onNote.bind(this);
}
@bindThis
public async init(params: any) {
// Subscribe events
this.subscriber.on('notesStream', this.onNote);
}
@bindThis
private async onNote(note: Packed<'Note'>) {
if (note.channelId) {
if (!this.followingChannels.has(note.channelId)) return;
@ -85,6 +88,7 @@ class HomeTimelineChannel extends Channel {
this.send('note', note);
}
@bindThis
public dispose() {
// Unsubscribe events
this.subscriber.off('notesStream', this.onNote);
@ -101,6 +105,7 @@ export class HomeTimelineChannelService {
) {
}
@bindThis
public create(id: string, connection: Channel['connection']): HomeTimelineChannel {
return new HomeTimelineChannel(
this.noteEntityService,

View File

@ -7,6 +7,7 @@ import type { Packed } from '@/misc/schema.js';
import { DI } from '@/di-symbols.js';
import { MetaService } from '@/core/MetaService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { bindThis } from '@/decorators.js';
import Channel from '../channel.js';
class HybridTimelineChannel extends Channel {
@ -22,9 +23,10 @@ class HybridTimelineChannel extends Channel {
connection: Channel['connection'],
) {
super(id, connection);
this.onNote = this.onNote.bind(this);
//this.onNote = this.onNote.bind(this);
}
@bindThis
public async init(params: any): Promise<void> {
const meta = await this.metaService.fetch();
if (meta.disableLocalTimeline && !this.user!.isAdmin && !this.user!.isModerator) return;
@ -33,6 +35,7 @@ class HybridTimelineChannel extends Channel {
this.subscriber.on('notesStream', this.onNote);
}
@bindThis
private async onNote(note: Packed<'Note'>) {
// チャンネルの投稿ではなく、自分自身の投稿 または
// チャンネルの投稿ではなく、その投稿のユーザーをフォローしている または
@ -95,6 +98,7 @@ class HybridTimelineChannel extends Channel {
this.send('note', note);
}
@bindThis
public dispose(): void {
// Unsubscribe events
this.subscriber.off('notesStream', this.onNote);
@ -112,6 +116,7 @@ export class HybridTimelineChannelService {
) {
}
@bindThis
public create(id: string, connection: Channel['connection']): HybridTimelineChannel {
return new HybridTimelineChannel(
this.metaService,

View File

@ -5,6 +5,7 @@ import { isUserRelated } from '@/misc/is-user-related.js';
import type { Packed } from '@/misc/schema.js';
import { MetaService } from '@/core/MetaService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { bindThis } from '@/decorators.js';
import Channel from '../channel.js';
class LocalTimelineChannel extends Channel {
@ -20,9 +21,10 @@ class LocalTimelineChannel extends Channel {
connection: Channel['connection'],
) {
super(id, connection);
this.onNote = this.onNote.bind(this);
//this.onNote = this.onNote.bind(this);
}
@bindThis
public async init(params: any) {
const meta = await this.metaService.fetch();
if (meta.disableLocalTimeline) {
@ -33,6 +35,7 @@ class LocalTimelineChannel extends Channel {
this.subscriber.on('notesStream', this.onNote);
}
@bindThis
private async onNote(note: Packed<'Note'>) {
if (note.user.host !== null) return;
if (note.visibility !== 'public') return;
@ -75,6 +78,7 @@ class LocalTimelineChannel extends Channel {
this.send('note', note);
}
@bindThis
public dispose() {
// Unsubscribe events
this.subscriber.off('notesStream', this.onNote);
@ -92,6 +96,7 @@ export class LocalTimelineChannelService {
) {
}
@bindThis
public create(id: string, connection: Channel['connection']): LocalTimelineChannel {
return new LocalTimelineChannel(
this.metaService,

View File

@ -2,6 +2,7 @@ import { Inject, Injectable } from '@nestjs/common';
import type { NotesRepository } from '@/models/index.js';
import { isInstanceMuted, isUserFromMutedInstance } from '@/misc/is-instance-muted.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { bindThis } from '@/decorators.js';
import Channel from '../channel.js';
class MainChannel extends Channel {
@ -18,6 +19,7 @@ class MainChannel extends Channel {
super(id, connection);
}
@bindThis
public async init(params: any) {
// Subscribe main stream channel
this.subscriber.on(`mainStream:${this.user!.id}`, async data => {
@ -66,6 +68,7 @@ export class MainChannelService {
) {
}
@bindThis
public create(id: string, connection: Channel['connection']): MainChannel {
return new MainChannel(
this.noteEntityService,

View File

@ -1,4 +1,5 @@
import { Inject, Injectable } from '@nestjs/common';
import { bindThis } from '@/decorators.js';
import Channel from '../channel.js';
class MessagingIndexChannel extends Channel {
@ -6,6 +7,7 @@ class MessagingIndexChannel extends Channel {
public static shouldShare = true;
public static requireCredential = true;
@bindThis
public async init(params: any) {
// Subscribe messaging index stream
this.subscriber.on(`messagingIndexStream:${this.user!.id}`, data => {
@ -23,6 +25,7 @@ export class MessagingIndexChannelService {
) {
}
@bindThis
public create(id: string, connection: Channel['connection']): MessagingIndexChannel {
return new MessagingIndexChannel(
id,

View File

@ -5,6 +5,7 @@ import type { UserGroup } from '@/models/entities/UserGroup.js';
import { MessagingService } from '@/core/MessagingService.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { DI } from '@/di-symbols.js';
import { bindThis } from '@/decorators.js';
import Channel from '../channel.js';
import type { StreamMessages } from '../types.js';
@ -31,11 +32,12 @@ class MessagingChannel extends Channel {
connection: Channel['connection'],
) {
super(id, connection);
this.onEvent = this.onEvent.bind(this);
this.onMessage = this.onMessage.bind(this);
this.emitTypers = this.emitTypers.bind(this);
//this.onEvent = this.onEvent.bind(this);
//this.onMessage = this.onMessage.bind(this);
//this.emitTypers = this.emitTypers.bind(this);
}
@bindThis
public async init(params: any) {
this.otherpartyId = params.otherparty;
this.otherparty = this.otherpartyId ? await this.usersRepository.findOneByOrFail({ id: this.otherpartyId }) : null;
@ -63,6 +65,7 @@ class MessagingChannel extends Channel {
this.subscriber.on(this.subCh, this.onEvent);
}
@bindThis
private onEvent(data: StreamMessages['messaging']['payload'] | StreamMessages['groupMessaging']['payload']) {
if (data.type === 'typing') {
const id = data.body;
@ -76,6 +79,7 @@ class MessagingChannel extends Channel {
}
}
@bindThis
public onMessage(type: string, body: any) {
switch (type) {
case 'read':
@ -95,6 +99,7 @@ class MessagingChannel extends Channel {
}
}
@bindThis
private async emitTypers() {
const now = new Date();
@ -111,6 +116,7 @@ class MessagingChannel extends Channel {
});
}
@bindThis
public dispose() {
this.subscriber.off(this.subCh, this.onEvent);
@ -138,6 +144,7 @@ export class MessagingChannelService {
) {
}
@bindThis
public create(id: string, connection: Channel['connection']): MessagingChannel {
return new MessagingChannel(
this.usersRepository,

View File

@ -1,5 +1,6 @@
import Xev from 'xev';
import { Inject, Injectable } from '@nestjs/common';
import { bindThis } from '@/decorators.js';
import Channel from '../channel.js';
const ev = new Xev();
@ -11,18 +12,21 @@ class QueueStatsChannel extends Channel {
constructor(id: string, connection: Channel['connection']) {
super(id, connection);
this.onStats = this.onStats.bind(this);
this.onMessage = this.onMessage.bind(this);
//this.onStats = this.onStats.bind(this);
//this.onMessage = this.onMessage.bind(this);
}
@bindThis
public async init(params: any) {
ev.addListener('queueStats', this.onStats);
}
@bindThis
private onStats(stats: any) {
this.send('stats', stats);
}
@bindThis
public onMessage(type: string, body: any) {
switch (type) {
case 'requestLog':
@ -37,6 +41,7 @@ class QueueStatsChannel extends Channel {
}
}
@bindThis
public dispose() {
ev.removeListener('queueStats', this.onStats);
}
@ -51,6 +56,7 @@ export class QueueStatsChannelService {
) {
}
@bindThis
public create(id: string, connection: Channel['connection']): QueueStatsChannel {
return new QueueStatsChannel(
id,

View File

@ -1,5 +1,6 @@
import Xev from 'xev';
import { Inject, Injectable } from '@nestjs/common';
import { bindThis } from '@/decorators.js';
import Channel from '../channel.js';
const ev = new Xev();
@ -11,18 +12,21 @@ class ServerStatsChannel extends Channel {
constructor(id: string, connection: Channel['connection']) {
super(id, connection);
this.onStats = this.onStats.bind(this);
this.onMessage = this.onMessage.bind(this);
//this.onStats = this.onStats.bind(this);
//this.onMessage = this.onMessage.bind(this);
}
@bindThis
public async init(params: any) {
ev.addListener('serverStats', this.onStats);
}
@bindThis
private onStats(stats: any) {
this.send('stats', stats);
}
@bindThis
public onMessage(type: string, body: any) {
switch (type) {
case 'requestLog':
@ -37,6 +41,7 @@ class ServerStatsChannel extends Channel {
}
}
@bindThis
public dispose() {
ev.removeListener('serverStats', this.onStats);
}
@ -51,6 +56,7 @@ export class ServerStatsChannelService {
) {
}
@bindThis
public create(id: string, connection: Channel['connection']): ServerStatsChannel {
return new ServerStatsChannel(
id,

View File

@ -1,11 +1,11 @@
import { Inject, Injectable } from '@nestjs/common';
import type { UserListJoiningsRepository, UserListsRepository } from '@/models/index.js';
import type { NotesRepository } from '@/models/index.js';
import type { UserListJoiningsRepository, UserListsRepository, NotesRepository } from '@/models/index.js';
import type { User } from '@/models/entities/User.js';
import { isUserRelated } from '@/misc/is-user-related.js';
import type { Packed } from '@/misc/schema.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { DI } from '@/di-symbols.js';
import { bindThis } from '@/decorators.js';
import Channel from '../channel.js';
class UserListChannel extends Channel {
@ -25,10 +25,11 @@ class UserListChannel extends Channel {
connection: Channel['connection'],
) {
super(id, connection);
this.updateListUsers = this.updateListUsers.bind(this);
this.onNote = this.onNote.bind(this);
//this.updateListUsers = this.updateListUsers.bind(this);
//this.onNote = this.onNote.bind(this);
}
@bindThis
public async init(params: any) {
this.listId = params.listId as string;
@ -48,6 +49,7 @@ class UserListChannel extends Channel {
this.listUsersClock = setInterval(this.updateListUsers, 5000);
}
@bindThis
private async updateListUsers() {
const users = await this.userListJoiningsRepository.find({
where: {
@ -59,6 +61,7 @@ class UserListChannel extends Channel {
this.listUsers = users.map(x => x.userId);
}
@bindThis
private async onNote(note: Packed<'Note'>) {
if (!this.listUsers.includes(note.userId)) return;
@ -93,6 +96,7 @@ class UserListChannel extends Channel {
this.send('note', note);
}
@bindThis
public dispose() {
// Unsubscribe events
this.subscriber.off(`userListStream:${this.listId}`, this.send);
@ -118,6 +122,7 @@ export class UserListChannelService {
) {
}
@bindThis
public create(id: string, connection: Channel['connection']): UserListChannel {
return new UserListChannel(
this.userListsRepository,

View File

@ -8,6 +8,7 @@ import type { Packed } from '@/misc/schema.js';
import type { GlobalEventService } from '@/core/GlobalEventService.js';
import type { NoteReadService } from '@/core/NoteReadService.js';
import type { NotificationService } from '@/core/NotificationService.js';
import { bindThis } from '@/decorators.js';
import type { ChannelsService } from './ChannelsService.js';
import type * as websocket from 'websocket';
import type { EventEmitter } from 'events';
@ -52,10 +53,10 @@ export default class Connection {
if (user) this.user = user;
if (token) this.token = token;
this.onWsConnectionMessage = this.onWsConnectionMessage.bind(this);
this.onUserEvent = this.onUserEvent.bind(this);
this.onNoteStreamMessage = this.onNoteStreamMessage.bind(this);
this.onBroadcastMessage = this.onBroadcastMessage.bind(this);
//this.onWsConnectionMessage = this.onWsConnectionMessage.bind(this);
//this.onUserEvent = this.onUserEvent.bind(this);
//this.onNoteStreamMessage = this.onNoteStreamMessage.bind(this);
//this.onBroadcastMessage = this.onBroadcastMessage.bind(this);
this.wsConnection.on('message', this.onWsConnectionMessage);
@ -74,6 +75,7 @@ export default class Connection {
}
}
@bindThis
private onUserEvent(data: StreamMessages['user']['payload']) { // { type, body }と展開するとそれぞれ型が分離してしまう
switch (data.type) {
case 'follow':
@ -119,6 +121,7 @@ export default class Connection {
/**
* クライアントからメッセージ受信時
*/
@bindThis
private async onWsConnectionMessage(data: websocket.Message) {
if (data.type !== 'utf8') return;
if (data.utf8Data == null) return;
@ -153,10 +156,12 @@ export default class Connection {
}
}
@bindThis
private onBroadcastMessage(data: StreamMessages['broadcast']['payload']) {
this.sendMessageToWs(data.type, data.body);
}
@bindThis
public cacheNote(note: Packed<'Note'>) {
const add = (note: Packed<'Note'>) => {
const existIndex = this.cachedNotes.findIndex(n => n.id === note.id);
@ -176,6 +181,7 @@ export default class Connection {
if (note.renote) add(note.renote);
}
@bindThis
private readNote(body: any) {
const id = body.id;
@ -190,6 +196,7 @@ export default class Connection {
}
}
@bindThis
private onReadNotification(payload: any) {
if (!payload.id) return;
this.notificationService.readNotification(this.user!.id, [payload.id]);
@ -198,6 +205,7 @@ export default class Connection {
/**
* 投稿購読要求時
*/
@bindThis
private onSubscribeNote(payload: any) {
if (!payload.id) return;
@ -215,6 +223,7 @@ export default class Connection {
/**
* 投稿購読解除要求時
*/
@bindThis
private onUnsubscribeNote(payload: any) {
if (!payload.id) return;
@ -225,6 +234,7 @@ export default class Connection {
}
}
@bindThis
private async onNoteStreamMessage(data: StreamMessages['note']['payload']) {
this.sendMessageToWs('noteUpdated', {
id: data.body.id,
@ -236,6 +246,7 @@ export default class Connection {
/**
* チャンネル接続要求時
*/
@bindThis
private onChannelConnectRequested(payload: any) {
const { channel, id, params, pong } = payload;
this.connectChannel(id, params, channel, pong);
@ -244,6 +255,7 @@ export default class Connection {
/**
* チャンネル切断要求時
*/
@bindThis
private onChannelDisconnectRequested(payload: any) {
const { id } = payload;
this.disconnectChannel(id);
@ -252,6 +264,7 @@ export default class Connection {
/**
* クライアントにメッセージ送信
*/
@bindThis
public sendMessageToWs(type: string, payload: any) {
this.wsConnection.send(JSON.stringify({
type: type,
@ -262,6 +275,7 @@ export default class Connection {
/**
* チャンネルに接続
*/
@bindThis
public connectChannel(id: string, params: any, channel: string, pong = false) {
const channelService = this.channelsService.getChannelService(channel);
@ -289,6 +303,7 @@ export default class Connection {
* チャンネルから切断
* @param id チャンネルコネクションID
*/
@bindThis
public disconnectChannel(id: string) {
const channel = this.channels.find(c => c.id === id);
@ -302,6 +317,7 @@ export default class Connection {
* チャンネルへメッセージ送信要求時
* @param data メッセージ
*/
@bindThis
private onChannelMessageRequested(data: any) {
const channel = this.channels.find(c => c.id === data.id);
if (channel != null && channel.onMessage != null) {
@ -309,12 +325,14 @@ export default class Connection {
}
}
@bindThis
private typingOnChannel(channel: ChannelModel['id']) {
if (this.user) {
this.globalEventService.publishChannelStream(channel, 'typing', this.user.id);
}
}
@bindThis
private typingOnMessaging(param: { partner?: User['id']; group?: UserGroup['id']; }) {
if (this.user) {
if (param.partner) {
@ -325,6 +343,7 @@ export default class Connection {
}
}
@bindThis
private async updateFollowing() {
const followings = await this.followingsRepository.find({
where: {
@ -336,6 +355,7 @@ export default class Connection {
this.following = new Set<string>(followings.map(x => x.followeeId));
}
@bindThis
private async updateMuting() {
const mutings = await this.mutingsRepository.find({
where: {
@ -347,6 +367,7 @@ export default class Connection {
this.muting = new Set<string>(mutings.map(x => x.muteeId));
}
@bindThis
private async updateBlocking() { // ここでいうBlockingは被Blockingの意
const blockings = await this.blockingsRepository.find({
where: {
@ -358,6 +379,7 @@ export default class Connection {
this.blocking = new Set<string>(blockings.map(x => x.blockerId));
}
@bindThis
private async updateFollowingChannels() {
const followings = await this.channelFollowingsRepository.find({
where: {
@ -369,6 +391,7 @@ export default class Connection {
this.followingChannels = new Set<string>(followings.map(x => x.followeeId));
}
@bindThis
private async updateUserProfile() {
this.userProfile = await this.userProfilesRepository.findOneBy({
userId: this.user!.id,
@ -378,6 +401,7 @@ export default class Connection {
/**
* ストリームが切れたとき
*/
@bindThis
public dispose() {
for (const c of this.channels.filter(c => c.dispose)) {
if (c.dispose) c.dispose();

View File

@ -23,6 +23,7 @@ import { ClipEntityService } from '@/core/entities/ClipEntityService.js';
import { ChannelEntityService } from '@/core/entities/ChannelEntityService.js';
import type { ChannelsRepository, ClipsRepository, GalleryPostsRepository, NotesRepository, PagesRepository, UserProfilesRepository, UsersRepository } from '@/models/index.js';
import { deepClone } from '@/misc/clone.js';
import { bindThis } from '@/decorators.js';
import manifest from './manifest.json' assert { type: 'json' };
import { FeedService } from './FeedService.js';
import { UrlPreviewService } from './UrlPreviewService.js';
@ -80,9 +81,10 @@ export class ClientServerService {
@Inject('queue:objectStorage') public objectStorageQueue: ObjectStorageQueue,
@Inject('queue:webhookDeliver') public webhookDeliverQueue: WebhookDeliverQueue,
) {
this.createServer = this.createServer.bind(this);
//this.createServer = this.createServer.bind(this);
}
@bindThis
private async manifestHandler(reply: FastifyReply) {
const res = deepClone(manifest);
@ -96,6 +98,7 @@ export class ClientServerService {
return (res);
}
@bindThis
public createServer(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) {
/* TODO
//#region Bull Dashboard

View File

@ -7,6 +7,7 @@ import type { Config } from '@/config.js';
import type { User } from '@/models/entities/User.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js';
import { bindThis } from '@/decorators.js';
@Injectable()
export class FeedService {
@ -31,6 +32,7 @@ export class FeedService {
) {
}
@bindThis
public async packFeed(user: User) {
const author = {
link: `${this.config.url}/@${user.username}`,

View File

@ -9,6 +9,7 @@ import { HttpRequestService } from '@/core/HttpRequestService.js';
import type Logger from '@/logger.js';
import { query } from '@/misc/prelude/url.js';
import { LoggerService } from '@/core/LoggerService.js';
import { bindThis } from '@/decorators.js';
@Injectable()
export class UrlPreviewService {
@ -28,6 +29,7 @@ export class UrlPreviewService {
this.logger = this.loggerService.getLogger('url-preview');
}
@bindThis
private wrap(url?: string): string | null {
return url != null
? url.match(/^https?:\/\//)
@ -39,6 +41,7 @@ export class UrlPreviewService {
: null;
}
@bindThis
public async handle(
request: FastifyRequest<{ Querystring: { url: string; lang: string; } }>,
reply: FastifyReply,