fix: user avatar mime change from gif to avif

This commit is contained in:
trisua 2025-06-25 23:15:24 -04:00
parent ffdb767518
commit 6e0f2985b9
20 changed files with 219 additions and 104 deletions

View file

@ -16,19 +16,32 @@ function regns_log(level, ...args) {
}
/// Query an existing namespace
globalThis.ns = (ns) => {
globalThis.ns = async (ns) => {
regns_log("info", "namespace query:", ns);
// get namespace from app base
const res = globalThis._app_base.ns_store[`$${ns}`];
let res = globalThis._app_base.ns_store[`$${ns}`];
let tries = 0;
if (!res) {
return console.error(
`namespace "${ns}" does not exist, please use one of the following:`,
Object.keys(globalThis._app_base.ns_store),
);
while (!res) {
if (tries >= 5) {
return console.error(
`namespace "${ns}" does not exist, please use one of the following:`,
Object.keys(globalThis._app_base.ns_store),
);
}
tries += 1;
res = globalThis._app_base.ns_store[`$${ns}`];
await new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 500);
});
}
regns_log("info", `found ns "${ns}" after ${tries} tries`);
return res;
};
@ -51,12 +64,12 @@ globalThis.reg_ns = (ns, deps) => {
_ident: ns,
_deps: deps || [],
/// Pull dependencies (other namespaces) as listed in the given `deps` argument
_get_deps: () => {
_get_deps: async () => {
const self = globalThis._app_base.ns_store[`$${ns}`];
const deps = {};
for (const dep of self._deps) {
const res = globalThis.ns(dep);
const res = await globalThis.ns(dep);
if (!res) {
regns_log("warn", "failed to pull dependency:", dep);
@ -72,16 +85,15 @@ globalThis.reg_ns = (ns, deps) => {
/// Store the real versions of functions
_fn_store: {},
/// Call a function in a namespace and load namespace dependencies
define: (name, func, types) => {
const self = globalThis.ns(ns);
define: async (name, func, types) => {
const self = await globalThis.ns(ns);
self._fn_store[name] = func; // store real function
self[name] = function (...args) {
self[name] = async (...args) => {
regns_log("info", "namespace call:", ns, name);
// js doesn't provide type checking, we do
if (types) {
for (const i in args) {
// biome-ignore lint: this is incorrect, you do not need a string literal to use typeof
if (types[i] && typeof args[i] !== types[i]) {
return console.error(
"argument does not pass type check:",
@ -94,7 +106,7 @@ globalThis.reg_ns = (ns, deps) => {
// ...
// we MUST return here, otherwise nothing will work in workers
return self._fn_store[name](self._get_deps(), ...args); // call with deps and arguments
return self._fn_store[name](await self._get_deps(), ...args); // call with deps and arguments
};
},
};
@ -104,11 +116,11 @@ globalThis.reg_ns = (ns, deps) => {
};
/// Call a namespace function quickly
globalThis.trigger = (id, args) => {
globalThis.trigger = async (id, args) => {
// get namespace
const s = id.split("::");
const [namespace, func] = [s[0], s.slice(1, s.length).join("::")];
const self = ns(namespace);
const self = await ns(namespace);
if (!self) {
return console.error("namespace does not exist:", namespace);