upload and thumbnail fix
This commit is contained in:
+14
-6
@@ -201,7 +201,8 @@ exports.uploadProjectMedia = onCall(
|
||||
detectedContentType = meta?.contentType || "";
|
||||
} catch {}
|
||||
}
|
||||
const ext = path.extname(sourcePath) || guessExtension(detectedContentType);
|
||||
const ext =
|
||||
path.extname(sourcePath) || guessExtension(detectedContentType);
|
||||
inputPath = `${baseInputPath}${ext || ""}`;
|
||||
await sourceFile.download({ destination: inputPath });
|
||||
const { size } = await fs.stat(inputPath);
|
||||
@@ -228,7 +229,9 @@ exports.uploadProjectMedia = onCall(
|
||||
} else if (/^https?:\/\//i.test(uri)) {
|
||||
const downloaded = await downloadFromHttp(uri);
|
||||
buffer = downloaded.buffer;
|
||||
if (!detectedContentType) detectedContentType = downloaded.contentType;
|
||||
if (!detectedContentType) {
|
||||
detectedContentType = downloaded.contentType;
|
||||
}
|
||||
const ext = guessExtension(downloaded.contentType);
|
||||
inputPath = `${baseInputPath}${ext}`;
|
||||
logger.info("[uploadProjectMedia] Downloaded remote resource", {
|
||||
@@ -288,8 +291,13 @@ exports.uploadProjectMedia = onCall(
|
||||
|
||||
const downloadToken = crypto.randomUUID();
|
||||
const sanitizedMetadata = sanitizeMetadata(metadata);
|
||||
// If we are writing the canonical playback file, make sure contentType is correct
|
||||
const forceVideoMp4 = /\/playback\.mp4$/i.test(storagePath);
|
||||
const effectiveContentType = forceVideoMp4
|
||||
? "video/mp4"
|
||||
: finalContentType;
|
||||
const uploadMetadata = {
|
||||
contentType: finalContentType,
|
||||
contentType: effectiveContentType,
|
||||
cacheControl: "public,max-age=86400",
|
||||
metadata: {
|
||||
...sanitizedMetadata,
|
||||
@@ -302,7 +310,7 @@ exports.uploadProjectMedia = onCall(
|
||||
logger.info("[uploadProjectMedia] Uploading to bucket", {
|
||||
projectId,
|
||||
storagePath,
|
||||
finalContentType,
|
||||
finalContentType: effectiveContentType,
|
||||
finalSize,
|
||||
});
|
||||
|
||||
@@ -341,13 +349,13 @@ exports.uploadProjectMedia = onCall(
|
||||
logger.info("✅ [uploadProjectMedia] Upload terminé", {
|
||||
projectId,
|
||||
storagePath,
|
||||
contentType: finalContentType,
|
||||
contentType: effectiveContentType,
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
url: fileUrl,
|
||||
contentType: finalContentType,
|
||||
contentType: effectiveContentType,
|
||||
storagePath,
|
||||
downloadToken,
|
||||
sourcePath: hasSourcePath ? sourcePath : null,
|
||||
|
||||
Reference in New Issue
Block a user