UNPKG

@itwin/imodels-client-management

Version:

iModels API client wrapper for applications that manage iModels.

70 lines 3.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ThumbnailOperations = void 0; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ const internal_1 = require("../../base/internal"); const types_1 = require("../../base/types"); class ThumbnailOperations extends internal_1.OperationsBase { /** * Downloads a thumbnail for a specific iModel. The Thumbnail returned is either a default one or a custom * uploaded one. Wraps the * {@link https://developer.bentley.com/apis/imodels-v2/operations/get-imodel-thumbnail/ Download iModel Thumbnail} * operation from iModels API. * @param {DownloadThumbnailParams} params parameters for this operation. See {@link DownloadThumbnailParams}. * @returns {Promise<Thumbnail>} downloaded Thumbnail. See {@link Thumbnail}. The method returns the data in binary * form which can then be consumed depending on the environment. * @example * Save data to local file (Node.js): * ``` * const thumbnail: Thumbnail = await iModelsClient.thumbnails.download({ ... }); * await fs.promises.writeFile("thumbnail.png", Buffer.from(thumbnail.data.buffer), "binary"); * ``` */ async download(params) { // By default iModels API returns a small thumbnail. We specify the size explicitly to be able // to return to user the information which thumbnail is this. const urlParams = { ...params.urlParams, size: params.urlParams?.size ?? types_1.ThumbnailSize.Small, }; const url = this._options.urlFormatter.getThumbnailUrl({ iModelId: params.iModelId, urlParams, }); const response = await this.sendGetRequest({ authorization: params.authorization, url, responseType: types_1.ContentType.Png, headers: params.headers, }); return { size: urlParams.size, imageType: types_1.ContentType.Png, image: response.body, }; } /** * Uploads a custom iModel Thumbnail. Wraps the * {@link https://developer.bentley.com/apis/imodels-v2/operations/upload-imodel-thumbnail/ Upload iModel Thumbnail} * operation from iModels API. * @param {UploadThumbnailParams} params parameters for this operation. See {@link UploadThumbnailParams}. * @returns {Promise<void>} a promise that resolves after operation completes. */ async upload(params) { const url = this._options.urlFormatter.getThumbnailUrl({ iModelId: params.iModelId, }); await this.sendPutRequest({ authorization: params.authorization, url, contentType: params.thumbnailProperties.imageType, body: params.thumbnailProperties.image, headers: params.headers, }); } } exports.ThumbnailOperations = ThumbnailOperations; //# sourceMappingURL=ThumbnailOperations.js.map