@abi-software/scaffoldvuer 1.17.0 → 1.17.1-beta.0
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/package.json +1 -1
- package/src/app/DropZone.vue +10 -91
- package/src/scripts/LocalFilesHelper.js +142 -0
package/package.json
CHANGED
package/src/app/DropZone.vue
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
/* eslint-disable no-alert, no-console */
|
|
16
16
|
import { markRaw } from 'vue';
|
|
17
17
|
import { SimpleDropzone } from "simple-dropzone";
|
|
18
|
-
import
|
|
18
|
+
import { createURLFromFiles } from "../scripts/LocalFilesHelper.js";
|
|
19
19
|
|
|
20
20
|
const getJSON = async (URL) => {
|
|
21
21
|
return fetch(URL)
|
|
@@ -44,107 +44,26 @@ export default {
|
|
|
44
44
|
findRealFilename: function(objectURL) {
|
|
45
45
|
return this.filesMapping[objectURL]
|
|
46
46
|
},
|
|
47
|
-
processTextureFile: function(textureData, flatarray) {
|
|
48
|
-
if (textureData && textureData.images && textureData.images.source) {
|
|
49
|
-
const images = textureData.images.source;
|
|
50
|
-
for (let i = 0; i < images.length; i++) {
|
|
51
|
-
const index = flatarray.findIndex(element => {
|
|
52
|
-
return element[0].includes(images[i]);
|
|
53
|
-
});
|
|
54
|
-
if (index > -1) {
|
|
55
|
-
const objectURL = URL.createObjectURL(flatarray[index][1]);
|
|
56
|
-
this.objectURLs.push(objectURL);
|
|
57
|
-
textureData.images.source[i] = objectURL;
|
|
58
|
-
this.filesMapping[objectURL] = images[i];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
const content = JSON.stringify(textureData);
|
|
62
|
-
let blob = new Blob([content], { type: "application/json" });
|
|
63
|
-
return URL.createObjectURL(blob);
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
createMetadataObjectURLs: async function (text, list, flatarray) {
|
|
67
|
-
let content = text;
|
|
68
|
-
for (const [key, file] of Object.entries(list)) {
|
|
69
|
-
if (content.includes(key)) {
|
|
70
|
-
const objectURL = URL.createObjectURL(file);
|
|
71
|
-
const re = new RegExp(key, "g");
|
|
72
|
-
content = content.replace(re, objectURL);
|
|
73
|
-
this.objectURLs.push(objectURL);
|
|
74
|
-
this.filesMapping[objectURL] = key;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
const data = JSON.parse(content);
|
|
78
|
-
for (let i = 0; i < data.length; i++) {
|
|
79
|
-
if (data[i] && data[i].Type) {
|
|
80
|
-
if (data[i].Type === "Texture") {
|
|
81
|
-
const textureData = await getJSON(data[i].URL);
|
|
82
|
-
URL.revokeObjectURL(data[i].URL);
|
|
83
|
-
const newURL = this.processTextureFile(textureData, flatarray)
|
|
84
|
-
data[i].URL = newURL;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
let newContent = JSON.stringify(data);
|
|
89
|
-
let blob = new Blob([newContent], { type: "application/json" });
|
|
90
|
-
const metaURL = URL.createObjectURL(blob);
|
|
91
|
-
this.objectURLs.push(metaURL);
|
|
92
|
-
this.$emit("files-drop", { url: metaURL, format : "metadata" } );
|
|
93
|
-
},
|
|
94
|
-
createGLTFURL: function (content, binary) {
|
|
95
|
-
let type = binary ? 'model/gltf+binary' : 'model/gltf+json';
|
|
96
|
-
let blob = new Blob([content], { type });
|
|
97
|
-
const gltfURL = URL.createObjectURL(blob);
|
|
98
|
-
this.objectURLs.push(gltfURL);
|
|
99
|
-
this.$emit("files-drop", { url: gltfURL, format : "gltf" });
|
|
100
|
-
},
|
|
101
47
|
revokeURLs: function () {
|
|
102
48
|
this.objectURLs.forEach(objectURL => URL.revokeObjectURL(objectURL));
|
|
103
49
|
this.objectURLs.length = 0;
|
|
104
50
|
this.filesMapping = markRaw({});
|
|
105
51
|
},
|
|
106
|
-
localDrop: function (fileMap) {
|
|
52
|
+
localDrop: async function (fileMap) {
|
|
107
53
|
this.revokeURLs();
|
|
108
|
-
const dataMaps = {};
|
|
109
|
-
let list = {};
|
|
110
|
-
let metadata = undefined;
|
|
111
|
-
let gltf = undefined;
|
|
112
|
-
let binary = false;
|
|
113
54
|
const flatarray = Array.from(fileMap);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
metadata = { rootPath, file: flatarray[i][1] };
|
|
119
|
-
break;
|
|
55
|
+
const data = await createURLFromFiles(flatarray);
|
|
56
|
+
if (data) {
|
|
57
|
+
if (data.objectURLs?.length > 0) {
|
|
58
|
+
this.objectURLs.push(...data.objectURLs);
|
|
120
59
|
}
|
|
121
|
-
if (
|
|
122
|
-
|
|
123
|
-
binary = true;
|
|
124
|
-
break;
|
|
60
|
+
if (data.filesMapping) {
|
|
61
|
+
Object.assign(this.filesMapping, data.filesMapping);
|
|
125
62
|
}
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
binary = false;
|
|
129
|
-
break;
|
|
63
|
+
if (data.format && data.url) {
|
|
64
|
+
this.$emit("files-drop", { url: data.url, format : data.format } );
|
|
130
65
|
}
|
|
131
66
|
}
|
|
132
|
-
if (metadata) {
|
|
133
|
-
flatarray.forEach(([filePath, file]) => {
|
|
134
|
-
if (file.name.match(/\.(json)$/)) {
|
|
135
|
-
const relativePath = path.relative(rootPath, filePath);
|
|
136
|
-
list[relativePath] = file;
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
const metaFileURL = URL.createObjectURL(metadata.file);
|
|
140
|
-
fetch(metaFileURL)
|
|
141
|
-
.then((response) => response.text())
|
|
142
|
-
.then((text) => this.createMetadataObjectURLs(text, list, flatarray));
|
|
143
|
-
URL.revokeObjectURL(metaFileURL);
|
|
144
|
-
}
|
|
145
|
-
if (gltf) {
|
|
146
|
-
this.createGLTFURL(gltf.file, binary);
|
|
147
|
-
}
|
|
148
67
|
},
|
|
149
68
|
},
|
|
150
69
|
};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
const getRelativePath = (from, to) => {
|
|
2
|
+
const fromParts = from.split('/').filter(Boolean);
|
|
3
|
+
const toParts = to.split('/').filter(Boolean);
|
|
4
|
+
while (fromParts.length && toParts.length && fromParts[0] === toParts[0]) {
|
|
5
|
+
fromParts.shift();
|
|
6
|
+
toParts.shift();
|
|
7
|
+
}
|
|
8
|
+
const upSteps = new Array(fromParts.length).fill('..');
|
|
9
|
+
return [...upSteps, ...toParts].join('/') || '.';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const processTextureFile = (textureData, flatarray, objectURLs, filesMapping) => {
|
|
13
|
+
if (textureData && textureData.images && textureData.images.source) {
|
|
14
|
+
const images = textureData.images.source;
|
|
15
|
+
for (let i = 0; i < images.length; i++) {
|
|
16
|
+
const index = flatarray.findIndex(element => {
|
|
17
|
+
return element[0].includes(images[i]);
|
|
18
|
+
});
|
|
19
|
+
if (index > -1) {
|
|
20
|
+
const objectURL = URL.createObjectURL(flatarray[index][1]);
|
|
21
|
+
objectURLs.push(objectURL);
|
|
22
|
+
textureData.images.source[i] = objectURL;
|
|
23
|
+
filesMapping[objectURL] = images[i];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const content = JSON.stringify(textureData);
|
|
27
|
+
let blob = new Blob([content], { type: "application/json" });
|
|
28
|
+
return URL.createObjectURL(blob)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const getJSON = async (URL) => {
|
|
33
|
+
return fetch(URL)
|
|
34
|
+
.then((response) => response.json())
|
|
35
|
+
.then((responseJson) => {return responseJson});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const createMetadataObjectURLs = async (text, list, flatarray) => {
|
|
39
|
+
let content = text;
|
|
40
|
+
const objectURLs = [];
|
|
41
|
+
const filesMapping = [];
|
|
42
|
+
for (const [key, file] of Object.entries(list)) {
|
|
43
|
+
if (content.includes(key)) {
|
|
44
|
+
const objectURL = URL.createObjectURL(file);
|
|
45
|
+
const re = new RegExp(key, "g");
|
|
46
|
+
content = content.replace(re, objectURL);
|
|
47
|
+
objectURLs.push(objectURL);
|
|
48
|
+
filesMapping[objectURL] = key;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const data = JSON.parse(content);
|
|
52
|
+
for (let i = 0; i < data.length; i++) {
|
|
53
|
+
if (data[i] && data[i].Type) {
|
|
54
|
+
if (data[i].Type === "Texture") {
|
|
55
|
+
const textureData = await getJSON(data[i].URL);
|
|
56
|
+
URL.revokeObjectURL(data[i].URL);
|
|
57
|
+
const newURL = processTextureFile(textureData, flatarray, objectURLs,
|
|
58
|
+
filesMapping);
|
|
59
|
+
data[i].URL = newURL;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
let newContent = JSON.stringify(data);
|
|
64
|
+
let blob = new Blob([newContent], { type: "application/json" });
|
|
65
|
+
const metaURL = URL.createObjectURL(blob);
|
|
66
|
+
objectURLs.push(metaURL);
|
|
67
|
+
return {
|
|
68
|
+
objectURLs,
|
|
69
|
+
filesMapping,
|
|
70
|
+
url: metaURL,
|
|
71
|
+
format: "metadata"
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const createNiftiURL = (content, zipped) => {
|
|
76
|
+
let type = zipped ? 'application/x-gzip' : 'image/nii';
|
|
77
|
+
let blob = new Blob([content], { type });
|
|
78
|
+
const url = URL.createObjectURL(blob);
|
|
79
|
+
return url;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const createGLTFURL = (content, binary) => {
|
|
83
|
+
let type = binary ? 'model/gltf+binary' : 'model/gltf+json';
|
|
84
|
+
let blob = new Blob([content], { type });
|
|
85
|
+
const gltfURL = URL.createObjectURL(blob);
|
|
86
|
+
const objectURLs = [ gltfURL ];
|
|
87
|
+
return {
|
|
88
|
+
objectURLs,
|
|
89
|
+
url: gltfURL,
|
|
90
|
+
format: "gltfURL"
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const createURLFromFiles = async (flatarray) => {
|
|
95
|
+
let list = {};
|
|
96
|
+
let rootPath = "";
|
|
97
|
+
let metadata = undefined;
|
|
98
|
+
let gltf = undefined;
|
|
99
|
+
let binary = false;
|
|
100
|
+
for (let i = 0; i < flatarray.length; i++) {
|
|
101
|
+
if (flatarray[i][1].name.includes("metadata.json")) {
|
|
102
|
+
rootPath = flatarray[i][0].replace(flatarray[i][1].name, "");
|
|
103
|
+
metadata = { rootPath, file: flatarray[i][1] };
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
if (flatarray[i][1].name.includes(".glb")) {
|
|
107
|
+
gltf = { rootPath, file: flatarray[i][1] };
|
|
108
|
+
binary = true;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
if (flatarray[i][1].name.includes(".gltf")) {
|
|
112
|
+
gltf = { rootPath, file: flatarray[i][1] };
|
|
113
|
+
binary = false;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (metadata) {
|
|
118
|
+
flatarray.forEach(([filePath, file]) => {
|
|
119
|
+
if (file.name.match(/\.(json)$/)) {
|
|
120
|
+
const relativePath = getRelativePath(rootPath, filePath);
|
|
121
|
+
list[relativePath] = file;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
const metaFileURL = URL.createObjectURL(metadata.file);
|
|
125
|
+
try {
|
|
126
|
+
const response = await fetch(metaFileURL);
|
|
127
|
+
if (!response.ok) {
|
|
128
|
+
throw new Error('Cant process local file');
|
|
129
|
+
}
|
|
130
|
+
const text = await response.text();
|
|
131
|
+
URL.revokeObjectURL(metaFileURL)
|
|
132
|
+
return await createMetadataObjectURLs(text, list, flatarray);
|
|
133
|
+
} catch (error) {
|
|
134
|
+
console.error("Fetch failed:", error);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (gltf) {
|
|
138
|
+
return createGLTFURL(gltf.file, binary);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { createNiftiURL, createURLFromFiles }
|