Further truncate Openinary paths to 25 chars to prevent Next.js cache ENAMETOOLONG errors
This commit is contained in:
+6
-6
@@ -14,9 +14,9 @@ export async function uploadToOpeninary(file: File, folder: string = "marmarislo
|
||||
.split('/')
|
||||
.filter(Boolean) // Avoid double slashes in folder path
|
||||
.map(part => {
|
||||
if (part.length > 50) {
|
||||
const hash = crypto.createHash('md5').update(part).digest('hex').substring(0, 8);
|
||||
return `${part.substring(0, 40)}-${hash}`;
|
||||
if (part.length > 25) {
|
||||
const hash = crypto.createHash('md5').update(part).digest('hex').substring(0, 5);
|
||||
return `${part.substring(0, 20)}-${hash}`;
|
||||
}
|
||||
return part;
|
||||
})
|
||||
@@ -27,9 +27,9 @@ export async function uploadToOpeninary(file: File, folder: string = "marmarislo
|
||||
const ext = lastDotIndex !== -1 ? file.name.substring(lastDotIndex) : '';
|
||||
let nameWithoutExt = lastDotIndex !== -1 ? file.name.substring(0, lastDotIndex) : file.name;
|
||||
|
||||
if (nameWithoutExt.length > 50) {
|
||||
const hash = crypto.createHash('md5').update(nameWithoutExt).digest('hex').substring(0, 8);
|
||||
nameWithoutExt = `${nameWithoutExt.substring(0, 40)}-${hash}`;
|
||||
if (nameWithoutExt.length > 25) {
|
||||
const hash = crypto.createHash('md5').update(nameWithoutExt).digest('hex').substring(0, 5);
|
||||
nameWithoutExt = `${nameWithoutExt.substring(0, 20)}-${hash}`;
|
||||
}
|
||||
const safeFileName = `${nameWithoutExt}${ext}`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user