@shapediver/viewer.shared.services 2.0.4 → 2.0.5
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.
|
@@ -4,11 +4,9 @@ export declare class HttpClient {
|
|
|
4
4
|
private _dataCache;
|
|
5
5
|
private _sessionLoading;
|
|
6
6
|
constructor();
|
|
7
|
-
private
|
|
7
|
+
private getSessionId;
|
|
8
8
|
addDataLoading(sessionId: string, callbacks: {
|
|
9
|
-
|
|
10
|
-
getTexture: (sessionId: string, assetData: string) => Promise<[ArrayBuffer, string]>;
|
|
11
|
-
getExport: (sessionId: string, assetData: string) => Promise<[ArrayBuffer, string]>;
|
|
9
|
+
getAsset: (url: string) => Promise<[ArrayBuffer, string, string]>;
|
|
12
10
|
downloadTexture: (sessionId: string, url: string) => Promise<[ArrayBuffer, string]>;
|
|
13
11
|
}): void;
|
|
14
12
|
get(href: string, config?: AxiosRequestConfig, textureLoading?: boolean): Promise<HttpResponse<any>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpClient.d.ts","sourceRoot":"","sources":["../../src/http-client/HttpClient.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAGjD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,qBACa,UAAU;IAGnB,OAAO,CAAC,UAAU,CAEX;IAEP,OAAO,CAAC,eAAe,
|
|
1
|
+
{"version":3,"file":"HttpClient.d.ts","sourceRoot":"","sources":["../../src/http-client/HttpClient.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAGjD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,qBACa,UAAU;IAGnB,OAAO,CAAC,UAAU,CAEX;IAEP,OAAO,CAAC,eAAe,CAKhB;;IA2BP,OAAO,CAAC,YAAY;IAeb,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE;QAChD,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;QAClE,eAAe,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;KACvF;IAIY,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,kBAAoD,EAAE,cAAc,GAAE,OAAe,GAAG,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;IAiE5I,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;IAInE,iBAAiB,CAAC,SAAS,EAAE,MAAM;CAK7C"}
|
|
@@ -45,7 +45,7 @@ let HttpClient = class HttpClient {
|
|
|
45
45
|
}
|
|
46
46
|
// #endregion Constructors (1)
|
|
47
47
|
// #region Public Methods (7)
|
|
48
|
-
|
|
48
|
+
getSessionId(href) {
|
|
49
49
|
// searching for "/session/SESSION_ID/{'output' | 'export' | 'texture'}/ASSET_DATA"
|
|
50
50
|
const parts = href.split('/');
|
|
51
51
|
const sessionPartIndex = parts.indexOf('session');
|
|
@@ -55,12 +55,7 @@ let HttpClient = class HttpClient {
|
|
|
55
55
|
// no such session has been registered, should never happen
|
|
56
56
|
if (!this._sessionLoading[sessionId])
|
|
57
57
|
return;
|
|
58
|
-
|
|
59
|
-
// the type is not supported
|
|
60
|
-
if (type !== 'output' && type !== 'export' && type !== 'texture')
|
|
61
|
-
return;
|
|
62
|
-
const assetData = parts[sessionPartIndex + 3];
|
|
63
|
-
return { sessionId, assetData, type };
|
|
58
|
+
return sessionId;
|
|
64
59
|
}
|
|
65
60
|
return;
|
|
66
61
|
}
|
|
@@ -72,79 +67,57 @@ let HttpClient = class HttpClient {
|
|
|
72
67
|
const dataKey = btoa(href);
|
|
73
68
|
if (dataKey in this._dataCache)
|
|
74
69
|
return yield this._dataCache[dataKey];
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
.then(result => {
|
|
97
|
-
resolve({
|
|
98
|
-
data: result[0],
|
|
99
|
-
headers: {
|
|
100
|
-
'content-type': result[1]
|
|
101
|
-
}
|
|
102
|
-
});
|
|
70
|
+
// try to get sessionId from href
|
|
71
|
+
let sessionId = this.getSessionId(href);
|
|
72
|
+
// if href does not have sessionId, use the first sesison, if available
|
|
73
|
+
if (!sessionId && Object.keys(this._sessionLoading).length > 0)
|
|
74
|
+
sessionId = Object.keys(this._sessionLoading)[0];
|
|
75
|
+
// get the session loading functions, if available
|
|
76
|
+
let sessionLoading;
|
|
77
|
+
if (sessionId)
|
|
78
|
+
sessionLoading = this._sessionLoading[sessionId];
|
|
79
|
+
// separation texture vs everything else
|
|
80
|
+
if (textureLoading) {
|
|
81
|
+
// if we have a sessionId and the sessionLoading functions and the image is not a blob or data, we load it via the sdk
|
|
82
|
+
if (sessionLoading !== undefined && sessionId !== undefined && !href.startsWith('blob:') && !href.startsWith('data:')) {
|
|
83
|
+
// take first session to load a texture that is not session related
|
|
84
|
+
this._dataCache[dataKey] = new Promise(resolve => {
|
|
85
|
+
sessionLoading.downloadTexture(sessionId, href).then((result) => {
|
|
86
|
+
resolve({
|
|
87
|
+
data: result[0],
|
|
88
|
+
headers: {
|
|
89
|
+
'content-type': result[1]
|
|
90
|
+
}
|
|
103
91
|
});
|
|
104
92
|
});
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
resolve({
|
|
112
|
-
data: result[0],
|
|
113
|
-
headers: {
|
|
114
|
-
'content-type': result[1]
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
break;
|
|
120
|
-
default:
|
|
121
|
-
this._dataCache[dataKey] = (0, axios_1.default)(href, Object.assign({ method: 'get' }, config));
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
// we can load blobs and data urls directly
|
|
97
|
+
// or load it directly if we don't have a session
|
|
98
|
+
this._dataCache[dataKey] = (0, axios_1.default)(href, Object.assign({ method: 'get' }, config));
|
|
122
99
|
}
|
|
123
100
|
}
|
|
124
101
|
else {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
data: result[0],
|
|
139
|
-
headers: {
|
|
140
|
-
'content-type': result[1]
|
|
141
|
-
}
|
|
142
|
-
});
|
|
102
|
+
try {
|
|
103
|
+
// if there is no session to load from, we use the fallback option
|
|
104
|
+
if (!sessionLoading)
|
|
105
|
+
throw new Error();
|
|
106
|
+
// all data links where we could somehow find a session to load it with
|
|
107
|
+
this._dataCache[dataKey] = new Promise(resolve => {
|
|
108
|
+
sessionLoading.getAsset(href)
|
|
109
|
+
.then((result) => {
|
|
110
|
+
resolve({
|
|
111
|
+
data: result[0],
|
|
112
|
+
headers: {
|
|
113
|
+
'content-type': result[1]
|
|
114
|
+
}
|
|
143
115
|
});
|
|
144
116
|
});
|
|
145
|
-
}
|
|
117
|
+
});
|
|
146
118
|
}
|
|
147
|
-
|
|
119
|
+
catch (e) {
|
|
120
|
+
// if this fails, we just load it directly
|
|
148
121
|
this._dataCache[dataKey] = (0, axios_1.default)(href, Object.assign({ method: 'get' }, config));
|
|
149
122
|
}
|
|
150
123
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpClient.js","sourceRoot":"","sources":["../../src/http-client/HttpClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAiD;AACjD,uCAAoC;AACpC,6EAAmF;AAInF,IAAa,UAAU,GAAvB,MAAa,UAAU;
|
|
1
|
+
{"version":3,"file":"HttpClient.js","sourceRoot":"","sources":["../../src/http-client/HttpClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAiD;AACjD,uCAAoC;AACpC,6EAAmF;AAInF,IAAa,UAAU,GAAvB,MAAa,UAAU;IAcnB,4BAA4B;IAE5B,2BAA2B;IAE3B;QAjBA,yBAAyB;QAEjB,eAAU,GAEd,EAAE,CAAC;QAEC,oBAAe,GAKnB,EAAE,CAAC;QAOH,eAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAC3B,QAAQ,CAAC,EAAE;YACP,OAAO,QAAQ,CAAC;QACpB,CAAC,EACD,KAAK,CAAC,EAAE;YACJ,MAAM,IAAI,wDAA+B,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC3F,CAAC,CAAC,CAAC;QACP,eAAK,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAC1B,QAAQ,CAAC,EAAE;YACP,OAAO,QAAQ,CAAC;QACpB,CAAC,EACD,KAAK,CAAC,EAAE;YACJ,MAAM,IAAI,wDAA+B,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;QAC/E,CAAC,CAAC,CAAC;IACX,CAAC;IAED,8BAA8B;IAE9B,6BAA6B;IAErB,YAAY,CAAC,IAAY;QAC7B,mFAAmF;QACnF,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC9B,MAAM,gBAAgB,GAAG,KAAK,C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ACP,0CAA0C;oBAC1C,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,IAAA,eAAK,EAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;iBACpF;aACJ;YAED,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACpC,CAAC;KAAA;IAEY,WAAW,CAAC,IAAY;;YACjC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;QAC3C,CAAC;KAAA;IAEM,iBAAiB,CAAC,SAAiB;QACtC,OAAO,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;IAC3C,CAAC;CAGJ,CAAA;AAvIY,UAAU;IADtB,IAAA,oBAAS,GAAE;;GACC,UAAU,CAuItB;AAvIY,gCAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapediver/viewer.shared.services",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "Michael Oppitz <michael@shapediver.com>",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"@ctrl/tinycolor": "^3.4.0",
|
|
43
43
|
"@sentry/browser": "^6.7.2",
|
|
44
44
|
"@sentry/tracing": "^6.7.2",
|
|
45
|
-
"@shapediver/sdk.geometry-api-sdk-v2": "^1.0.
|
|
45
|
+
"@shapediver/sdk.geometry-api-sdk-v2": "^1.0.25",
|
|
46
46
|
"@shapediver/viewer.settings": "0.1.36",
|
|
47
|
-
"@shapediver/viewer.shared.build-data": "2.0.
|
|
47
|
+
"@shapediver/viewer.shared.build-data": "2.0.5",
|
|
48
48
|
"@types/dompurify": "^2.3.1",
|
|
49
49
|
"@types/ua-parser-js": "^0.7.36",
|
|
50
50
|
"@types/uuid": "^8.3.0",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"ua-parser-js": "^0.7.28",
|
|
56
56
|
"uuid": "^8.3.2"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "35de65c2189ae1c5b797e0a0d255ef2db32d2fb1"
|
|
59
59
|
}
|
|
@@ -13,9 +13,7 @@ export class HttpClient {
|
|
|
13
13
|
|
|
14
14
|
private _sessionLoading: {
|
|
15
15
|
[key: string]: {
|
|
16
|
-
|
|
17
|
-
getTexture: (sessionId: string, assetData: string) => Promise<[ArrayBuffer, string]>,
|
|
18
|
-
getExport: (sessionId: string, assetData: string) => Promise<[ArrayBuffer, string]>,
|
|
16
|
+
getAsset: (url: string) => Promise<[ArrayBuffer, string, string]>,
|
|
19
17
|
downloadTexture: (sessionId: string, url: string) => Promise<[ArrayBuffer, string]>,
|
|
20
18
|
}
|
|
21
19
|
} = {};
|
|
@@ -45,7 +43,7 @@ export class HttpClient {
|
|
|
45
43
|
|
|
46
44
|
// #region Public Methods (7)
|
|
47
45
|
|
|
48
|
-
private
|
|
46
|
+
private getSessionId(href: string): string | undefined {
|
|
49
47
|
// searching for "/session/SESSION_ID/{'output' | 'export' | 'texture'}/ASSET_DATA"
|
|
50
48
|
const parts = href.split('/');
|
|
51
49
|
const sessionPartIndex = parts.indexOf('session');
|
|
@@ -55,23 +53,13 @@ export class HttpClient {
|
|
|
55
53
|
const sessionId = parts[sessionPartIndex + 1];
|
|
56
54
|
// no such session has been registered, should never happen
|
|
57
55
|
if (!this._sessionLoading[sessionId]) return;
|
|
58
|
-
|
|
59
|
-
const type = parts[sessionPartIndex + 2];
|
|
60
|
-
// the type is not supported
|
|
61
|
-
if (type !== 'output' && type !== 'export' && type !== 'texture') return;
|
|
62
|
-
|
|
63
|
-
const assetData = parts[sessionPartIndex + 3];
|
|
64
|
-
|
|
65
|
-
return { sessionId, assetData, type };
|
|
56
|
+
return sessionId;
|
|
66
57
|
}
|
|
67
|
-
|
|
68
58
|
return;
|
|
69
59
|
}
|
|
70
60
|
|
|
71
61
|
public addDataLoading(sessionId: string, callbacks: {
|
|
72
|
-
|
|
73
|
-
getTexture: (sessionId: string, assetData: string) => Promise<[ArrayBuffer, string]>,
|
|
74
|
-
getExport: (sessionId: string, assetData: string) => Promise<[ArrayBuffer, string]>,
|
|
62
|
+
getAsset: (url: string) => Promise<[ArrayBuffer, string, string]>,
|
|
75
63
|
downloadTexture: (sessionId: string, url: string) => Promise<[ArrayBuffer, string]>,
|
|
76
64
|
}) {
|
|
77
65
|
this._sessionLoading[sessionId] = callbacks;
|
|
@@ -80,88 +68,65 @@ export class HttpClient {
|
|
|
80
68
|
public async get(href: string, config: AxiosRequestConfig = { responseType: 'arraybuffer' }, textureLoading: boolean = false): Promise<HttpResponse<any>> {
|
|
81
69
|
const dataKey = btoa(href);
|
|
82
70
|
if (dataKey in this._dataCache) return await this._dataCache[dataKey];
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
})
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
});
|
|
117
|
-
break;
|
|
118
|
-
|
|
119
|
-
case 'texture':
|
|
120
|
-
this._dataCache[dataKey] = new Promise<HttpResponse<ArrayBuffer>>(resolve => {
|
|
121
|
-
this._sessionLoading[loadingInfo.sessionId]
|
|
122
|
-
.getTexture(loadingInfo.sessionId, loadingInfo.assetData)
|
|
123
|
-
.then(result => {
|
|
124
|
-
resolve({
|
|
125
|
-
data: result[0],
|
|
126
|
-
headers: {
|
|
127
|
-
'content-type': result[1]
|
|
128
|
-
}
|
|
129
|
-
})
|
|
130
|
-
})
|
|
131
|
-
|
|
71
|
+
|
|
72
|
+
// try to get sessionId from href
|
|
73
|
+
let sessionId = this.getSessionId(href);
|
|
74
|
+
|
|
75
|
+
// if href does not have sessionId, use the first sesison, if available
|
|
76
|
+
if(!sessionId && Object.keys(this._sessionLoading).length > 0)
|
|
77
|
+
sessionId = Object.keys(this._sessionLoading)[0];
|
|
78
|
+
|
|
79
|
+
// get the session loading functions, if available
|
|
80
|
+
let sessionLoading: {
|
|
81
|
+
getAsset: (url: string) => Promise<[ArrayBuffer, string, string]>,
|
|
82
|
+
downloadTexture: (sessionId: string, url: string) => Promise<[ArrayBuffer, string]>,
|
|
83
|
+
} | undefined;
|
|
84
|
+
if(sessionId)
|
|
85
|
+
sessionLoading = this._sessionLoading[sessionId];
|
|
86
|
+
|
|
87
|
+
// separation texture vs everything else
|
|
88
|
+
if(textureLoading) {
|
|
89
|
+
// if we have a sessionId and the sessionLoading functions and the image is not a blob or data, we load it via the sdk
|
|
90
|
+
if(sessionLoading !== undefined && sessionId !== undefined && !href.startsWith('blob:') && !href.startsWith('data:')) {
|
|
91
|
+
// take first session to load a texture that is not session related
|
|
92
|
+
this._dataCache[dataKey] = new Promise<HttpResponse<any>>(resolve => {
|
|
93
|
+
sessionLoading!.downloadTexture(sessionId!, href).then((result) => {
|
|
94
|
+
resolve({
|
|
95
|
+
data: result[0],
|
|
96
|
+
headers: {
|
|
97
|
+
'content-type': result[1]
|
|
98
|
+
}
|
|
99
|
+
})
|
|
132
100
|
});
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
101
|
+
});
|
|
102
|
+
} else {
|
|
103
|
+
// we can load blobs and data urls directly
|
|
104
|
+
// or load it directly if we don't have a session
|
|
105
|
+
this._dataCache[dataKey] = axios(href, Object.assign({ method: 'get' }, config));
|
|
137
106
|
}
|
|
138
107
|
} else {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const sessionId = Object.keys(this._sessionLoading)[0];
|
|
148
|
-
|
|
149
|
-
this._dataCache[dataKey] = new Promise<HttpResponse<any>>(resolve => {
|
|
150
|
-
this._sessionLoading[sessionId].downloadTexture(sessionId, href).then((result) => {
|
|
108
|
+
try{
|
|
109
|
+
// if there is no session to load from, we use the fallback option
|
|
110
|
+
if(!sessionLoading) throw new Error();
|
|
111
|
+
|
|
112
|
+
// all data links where we could somehow find a session to load it with
|
|
113
|
+
this._dataCache[dataKey] = new Promise<HttpResponse<ArrayBuffer>>(resolve => {
|
|
114
|
+
sessionLoading!.getAsset(href)
|
|
115
|
+
.then((result) => {
|
|
151
116
|
resolve({
|
|
152
117
|
data: result[0],
|
|
153
118
|
headers: {
|
|
154
119
|
'content-type': result[1]
|
|
155
120
|
}
|
|
156
121
|
})
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
122
|
+
})
|
|
123
|
+
});
|
|
124
|
+
} catch(e) {
|
|
125
|
+
// if this fails, we just load it directly
|
|
161
126
|
this._dataCache[dataKey] = axios(href, Object.assign({ method: 'get' }, config));
|
|
162
127
|
}
|
|
163
128
|
}
|
|
164
|
-
|
|
129
|
+
|
|
165
130
|
return this._dataCache[dataKey];
|
|
166
131
|
}
|
|
167
132
|
|