Skip to content

Commit

Permalink
Merge branch 'main' of github.com:GEOLYTIX/xyz into fix-fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
eo-uk committed Oct 19, 2023
2 parents 691f641 + 4026463 commit 7d4c392
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 61 deletions.
44 changes: 26 additions & 18 deletions lib/layer/format/vector.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ export default layer => {

layer.params ??= {}

// If layer configuration is wrong and contains both cluster.distance and cluster.resolution, error and return
if (layer.cluster?.distance && layer.cluster?.resolution) {

console.error(`Layer: ${layer.key}, cluster.distance and cluster.resolution are mutually exclusive. You cannot use them both on the same layer. Please remove one of them. `)

return;
};

if (layer.cluster?.resolution) {
layer.format = 'cluster';
layer.params.viewport = true;
Expand All @@ -33,33 +41,33 @@ export default layer => {
}

if (!features) return;

layer.source = new ol.source.Vector({
features: mapp.utils.featureFormats[layer.format](layer, [features].flat())
})

delete layer.xhr

if (layer.fade) mapp.layer.fade(layer)

// Geojson is a cluster layer.
if (layer.cluster?.distance) {

// Create cluster source.
layer.cluster.source = new ol.source.Cluster({
distance: layer.cluster.distance,
source: layer.source
})

layer.L.setSource(layer.cluster.source)
return;
}

// Set source if not cluster
layer.L.setSource(layer.source)
}

layer.reload = ()=>{
layer.reload = () => {

// Do not reload the layer if features have been assigned.
if (layer.features) return;
Expand Down Expand Up @@ -90,21 +98,21 @@ export default layer => {

clearTimeout(layer.timeout)

layer.timeout = setTimeout(()=>{
layer.timeout = setTimeout(() => {

layer.xhr = mapp.utils.xhr(
`${layer.mapview.host}/api/query?${mapp.utils.paramString({
template: layer.params.template || layer.format,
locale: layer.mapview.locale.key,
layer: layer.key,
table,
filter: layer.filter?.current,
...layer.params
})}`)
.then(layer.setSource)
template: layer.params.template || layer.format,
locale: layer.mapview.locale.key,
layer: layer.key,
table,
filter: layer.filter?.current,
...layer.params
})}`)
.then(layer.setSource)

}, 100)

}

// Create Openlayer Vector Layer
Expand Down Expand Up @@ -173,11 +181,11 @@ export default layer => {
})

}

// Return length for calculation of max_size.
return features.length
})

if (!feature_counts.length) return;

// Calculate max_size for cluster size styling.
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/style.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default (style, feature) => {
scale *= style.highlightScale || 1

// Create icon url from svgSymbols method if not defined as url or svg source.
icon.url = icon.url || icon.svg || mapp.utils.svgSymbols[icon.type](icon, feature)
icon.url = icon.url || icon.svg || mapp.utils.svgSymbols[icon.type||'dot'](icon, feature)

if (!icon.url) return;

Expand Down
13 changes: 9 additions & 4 deletions mod/provider/cloudfront.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const { join } = require('path')

const { getSignedUrl } = require('@aws-sdk/cloudfront-signer');

const logger = require('../utils/logger')

module.exports = async ref => {

try {
Expand All @@ -28,15 +30,18 @@ module.exports = async ref => {
privateKey: String(readFileSync(join(__dirname, `../../${process.env.KEY_CLOUDFRONT}.pem`)))
});

// Return signedURL only from request.
if (ref.params?.signedURL) {

return signedURL;
}

const response = await fetch(signedURL, {
agent: process.env.CUSTOM_AGENT && httpsAgent
})

if (ref.params?.signedURL) {
logger(`${response.status} - ${url}`,'cloudfront')

return signedURL;
}

if (response.status >= 300) return new Error(`${response.status} ${ref}`)

if (url.match(/\.json$/i)) return await response.json()
Expand Down
30 changes: 22 additions & 8 deletions mod/templates/_templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,28 @@ const cloudfront = require('../provider/cloudfront')

const file = require('../provider/file')

const logger = require('../utils/logger')

const getFrom = {
https: async ref => {
https: async url => {

try {

const response = await fetch(url)

logger(`${response.status} - ${url}`,'fetch')

const response = await fetch(ref)
if (url.match(/\.json$/i)) {
return await response.json()
}

return await response.text()

if (ref.match(/\.json$/i)) {
return await response.json()
} catch (err) {
console.error(err)
return;
}

return await response.text()

},
file: ref => file(ref.split(':')[1]),
cloudfront: ref => cloudfront(ref.split(':')[1]),
Expand All @@ -46,12 +58,14 @@ module.exports = async (key, language = 'en', params = {}) => {
// Prevent prototype polluting assignment.
if (/__proto__/.test(key)) return;

const _templates = await custom_templates;

const templates = merge({},
view_templates,
mail_templates,
msg_templates,
await custom_templates)

_templates)
if (!Object.hasOwn(templates, key)) {

console.warn(`Template key ${key} not found in templates`)
Expand Down
28 changes: 0 additions & 28 deletions mod/templates/custom.js

This file was deleted.

2 changes: 0 additions & 2 deletions mod/user/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ async function view(req, res, message) {
msg: message || ' '
})

//res.clearCookie(process.env.TITLE)

// Clear user token cookie.
res.setHeader('Set-Cookie', `${process.env.TITLE}=null;HttpOnly;Max-Age=0;Path=${process.env.DIR || '/'}`)

Expand Down

0 comments on commit 7d4c392

Please sign in to comment.