Skip to content

Commit 7097408

Browse files
committed
storage
1 parent 52a4007 commit 7097408

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

src/lib/components/image-upload.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@
132132
const arrayBuffer = await processedFile.arrayBuffer();
133133
const base64 = arrayBufferToBase64(arrayBuffer);
134134
// Use the validated original type - server will re-compress to WebP anyway
135-
const uploadType = isAcceptedImageType(processedFile.type)
136-
? processedFile.type
137-
: file.type;
135+
const uploadType = isAcceptedImageType(processedFile.type) ? processedFile.type : file.type;
138136
const result = await upload({
139137
data: base64,
140138
type: uploadType,

src/lib/data/private/storage.remote.ts

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,27 @@ const FolderSchema = v.optional(v.picklist([...ALLOWED_FOLDERS]));
1313
const MAX_BASE64_SIZE = Math.ceil(10 * 1024 * 1024 * 1.37);
1414

1515
const UploadSchema = v.object({
16-
data: v.pipe(
17-
v.string(),
18-
v.maxLength(MAX_BASE64_SIZE, "File too large (max 10MB)"),
19-
),
16+
data: v.pipe(v.string(), v.maxLength(MAX_BASE64_SIZE, "File too large (max 10MB)")),
2017
type: v.picklist([...ACCEPTED_IMAGE_TYPES], "Unsupported image format"),
2118
name: v.pipe(v.string(), v.maxLength(255)),
2219
folder: FolderSchema,
2320
});
2421

25-
export const upload = command(
26-
UploadSchema,
27-
async ({ data, type, name, folder }) => {
28-
await requireUtCodeMember();
22+
export const upload = command(UploadSchema, async ({ data, type, name, folder }) => {
23+
await requireUtCodeMember();
2924

30-
const path = folder ?? "uploads";
31-
const inputBuffer = Buffer.from(data, "base64");
25+
const path = folder ?? "uploads";
26+
const inputBuffer = Buffer.from(data, "base64");
3227

33-
// Compress and convert to WebP
34-
const {
35-
buffer,
36-
type: outputType,
37-
extension,
38-
} = await compressImage(inputBuffer, type);
28+
// Compress and convert to WebP
29+
const { buffer, type: outputType, extension } = await compressImage(inputBuffer, type);
3930

40-
// Replace original extension with output extension
41-
const baseName = name.replace(/\.[^.]+$/, "");
42-
const outputName = `${baseName}.${extension}`;
31+
// Replace original extension with output extension
32+
const baseName = name.replace(/\.[^.]+$/, "");
33+
const outputName = `${baseName}.${extension}`;
4334

44-
return await uploadBuffer(buffer, outputType, outputName, path);
45-
},
46-
);
35+
return await uploadBuffer(buffer, outputType, outputName, path);
36+
});
4737

4838
export const remove = command(S3KeySchema, async (key) => {
4939
await requireUtCodeMember();

0 commit comments

Comments
 (0)