From 4f6ceb3fa035a5e23c93fb384316c5ae51a6fa2d Mon Sep 17 00:00:00 2001 From: MickaelK Date: Mon, 24 Jun 2024 23:19:40 +1000 Subject: [PATCH] chore (canary): canary release for rewrite --- public/assets/pages/filespage/ctrl_upload.js | 13 ++++++++----- .../pages/viewerpage/application_editor.js | 19 ++++++++++--------- .../pages/viewerpage/application_form.js | 10 ++++++---- public/assets/pages/viewerpage/model_files.js | 17 ++++++++--------- server/ctrl/static.go | 7 +------ 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/public/assets/pages/filespage/ctrl_upload.js b/public/assets/pages/filespage/ctrl_upload.js index b168853f..74276692 100644 --- a/public/assets/pages/filespage/ctrl_upload.js +++ b/public/assets/pages/filespage/ctrl_upload.js @@ -392,7 +392,7 @@ function workerImplDirectory({ error, progress }) { async function processFiles(filelist) { // TODO const files = []; const detectFiletype = (file) => { - // the 4096 is an heuristic I've observed and taken from: + // the 4096 is an heuristic observed and taken from: // https://stackoverflow.com/questions/25016442 // however the proposed answer is just wrong as it doesn't consider folder with // name such as: test.png and as Stackoverflow favor consanguinity with their @@ -413,10 +413,13 @@ async function processFiles(filelist) { // TODO for (const currentFile of filelist) { const type = await detectFiletype(currentFile); const file = { type, date: currentFile.lastModified, name: currentFile.name, path: currentFile.name }; - if (type === "directory") file.path += "/"; - else if (type === "file") { - fs.push({ type: "file", path, exec: workerImplFile, entry: currentFile }); - } else assert.fail(`NOT_SUPPORTED type="${type}"`, type); + if (type === "directory") { + file.path += "/"; + } else if (type === "file") { + file.entry = currentFile; + } else { + assert.fail(`NOT_SUPPORTED type="${type}"`, type); + } file.exec = workerImplFile.bind(file); files.push(file); } diff --git a/public/assets/pages/viewerpage/application_editor.js b/public/assets/pages/viewerpage/application_editor.js index 8bc4526e..7cb8d00b 100644 --- a/public/assets/pages/viewerpage/application_editor.js +++ b/public/assets/pages/viewerpage/application_editor.js @@ -64,7 +64,7 @@ export default async function(render) { rxjs.mergeMap((arr) => rxjs.from(loadMode(extname(getFilename()))).pipe( rxjs.map((mode) => arr.concat([mode])), )), - rxjs.mergeMap((arr) => options(getCurrentPath()).pipe( + rxjs.mergeMap((arr) => options().pipe( rxjs.map((acl) => arr.concat([acl])), )), )), @@ -145,13 +145,11 @@ export default async function(render) { $fab.classList.remove("hidden"); $fab.render($ICON.LOADING); $fab.disabled = true; - return rxjs.of(cm.getValue()).pipe( - save(), - rxjs.tap((content) => { - $fab.removeAttribute("disabled"); - content$.next(content); - }), - ); + const content = cm.getValue(); + return save(content).pipe(rxjs.tap(() => { + $fab.removeAttribute("disabled"); + content$.next(content); + })); }), rxjs.catchError(ctrlError()), )); @@ -175,7 +173,10 @@ export default async function(render) { ); }); if (userAction === MODAL_RIGHT_BUTTON) { - console.log("TODO: SAVE THE DATA"); + const $fab = $dom.fab(); + $fab.render($ICON.LOADING); + $fab.disabled = true; + await save(cm.getValue()).toPromise(); } return false; }), diff --git a/public/assets/pages/viewerpage/application_form.js b/public/assets/pages/viewerpage/application_form.js index 7f8d202c..2cb09392 100644 --- a/public/assets/pages/viewerpage/application_form.js +++ b/public/assets/pages/viewerpage/application_form.js @@ -7,8 +7,9 @@ import { createForm } from "../../lib/form.js"; import { formTmpl } from "../../components/form.js"; import ctrlError from "../ctrl_error.js"; -import { transition, getFile$, saveFile$ } from "./common.js"; +import { transition } from "./common.js"; import { $ICON } from "./common_fab.js"; +import { cat, save } from "./model_files.js"; import "../../components/icon.js"; import "../../components/menubar.js"; @@ -35,7 +36,7 @@ export default function(render) { const file$ = new rxjs.ReplaySubject(1); // feature1: setup the dom - effect(getFile$().pipe( + effect(cat().pipe( rxjs.map((content) => JSON.parse(content)), rxjs.mergeMap((formSpec) => rxjs.from(createForm(formSpec, formTmpl({ renderLeaf: ({ label, format, description, required }) => createElement(` @@ -100,8 +101,9 @@ export default function(render) { $fab.disabled = true; }), rxjs.mergeMap(($fab) => rxjs.of(JSON.stringify(formState())).pipe( - saveFile$(), - rxjs.mergeMap(() => getFile$().pipe(rxjs.tap((formSpec) => file$.next(JSON.parse(formSpec))))), + rxjs.tap((a) => console.log(a)), + // rxjs.mergeMap((content) => save(content)), + rxjs.mergeMap(() => cat().pipe(rxjs.tap((formSpec) => file$.next(JSON.parse(formSpec))))), )), rxjs.tap(() => { $fab.render($ICON.SAVING); diff --git a/public/assets/pages/viewerpage/model_files.js b/public/assets/pages/viewerpage/model_files.js index eafd2032..b3b4ad28 100644 --- a/public/assets/pages/viewerpage/model_files.js +++ b/public/assets/pages/viewerpage/model_files.js @@ -1,9 +1,9 @@ import rxjs from "../../lib/rx.js"; import ajax from "../../lib/ajax.js"; -import { getDownloadUrl } from "./common.js"; +import { getDownloadUrl, getCurrentPath } from "./common.js"; -export const options = (path) => ajax({ - url: `api/files/cat?path=${path}`, +export const options = () => ajax({ + url: `api/files/cat?path=${encodeURIComponent(getCurrentPath())}`, method: "OPTIONS", }).pipe(rxjs.map((res) => res.responseHeaders.allow.replace(/\r/, "").split(", "))); @@ -11,9 +11,8 @@ export const cat = () => ajax(getDownloadUrl()).pipe( rxjs.map(({ response }) => response), ); -export const save = () => { - return rxjs.pipe( - rxjs.delay(2000), - rxjs.tap((content) => console.log("SAVED")), - ); -}; +export const save = (content) => ajax({ + url: getDownloadUrl(), + method: "POST", + body: content, +}); diff --git a/server/ctrl/static.go b/server/ctrl/static.go index affbb009..1aa2e0be 100644 --- a/server/ctrl/static.go +++ b/server/ctrl/static.go @@ -194,11 +194,6 @@ func ServeBackofficeHandler(ctx *App, res http.ResponseWriter, req *http.Request } func ServeFrontofficeHandler(ctx *App, res http.ResponseWriter, req *http.Request) { - url := req.URL.Path - if filepath.Ext(filepath.Base(url)) != "" { - ServeFile("/")(ctx, res, req) - return - } ua := req.Header.Get("User-Agent") if strings.Contains(ua, "MSIE ") || strings.Contains(ua, "Trident/") || strings.Contains(ua, "Edge/") { // Microsoft is behaving on many occasion differently than Firefox / Chrome. @@ -214,7 +209,7 @@ func ServeFrontofficeHandler(ctx *App, res http.ResponseWriter, req *http.Reques `))) return } - url = TrimBase(req.URL.Path) + url := TrimBase(req.URL.Path) if url != "/" && strings.HasPrefix(url, "/s/") == false && strings.HasPrefix(url, "/view/") == false && strings.HasPrefix(url, "/files/") == false && url != "/login" && url != "/logout" && strings.HasPrefix(url, "/tags") == false {