feat: add per user pv chart
This commit is contained in:
parent
4c4af2ae84
commit
969e9df889
13 changed files with 153 additions and 4 deletions
|
@ -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,
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue