mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-27 11:53:09 +02:00
wip
This commit is contained in:
parent
78558eb666
commit
07bbadbbdc
5 changed files with 117 additions and 91 deletions
|
@ -6,98 +6,10 @@ import * as Redis from 'ioredis';
|
|||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
requireModerator: true,
|
||||
|
||||
tags: ['admin', 'meta'],
|
||||
|
||||
res: {
|
||||
type: 'object',
|
||||
optional: false, nullable: false,
|
||||
properties: {
|
||||
machine: {
|
||||
type: 'string',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
os: {
|
||||
type: 'string',
|
||||
optional: false, nullable: false,
|
||||
example: 'linux',
|
||||
},
|
||||
node: {
|
||||
type: 'string',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
psql: {
|
||||
type: 'string',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
cpu: {
|
||||
type: 'object',
|
||||
optional: false, nullable: false,
|
||||
properties: {
|
||||
model: {
|
||||
type: 'string',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
cores: {
|
||||
type: 'number',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
mem: {
|
||||
type: 'object',
|
||||
optional: false, nullable: false,
|
||||
properties: {
|
||||
total: {
|
||||
type: 'number',
|
||||
optional: false, nullable: false,
|
||||
format: 'bytes',
|
||||
},
|
||||
},
|
||||
},
|
||||
fs: {
|
||||
type: 'object',
|
||||
optional: false, nullable: false,
|
||||
properties: {
|
||||
total: {
|
||||
type: 'number',
|
||||
optional: false, nullable: false,
|
||||
format: 'bytes',
|
||||
},
|
||||
used: {
|
||||
type: 'number',
|
||||
optional: false, nullable: false,
|
||||
format: 'bytes',
|
||||
},
|
||||
},
|
||||
},
|
||||
net: {
|
||||
type: 'object',
|
||||
optional: false, nullable: false,
|
||||
properties: {
|
||||
interface: {
|
||||
type: 'string',
|
||||
optional: false, nullable: false,
|
||||
example: 'eth0',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} 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> {
|
||||
export default class extends Endpoint<'admin/server-info'> {
|
||||
name = 'admin/server-info' as const;
|
||||
constructor(
|
||||
@Inject(DI.db)
|
||||
private db: DataSource,
|
||||
|
@ -106,7 +18,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||
private redisClient: Redis.Redis,
|
||||
|
||||
) {
|
||||
super(meta, paramDef, async () => {
|
||||
super(async () => {
|
||||
const memStats = await si.mem();
|
||||
const fsStats = await si.fsSize();
|
||||
const netInterface = await si.networkInterfaceDefault();
|
||||
|
|
|
@ -1613,6 +1613,19 @@ export const endpoints = {
|
|||
res: undefined,
|
||||
}],
|
||||
},
|
||||
'admin/server-info': {
|
||||
requireCredential: true,
|
||||
requireModerator: true,
|
||||
|
||||
tags: ['admin', 'meta'],
|
||||
|
||||
defines: [{
|
||||
req: undefined,
|
||||
res: {
|
||||
$ref: 'https://misskey-hub.net/api/schemas/ServerInfoAdmin',
|
||||
}
|
||||
}],
|
||||
},
|
||||
} as const satisfies { [x: string]: IEndpointMeta; };
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,6 +47,10 @@ import {
|
|||
InstanceMetaSharedSchema,
|
||||
InstanceMetaAdminSchema,
|
||||
} from './schemas/instance-meta.js';
|
||||
import {
|
||||
ServerInfoSchema,
|
||||
ServerInfoAdminSchema,
|
||||
} from './schemas/server-info.js';
|
||||
import { Error, ApiError } from './schemas/error.js';
|
||||
import type { JSONSchema7, JSONSchema7Definition, GetDef, GetRefs, GetKeys, UnionToArray } from 'schema-type';
|
||||
|
||||
|
@ -95,6 +99,8 @@ export const refs = {
|
|||
AbuseUserReport: packedAbuseUserReportSchema,
|
||||
InstanceMetaShared: InstanceMetaSharedSchema,
|
||||
InstanceMetaAdmin: InstanceMetaAdminSchema,
|
||||
ServerInfo: ServerInfoSchema,
|
||||
ServerInfoAdmin: ServerInfoAdminSchema,
|
||||
|
||||
Error: Error,
|
||||
ApiError: ApiError,
|
||||
|
|
86
packages/misskey-js/src/schemas/server-info.ts
Normal file
86
packages/misskey-js/src/schemas/server-info.ts
Normal file
|
@ -0,0 +1,86 @@
|
|||
import type { JSONSchema7Definition } from 'schema-type';
|
||||
|
||||
export const ServerInfoSchema = {
|
||||
$id: 'https://misskey-hub.net/api/schemas/ServerInfo',
|
||||
|
||||
type: 'object',
|
||||
properties: {
|
||||
machine: {
|
||||
type: 'string',
|
||||
},
|
||||
cpu: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
model: { type: 'string' },
|
||||
cores: { type: 'number' },
|
||||
},
|
||||
required: ['model', 'cores'],
|
||||
},
|
||||
mem: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
total: { type: 'number', format: 'bytes' },
|
||||
},
|
||||
required: ['total'],
|
||||
},
|
||||
fs: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
total: { type: 'number', format: 'bytes' },
|
||||
used: { type: 'number', format: 'bytes' },
|
||||
},
|
||||
},
|
||||
},
|
||||
required: [
|
||||
'machine',
|
||||
'cpu',
|
||||
'mem',
|
||||
'fs',
|
||||
],
|
||||
} as const satisfies JSONSchema7Definition;
|
||||
|
||||
export const ServerInfoAdminSchema = {
|
||||
$id: 'https://misskey-hub.net/api/schemas/ServerInfoAdmin',
|
||||
|
||||
allOf: [
|
||||
{ $ref: 'https://misskey-hub.net/api/schemas/ServerInfo' },
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
os: {
|
||||
type: 'string',
|
||||
enum: [
|
||||
// NodeJS.Platform
|
||||
'aix',
|
||||
'android',
|
||||
'darwin',
|
||||
'freebsd',
|
||||
'haiku',
|
||||
'linux',
|
||||
'openbsd',
|
||||
'sunos',
|
||||
'win32',
|
||||
'cygwin',
|
||||
'netbsd',
|
||||
]
|
||||
},
|
||||
node: { type: 'string', examples: ['v14.17.0'] },
|
||||
psql: { type: 'string' },
|
||||
redis: { type: 'string' },
|
||||
net: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
interface: { type: 'string', examples: ['eth0'] },
|
||||
},
|
||||
required: ['interface'],
|
||||
},
|
||||
},
|
||||
required: [
|
||||
'os',
|
||||
'node',
|
||||
'psql',
|
||||
'net',
|
||||
],
|
||||
},
|
||||
],
|
||||
} as const satisfies JSONSchema7Definition;
|
|
@ -110,6 +110,15 @@ describe('schemas', () => {
|
|||
test('abuse user report', () => {
|
||||
type AbuseUserReport = Packed<'AbuseUserReport'>;
|
||||
});
|
||||
test('meta', () => {
|
||||
type MetaShared = Packed<'InstanceMetaShared'>;
|
||||
//type Meta = Packed<'InstanceMeta'>;
|
||||
type MetaAdmin = Packed<'InstanceMetaAdmin'>;
|
||||
});
|
||||
test('server info', () => {
|
||||
type ServerInfo = Packed<'ServerInfo'>;
|
||||
type ServerInfoAdmin = Packed<'ServerInfoAdmin'>;
|
||||
});
|
||||
test('error', () => {
|
||||
type Error = Packed<'Error'>;
|
||||
type ApiError = Packed<'ApiError'>;
|
||||
|
|
Loading…
Reference in a new issue