Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ createWorker(Tasks.POST_IMAGES, "./tasks/post-images/processor.ts");
createWorker(Tasks.URL_METADATA, "./tasks/url-metadata/processor.ts");
createWorker(Tasks.SYNC_AUTHOR, "./tasks/sync-author/processor.ts");
createWorker(Tasks.SYNC_COLLECTION, "./tasks/sync-collection/processor.ts");
createWorker(Tasks.SYNC_POST, "./tasks/sync-post/processor.ts");
createHealthcheck();
2 changes: 1 addition & 1 deletion apps/worker/src/tasks/post-images/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function createAndUploadPostImage(
layout: LayoutFunction,
signal: AbortSignal,
) {
const BUCKET = await s3.createBucket(env.S3_BUCKET);
const BUCKET = await s3.ensureBucket(env.S3_BUCKET);
await createPostImage(layout, data).then((buf) => {
signal.throwIfAborted();
return s3.upload(BUCKET, key, undefined, buf, "image/png");
Expand Down
2 changes: 1 addition & 1 deletion apps/worker/src/tasks/sync-author/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function processProfileImg(

Readable.fromWeb(stream as never).pipe(pipeline);

const bucket = await s3.createBucket(env.S3_BUCKET);
const bucket = await s3.ensureBucket(env.S3_BUCKET);
await s3.upload(bucket, uploadKey, undefined, pipeline, "image/jpeg");
}

Expand Down
15 changes: 0 additions & 15 deletions apps/worker/src/tasks/sync-collection/processor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ test("Creates an example collection successfully", async () => {
where: deleteWhere,
} as never);

vi.mocked(db.select).mockReturnValue({
from: vi.fn().mockReturnValue({
where: vi.fn().mockResolvedValue([{ slug: "example-author" }]),
}),
} as never);

vi.mocked(github.getContents).mockImplementation(((params: {
path: string;
}) => {
Expand Down Expand Up @@ -302,15 +296,6 @@ test("Handles collection with multiple authors", async () => {
where: deleteWhere,
} as never);

// Both authors exist
vi.mocked(db.select).mockReturnValue({
from: vi.fn().mockReturnValue({
where: vi
.fn()
.mockResolvedValue([{ slug: "example-author" }, { slug: "co-author" }]),
}),
} as never);

vi.mocked(github.getContents).mockImplementation(((params: {
path: string;
}) => {
Expand Down
10 changes: 3 additions & 7 deletions apps/worker/src/tasks/sync-collection/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import { Value } from "@sinclair/typebox/value";
import sharp from "sharp";
import { Readable } from "node:stream";
import { s3 } from "@playfulprogramming/s3";

function extractLocale(name: string) {
const match = name.match(/\.([a-z]+)\.md$/);
return match ? match[1] : "en";
}
import { extractLocale } from "../../utils/extractLocale.ts";

const IMAGE_SIZE_MAX = 2048;

Expand All @@ -36,7 +32,7 @@ async function processImg(

Readable.fromWeb(stream as never).pipe(pipeline);

const bucket = await s3.createBucket(env.S3_BUCKET);
const bucket = await s3.ensureBucket(env.S3_BUCKET);
await s3.upload(bucket, uploadKey, undefined, pipeline, "image/jpeg");
}

Expand All @@ -60,7 +56,7 @@ export default createProcessor(
});

if (collectionMetaResponse.data === undefined) {
if (collectionMetaResponse.response.status == 404) {
if (collectionMetaResponse.response.status === 404) {
console.log(
`Metadata for ${collectionId} (${collectionMetaUrl.pathname}) returned 404 - removing collection entry.`,
);
Expand Down
Loading