UNPKG

@esri/solution-common

Version:

Provides general helper functions for @esri/solution.js.

84 lines 3.29 kB
"use strict"; /** @license * Copyright 2018 Esri * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.addTextResource = exports.addBlobResource = void 0; const arcgisRestJS_1 = require("../arcgisRestJS"); /** * Adds a blob resource. * * @param blob Blob containing the resource to add * @param itemId Id of the item to add the resource to * @param folder A prefix string added to the filename in the storage; use null or undefined for no folder * @param filename File name used to rename an existing file resource uploaded. * File name must have the file resource extension. * @param authentication Credentials for the request */ function addBlobResource(blob, itemId, folder, filename, authentication) { // Check that the filename has an extension because it is required by the addResources call if (filename && filename.indexOf(".") < 0) { return new Promise((resolve, reject) => { reject(new arcgisRestJS_1.ArcGISAuthError("Filename must have an extension indicating its type")); }); } const requestOptions = { id: itemId, resource: blob, name: filename, authentication: authentication, params: {}, }; if (folder) { requestOptions.params = { resourcesPrefix: folder, }; } return (0, arcgisRestJS_1.addItemResource)(requestOptions); } exports.addBlobResource = addBlobResource; /** * Adds a text resource. * * @param content Text to add as a resource * @param itemId Id of the item to add the resource to * @param folder A prefix string added to the filename in the storage; use null or undefined for no folder * @param filename File name used to rename an existing file resource uploaded, or to be used together with * text as file name for it. File name must have the file resource extension. * @param authentication Credentials for the request */ function addTextResource(content, itemId, folder, filename, authentication) { // Check that the filename has an extension because it is required by the addResources call if (filename && filename.indexOf(".") < 0) { return new Promise((resolve, reject) => { reject(new arcgisRestJS_1.ArcGISAuthError("Filename must have an extension indicating its type")); }); } const requestOptions = { id: itemId, content, name: filename, authentication: authentication, params: {}, }; if (folder) { requestOptions.params = { resourcesPrefix: folder, }; } return (0, arcgisRestJS_1.addItemResource)(requestOptions); } exports.addTextResource = addTextResource; //# sourceMappingURL=add-resource.js.map