Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
execute: function (id, fileName) {
console.info(`Exporting item ${id} to file ${fileName}`);
// construct the search call..
let model = {};
return getItem(id)
.then((item) => {
model.item = item;
if (this.shouldFetchData(item.type)){
console.info(`...Fetching ./data for item of type ${item.type}`);
return getItemData(id);
} else {
console.info(`...Items of type ${item.type} do not have json ./data - skipping`);
return Promise.resolve();
}
})
.then((maybeData) => {
if (maybeData) {
model.data = maybeData;
}
// now write out the file...
jsonfile.writeFileSync(fileName, model, {spaces: 2});
// redirect to the homepage unless the user is signed in
if (!session) {
this.redirect(302, "/");
return;
}
const { webmapId } = params;
// if we are on the server we won't have an actuall UserSession just a
// JSON representation of one. So we need to hydrate a UserSession.
const userSession = process.browser ? session : new UserSession(session);
// next we can request both the webmap item and the webmap data (the JSON)
// and process the data to get a list of layers.
return Promise.all([
getItem(webmapId, {
authentication: userSession
}).catch(error => {
return retryWithNewSession(error, this.fetch);
}),
getItemData(webmapId, {
authentication: userSession
}).catch(error => {
return retryWithNewSession(error, this.fetch);
})
]).then(([item, webmap]) => {
const layers = webmap.operationalLayers
.concat(webmap.baseMap.baseMapLayers)
.map(layer => {
return {
title: layer.title || layer.id,
url: layer.url,
loadItemId() {
const { itemId, url } = this.get();
const { session } = this.store.get();
if (itemId) {
getItem(itemId, {
authentication: session
})
.catch(error => {
return retryWithNewSession(error, fetch);
})
.then(item => {
this.set({ item, url: url || item.url });
});
}
},
export function getItem(
id: string,
authentication: interfaces.UserSession
): Promise {
const requestOptions = {
authentication: authentication
};
return portal.getItem(id, requestOptions);
}
export function getItemBase(
itemId: string,
authentication: interfaces.UserSession
): Promise {
const itemParam: request.IRequestOptions = {
authentication: authentication
};
return portal.getItem(itemId, itemParam);
}
public async getItem(itemId : string) : Promise{
const item = await getItem(itemId, {
portal: this.restURL,
authentication: this.authentication,
});
const itemData = await getItemData(itemId, {
authentication: this.authentication,
portal: this.restURL,
});
let data;
if(typeof itemData === 'string'){
try {
data = JSON.parse(itemData);
} catch(e){
data = itemData;
}
} else {