Fix Asset detection from path (#578)
* Fix Asset detection from path * do not override fileName * Generilize extension multi split detection
This commit is contained in:
Родитель
6a84effee7
Коммит
5cd7e9128e
|
@ -57,6 +57,12 @@ describe("Asset Service", () => {
|
|||
expect(asset.type).toEqual(AssetType.Video);
|
||||
});
|
||||
|
||||
it("detects a video asset by common file extension", () => {
|
||||
const path = "C:\\dir1\\dir2\\asset1.mp4#t=5";
|
||||
const asset = AssetService.createAssetFromFilePath(path);
|
||||
expect(asset.type).toEqual(AssetType.Video);
|
||||
});
|
||||
|
||||
it("detects a tfrecord asset by common file extension", () => {
|
||||
const path = "C:\\dir1\\dir2\\asset1.tfrecord";
|
||||
const asset = AssetService.createAssetFromFilePath(path);
|
||||
|
@ -68,6 +74,18 @@ describe("Asset Service", () => {
|
|||
const asset = AssetService.createAssetFromFilePath(path);
|
||||
expect(asset.type).toEqual(AssetType.Unknown);
|
||||
});
|
||||
|
||||
it("detects an asset in case asset name contains other file extension in the middle", () => {
|
||||
const path = "C:\\dir1\\dir2\\asset1.docx.jpg";
|
||||
const asset = AssetService.createAssetFromFilePath(path);
|
||||
expect(asset.type).toEqual(AssetType.Image);
|
||||
});
|
||||
|
||||
it("detects an asset in case asset name contains other file extension in the middle", () => {
|
||||
const path = "C:\\dir1\\dir2\\asset1.jpg.docx";
|
||||
const asset = AssetService.createAssetFromFilePath(path);
|
||||
expect(asset.type).toEqual(AssetType.Unknown);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Instance Methods", () => {
|
||||
|
|
|
@ -33,9 +33,11 @@ export class AssetService {
|
|||
// fileNameParts[0] = "video"
|
||||
// fileNameParts[1] = "mp4"
|
||||
// fileNameParts[2] = "t=5"
|
||||
const fileNameParts = pathParts[pathParts.length - 1].split(/[\.\?#]/);
|
||||
fileName = fileName || `${fileNameParts[0]}.${fileNameParts[1]}`;
|
||||
const assetFormat = fileNameParts.length >= 2 ? fileNameParts[1] : "";
|
||||
fileName = fileName || pathParts[pathParts.length - 1];
|
||||
const fileNameParts = fileName.split(".");
|
||||
const extensionParts = fileNameParts[fileNameParts.length - 1].split(/[\?#]/);
|
||||
const assetFormat = extensionParts[0];
|
||||
|
||||
const assetType = this.getAssetType(assetFormat);
|
||||
|
||||
return {
|
||||
|
|
Загрузка…
Ссылка в новой задаче