fix: handle base64 in manga service
Node.js CI / CI (pull_request) Failing after 2m8s
Security Scan and Upload / Security & DefectDojo Upload (pull_request) Successful in 2m10s

This commit is contained in:
2026-02-20 16:46:59 -08:00
parent 4b2a8e6fed
commit 08e25d9f60
+18 -2
View File
@@ -10,6 +10,7 @@ import {
validateUrl,
validateRating,
validateStringLength,
validateDataUrl,
MAX_LENGTHS,
} from "../utils/validation";
@@ -42,8 +43,23 @@ export class MangaService {
}
// Validate cover image URL
if (data.coverImage && !validateUrl(data.coverImage)) {
throw new Error("Invalid cover image URL. Only http and https URLs are allowed.");
if (data.coverImage) {
if (data.coverImage.startsWith("data:")) {
const sizeInBytes = data.coverImage.length * 0.75;
if (sizeInBytes > MAX_LENGTHS.DATA_URL) {
throw new Error("Cover image must be under 5MB.");
}
if (!validateDataUrl(data.coverImage)) {
throw new Error("Invalid image data URL.");
}
} else {
if (!validateStringLength(data.coverImage, MAX_LENGTHS.URL)) {
throw new Error(`Cover image URL must be ${MAX_LENGTHS.URL} characters or less.`);
}
if (!validateUrl(data.coverImage)) {
throw new Error("Invalid cover image URL. Only http and https URLs are allowed.");
}
}
}
// Validate tags