Commit a641707c authored by Athanasios's avatar Athanasios
Browse files

modify temporary assets

parent e6e18900
......@@ -2,6 +2,7 @@ const fs = require("fs");
const fsprom = require('fs').promises;
const boxIntersect = require("box-intersect");
const path = require('path');
const tempAssets = require("../src/tempAssets");
// const getLayers = (layers) => {
// return new Promise((resolve, reject) => {
......@@ -21,15 +22,12 @@ const path = require('path');
const getLayers = async (layers) => {
let assets = await getAllAssets();
let requestedLayers = layers.split(",");
assets = assets.filter(asset => requestedLayers.includes(asset.id));
assets = assets.filter(asset => asset.scope == "public");
return assets;
}
const getAllAssets = async () => {
......@@ -38,8 +36,7 @@ const getAllAssets = async () => {
let assetsJson = await fsprom.readFile('./assets/assets.json', 'utf8');
let assets = JSON.parse(assetsJson);
let tempassetsJson = await fsprom.readFile('./assets/temporaryAssets.json', 'utf8');
let tempassets = JSON.parse(tempassetsJson);
let tempassets = await tempAssets.getTempAssets();
assets.push(...tempassets);
return assets;
......@@ -166,13 +163,10 @@ const allLayersExist = async (layers) => {
const getPublicLayers = async () => {
let assets = await getAllAssets();
assets = assets.filter(asset => asset.scope == "public");
return assets;
}
const isPublic = (url) => {
......
......@@ -14,13 +14,13 @@ const addTempLayer = (req, res) => {
await removeExpired();
let doc = await fetch(req.body.url);
let nd = await doc.json();
doc = await doc.json();
let tempLayer = {
name: `(tmp) ${req.body.name}`,
id: uuidv4(),
boundingbox: nd.store.extent,
boundingbox: doc.store.extent,
url: req.body.url,
creationTime: Date.now(),
scope: "public"
......@@ -68,5 +68,22 @@ const removeExpired = async () => {
}
const getTempAssets = async () => {
module.exports = { addTempLayer };
\ No newline at end of file
try {
await removeExpired();
let tempassetsJson = await fs.readFile('./assets/temporaryAssets.json', 'utf8');
let tempassets = JSON.parse(tempassetsJson);
return tempassets;
} catch (error) {
console.log(error);
}
}
module.exports = { addTempLayer, getTempAssets };
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment