From 0571b839785edcf44801992bfa66c9a49d478c2e Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 5 Jun 2023 06:55:13 +0000 Subject: [PATCH] wip --- .../api/endpoints/charts/active-users.ts | 26 +--- .../server/api/endpoints/charts/ap-request.ts | 26 +--- .../src/server/api/endpoints/charts/drive.ts | 26 +--- .../server/api/endpoints/charts/federation.ts | 26 +--- .../server/api/endpoints/charts/instance.ts | 27 +--- .../src/server/api/endpoints/charts/notes.ts | 26 +--- .../src/server/api/endpoints/charts/users.ts | 26 +--- packages/misskey-js/src/endpoints.ts | 134 ++++++++++++++++++ 8 files changed, 155 insertions(+), 162 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/charts/active-users.ts b/packages/backend/src/server/api/endpoints/charts/active-users.ts index 2ab58e4309..6d20a40e27 100644 --- a/packages/backend/src/server/api/endpoints/charts/active-users.ts +++ b/packages/backend/src/server/api/endpoints/charts/active-users.ts @@ -1,35 +1,15 @@ import { Injectable } from '@nestjs/common'; -import { getJsonSchema } from '@/core/chart/core.js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import ActiveUsersChart from '@/core/chart/charts/active-users.js'; -import { schema } from '@/core/chart/charts/entities/active-users.js'; - -export const meta = { - tags: ['charts', 'users'], - - res: getJsonSchema(schema), - - allowGet: true, - cacheSec: 60 * 60, -} as const; - -export const paramDef = { - type: 'object', - properties: { - span: { type: 'string', enum: ['day', 'hour'] }, - limit: { type: 'integer', minimum: 1, maximum: 500, default: 30 }, - offset: { type: 'integer', nullable: true, default: null }, - }, - required: ['span'], -} as const; // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'charts/active-users'> { + name = 'charts/active-users' as const; constructor( private activeUsersChart: ActiveUsersChart, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { return await this.activeUsersChart.getChart(ps.span, ps.limit, ps.offset ? new Date(ps.offset) : null); }); } diff --git a/packages/backend/src/server/api/endpoints/charts/ap-request.ts b/packages/backend/src/server/api/endpoints/charts/ap-request.ts index e40a53d82e..15472fbea7 100644 --- a/packages/backend/src/server/api/endpoints/charts/ap-request.ts +++ b/packages/backend/src/server/api/endpoints/charts/ap-request.ts @@ -1,35 +1,15 @@ import { Injectable } from '@nestjs/common'; -import { getJsonSchema } from '@/core/chart/core.js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import ApRequestChart from '@/core/chart/charts/ap-request.js'; -import { schema } from '@/core/chart/charts/entities/ap-request.js'; - -export const meta = { - tags: ['charts'], - - res: getJsonSchema(schema), - - allowGet: true, - cacheSec: 60 * 60, -} as const; - -export const paramDef = { - type: 'object', - properties: { - span: { type: 'string', enum: ['day', 'hour'] }, - limit: { type: 'integer', minimum: 1, maximum: 500, default: 30 }, - offset: { type: 'integer', nullable: true, default: null }, - }, - required: ['span'], -} as const; // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'charts/ap-request'> { + name = 'charts/ap-request' as const; constructor( private apRequestChart: ApRequestChart, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { return await this.apRequestChart.getChart(ps.span, ps.limit, ps.offset ? new Date(ps.offset) : null); }); } diff --git a/packages/backend/src/server/api/endpoints/charts/drive.ts b/packages/backend/src/server/api/endpoints/charts/drive.ts index 9a5aff4af9..9e1d475e7f 100644 --- a/packages/backend/src/server/api/endpoints/charts/drive.ts +++ b/packages/backend/src/server/api/endpoints/charts/drive.ts @@ -1,35 +1,15 @@ import { Injectable } from '@nestjs/common'; -import { getJsonSchema } from '@/core/chart/core.js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import DriveChart from '@/core/chart/charts/drive.js'; -import { schema } from '@/core/chart/charts/entities/drive.js'; - -export const meta = { - tags: ['charts', 'drive'], - - res: getJsonSchema(schema), - - allowGet: true, - cacheSec: 60 * 60, -} as const; - -export const paramDef = { - type: 'object', - properties: { - span: { type: 'string', enum: ['day', 'hour'] }, - limit: { type: 'integer', minimum: 1, maximum: 500, default: 30 }, - offset: { type: 'integer', nullable: true, default: null }, - }, - required: ['span'], -} as const; // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'charts/drive'> { + name = 'charts/drive' as const; constructor( private driveChart: DriveChart, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { return await this.driveChart.getChart(ps.span, ps.limit, ps.offset ? new Date(ps.offset) : null); }); } diff --git a/packages/backend/src/server/api/endpoints/charts/federation.ts b/packages/backend/src/server/api/endpoints/charts/federation.ts index ed3a968681..b04fad9234 100644 --- a/packages/backend/src/server/api/endpoints/charts/federation.ts +++ b/packages/backend/src/server/api/endpoints/charts/federation.ts @@ -1,35 +1,15 @@ import { Injectable } from '@nestjs/common'; -import { getJsonSchema } from '@/core/chart/core.js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import FederationChart from '@/core/chart/charts/federation.js'; -import { schema } from '@/core/chart/charts/entities/federation.js'; - -export const meta = { - tags: ['charts'], - - res: getJsonSchema(schema), - - allowGet: true, - cacheSec: 60 * 60, -} as const; - -export const paramDef = { - type: 'object', - properties: { - span: { type: 'string', enum: ['day', 'hour'] }, - limit: { type: 'integer', minimum: 1, maximum: 500, default: 30 }, - offset: { type: 'integer', nullable: true, default: null }, - }, - required: ['span'], -} as const; // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'charts/federation'> { + name = 'charts/federation' as const; constructor( private federationChart: FederationChart, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { return await this.federationChart.getChart(ps.span, ps.limit, ps.offset ? new Date(ps.offset) : null); }); } diff --git a/packages/backend/src/server/api/endpoints/charts/instance.ts b/packages/backend/src/server/api/endpoints/charts/instance.ts index c992d525c9..ea280e2884 100644 --- a/packages/backend/src/server/api/endpoints/charts/instance.ts +++ b/packages/backend/src/server/api/endpoints/charts/instance.ts @@ -1,36 +1,15 @@ import { Injectable } from '@nestjs/common'; -import { getJsonSchema } from '@/core/chart/core.js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import InstanceChart from '@/core/chart/charts/instance.js'; -import { schema } from '@/core/chart/charts/entities/instance.js'; - -export const meta = { - tags: ['charts'], - - res: getJsonSchema(schema), - - allowGet: true, - cacheSec: 60 * 60, -} as const; - -export const paramDef = { - type: 'object', - properties: { - span: { type: 'string', enum: ['day', 'hour'] }, - limit: { type: 'integer', minimum: 1, maximum: 500, default: 30 }, - offset: { type: 'integer', nullable: true, default: null }, - host: { type: 'string' }, - }, - required: ['span', 'host'], -} as const; // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'charts/instance'> { + name = 'charts/instance' as const; constructor( private instanceChart: InstanceChart, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { return await this.instanceChart.getChart(ps.span, ps.limit, ps.offset ? new Date(ps.offset) : null, ps.host); }); } diff --git a/packages/backend/src/server/api/endpoints/charts/notes.ts b/packages/backend/src/server/api/endpoints/charts/notes.ts index 5750cd5b78..d7b51cf3f2 100644 --- a/packages/backend/src/server/api/endpoints/charts/notes.ts +++ b/packages/backend/src/server/api/endpoints/charts/notes.ts @@ -1,35 +1,15 @@ import { Injectable } from '@nestjs/common'; -import { getJsonSchema } from '@/core/chart/core.js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import NotesChart from '@/core/chart/charts/notes.js'; -import { schema } from '@/core/chart/charts/entities/notes.js'; - -export const meta = { - tags: ['charts', 'notes'], - - res: getJsonSchema(schema), - - allowGet: true, - cacheSec: 60 * 60, -} as const; - -export const paramDef = { - type: 'object', - properties: { - span: { type: 'string', enum: ['day', 'hour'] }, - limit: { type: 'integer', minimum: 1, maximum: 500, default: 30 }, - offset: { type: 'integer', nullable: true, default: null }, - }, - required: ['span'], -} as const; // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'charts/notes'> { + name = 'charts/notes' as const; constructor( private notesChart: NotesChart, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { return await this.notesChart.getChart(ps.span, ps.limit, ps.offset ? new Date(ps.offset) : null); }); } diff --git a/packages/backend/src/server/api/endpoints/charts/users.ts b/packages/backend/src/server/api/endpoints/charts/users.ts index 1374f02046..e4c375c81d 100644 --- a/packages/backend/src/server/api/endpoints/charts/users.ts +++ b/packages/backend/src/server/api/endpoints/charts/users.ts @@ -1,35 +1,15 @@ import { Injectable } from '@nestjs/common'; -import { getJsonSchema } from '@/core/chart/core.js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import UsersChart from '@/core/chart/charts/users.js'; -import { schema } from '@/core/chart/charts/entities/users.js'; - -export const meta = { - tags: ['charts', 'users'], - - res: getJsonSchema(schema), - - allowGet: true, - cacheSec: 60 * 60, -} as const; - -export const paramDef = { - type: 'object', - properties: { - span: { type: 'string', enum: ['day', 'hour'] }, - limit: { type: 'integer', minimum: 1, maximum: 500, default: 30 }, - offset: { type: 'integer', nullable: true, default: null }, - }, - required: ['span'], -} as const; // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'charts/users'> { + name = 'charts/users' as const; constructor( private usersChart: UsersChart, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { return await this.usersChart.getChart(ps.span, ps.limit, ps.offset ? new Date(ps.offset) : null); }); } diff --git a/packages/misskey-js/src/endpoints.ts b/packages/misskey-js/src/endpoints.ts index d9ffd80b73..39863512c0 100644 --- a/packages/misskey-js/src/endpoints.ts +++ b/packages/misskey-js/src/endpoints.ts @@ -3088,6 +3088,140 @@ export const endpoints = { res: chartSchemaToJSONSchema(chartsSchemas.perUserReactions) satisfies JSONSchema7, }], }, + 'charts/active-users': { + tags: ['charts', 'users'], + + allowGet: true, + cacheSec: 60 * 60, + + defines: [{ + req: { + type: 'object', + properties: { + span: { type: 'string', enum: ['day', 'hour'] }, + limit: { type: 'integer', minimum: 1, maximum: 500, default: 30 }, + offset: { type: 'integer', nullable: true, default: null }, + }, + required: ['span'], + }, + res: chartSchemaToJSONSchema(chartsSchemas.activeUsers) satisfies JSONSchema7, + }], + }, + 'charts/ap-request': { + tags: ['charts'], + + allowGet: true, + cacheSec: 60 * 60, + + defines: [{ + req: { + type: 'object', + properties: { + span: { type: 'string', enum: ['day', 'hour'] }, + limit: { type: 'integer', minimum: 1, maximum: 500, default: 30 }, + offset: { type: 'integer', nullable: true, default: null }, + }, + required: ['span'], + }, + res: chartSchemaToJSONSchema(chartsSchemas.apRequest) satisfies JSONSchema7, + }], + }, + 'charts/drive': { + tags: ['charts', 'drive'], + + allowGet: true, + cacheSec: 60 * 60, + + defines: [{ + req: { + type: 'object', + properties: { + span: { type: 'string', enum: ['day', 'hour'] }, + limit: { type: 'integer', minimum: 1, maximum: 500, default: 30 }, + offset: { type: 'integer', nullable: true, default: null }, + }, + required: ['span'], + }, + res: chartSchemaToJSONSchema(chartsSchemas.drive) satisfies JSONSchema7, + }], + }, + 'charts/federation': { + tags: ['charts'], + + allowGet: true, + cacheSec: 60 * 60, + + defines: [{ + req: { + type: 'object', + properties: { + span: { type: 'string', enum: ['day', 'hour'] }, + limit: { type: 'integer', minimum: 1, maximum: 500, default: 30 }, + offset: { type: 'integer', nullable: true, default: null }, + }, + required: ['span'], + }, + res: chartSchemaToJSONSchema(chartsSchemas.federation) satisfies JSONSchema7, + }], + }, + 'charts/instance': { + tags: ['charts'], + + allowGet: true, + cacheSec: 60 * 60, + + defines: [{ + req: { + type: 'object', + properties: { + span: { type: 'string', enum: ['day', 'hour'] }, + limit: { type: 'integer', minimum: 1, maximum: 500, default: 30 }, + offset: { type: 'integer', nullable: true, default: null }, + host: { type: 'string' }, + }, + required: ['span', 'host'], + }, + res: chartSchemaToJSONSchema(chartsSchemas.instance) satisfies JSONSchema7, + }], + }, + 'charts/notes': { + tags: ['charts', 'notes'], + + allowGet: true, + cacheSec: 60 * 60, + + defines: [{ + req: { + type: 'object', + properties: { + span: { type: 'string', enum: ['day', 'hour'] }, + limit: { type: 'integer', minimum: 1, maximum: 500, default: 30 }, + offset: { type: 'integer', nullable: true, default: null }, + }, + required: ['span'], + }, + res: chartSchemaToJSONSchema(chartsSchemas.notes) satisfies JSONSchema7, + }], + }, + 'charts/users': { + tags: ['charts', 'users'], + + allowGet: true, + cacheSec: 60 * 60, + + defines: [{ + req: { + type: 'object', + properties: { + span: { type: 'string', enum: ['day', 'hour'] }, + limit: { type: 'integer', minimum: 1, maximum: 500, default: 30 }, + offset: { type: 'integer', nullable: true, default: null }, + }, + required: ['span'], + }, + res: chartSchemaToJSONSchema(chartsSchemas.users) satisfies JSONSchema7, + }], + }, //#endregion } as const satisfies { [x: string]: IEndpointMeta; };