nuxt-media-library 0.0.55 → 0.0.56
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/module.json
CHANGED
|
@@ -6,7 +6,7 @@ import { createServiceUpload } from "../utils/uploader/serviceUpload.js";
|
|
|
6
6
|
import {
|
|
7
7
|
resolveServiceUpload
|
|
8
8
|
} from "../utils/uploader/serviceBackends.js";
|
|
9
|
-
import { kindForFile } from "../utils/fileAccept.js";
|
|
9
|
+
import { kindForFile, mimeForFile } from "../utils/fileAccept.js";
|
|
10
10
|
import { useMLChunkUploader } from "./useMLChunkUploader.js";
|
|
11
11
|
import { useMLProcessingStatus } from "./useMLProcessingStatus.js";
|
|
12
12
|
let seq = 0;
|
|
@@ -97,6 +97,7 @@ export function useMLMediaUpload(defaults = {}) {
|
|
|
97
97
|
async function uploadViaNuxt() {
|
|
98
98
|
uploader = new ChunkUploader(cfg);
|
|
99
99
|
const create = {
|
|
100
|
+
mime_type: mimeForFile(file),
|
|
100
101
|
kind,
|
|
101
102
|
visibility: opts.visibility,
|
|
102
103
|
processing_config: opts.processingConfig,
|
|
@@ -22,5 +22,11 @@ export declare function partitionFiles(files: readonly File[], opts?: FileFilter
|
|
|
22
22
|
* sessions must send `kind`; the service no longer infers it.
|
|
23
23
|
*/
|
|
24
24
|
export declare function kindForFile(file: Pick<File, 'name' | 'type'>): string;
|
|
25
|
+
/**
|
|
26
|
+
* The MIME type an upload session should declare for a file. The server
|
|
27
|
+
* requires one, and browsers leave `File.type` empty for many extensions
|
|
28
|
+
* (e.g. `.glb`): fall back to the extension, then `application/octet-stream`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function mimeForFile(file: Pick<File, 'name' | 'type'>): string;
|
|
25
31
|
/** "image,video" → "images and videos", for messages such as "This field takes …". */
|
|
26
32
|
export declare function describeKinds(kinds: readonly string[] | string | null | undefined): string;
|
|
@@ -84,6 +84,35 @@ export function kindForFile(file) {
|
|
|
84
84
|
const ext = /\.([a-z0-9]{1,8})$/i.exec(file.name)?.[1]?.toLowerCase() ?? "";
|
|
85
85
|
return EXT_KIND[ext] ?? "other";
|
|
86
86
|
}
|
|
87
|
+
const EXT_MIME = {
|
|
88
|
+
glb: "model/gltf-binary",
|
|
89
|
+
gltf: "model/gltf+json",
|
|
90
|
+
obj: "application/octet-stream",
|
|
91
|
+
fbx: "application/octet-stream",
|
|
92
|
+
stl: "application/octet-stream",
|
|
93
|
+
usdz: "application/octet-stream",
|
|
94
|
+
zip: "application/zip",
|
|
95
|
+
tar: "application/x-tar",
|
|
96
|
+
gz: "application/gzip",
|
|
97
|
+
tgz: "application/gzip",
|
|
98
|
+
"7z": "application/x-7z-compressed",
|
|
99
|
+
rar: "application/x-rar-compressed",
|
|
100
|
+
md: "text/markdown",
|
|
101
|
+
txt: "text/plain",
|
|
102
|
+
csv: "text/csv",
|
|
103
|
+
woff: "font/woff",
|
|
104
|
+
woff2: "font/woff2",
|
|
105
|
+
ttf: "font/ttf",
|
|
106
|
+
otf: "font/otf",
|
|
107
|
+
heic: "image/heic",
|
|
108
|
+
heif: "image/heif",
|
|
109
|
+
mkv: "video/x-matroska"
|
|
110
|
+
};
|
|
111
|
+
export function mimeForFile(file) {
|
|
112
|
+
if (file.type) return file.type;
|
|
113
|
+
const ext = /\.([a-z0-9]{1,8})$/i.exec(file.name)?.[1]?.toLowerCase() ?? "";
|
|
114
|
+
return EXT_MIME[ext] ?? "application/octet-stream";
|
|
115
|
+
}
|
|
87
116
|
export function describeKinds(kinds) {
|
|
88
117
|
const NAMES = {
|
|
89
118
|
image: "images",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { mimeForFile } from "../fileAccept.js";
|
|
1
2
|
const SESSIONS = "/manage/uploads/sessions";
|
|
2
3
|
const DEFAULT_PART_SIZE = 8 * 1024 * 1024;
|
|
3
4
|
const MIN_REFRESH_DELAY_MS = 1e3;
|
|
@@ -34,7 +35,7 @@ export function createServiceUpload(deps) {
|
|
|
34
35
|
method: "POST",
|
|
35
36
|
headers: options.headers,
|
|
36
37
|
body: {
|
|
37
|
-
mimeType: file
|
|
38
|
+
mimeType: mimeForFile(file),
|
|
38
39
|
sizeBytes: file.size,
|
|
39
40
|
filename: file.name,
|
|
40
41
|
...options.body
|
|
@@ -89,7 +90,7 @@ export function createServiceUpload(deps) {
|
|
|
89
90
|
try {
|
|
90
91
|
const result = await uploader.uploadFile(file, {
|
|
91
92
|
sessionId,
|
|
92
|
-
create: { mime_type: file
|
|
93
|
+
create: { mime_type: mimeForFile(file) },
|
|
93
94
|
onProgress: options.onProgress,
|
|
94
95
|
onState: options.onState
|
|
95
96
|
});
|