mirror of
https://github.com/sim1222/misskey.git
synced 2025-08-03 23:16:28 +09:00
feat: add per user pv chart
This commit is contained in:
37
packages/backend/src/server/api/endpoints/charts/user/pv.ts
Normal file
37
packages/backend/src/server/api/endpoints/charts/user/pv.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { getJsonSchema } from '@/core/chart/core.js';
|
||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import PerUserPvChart from '@/core/chart/charts/per-user-pv.js';
|
||||
import { schema } from '@/core/chart/charts/entities/per-user-notes.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 },
|
||||
userId: { type: 'string', format: 'misskey:id' },
|
||||
},
|
||||
required: ['span', 'userId'],
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
@Injectable()
|
||||
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
constructor(
|
||||
private perUserPvChart: PerUserPvChart,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
return await this.perUserPvChart.getChart(ps.span, ps.limit, ps.offset ? new Date(ps.offset) : null, ps.userId);
|
||||
});
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import { RemoteUserResolveService } from '@/core/RemoteUserResolveService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import PerUserPvChart from '@/core/chart/charts/per-user-pv.js';
|
||||
import { ApiError } from '../../error.js';
|
||||
import { ApiLoggerService } from '../../ApiLoggerService.js';
|
||||
import type { FindOptionsWhere } from 'typeorm';
|
||||
@ -90,9 +91,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
|
||||
private userEntityService: UserEntityService,
|
||||
private remoteUserResolveService: RemoteUserResolveService,
|
||||
private perUserPvChart: PerUserPvChart,
|
||||
private apiLoggerService: ApiLoggerService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
super(meta, paramDef, async (ps, me, _1, _2, _3, ip) => {
|
||||
let user;
|
||||
|
||||
const isAdminOrModerator = me && (me.isAdmin || me.isModerator);
|
||||
@ -137,6 +139,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
throw new ApiError(meta.errors.noSuchUser);
|
||||
}
|
||||
|
||||
if (me == null && ip != null) {
|
||||
this.perUserPvChart.commitByVisitor(user, ip);
|
||||
} else if (me && me.id !== user.id) {
|
||||
this.perUserPvChart.commitByUser(user, me.id);
|
||||
}
|
||||
|
||||
return await this.userEntityService.pack(user, me, {
|
||||
detail: true,
|
||||
});
|
||||
|
Reference in New Issue
Block a user