@atproto/ozone 0.4.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/dist/api/label/subscribeLabels.d.ts.map +1 -1
- package/dist/api/label/subscribeLabels.js +4 -2
- package/dist/api/label/subscribeLabels.js.map +1 -1
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +2 -8
- package/dist/context.js.map +1 -1
- package/dist/daemon/context.d.ts.map +1 -1
- package/dist/daemon/context.js +1 -6
- package/dist/daemon/context.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mod-service/index.d.ts +4 -2
- package/dist/mod-service/index.d.ts.map +1 -1
- package/dist/mod-service/index.js +9 -3
- package/dist/mod-service/index.js.map +1 -1
- package/dist/safe-fetch.d.ts +0 -6
- package/dist/safe-fetch.d.ts.map +1 -1
- package/dist/safe-fetch.js +0 -30
- package/dist/safe-fetch.js.map +1 -1
- package/dist/sequencer/outbox.d.ts +3 -0
- package/dist/sequencer/outbox.d.ts.map +1 -1
- package/dist/sequencer/outbox.js +76 -42
- package/dist/sequencer/outbox.js.map +1 -1
- package/dist/video-invalidator.d.ts +9 -0
- package/dist/video-invalidator.d.ts.map +1 -0
- package/dist/video-invalidator.js +20 -0
- package/dist/video-invalidator.js.map +1 -0
- package/package.json +9 -11
package/dist/safe-fetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safe-fetch.js","sourceRoot":"","sources":["../src/safe-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA0B,MAAM,aAAa,CAAA;AAC/D,OAAO,
|
|
1
|
+
{"version":3,"file":"safe-fetch.js","sourceRoot":"","sources":["../src/safe-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA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,KAAK,CAAC,mBAAmB,CAAC,CAAC,EAClD,IAAI,CAAC,OAAO,CACb,CAAA;QACD,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IACpB,CAAC;IAEO,UAAU;QAChB,IAAI,IAAI,CAAC,KAAK;YAAE,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACxC,IAAI,CAAC,KAAK,GAAG,SAAS,CAAA;IACxB,CAAC;CACF","sourcesContent":["import { Transform, type TransformCallback } from 'node:stream'\nimport { safeFetchWrap } from '@atproto-labs/fetch-node'\n\nconst DEFAULT_RESPONSE_MAX_SIZE = 10 * 1024 * 1024\n\nexport const createSafeFetch = ({\n timeout = Infinity,\n responseMaxSize = DEFAULT_RESPONSE_MAX_SIZE,\n}: {\n timeout?: number\n responseMaxSize?: number\n} = {}) => {\n const safeFetch = safeFetchWrap({\n allowCustomPort: true,\n allowImplicitRedirect: true,\n allowIpHost: false,\n responseMaxSize,\n timeout,\n })\n\n return (input: Parameters<typeof globalThis.fetch>[0], init?: RequestInit) =>\n safeFetch(input, { ...init, redirect: 'error' })\n}\n\nexport class BodyTimeoutTransform extends Transform {\n private timer: NodeJS.Timeout | undefined\n\n constructor(private readonly timeout: number) {\n super()\n this.resetTimer()\n }\n\n override _transform(\n chunk: unknown,\n encoding: BufferEncoding,\n callback: TransformCallback,\n ) {\n this.resetTimer()\n callback(null, chunk)\n }\n\n override _flush(callback: TransformCallback) {\n this.clearTimer()\n callback()\n }\n\n override _destroy(\n error: Error | null,\n callback: (error?: Error | null) => void,\n ) {\n this.clearTimer()\n callback(error)\n }\n\n private resetTimer() {\n this.clearTimer()\n this.timer = setTimeout(\n () => this.destroy(new Error('Blob body timeout')),\n this.timeout,\n )\n this.timer.unref()\n }\n\n private clearTimer() {\n if (this.timer) clearTimeout(this.timer)\n this.timer = undefined\n }\n}\n"]}
|
|
@@ -2,10 +2,13 @@ import { AsyncBuffer } from '@atproto/common';
|
|
|
2
2
|
import type { LabelsEvt, Sequencer } from './sequencer.js';
|
|
3
3
|
export type OutboxOpts = {
|
|
4
4
|
maxBufferSize: number;
|
|
5
|
+
onOverflow?: () => void;
|
|
5
6
|
};
|
|
6
7
|
export declare class Outbox {
|
|
7
8
|
sequencer: Sequencer;
|
|
9
|
+
private readonly opts;
|
|
8
10
|
private caughtUp;
|
|
11
|
+
private readonly maxBufferSize;
|
|
9
12
|
lastSeen: number;
|
|
10
13
|
cutoverBuffer: LabelsEvt[];
|
|
11
14
|
outBuffer: AsyncBuffer<LabelsEvt>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outbox.d.ts","sourceRoot":"","sources":["../../src/sequencer/outbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"outbox.d.ts","sourceRoot":"","sources":["../../src/sequencer/outbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7C,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1D,MAAM,MAAM,UAAU,GAAG;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAA;CACxB,CAAA;AAED,qBAAa,MAAM;IASR,SAAS,EAAE,SAAS;IAC3B,OAAO,CAAC,QAAQ,CAAC,IAAI;IATvB,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAQ;IACtC,QAAQ,SAAK;IAEb,aAAa,EAAE,SAAS,EAAE,CAAA;IAC1B,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,CAAA;IAEjC,YACS,SAAS,EAAE,SAAS,EACV,IAAI,GAAE,OAAO,CAAC,UAAU,CAAM,EAMhD;IAWM,MAAM,CACX,cAAc,CAAC,EAAE,MAAM,EACvB,MAAM,CAAC,EAAE,WAAW,GACnB,cAAc,CAAC,SAAS,CAAC,CA4F3B;IAGM,WAAW,CAAC,cAAc,EAAE,MAAM,yGAexC;CACF"}
|
package/dist/sequencer/outbox.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { AsyncBuffer
|
|
1
|
+
import { AsyncBuffer } from '@atproto/common';
|
|
2
2
|
import { InvalidRequestError } from '@atproto/xrpc-server';
|
|
3
3
|
export class Outbox {
|
|
4
4
|
constructor(sequencer, opts = {}) {
|
|
5
5
|
this.sequencer = sequencer;
|
|
6
|
+
this.opts = opts;
|
|
6
7
|
this.caughtUp = false;
|
|
7
8
|
this.lastSeen = -1;
|
|
8
9
|
const { maxBufferSize = 500 } = opts;
|
|
10
|
+
this.maxBufferSize = maxBufferSize;
|
|
9
11
|
this.cutoverBuffer = [];
|
|
10
12
|
this.outBuffer = new AsyncBuffer(maxBufferSize);
|
|
11
13
|
}
|
|
@@ -19,69 +21,101 @@ export class Outbox {
|
|
|
19
21
|
// 3. streaming: we're all caught up on historic state, so the sequencer outputs events and we
|
|
20
22
|
// immediately yield them
|
|
21
23
|
async *events(backfillCursor, signal) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
if (signal?.aborted || this.sequencer.destroyed)
|
|
25
|
+
return;
|
|
26
|
+
let stopped = false;
|
|
27
|
+
// 1. create lifecycle events
|
|
28
|
+
// (stop, overflow, adding events, cutover)
|
|
29
|
+
const stop = (err) => {
|
|
30
|
+
if (stopped)
|
|
31
|
+
return;
|
|
32
|
+
stopped = true;
|
|
33
|
+
this.sequencer.off('events', addToBuffer);
|
|
34
|
+
this.sequencer.off('close', onClose);
|
|
35
|
+
signal?.removeEventListener('abort', onClose);
|
|
36
|
+
this.cutoverBuffer = [];
|
|
37
|
+
this.outBuffer.curr.length = 0;
|
|
38
|
+
if (err !== undefined) {
|
|
39
|
+
this.outBuffer.throw(err);
|
|
29
40
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
41
|
+
else {
|
|
42
|
+
this.outBuffer.close();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const onClose = () => stop();
|
|
46
|
+
const overflow = () => {
|
|
47
|
+
stop(new InvalidRequestError('Stream consumer too slow', 'ConsumerTooSlow'));
|
|
48
|
+
// @NOTE The consumer may be suspended in a socket write, so it cannot
|
|
49
|
+
// deliver the error or release this connection itself.
|
|
50
|
+
this.opts.onOverflow?.();
|
|
51
|
+
};
|
|
36
52
|
const addToBuffer = (evts) => {
|
|
37
|
-
if (
|
|
53
|
+
if (stopped)
|
|
54
|
+
return;
|
|
55
|
+
const size = this.caughtUp
|
|
56
|
+
? this.outBuffer.size
|
|
57
|
+
: this.cutoverBuffer.length;
|
|
58
|
+
if (size + evts.length > this.maxBufferSize) {
|
|
59
|
+
overflow();
|
|
60
|
+
}
|
|
61
|
+
else if (this.caughtUp) {
|
|
38
62
|
this.outBuffer.pushMany(evts);
|
|
39
63
|
}
|
|
40
64
|
else {
|
|
41
|
-
this.cutoverBuffer
|
|
65
|
+
this.cutoverBuffer.push(...evts);
|
|
42
66
|
}
|
|
43
67
|
};
|
|
44
|
-
if (!signal?.aborted) {
|
|
45
|
-
this.sequencer.on('events', addToBuffer);
|
|
46
|
-
}
|
|
47
|
-
signal?.addEventListener('abort', () => this.sequencer.off('events', addToBuffer));
|
|
48
68
|
const cutover = async () => {
|
|
49
|
-
// only need to perform cutover if we've been backfilling
|
|
50
69
|
if (backfillCursor !== undefined) {
|
|
51
70
|
const cutoverEvts = await this.sequencer.requestLabelRange({
|
|
52
71
|
earliestId: this.lastSeen > -1 ? this.lastSeen : backfillCursor,
|
|
72
|
+
limit: this.maxBufferSize + 1,
|
|
53
73
|
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
74
|
+
if (stopped)
|
|
75
|
+
return;
|
|
76
|
+
const last = cutoverEvts.at(-1)?.seq ?? this.lastSeen;
|
|
77
|
+
const buffered = this.cutoverBuffer.filter((evt) => evt.seq > last);
|
|
57
78
|
this.caughtUp = true;
|
|
58
79
|
this.cutoverBuffer = [];
|
|
59
|
-
|
|
60
|
-
else {
|
|
61
|
-
this.caughtUp = true;
|
|
80
|
+
addToBuffer([...cutoverEvts, ...buffered]);
|
|
62
81
|
}
|
|
63
82
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
83
|
+
// 2. wire up close events
|
|
84
|
+
signal?.addEventListener('abort', onClose, { once: true });
|
|
85
|
+
this.sequencer.once('close', onClose);
|
|
86
|
+
// 3. backfill and tail
|
|
87
|
+
try {
|
|
88
|
+
// backfill if needed
|
|
89
|
+
if (backfillCursor !== undefined) {
|
|
90
|
+
for await (const evt of this.getBackfill(backfillCursor)) {
|
|
91
|
+
if (stopped)
|
|
92
|
+
return;
|
|
93
|
+
this.lastSeen = evt.seq;
|
|
94
|
+
yield evt;
|
|
95
|
+
if (stopped)
|
|
69
96
|
return;
|
|
70
|
-
if (evt.seq > this.lastSeen) {
|
|
71
|
-
this.lastSeen = evt.seq;
|
|
72
|
-
yield evt;
|
|
73
|
-
}
|
|
74
97
|
}
|
|
75
98
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
99
|
+
else {
|
|
100
|
+
this.caughtUp = true;
|
|
101
|
+
}
|
|
102
|
+
if (stopped || this.sequencer.destroyed)
|
|
103
|
+
return;
|
|
104
|
+
// ingest from sequencer
|
|
105
|
+
this.sequencer.on('events', addToBuffer);
|
|
106
|
+
// initiate cutover
|
|
107
|
+
void cutover().catch(stop);
|
|
108
|
+
// live tail remaining events
|
|
109
|
+
for await (const evt of this.outBuffer.events()) {
|
|
110
|
+
if (evt.seq > this.lastSeen) {
|
|
111
|
+
this.lastSeen = evt.seq;
|
|
112
|
+
yield evt;
|
|
82
113
|
}
|
|
83
114
|
}
|
|
84
115
|
}
|
|
116
|
+
finally {
|
|
117
|
+
stop();
|
|
118
|
+
}
|
|
85
119
|
}
|
|
86
120
|
// yields only historical events
|
|
87
121
|
async *getBackfill(backfillCursor) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outbox.js","sourceRoot":"","sources":["../../src/sequencer/outbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"outbox.js","sourceRoot":"","sources":["../../src/sequencer/outbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAQ1D,MAAM,OAAO,MAAM;IAQjB,YACS,SAAoB,EACV,IAAI,GAAwB,EAAE;QADxC,cAAS,GAAT,SAAS,CAAW;QACV,SAAI,GAAJ,IAAI,CAA0B;QATzC,aAAQ,GAAG,KAAK,CAAA;QAExB,aAAQ,GAAG,CAAC,CAAC,CAAA;QASX,MAAM,EAAE,aAAa,GAAG,GAAG,EAAE,GAAG,IAAI,CAAA;QACpC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAClC,IAAI,CAAC,aAAa,GAAG,EAAE,CAAA;QACvB,IAAI,CAAC,SAAS,GAAG,IAAI,WAAW,CAAY,aAAa,CAAC,CAAA;IAC5D,CAAC;IAED,kCAAkC;IAClC,uGAAuG;IACvG,oEAAoE;IACpE,gFAAgF;IAChF,qFAAqF;IACrF,wGAAwG;IACxG,yGAAyG;IACzG,8FAA8F;IAC9F,yBAAyB;IACzB,KAAK,CAAC,CAAC,MAAM,CACX,cAAuB,EACvB,MAAoB;QAEpB,IAAI,MAAM,EAAE,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,SAAS;YAAE,OAAM;QACvD,IAAI,OAAO,GAAG,KAAK,CAAA;QAEnB,6BAA6B;QAC7B,2CAA2C;QAC3C,MAAM,IAAI,GAAG,CAAC,GAAa,EAAE,EAA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CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,cAAc;gBAC/D,KAAK,EAAE,SAAS;aACjB,CAAC,CAAA;YACF,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;gBACvB,MAAM,GAAG,CAAA;YACX,CAAC;YACD,wFAAwF;YACxF,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAA;YAC/C,IAAI,SAAS,GAAG,IAAI,CAAC,QAAQ,GAAG,SAAS,GAAG,CAAC;gBAAE,MAAK;YACpD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;gBAAE,MAAK;QAC5B,CAAC;IACH,CAAC;CACF","sourcesContent":["import { AsyncBuffer } from '@atproto/common'\nimport { InvalidRequestError } from '@atproto/xrpc-server'\nimport type { LabelsEvt, Sequencer } from './sequencer.js'\n\nexport type OutboxOpts = {\n maxBufferSize: number\n onOverflow?: () => void\n}\n\nexport class Outbox {\n private caughtUp = false\n private readonly maxBufferSize: number\n lastSeen = -1\n\n cutoverBuffer: LabelsEvt[]\n outBuffer: AsyncBuffer<LabelsEvt>\n\n constructor(\n public sequencer: Sequencer,\n private readonly opts: Partial<OutboxOpts> = {},\n ) {\n const { maxBufferSize = 500 } = opts\n this.maxBufferSize = maxBufferSize\n this.cutoverBuffer = []\n this.outBuffer = new AsyncBuffer<LabelsEvt>(maxBufferSize)\n }\n\n // event stream occurs in 3 phases\n // 1. backfill events: events that have been added to the DB since the last time a connection was open.\n // The outbox is not yet listening for new events from the sequencer\n // 2. cutover: the outbox has caught up with where the sequencer purports to be,\n // but the sequencer might already be halfway through sending out a round of updates.\n // Therefore, we start accepting the sequencer's events in a buffer, while making our own request to the\n // database to ensure we're caught up. We then dedupe the query & the buffer & stream the events in order\n // 3. streaming: we're all caught up on historic state, so the sequencer outputs events and we\n // immediately yield them\n async *events(\n backfillCursor?: number,\n signal?: AbortSignal,\n ): AsyncGenerator<LabelsEvt> {\n if (signal?.aborted || this.sequencer.destroyed) return\n let stopped = false\n\n // 1. create lifecycle events\n // (stop, overflow, adding events, cutover)\n const stop = (err?: unknown) => {\n if (stopped) return\n stopped = true\n this.sequencer.off('events', addToBuffer)\n this.sequencer.off('close', onClose)\n signal?.removeEventListener('abort', onClose)\n this.cutoverBuffer = []\n this.outBuffer.curr.length = 0\n if (err !== undefined) {\n this.outBuffer.throw(err)\n } else {\n this.outBuffer.close()\n }\n }\n const onClose = () => stop()\n const overflow = () => {\n stop(\n new InvalidRequestError('Stream consumer too slow', 'ConsumerTooSlow'),\n )\n // @NOTE The consumer may be suspended in a socket write, so it cannot\n // deliver the error or release this connection itself.\n this.opts.onOverflow?.()\n }\n const addToBuffer = (evts: LabelsEvt[]) => {\n if (stopped) return\n const size = this.caughtUp\n ? this.outBuffer.size\n : this.cutoverBuffer.length\n if (size + evts.length > this.maxBufferSize) {\n overflow()\n } else if (this.caughtUp) {\n this.outBuffer.pushMany(evts)\n } else {\n this.cutoverBuffer.push(...evts)\n }\n }\n const cutover = async () => {\n if (backfillCursor !== undefined) {\n const cutoverEvts = await this.sequencer.requestLabelRange({\n earliestId: this.lastSeen > -1 ? this.lastSeen : backfillCursor,\n limit: this.maxBufferSize + 1,\n })\n if (stopped) return\n const last = cutoverEvts.at(-1)?.seq ?? this.lastSeen\n const buffered = this.cutoverBuffer.filter((evt) => evt.seq > last)\n this.caughtUp = true\n this.cutoverBuffer = []\n addToBuffer([...cutoverEvts, ...buffered])\n }\n }\n\n // 2. wire up close events\n signal?.addEventListener('abort', onClose, { once: true })\n this.sequencer.once('close', onClose)\n\n // 3. backfill and tail\n try {\n // backfill if needed\n if (backfillCursor !== undefined) {\n for await (const evt of this.getBackfill(backfillCursor)) {\n if (stopped) return\n this.lastSeen = evt.seq\n yield evt\n if (stopped) return\n }\n } else {\n this.caughtUp = true\n }\n if (stopped || this.sequencer.destroyed) return\n\n // ingest from sequencer\n this.sequencer.on('events', addToBuffer)\n\n // initiate cutover\n void cutover().catch(stop)\n\n // live tail remaining events\n for await (const evt of this.outBuffer.events()) {\n if (evt.seq > this.lastSeen) {\n this.lastSeen = evt.seq\n yield evt\n }\n }\n } finally {\n stop()\n }\n }\n\n // yields only historical events\n async *getBackfill(backfillCursor: number) {\n const PAGE_SIZE = 500\n while (true) {\n const evts = await this.sequencer.requestLabelRange({\n earliestId: this.lastSeen > -1 ? this.lastSeen : backfillCursor,\n limit: PAGE_SIZE,\n })\n for (const evt of evts) {\n yield evt\n }\n // if we're within half a pagesize of the sequencer, we call it good & switch to cutover\n const seqCursor = this.sequencer.lastSeen ?? -1\n if (seqCursor - this.lastSeen < PAGE_SIZE / 2) break\n if (evts.length < 1) break\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type VideoInvalidatorConfig = {
|
|
2
|
+
url: string;
|
|
3
|
+
helperKey: string;
|
|
4
|
+
};
|
|
5
|
+
export declare class VideoInvalidator {
|
|
6
|
+
readonly invalidate: (did: string, cid: string) => Promise<void>;
|
|
7
|
+
constructor(cfg: VideoInvalidatorConfig);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=video-invalidator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video-invalidator.d.ts","sourceRoot":"","sources":["../src/video-invalidator.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,sBAAsB,GAAG;IACnC,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAID,qBAAa,gBAAgB;IAC3B,QAAQ,CAAC,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAEhE,YAAY,GAAG,EAAE,sBAAsB,EAetC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Invalidates transcoded video content associated with a source blob.
|
|
2
|
+
// @NOTE this does not remove the blob from PDS storage.
|
|
3
|
+
export class VideoInvalidator {
|
|
4
|
+
constructor(cfg) {
|
|
5
|
+
this.invalidate = async (did, cid) => {
|
|
6
|
+
const url = new URL(cfg.url);
|
|
7
|
+
url.searchParams.set('did', did);
|
|
8
|
+
url.searchParams.set('cid', cid);
|
|
9
|
+
const res = await fetch(url.toString(), {
|
|
10
|
+
method: 'POST',
|
|
11
|
+
headers: { 'helper-key': cfg.helperKey },
|
|
12
|
+
signal: AbortSignal.timeout(90e3),
|
|
13
|
+
});
|
|
14
|
+
if (!res.ok) {
|
|
15
|
+
throw new Error(`Video invalidation failed with status ${res.status}`);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=video-invalidator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video-invalidator.js","sourceRoot":"","sources":["../src/video-invalidator.ts"],"names":[],"mappings":"AAKA,sEAAsE;AACtE,wDAAwD;AACxD,MAAM,OAAO,gBAAgB;IAG3B,YAAY,GAA2B;QACrC,IAAI,CAAC,UAAU,GAAG,KAAK,EAAE,GAAW,EAAE,GAAW,EAAE,EAAE;YACnD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YAC5B,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;YAChC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;YAEhC,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE;gBACtC,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE,EAAE,YAAY,EAAE,GAAG,CAAC,SAAS,EAAE;gBACxC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC;aAClC,CAAC,CAAA;YACF,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;gBACZ,MAAM,IAAI,KAAK,CAAC,yCAAyC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAA;YACxE,CAAC;QACH,CAAC,CAAA;IACH,CAAC;CACF","sourcesContent":["export type VideoInvalidatorConfig = {\n url: string\n helperKey: string\n}\n\n// Invalidates transcoded video content associated with a source blob.\n// @NOTE this does not remove the blob from PDS storage.\nexport class VideoInvalidator {\n readonly invalidate: (did: string, cid: string) => Promise<void>\n\n constructor(cfg: VideoInvalidatorConfig) {\n this.invalidate = async (did: string, cid: string) => {\n const url = new URL(cfg.url)\n url.searchParams.set('did', did)\n url.searchParams.set('cid', cid)\n\n const res = await fetch(url.toString(), {\n method: 'POST',\n headers: { 'helper-key': cfg.helperKey },\n signal: AbortSignal.timeout(90e3),\n })\n if (!res.ok) {\n throw new Error(`Video invalidation failed with status ${res.status}`)\n }\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/ozone",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Backend service for moderating the Bluesky network.",
|
|
6
6
|
"keywords": [
|
|
@@ -42,7 +42,6 @@
|
|
|
42
42
|
"@opentelemetry/instrumentation-pg": "^0.72.0",
|
|
43
43
|
"compression": "^1.7.4",
|
|
44
44
|
"cors": "^2.8.5",
|
|
45
|
-
"dotenv": "^17.4.2",
|
|
46
45
|
"express": "^4.17.2",
|
|
47
46
|
"http-terminator": "^3.2.0",
|
|
48
47
|
"kysely": "^0.29.2",
|
|
@@ -56,16 +55,16 @@
|
|
|
56
55
|
"uint8arrays": "^5.0.0",
|
|
57
56
|
"undici": "^8.5.0",
|
|
58
57
|
"ws": "^8.12.0",
|
|
59
|
-
"@atproto-labs/fetch-node": "^0.3.7",
|
|
60
58
|
"@atproto-labs/opentelemetry-node": "^0.2.1",
|
|
61
59
|
"@atproto/common": "^0.8.3",
|
|
60
|
+
"@atproto-labs/fetch-node": "^0.4.0",
|
|
62
61
|
"@atproto/crypto": "^0.5.5",
|
|
63
|
-
"@atproto/
|
|
64
|
-
"@atproto/
|
|
65
|
-
"@atproto/ws-client": "^0.2.1",
|
|
62
|
+
"@atproto/lex": "^0.3.12",
|
|
63
|
+
"@atproto/identity": "^0.5.14",
|
|
66
64
|
"@atproto/lex-password-session": "^0.2.3",
|
|
67
|
-
"@atproto/
|
|
68
|
-
"@atproto/
|
|
65
|
+
"@atproto/ws-client": "^0.2.1",
|
|
66
|
+
"@atproto/syntax": "^0.7.6",
|
|
67
|
+
"@atproto/xrpc-server": "^0.13.2"
|
|
69
68
|
},
|
|
70
69
|
"devDependencies": {
|
|
71
70
|
"@did-plc/server": "^0.0.1",
|
|
@@ -77,9 +76,9 @@
|
|
|
77
76
|
"@types/qs": "^6.15.1",
|
|
78
77
|
"@types/ws": "^8.18.1",
|
|
79
78
|
"jest": "^30.5.1",
|
|
80
|
-
"@atproto/api": "^0.
|
|
79
|
+
"@atproto/api": "^0.21.0",
|
|
81
80
|
"@atproto/lexicon": "^0.7.14",
|
|
82
|
-
"@atproto/pds": "^0.5.
|
|
81
|
+
"@atproto/pds": "^0.5.35"
|
|
83
82
|
},
|
|
84
83
|
"scripts": {
|
|
85
84
|
"codegen:lex": "lex build --clear --indexFile --lexicons ../../lexicons",
|
|
@@ -87,7 +86,6 @@
|
|
|
87
86
|
"build": "tsc --build tsconfig.build.json",
|
|
88
87
|
"start": "node --enable-source-maps dist/bin.js",
|
|
89
88
|
"test": "NODE_OPTIONS=--experimental-vm-modules ../dev-infra/with-test-redis-and-db.sh jest",
|
|
90
|
-
"test:log": "tail -50 test.log | pino-pretty",
|
|
91
89
|
"test:updateSnapshot": "NODE_OPTIONS=--experimental-vm-modules ../dev-infra/with-test-redis-and-db.sh jest --updateSnapshot",
|
|
92
90
|
"migration:create": "node ./bin/migration-create.ts"
|
|
93
91
|
}
|