@shapediver/viewer.shared.services
Advanced tools
Comparing version 3.2.7 to 3.2.8
@@ -5,2 +5,3 @@ import { AxiosRequestConfig } from 'axios'; | ||
export declare class HttpClient { | ||
private readonly _logger; | ||
private static _instance; | ||
@@ -55,5 +56,6 @@ private _dataCache; | ||
* Get the requested texture either as a download or from the cache. | ||
* If the texture is not available, undefined is returned. | ||
* | ||
* @param href | ||
* @returns | ||
* @param href The URL of the texture to load. | ||
* @returns Either the texture as a buffer and blob or undefined if the texture could not be loaded. | ||
*/ | ||
@@ -63,3 +65,3 @@ loadTexture(href: string): Promise<HttpResponse<{ | ||
blob: Blob; | ||
}>>; | ||
}> | undefined>; | ||
/** | ||
@@ -66,0 +68,0 @@ * Add the data loading options from a session. |
@@ -20,2 +20,3 @@ "use strict"; | ||
const base64_1 = require("../utilities/base64"); | ||
const Logger_1 = require("../logger/Logger"); | ||
class HttpClient { | ||
@@ -26,2 +27,4 @@ // #endregion Properties (7) | ||
constructor() { | ||
// #region Properties (7) | ||
this._logger = Logger_1.Logger.instance; | ||
this._dataCache = new Map(); | ||
@@ -34,8 +37,8 @@ this._enableCaching = true; | ||
// #endregion Constructors (1) | ||
// #region Public Static Accessors (1) | ||
// #region Public Static Getters And Setters (1) | ||
static get instance() { | ||
return this._instance || (this._instance = new this()); | ||
} | ||
// #endregion Public Static Accessors (1) | ||
// #region Public Accessors (6) | ||
// #endregion Public Static Getters And Setters (1) | ||
// #region Public Getters And Setters (6) | ||
get enableCaching() { | ||
@@ -61,3 +64,3 @@ return this._enableCaching; | ||
} | ||
// #endregion Public Accessors (6) | ||
// #endregion Public Getters And Setters (6) | ||
// #region Public Methods (5) | ||
@@ -184,20 +187,32 @@ /** | ||
* Get the requested texture either as a download or from the cache. | ||
* If the texture is not available, undefined is returned. | ||
* | ||
* @param href | ||
* @returns | ||
* @param href The URL of the texture to load. | ||
* @returns Either the texture as a buffer and blob or undefined if the texture could not be loaded. | ||
*/ | ||
loadTexture(href) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const response = yield this.get(href, undefined, true); | ||
const buffer = response.data; | ||
const arrayBufferView = new Uint8Array(response.data); | ||
const blob = new Blob([arrayBufferView], { type: response.headers['content-type'] }); | ||
return { | ||
data: { | ||
buffer, | ||
blob | ||
}, | ||
size: response.data.byteLength, | ||
headers: response.headers | ||
}; | ||
let result; | ||
try { | ||
const response = yield this.get(href, undefined, true); | ||
const buffer = response.data; | ||
const arrayBufferView = new Uint8Array(response.data); | ||
const blob = new Blob([arrayBufferView], { type: response.headers['content-type'] }); | ||
// assign the result | ||
result = { | ||
data: { | ||
buffer, | ||
blob | ||
}, | ||
size: response.data.byteLength, | ||
headers: response.headers | ||
}; | ||
} | ||
catch (e) { | ||
// log the error and return undefined | ||
this._logger.error(`Failed to load texture: ${e}`); | ||
} | ||
// return undefined if the texture could not be loaded | ||
// that way the loading can be continued without the texture | ||
return result; | ||
}); | ||
@@ -204,0 +219,0 @@ } |
{ | ||
"name": "@shapediver/viewer.shared.services", | ||
"version": "3.2.7", | ||
"version": "3.2.8", | ||
"description": "", | ||
@@ -45,3 +45,3 @@ "keywords": [], | ||
"@shapediver/viewer.settings": "1.0.2", | ||
"@shapediver/viewer.shared.build-data": "3.2.7", | ||
"@shapediver/viewer.shared.build-data": "3.2.8", | ||
"@types/dompurify": "^2.3.1", | ||
@@ -56,3 +56,3 @@ "@types/ua-parser-js": "^0.7.36", | ||
}, | ||
"gitHead": "d21783f03fd4f64b1e44708998c55c1685f76701" | ||
"gitHead": "a8c27c745498812d103635aeec6d5311d6e8c8e3" | ||
} |
@@ -5,7 +5,10 @@ import axios, { AxiosRequestConfig } from 'axios'; | ||
import { HttpResponse } from './HttpResponse'; | ||
import { Converter } from '../converter/Converter'; | ||
import { btoaCustom } from '../utilities/base64'; | ||
import { Logger } from '../logger/Logger'; | ||
export class HttpClient { | ||
// #region Properties (7) | ||
private readonly _logger: Logger = Logger.instance; | ||
private static _instance: HttpClient; | ||
@@ -40,3 +43,3 @@ | ||
// #region Public Static Accessors (1) | ||
// #region Public Static Getters And Setters (1) | ||
@@ -47,5 +50,5 @@ public static get instance() { | ||
// #endregion Public Static Accessors (1) | ||
// #endregion Public Static Getters And Setters (1) | ||
// #region Public Accessors (6) | ||
// #region Public Getters And Setters (6) | ||
@@ -78,3 +81,3 @@ public get enableCaching(): boolean { | ||
// #endregion Public Accessors (6) | ||
// #endregion Public Getters And Setters (6) | ||
@@ -129,3 +132,3 @@ // #region Public Methods (5) | ||
*/ | ||
public async get(href: string, config: AxiosRequestConfig = { responseType: 'arraybuffer' }, textureLoading: boolean = false): Promise<HttpResponse<unknown>> { | ||
public async get(href: string, config: AxiosRequestConfig = { responseType: 'arraybuffer' }, textureLoading: boolean = false): Promise<HttpResponse<unknown>> { | ||
const dataKey = this.hrefToDataKey(href); | ||
@@ -212,19 +215,33 @@ | ||
* Get the requested texture either as a download or from the cache. | ||
* If the texture is not available, undefined is returned. | ||
* | ||
* @param href | ||
* @returns | ||
* @param href The URL of the texture to load. | ||
* @returns Either the texture as a buffer and blob or undefined if the texture could not be loaded. | ||
*/ | ||
public async loadTexture(href: string): Promise<HttpResponse<{ buffer: ArrayBuffer, blob: Blob }>> { | ||
const response = await (this.get(href, undefined, true) as Promise<HttpResponse<ArrayBuffer>>); | ||
const buffer = response.data; | ||
const arrayBufferView = new Uint8Array( response.data ); | ||
const blob = new Blob([ arrayBufferView ], { type: response.headers['content-type'] } ); | ||
return { | ||
data: { | ||
buffer, | ||
blob | ||
}, | ||
size: response.data.byteLength, | ||
headers: response.headers | ||
}; | ||
public async loadTexture(href: string): Promise<HttpResponse<{ buffer: ArrayBuffer, blob: Blob }> | undefined> { | ||
let result: HttpResponse<{ buffer: ArrayBuffer, blob: Blob }> | undefined; | ||
try { | ||
const response = await this.get(href, undefined, true) as HttpResponse<ArrayBuffer>; | ||
const buffer = response.data; | ||
const arrayBufferView = new Uint8Array(response.data); | ||
const blob = new Blob([arrayBufferView], { type: response.headers['content-type'] }); | ||
// assign the result | ||
result = { | ||
data: { | ||
buffer, | ||
blob | ||
}, | ||
size: response.data.byteLength, | ||
headers: response.headers | ||
}; | ||
} catch (e) { | ||
// log the error and return undefined | ||
this._logger.error(`Failed to load texture: ${e}`); | ||
} | ||
// return undefined if the texture could not be loaded | ||
// that way the loading can be continued without the texture | ||
return result; | ||
} | ||
@@ -231,0 +248,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
392688
6318
+ Added@shapediver/viewer.shared.build-data@3.2.8(transitive)
- Removed@shapediver/viewer.shared.build-data@3.2.7(transitive)