From 607b7a00ad0736eccb096996bb4c8fcd554e2a5e Mon Sep 17 00:00:00 2001 From: MickaelK Date: Sat, 28 Dec 2024 02:21:34 +1100 Subject: [PATCH] chore (refactoring): cleanup --- config/mime.json | 5 +++- public/assets/index.js | 2 +- public/assets/lib/ajax.js | 27 +++++++------------ .../lib/vendor/shp-to-geojson.browser.js | 2 ++ public/assets/pages/ctrl_error.js | 1 - public/assets/pages/ctrl_viewerpage.js | 2 ++ .../pages/viewerpage/application_map.js | 7 ++--- public/assets/pages/viewerpage/mimetype.js | 4 ++- public/package.json | 3 +++ 9 files changed, 29 insertions(+), 24 deletions(-) diff --git a/config/mime.json b/config/mime.json index acc73819..d0b0ceea 100644 --- a/config/mime.json +++ b/config/mime.json @@ -23,7 +23,8 @@ "crw": "image/x-canon-crw", "css": "text/css", "csv": "text/csv", - "dcm": "image/dicom", + "dbf": "application/dbf", + "dcm": "image/dicom", "dcr": "image/x-kodak-dcr", "deb": "application/octet-stream", "der": "application/x-x509-ca-cert", @@ -128,6 +129,7 @@ "pptm": "application/vnd.ms-powerpoint.presentation.macroEnabled.12", "pptx": "application/powerpoint", "prc": "application/x-pilot", + "prj": "application/text", "properties": "text/x-ini", "ps": "application/postscript", "psd": "image/vnd.adobe.photoshop", @@ -145,6 +147,7 @@ "sea": "application/x-sea", "shtml": "text/html", "shp": "application/vnd.shp", + "shx": "application/vnd.shx", "sit": "application/x-stuffit", "so": "application/octet-stream", "sr2": "image/x-sony-sr2", diff --git a/public/assets/index.js b/public/assets/index.js index 20b90f79..65b7741a 100644 --- a/public/assets/index.js +++ b/public/assets/index.js @@ -47,7 +47,7 @@ function execute(module, $app, opts) { function poweredBy($app) { return createElement(` -
+
Powered By Filestash
`); diff --git a/public/assets/lib/ajax.js b/public/assets/lib/ajax.js index c534d454..d529c515 100644 --- a/public/assets/lib/ajax.js +++ b/public/assets/lib/ajax.js @@ -39,29 +39,22 @@ function processError(xhr, err) { let responseText = ""; try { responseText = xhr?.responseText; - } catch (err) { - if (err.name === "InvalidStateError") {} // InvalidStateError: Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'arraybuffer'). - else throw err; - } + // InvalidStateError: Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'arraybuffer'). + } catch (err) {} - const response = (function(content) { - let message = content; + const message = (function(content) { try { - message = JSON.parse(content); + return JSON.parse(content).message; } catch (err) { - return { - message: Array.from(new Set( - content.replace(/<[^>]*>/g, "") - .replace(/\n{2,}/, "\n") - .trim() - .split("\n") - )).join(" ") - }; + return Array.from(new Set( + content.replace(/<[^>]*>/g, "") + .replace(/\n{2,}/, "\n") + .trim() + .split("\n") + )).join(" "); } - return message || { message: "empty response" }; })(responseText); - const message = response.message || null; if (window.navigator.onLine === false) { return new AjaxError("Connection Lost", err, "NO_INTERNET"); } diff --git a/public/assets/lib/vendor/shp-to-geojson.browser.js b/public/assets/lib/vendor/shp-to-geojson.browser.js index 97cb3d6c..7188f00c 100644 --- a/public/assets/lib/vendor/shp-to-geojson.browser.js +++ b/public/assets/lib/vendor/shp-to-geojson.browser.js @@ -1,3 +1,4 @@ +// @ts-nocheck function createCommonjsModule(fn) { var module = { exports: {} }; return fn(module, module.exports), module.exports; @@ -2740,3 +2741,4 @@ class BrowserShp extends Shp { export { BrowserShp as default }; export const Buffer = buffer.Buffer; +export const DBase = Properties; diff --git a/public/assets/pages/ctrl_error.js b/public/assets/pages/ctrl_error.js index 50661aea..6189a475 100644 --- a/public/assets/pages/ctrl_error.js +++ b/public/assets/pages/ctrl_error.js @@ -99,7 +99,6 @@ function formatTrace(str) { .join("\n"); } - const css = ` .error-page { width: 80%; diff --git a/public/assets/pages/ctrl_viewerpage.js b/public/assets/pages/ctrl_viewerpage.js index 68fee5ce..b56ffcac 100644 --- a/public/assets/pages/ctrl_viewerpage.js +++ b/public/assets/pages/ctrl_viewerpage.js @@ -41,6 +41,8 @@ function loadModule(appName) { return import("./viewerpage/application_map.js"); case "url": return import("./viewerpage/application_url.js"); + case "table": + return import("./viewerpage/application_table.js"); default: throw new ApplicationError("Internal Error", `Unknown opener app "${appName}" at "${getCurrentPath()}"`); } diff --git a/public/assets/pages/viewerpage/application_map.js b/public/assets/pages/viewerpage/application_map.js index 4246eb36..8ecb932d 100644 --- a/public/assets/pages/viewerpage/application_map.js +++ b/public/assets/pages/viewerpage/application_map.js @@ -1,7 +1,6 @@ import { createElement, nop } from "../../lib/skeleton/index.js"; import rxjs, { effect } from "../../lib/rx.js"; import { qs } from "../../lib/dom.js"; -import { extname } from "../../lib/path.js"; import ajax from "../../lib/ajax.js"; import { loadCSS, loadJS } from "../../helpers/loader.js"; import { createLoader } from "../../components/loader.js"; @@ -33,12 +32,14 @@ export default async function(render, { mime, getDownloadUrl = nop, getFilename const removeLoader = createLoader(qs($page, "#map")); await effect(ajax({ url: getDownloadUrl(), responseType: "arraybuffer" }).pipe( rxjs.map(({ response }) => response), - rxjs.mergeMap(async(data) => { switch(mime) { + rxjs.mergeMap(async(data) => { + switch (mime) { case "application/geo+json": return loadGeoJSON(map, JSON.parse(new TextDecoder().decode(data))); case "application/vnd.ogc.wms_xml": return loadWMS(map, new TextDecoder().decode(data)); case "application/vnd.shp": return await loadSHP(map, data); default: throw new Error(`Insupported mime type: '${mime}'`); - }}), + } + }), removeLoader, rxjs.catchError(ctrlError()), )); diff --git a/public/assets/pages/viewerpage/mimetype.js b/public/assets/pages/viewerpage/mimetype.js index 86e6cb76..e8e66cf3 100644 --- a/public/assets/pages/viewerpage/mimetype.js +++ b/public/assets/pages/viewerpage/mimetype.js @@ -34,7 +34,9 @@ export function opener(file = "", mimes) { return ["3d", { mime }]; } else if (mime === "application/x-url") { return ["url", { mime }]; - } else if (type === "application") { + } else if (["application/dbf"].indexOf(mime) !== -1) { + return ["table", { mime }]; + } else if (type === "application" && mime !== "application/text") { return ["download", { mime }]; } return ["editor", { mime }]; diff --git a/public/package.json b/public/package.json index 16e85d1a..4248f521 100644 --- a/public/package.json +++ b/public/package.json @@ -127,6 +127,9 @@ ], "no-template-curly-in-string": [ "off" + ], + "new-cap": [ + "off" ] } },