Skip to content

Commit f2bd3f8

Browse files
committed
Merge branch 'v0/global/db0811' of https://github.com/thinc-org/ipix into v0/global/db0811
2 parents 70207b5 + 670d7ca commit f2bd3f8

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

apps/api/src/modules/image/upload-multipart.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,6 +1565,7 @@ export const uploadRouter = new Elysia({ prefix: "/v1" })
15651565
spaceId: it.spaceId,
15661566
itemId: it.id,
15671567
assetId: assetRow.id,
1568+
sha256: shaBytes,
15681569
variants: [
15691570
{ variant: "thumb", algoV: 1, ext: "webp", maxEdge: 360 },
15701571
{ variant: "web", algoV: 1, ext: "webp", maxEdge: 1080 },

packages/s3/src/worker-preview.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { drizzle, NodePgDatabase } from "drizzle-orm/node-postgres";
2+
import * as schema from "@repo/rdb/schema";
13
import { Queue, Worker, Job } from "bullmq";
24
import Redis from "ioredis";
35
import {
@@ -12,9 +14,31 @@ import { Client as PgClient } from "pg";
1214
import sharp from "sharp";
1315
import type { Readable } from "stream";
1416
import exifr from "exifr";
17+
import { eq } from "drizzle-orm";
1518

1619
type ImageMetadata = sharp.Metadata;
1720

21+
export interface DatabaseClientOptions {
22+
databaseUrl?: string;
23+
max?: number;
24+
}
25+
26+
export type DatabaseInstance = NodePgDatabase<typeof schema>;
27+
28+
export const createDb = (opts?: DatabaseClientOptions): DatabaseInstance => {
29+
return drizzle({
30+
logger: true,
31+
schema,
32+
casing: "snake_case",
33+
connection: {
34+
connectionString: process.env.DATABASE_URL!,
35+
max: opts?.max,
36+
},
37+
});
38+
};
39+
40+
const db = createDb({ databaseUrl: process.env.DATABASE_URL })
41+
1842
// Job contract
1943
// Inputs:
2044
// - spaceId, itemId, assetId: uuid strings
@@ -43,6 +67,7 @@ export type PreviewJob = {
4367
spaceId: string;
4468
itemId: string;
4569
assetId: string;
70+
sha256: Buffer<ArrayBuffer>
4671
sha24?: string;
4772
contentType?: string;
4873
sourceKey?: string;
@@ -276,7 +301,7 @@ async function copyOrPutPreview(
276301
export const previewWorker = new Worker<PreviewJob>(
277302
PREVIEW_QUEUE_NAME,
278303
async (job: Job<PreviewJob>) => {
279-
const { spaceId, itemId, assetId } = job.data;
304+
const { spaceId, itemId, assetId, sha256 } = job.data;
280305
const sha24 = job.data.sha24 ?? (await ensureSha24(assetId));
281306
const sourceKey = job.data.sourceKey ?? (await ensureCanonKey(assetId));
282307
let { buf: src, contentType } = await getSourceObjectBufferAndCt(sourceKey);
@@ -330,6 +355,9 @@ export const previewWorker = new Worker<PreviewJob>(
330355
gpdDop: null,
331356
gpsTimestamp: null,
332357
};
358+
try {
359+
await db.update(schema.storageSchema.fileAsset).set(imgMetadataInsertObj).where(eq(schema.storageSchema.fileAsset.sha256, sha256))
360+
} catch { /* do nothing */ }
333361
/* const updateFileAssetQuery = await pg.query<{
334362
id: string;
335363
object_key: string;

0 commit comments

Comments
 (0)