sharkey/packages/backend/src/server/api/endpoints/server-info.ts
Shun Sakai c2370a1be6
chore: 著作権とライセンスについての情報を各ファイルに追加する (#11348)
* chore: Add the SPDX information to each file

Add copyright and licensing information as defined in version 3.0 of
the REUSE Specification.

* tweak format

---------

Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2023-07-27 14:31:52 +09:00

68 lines
1.3 KiB
TypeScript

/*
* SPDX-FileCopyrightText: syuilo and other misskey contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
import * as os from 'node:os';
import si from 'systeminformation';
import { Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { MetaService } from '@/core/MetaService.js';
export const meta = {
requireCredential: false,
allowGet: true,
cacheSec: 60 * 1,
tags: ['meta'],
} as const;
export const paramDef = {
type: 'object',
properties: {},
required: [],
} as const;
// eslint-disable-next-line import/no-default-export
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
constructor(
private metaService: MetaService,
) {
super(meta, paramDef, async () => {
if (!(await this.metaService.fetch()).enableServerMachineStats) return {
machine: '?',
cpu: {
model: '?',
cores: 0,
},
mem: {
total: 0,
},
fs: {
total: 0,
used: 0,
},
};
const memStats = await si.mem();
const fsStats = await si.fsSize();
return {
machine: os.hostname(),
cpu: {
model: os.cpus()[0].model,
cores: os.cpus().length,
},
mem: {
total: memStats.total,
},
fs: {
total: fsStats[0].size,
used: fsStats[0].used,
},
};
});
}
}