chore (refactoring): 3d app revamp

This commit is contained in:
MickaelK 2025-01-13 22:53:02 +11:00
parent fd839808b7
commit 0d4709595c
7 changed files with 32 additions and 24 deletions

View file

@ -9,11 +9,12 @@ const config$ = ajax({
rxjs.map(({ responseJSON }) => responseJSON.result),
);
export function get() {
return config$;
}
export async function init() {
const config = await config$.toPromise();
window.CONFIG = config;
}
export function get(key) {
if (key) return window.CONFIG[key];
return window.CONFIG;
}

View file

@ -68,7 +68,7 @@ export default function(render) {
function processError(err) {
let msg, trace;
if (err instanceof AjaxError) {
msg = t(err.message);
msg = t(err.code());
trace = `
type: ${err.type()}
code: ${err.code()}

View file

@ -1,9 +1,11 @@
import { createElement, createRender, nop } from "../../lib/skeleton/index.js";
import rxjs, { effect } from "../../lib/rx.js";
import { qs } from "../../lib/dom.js";
import { AjaxError } from "../../lib/error.js";
import { load as loadPlugin } from "../../model/plugin.js";
import { loadCSS } from "../../helpers/loader.js";
import { createLoader } from "../../components/loader.js";
import t from "../../locales/index.js";
import ctrlError from "../ctrl_error.js";
import componentDownloader, { init as initDownloader } from "./application_downloader.js";
@ -63,7 +65,15 @@ export default async function(render, { mime, acl$, getDownloadUrl = nop, getFil
hasCube, mime, is2D: loader.is2D,
})),
)),
rxjs.catchError(ctrlError()),
rxjs.catchError((err) => {
let _err = err;
if (err.response.status === 401) {
_err = new Error(err.message);
_err.status = err.response.status;
_err = new AjaxError(err.message, _err, "Not Authorised");
}
return ctrlError()(_err);
}),
));
}

View file

@ -27,8 +27,8 @@ export default function({ THREE, $page, $menubar, mesh, refresh, is2D }) {
maxDim * 1000,
);
const controls = new OrbitControls(camera, renderer.domElement);
controls.zoomToCursor = true;
if (is2D()) {
controls.zoomToCursor = true;
controls.enableRotate = false;
controls.mouseButtons = {
LEFT: THREE.MOUSE.PAN,

View file

@ -368,6 +368,7 @@ func (this *Configuration) Export() interface{} {
Thumbnailer []string `json:"thumbnailer"`
EnableChromecast bool `json:"enable_chromecast"`
Origin string `json:"origin"`
Version string `json:"version"`
}{
Editor: this.Get("general.editor").String(),
ForkButton: this.Get("general.fork_button").Bool(),
@ -415,6 +416,7 @@ func (this *Configuration) Export() interface{} {
}
return scheme + host
}(),
Version: BUILD_REF[:7],
}
}

View file

@ -194,7 +194,7 @@ func ServeBackofficeHandler(ctx *App, res http.ResponseWriter, req *http.Request
head.Add(
"Link",
fmt.Sprintf(`<%s>; rel="preload"; as="script"; crossorigin="anonymous";`, WithBase(
strings.Replace(href, "/assets/", "/assets/"+version()+"/", 1),
strings.Replace(href, "/assets/", "/assets/"+BUILD_REF+"/", 1),
)),
)
}
@ -287,7 +287,7 @@ func ServeFrontofficeHandler(ctx *App, res http.ResponseWriter, req *http.Reques
head.Add(
"Link",
fmt.Sprintf(`<%s>; rel="preload"; as="script"; crossorigin="anonymous";`, WithBase(
strings.Replace(href, "/assets/", "/assets/"+version()+"/", 1),
strings.Replace(href, "/assets/", "/assets/"+BUILD_REF+"/", 1),
)),
)
}
@ -431,7 +431,7 @@ func ServeFile(chroot string) func(*App, http.ResponseWriter, *http.Request) {
chroot,
strings.Replace(
TrimBase(req.URL.Path),
"assets/"+version()+"/",
"assets/"+BUILD_REF+"/",
"assets/",
1,
),
@ -546,7 +546,7 @@ func ServeIndex(indexPath string) func(*App, http.ResponseWriter, *http.Request)
res.WriteHeader(http.StatusOK)
template.Must(template.New(indexPath).Parse(string(b))).Execute(res, map[string]any{
"base": WithBase("/"),
"version": version(),
"version": BUILD_REF,
"license": LICENSE,
})
}
@ -572,7 +572,3 @@ func InitPluginList(code []byte) {
}
}
}
func version() string {
return BUILD_REF[:7]
}

View file

@ -13,20 +13,19 @@ func main() {
cmd.Stdout = b
cmd.Run()
content := fmt.Sprintf(`package common
func init() {
BUILD_REF = "%s"
BUILD_DATE = "%s"
}
`, strings.TrimSpace(b.String()), time.Now().Format("20060102"))
f, err := os.OpenFile("../common/constants_generated.go", os.O_CREATE|os.O_WRONLY, os.ModePerm)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
return
}
f.Write([]byte(content))
f.Write([]byte(fmt.Sprintf(`
package common
func init() {
BUILD_REF = "%s"
BUILD_DATE = "%s"
}
`, b.String()[0:7], time.Now().Format("20060102"))))
f.Close()
}