@esri/solution-common
Version:
Provides general helper functions for @esri/solution.js.
70 lines • 3.03 kB
JavaScript
;
/** @license
* Copyright 2020 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.convertItemResourceToStorageResource = void 0;
const solution_resource_1 = require("./solution-resource");
/**
* Generates a folder and filename for storing a copy of an item's resource in a storage item.
*
* @param prefix Base prefix for resource
* @param sourceResourceFilename Either filename or folder/filename to resource
* @param storageVersion Version of the Solution template
* @param storageFileType Optional argument that when supplied will control the how the prefix is created
* @returns Folder and filename for storage; folder is the itemID plus ("_" + storageFolder) if storageFolder
* exists plus ("_" + part of sourceResourceFilename before "/" if that separator exists);
* file is sourceResourceFilename
* @see convertStorageResourceToItemResource
*/
function convertItemResourceToStorageResource(prefix, sourceResourceFilename, storageVersion = 0, storageFileType) {
/* istanbul ignore else */
if (storageFileType !== undefined) {
switch (storageFileType) {
case solution_resource_1.SolutionResourceType.data:
prefix = `${prefix}_info_data`;
break;
case solution_resource_1.SolutionResourceType.fakezip:
prefix = `${prefix}_info_dataz`;
break;
case solution_resource_1.SolutionResourceType.info:
prefix = `${prefix}_info`;
break;
case solution_resource_1.SolutionResourceType.metadata:
prefix = `${prefix}_info_metadata`;
break;
case solution_resource_1.SolutionResourceType.thumbnail:
prefix = `${prefix}_info_thumbnail`;
break;
}
}
let folder = prefix;
let filename = sourceResourceFilename;
const iLastSlash = filename.lastIndexOf("/");
if (iLastSlash >= 0) {
let subpath = filename.substr(0, iLastSlash);
if (storageVersion === 0) {
subpath = subpath.replace("/", "_");
folder += "_" + subpath;
}
else {
folder += "/" + subpath;
}
filename = filename.substr(iLastSlash + 1);
}
return { folder, filename };
}
exports.convertItemResourceToStorageResource = convertItemResourceToStorageResource;
//# sourceMappingURL=convert-item-resource-to-storage-resource.js.map