@travetto/asset
Advanced tools
Comparing version 3.1.10 to 3.1.11
{ | ||
"name": "@travetto/asset", | ||
"version": "3.1.10", | ||
"version": "3.1.11", | ||
"description": "Modular library for storing and retrieving binary assets", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -52,3 +52,7 @@ import fs from 'fs/promises'; | ||
const buffer = await this.readChunk(filePath, 4100); | ||
return fileType.fromBuffer(buffer); | ||
const matched = await fileType.fromBuffer(buffer); | ||
if (matched?.mime === 'video/mp4' && filePath.endsWith('.m4a')) { | ||
return { ext: '.m4a', mime: 'audio/mpeg' }; | ||
} | ||
return matched; | ||
} | ||
@@ -63,3 +67,4 @@ | ||
const ext = mime.getExtension(type); | ||
const newFile = filePath.replace(/[.][^.]+$/, ext!); | ||
const baseName = path.basename(filePath, path.extname(filePath)); | ||
const newFile = `${baseName}.${ext}`; | ||
@@ -78,12 +83,11 @@ if (filePath !== newFile) { | ||
static async resolveFileType(pth: string): Promise<string> { | ||
let contentType = path.extname(pth); | ||
const detected = await this.detectFileType(pth); | ||
let contentType: string | undefined | null = undefined; | ||
if (detected) { | ||
if (!detected || detected.mime === 'application/octet-stream') { | ||
contentType = mime.getType(pth); | ||
} else { | ||
contentType = detected.mime; | ||
} else { | ||
contentType = mime.getType(pth) ?? contentType; | ||
} | ||
return contentType; | ||
return contentType ?? 'application/octet-stream'; | ||
} | ||
@@ -103,3 +107,4 @@ | ||
filename = path.basename(file); | ||
if (!filename.includes('.')) { | ||
const extName = path.extname(file); | ||
if (!extName) { | ||
const ext = mime.getExtension(contentType); | ||
@@ -106,0 +111,0 @@ if (ext) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26839
17
330