generated from nhcarrigan/template
fix: handle base64 in game service
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
|||||||
validateUrl,
|
validateUrl,
|
||||||
validateRating,
|
validateRating,
|
||||||
validateStringLength,
|
validateStringLength,
|
||||||
|
validateDataUrl,
|
||||||
MAX_LENGTHS,
|
MAX_LENGTHS,
|
||||||
} from "../utils/validation";
|
} from "../utils/validation";
|
||||||
|
|
||||||
@@ -42,9 +43,24 @@ export class GameService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate cover image URL
|
// Validate cover image URL
|
||||||
if (data.coverImage && !validateUrl(data.coverImage)) {
|
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.");
|
throw new Error("Invalid cover image URL. Only http and https URLs are allowed.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Validate tags
|
// Validate tags
|
||||||
if (data.tags) {
|
if (data.tags) {
|
||||||
|
|||||||
Reference in New Issue
Block a user