@assethub/cli 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +63 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -437,6 +437,61 @@ const extensionFromMimeType = (mimeType, mediaType) => {
|
|
|
437
437
|
return 'gltf';
|
|
438
438
|
return mediaType === 'image' ? 'png' : 'glb';
|
|
439
439
|
};
|
|
440
|
+
const contentTypeFromExtension = (extension) => {
|
|
441
|
+
switch (extension.toLowerCase()) {
|
|
442
|
+
case 'png':
|
|
443
|
+
return 'image/png';
|
|
444
|
+
case 'jpg':
|
|
445
|
+
case 'jpeg':
|
|
446
|
+
return 'image/jpeg';
|
|
447
|
+
case 'webp':
|
|
448
|
+
return 'image/webp';
|
|
449
|
+
case 'gif':
|
|
450
|
+
return 'image/gif';
|
|
451
|
+
case 'bmp':
|
|
452
|
+
return 'image/bmp';
|
|
453
|
+
case 'tif':
|
|
454
|
+
case 'tiff':
|
|
455
|
+
return 'image/tiff';
|
|
456
|
+
case 'glb':
|
|
457
|
+
return 'model/gltf-binary';
|
|
458
|
+
case 'gltf':
|
|
459
|
+
return 'model/gltf+json';
|
|
460
|
+
case 'obj':
|
|
461
|
+
return 'model/obj';
|
|
462
|
+
case 'fbx':
|
|
463
|
+
return 'application/fbx';
|
|
464
|
+
case 'stl':
|
|
465
|
+
return 'model/stl';
|
|
466
|
+
case 'ply':
|
|
467
|
+
return 'text/plain';
|
|
468
|
+
case 'usdz':
|
|
469
|
+
return 'model/vnd.usdz+zip';
|
|
470
|
+
case 'usd':
|
|
471
|
+
case 'usdc':
|
|
472
|
+
return 'model/vnd.usd';
|
|
473
|
+
default:
|
|
474
|
+
return undefined;
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
const isNonspecificContentType = (contentType) => {
|
|
478
|
+
const clean = contentType?.split(';')[0]?.trim().toLowerCase() ?? '';
|
|
479
|
+
return (clean === '' ||
|
|
480
|
+
clean === 'application/octet-stream' ||
|
|
481
|
+
clean === 'binary/octet-stream');
|
|
482
|
+
};
|
|
483
|
+
const inferContentTypeFromFileName = (fileName) => {
|
|
484
|
+
const extension = extname(fileName).replace(/^\./, '');
|
|
485
|
+
if (extension === '')
|
|
486
|
+
return undefined;
|
|
487
|
+
return contentTypeFromExtension(extension);
|
|
488
|
+
};
|
|
489
|
+
const resolveUploadContentType = (fileName, explicitContentType) => {
|
|
490
|
+
if (!isNonspecificContentType(explicitContentType)) {
|
|
491
|
+
return explicitContentType;
|
|
492
|
+
}
|
|
493
|
+
return inferContentTypeFromFileName(fileName);
|
|
494
|
+
};
|
|
440
495
|
const ensureFileNameExtension = (fileName, mediaType, mimeType) => {
|
|
441
496
|
if (extname(fileName) !== '') {
|
|
442
497
|
return fileName;
|
|
@@ -699,15 +754,19 @@ const uploadSourceDescriptor = async ({ descriptor, client, mediaType, }) => {
|
|
|
699
754
|
if (descriptor.kind === 'source') {
|
|
700
755
|
return descriptor.source;
|
|
701
756
|
}
|
|
702
|
-
const file = descriptor.kind === 'file'
|
|
703
|
-
? await readBlob(descriptor.path, descriptor.contentType)
|
|
704
|
-
: descriptor.blob;
|
|
705
757
|
const fileName = descriptor.kind === 'file'
|
|
706
758
|
? basename(descriptor.path)
|
|
707
759
|
: descriptor.fileName;
|
|
760
|
+
const fileNameWithExtension = ensureFileNameExtension(fileName, mediaType, descriptor.contentType);
|
|
761
|
+
const contentType = resolveUploadContentType(fileNameWithExtension, descriptor.contentType);
|
|
762
|
+
const file = descriptor.kind === 'file'
|
|
763
|
+
? await readBlob(descriptor.path, contentType)
|
|
764
|
+
: isNonspecificContentType(descriptor.blob.type) && contentType != null
|
|
765
|
+
? new Blob([descriptor.blob], { type: contentType })
|
|
766
|
+
: descriptor.blob;
|
|
708
767
|
const upload = await client.v2.uploadFile({
|
|
709
768
|
file,
|
|
710
|
-
fileName:
|
|
769
|
+
fileName: fileNameWithExtension,
|
|
711
770
|
mediaType,
|
|
712
771
|
});
|
|
713
772
|
return { fileRef: upload.fileRef };
|