2023-07-27 14:31:52 +09:00
|
|
|
/*
|
2024-02-13 15:50:11 +00:00
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
2023-07-27 14:31:52 +09:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
*/
|
|
|
|
|
|
2022-04-17 14:42:13 +09:00
|
|
|
import Xev from 'xev';
|
2023-02-16 15:09:41 +01:00
|
|
|
import { Injectable } from '@nestjs/common';
|
2022-12-04 15:03:09 +09:00
|
|
|
import { bindThis } from '@/decorators.js';
|
2023-12-27 15:08:59 +09:00
|
|
|
import Channel, { type MiChannelService } from '../channel.js';
|
2018-10-07 11:06:17 +09:00
|
|
|
|
2022-04-17 14:42:13 +09:00
|
|
|
const ev = new Xev();
|
2018-10-07 11:06:17 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
class ServerStatsChannel extends Channel {
|
2018-10-11 23:01:57 +09:00
|
|
|
public readonly chName = 'serverStats';
|
2018-10-11 23:07:20 +09:00
|
|
|
public static shouldShare = true;
|
2023-12-27 15:08:59 +09:00
|
|
|
public static requireCredential = false as const;
|
2018-10-11 23:01:57 +09:00
|
|
|
|
2022-02-27 11:07:39 +09:00
|
|
|
constructor(id: string, connection: Channel['connection']) {
|
|
|
|
|
super(id, connection);
|
2022-12-04 15:03:09 +09:00
|
|
|
//this.onStats = this.onStats.bind(this);
|
|
|
|
|
//this.onMessage = this.onMessage.bind(this);
|
2022-02-27 11:07:39 +09:00
|
|
|
}
|
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2018-10-07 11:06:17 +09:00
|
|
|
public async init(params: any) {
|
|
|
|
|
ev.addListener('serverStats', this.onStats);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2018-10-07 11:06:17 +09:00
|
|
|
private onStats(stats: any) {
|
|
|
|
|
this.send('stats', stats);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2018-10-07 11:06:17 +09:00
|
|
|
public onMessage(type: string, body: any) {
|
|
|
|
|
switch (type) {
|
|
|
|
|
case 'requestLog':
|
|
|
|
|
ev.once(`serverStatsLog:${body.id}`, statsLog => {
|
|
|
|
|
this.send('statsLog', statsLog);
|
|
|
|
|
});
|
|
|
|
|
ev.emit('requestServerStatsLog', {
|
|
|
|
|
id: body.id,
|
2021-12-09 23:58:30 +09:00
|
|
|
length: body.length,
|
2018-10-07 11:06:17 +09:00
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2018-10-07 11:06:17 +09:00
|
|
|
public dispose() {
|
|
|
|
|
ev.removeListener('serverStats', this.onStats);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-18 03:27:08 +09:00
|
|
|
|
|
|
|
|
@Injectable()
|
2023-12-27 15:08:59 +09:00
|
|
|
export class ServerStatsChannelService implements MiChannelService<false> {
|
2022-09-18 03:27:08 +09:00
|
|
|
public readonly shouldShare = ServerStatsChannel.shouldShare;
|
|
|
|
|
public readonly requireCredential = ServerStatsChannel.requireCredential;
|
2023-12-27 15:08:59 +09:00
|
|
|
public readonly kind = ServerStatsChannel.kind;
|
2022-09-18 03:27:08 +09:00
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2022-09-18 03:27:08 +09:00
|
|
|
public create(id: string, connection: Channel['connection']): ServerStatsChannel {
|
|
|
|
|
return new ServerStatsChannel(
|
|
|
|
|
id,
|
|
|
|
|
connection,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|