summaryrefslogtreecommitdiff
path: root/packages/backend/src/models/SkApFetchLog.ts
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-01-30 22:36:19 -0500
committerHazelnoot <acomputerdog@gmail.com>2025-02-16 19:25:22 -0500
commit81944b3bdf49cf95294adcefc265a568b921dee0 (patch)
tree3693a235357d9d9576b694128e03a065d36921b9 /packages/backend/src/models/SkApFetchLog.ts
parentrename activity_log and activity_context to ap_inbox_log and ap_context (diff)
downloadsharkey-81944b3bdf49cf95294adcefc265a568b921dee0.tar.gz
sharkey-81944b3bdf49cf95294adcefc265a568b921dee0.tar.bz2
sharkey-81944b3bdf49cf95294adcefc265a568b921dee0.zip
implement AP fetch logs
Diffstat (limited to 'packages/backend/src/models/SkApFetchLog.ts')
-rw-r--r--packages/backend/src/models/SkApFetchLog.ts89
1 files changed, 89 insertions, 0 deletions
diff --git a/packages/backend/src/models/SkApFetchLog.ts b/packages/backend/src/models/SkApFetchLog.ts
new file mode 100644
index 0000000000..1e7d861b6c
--- /dev/null
+++ b/packages/backend/src/models/SkApFetchLog.ts
@@ -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);
+ }
+ }
+}