robodev 0.22.0 → 0.23.0
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/package.json
CHANGED
|
@@ -342,6 +342,12 @@ export async function validateAlien(
|
|
|
342
342
|
const ALLOWED_PLANET_IMAGE_TYPES = new Set(["image/jpeg", "image/png", "image/webp"]);
|
|
343
343
|
const MAX_PLANET_IMAGE_BYTES = 2 * 1024 * 1024;
|
|
344
344
|
|
|
345
|
+
/** Matches dashboard sanitizeFilename / KEY_RE. */
|
|
346
|
+
function sanitizeFilename(name: string): string {
|
|
347
|
+
const base = name.split(/[/\\]/).pop() ?? "";
|
|
348
|
+
return base.replace(/[^A-Za-z0-9._-]+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 80);
|
|
349
|
+
}
|
|
350
|
+
|
|
345
351
|
export async function savePlanetImage(
|
|
346
352
|
ctx: ApiHandlerContext<unknown, unknown>,
|
|
347
353
|
file: UploadedFile,
|
|
@@ -354,8 +360,9 @@ export async function savePlanetImage(
|
|
|
354
360
|
return fail(400, "Unsupported image type");
|
|
355
361
|
}
|
|
356
362
|
|
|
357
|
-
const fileName =
|
|
358
|
-
const
|
|
363
|
+
const fileName = file.filename || "image";
|
|
364
|
+
const safe = sanitizeFilename(fileName) || "image";
|
|
365
|
+
const key = `planet-images/${ctx.user!.id}/${crypto.randomUUID()}-${safe}`;
|
|
359
366
|
const [row] = await ctx.db
|
|
360
367
|
.insert(media)
|
|
361
368
|
.values({
|
|
@@ -342,6 +342,12 @@ export async function validateAlien(
|
|
|
342
342
|
const ALLOWED_PLANET_IMAGE_TYPES = new Set(["image/jpeg", "image/png", "image/webp"]);
|
|
343
343
|
const MAX_PLANET_IMAGE_BYTES = 2 * 1024 * 1024;
|
|
344
344
|
|
|
345
|
+
/** Matches dashboard sanitizeFilename / KEY_RE. */
|
|
346
|
+
function sanitizeFilename(name: string): string {
|
|
347
|
+
const base = name.split(/[/\\]/).pop() ?? "";
|
|
348
|
+
return base.replace(/[^A-Za-z0-9._-]+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 80);
|
|
349
|
+
}
|
|
350
|
+
|
|
345
351
|
export async function savePlanetImage(
|
|
346
352
|
ctx: ApiHandlerContext<unknown, unknown>,
|
|
347
353
|
file: UploadedFile,
|
|
@@ -354,8 +360,9 @@ export async function savePlanetImage(
|
|
|
354
360
|
return fail(400, "Unsupported image type");
|
|
355
361
|
}
|
|
356
362
|
|
|
357
|
-
const fileName =
|
|
358
|
-
const
|
|
363
|
+
const fileName = file.filename || "image";
|
|
364
|
+
const safe = sanitizeFilename(fileName) || "image";
|
|
365
|
+
const key = `planet-images/${ctx.user!.id}/${crypto.randomUUID()}-${safe}`;
|
|
359
366
|
const [row] = await ctx.db
|
|
360
367
|
.insert(media)
|
|
361
368
|
.values({
|