feat(17-02): refactor image service and routes to use S3 storage service
- Replace Bun.write/mkdir with uploadImage() from storage.service - Remove uploadsDir parameter from fetchImageFromUrl - Update tests to mock storage service instead of checking filesystem
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { uploadImage } from "./storage.service";
|
||||
|
||||
const ALLOWED_TYPES = ["image/jpeg", "image/png", "image/webp"];
|
||||
const MAX_SIZE = 5 * 1024 * 1024; // 5MB
|
||||
@@ -13,7 +12,6 @@ interface FetchImageResult {
|
||||
|
||||
export async function fetchImageFromUrl(
|
||||
url: string,
|
||||
uploadsDir = "uploads",
|
||||
): Promise<FetchImageResult> {
|
||||
// Validate URL format
|
||||
let parsedUrl: URL;
|
||||
@@ -74,9 +72,8 @@ export async function fetchImageFromUrl(
|
||||
const ext = contentType === "image/jpeg" ? "jpg" : contentType.split("/")[1];
|
||||
const filename = `${Date.now()}-${randomUUID()}.${ext}`;
|
||||
|
||||
// Ensure directory exists and write
|
||||
await mkdir(uploadsDir, { recursive: true });
|
||||
await Bun.write(join(uploadsDir, filename), buffer);
|
||||
// Upload to object storage
|
||||
await uploadImage(Buffer.from(buffer), filename, contentType);
|
||||
|
||||
return { filename, sourceUrl: url };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user