implement AP fetch logs
This commit is contained in:
parent
cc2edae7ab
commit
81944b3bdf
11 changed files with 395 additions and 95 deletions
|
|
@ -82,6 +82,7 @@ import {
|
|||
MiWebhook,
|
||||
NoteEdit,
|
||||
SkApContext,
|
||||
SkApFetchLog,
|
||||
SkApInboxLog,
|
||||
} from './_.js';
|
||||
import type { DataSource } from 'typeorm';
|
||||
|
|
@ -134,6 +135,12 @@ const $apContextRepository: Provider = {
|
|||
inject: [DI.db],
|
||||
};
|
||||
|
||||
const $apFetchLogsRepository: Provider = {
|
||||
provide: DI.apFetchLogsRepository,
|
||||
useFactory: (db: DataSource) => db.getRepository(SkApFetchLog).extend(miRepository as MiRepository<SkApFetchLog>),
|
||||
inject: [DI.db],
|
||||
};
|
||||
|
||||
const $apInboxLogsRepository: Provider = {
|
||||
provide: DI.apInboxLogsRepository,
|
||||
useFactory: (db: DataSource) => db.getRepository(SkApInboxLog).extend(miRepository as MiRepository<SkApInboxLog>),
|
||||
|
|
@ -541,6 +548,7 @@ const $noteScheduleRepository: Provider = {
|
|||
$avatarDecorationsRepository,
|
||||
$latestNotesRepository,
|
||||
$apContextRepository,
|
||||
$apFetchLogsRepository,
|
||||
$apInboxLogsRepository,
|
||||
$noteFavoritesRepository,
|
||||
$noteThreadMutingsRepository,
|
||||
|
|
@ -617,6 +625,7 @@ const $noteScheduleRepository: Provider = {
|
|||
$avatarDecorationsRepository,
|
||||
$latestNotesRepository,
|
||||
$apContextRepository,
|
||||
$apFetchLogsRepository,
|
||||
$apInboxLogsRepository,
|
||||
$noteFavoritesRepository,
|
||||
$noteThreadMutingsRepository,
|
||||
|
|
|
|||
89
packages/backend/src/models/SkApFetchLog.ts
Normal file
89
packages/backend/src/models/SkApFetchLog.ts
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { Column, Index, JoinColumn, ManyToOne, PrimaryColumn, Entity } from 'typeorm';
|
||||
import { SkApContext } from '@/models/SkApContext.js';
|
||||
import { id } from './util/id.js';
|
||||
|
||||
/**
|
||||
* Records objects fetched via AP
|
||||
*/
|
||||
@Entity('ap_fetch_log')
|
||||
export class SkApFetchLog {
|
||||
@PrimaryColumn({
|
||||
...id(),
|
||||
primaryKeyConstraintName: 'PK_ap_fetch_log',
|
||||
})
|
||||
public id: string;
|
||||
|
||||
@Index('IDX_ap_fetch_log_at')
|
||||
@Column('timestamptz')
|
||||
public at: Date;
|
||||
|
||||
/**
|
||||
* Processing duration in milliseconds
|
||||
*/
|
||||
@Column('double precision', { nullable: true })
|
||||
public duration: number | null = null;
|
||||
|
||||
/**
|
||||
* DB hostname extracted from responseUri, or requestUri if fetch is incomplete
|
||||
*/
|
||||
@Index('IDX_ap_fetch_log_host')
|
||||
@Column('text')
|
||||
public host: string;
|
||||
|
||||
/**
|
||||
* Original requested URI
|
||||
*/
|
||||
@Column('text', {
|
||||
name: 'request_uri',
|
||||
})
|
||||
public requestUri: string;
|
||||
|
||||
/**
|
||||
* Canonical URI / object ID, taken from the final payload
|
||||
*/
|
||||
@Column('text', {
|
||||
name: 'object_uri',
|
||||
nullable: true,
|
||||
})
|
||||
@Index('IDX_ap_fetch_log_object_uri')
|
||||
public objectUri: string | null = null;
|
||||
|
||||
@Column('boolean', { nullable: true })
|
||||
public accepted: boolean | null = null;
|
||||
|
||||
@Column('text', { nullable: true })
|
||||
public result: string | null = null;
|
||||
|
||||
@Column('jsonb', { nullable: true })
|
||||
// https://github.com/typeorm/typeorm/issues/8559
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
public object: any | null = null;
|
||||
|
||||
@Column({
|
||||
type: 'text',
|
||||
name: 'context_hash',
|
||||
nullable: true,
|
||||
})
|
||||
public contextHash: string | null;
|
||||
|
||||
@ManyToOne(() => SkApContext, {
|
||||
onDelete: 'CASCADE',
|
||||
nullable: true,
|
||||
})
|
||||
@JoinColumn({
|
||||
name: 'context_hash',
|
||||
foreignKeyConstraintName: 'FK_ap_fetch_log_context_hash',
|
||||
})
|
||||
public context: SkApContext | null;
|
||||
|
||||
constructor(data?: Partial<SkApFetchLog>) {
|
||||
if (data) {
|
||||
Object.assign(this, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -83,6 +83,7 @@ import { MiBubbleGameRecord } from '@/models/BubbleGameRecord.js';
|
|||
import { MiReversiGame } from '@/models/ReversiGame.js';
|
||||
import { MiNoteSchedule } from '@/models/NoteSchedule.js';
|
||||
import { SkApInboxLog } from '@/models/SkApInboxLog.js';
|
||||
import { SkApFetchLog } from '@/models/SkApFetchLog.js';
|
||||
import { SkApContext } from '@/models/SkApContext.js';
|
||||
import type { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity.js';
|
||||
|
||||
|
|
@ -132,6 +133,7 @@ export const miRepository = {
|
|||
export {
|
||||
SkLatestNote,
|
||||
SkApContext,
|
||||
SkApFetchLog,
|
||||
SkApInboxLog,
|
||||
MiAbuseUserReport,
|
||||
MiAbuseReportNotificationRecipient,
|
||||
|
|
@ -234,6 +236,7 @@ export type InstancesRepository = Repository<MiInstance> & MiRepository<MiInstan
|
|||
export type MetasRepository = Repository<MiMeta> & MiRepository<MiMeta>;
|
||||
export type LatestNotesRepository = Repository<SkLatestNote> & MiRepository<SkLatestNote>;
|
||||
export type ApContextsRepository = Repository<SkApContext> & MiRepository<SkApContext>;
|
||||
export type ApFetchLogsRepository = Repository<SkApFetchLog> & MiRepository<SkApFetchLog>;
|
||||
export type ApInboxLogsRepository = Repository<SkApInboxLog> & MiRepository<SkApInboxLog>;
|
||||
export type ModerationLogsRepository = Repository<MiModerationLog> & MiRepository<MiModerationLog>;
|
||||
export type MutingsRepository = Repository<MiMuting> & MiRepository<MiMuting>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue