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

@ -117,7 +117,7 @@ media_theme_pref();
);
});
self.define("clean_date_codes", ({ $ }) => {
self.define("clean_date_codes", async ({ $ }) => {
for (const element of Array.from(document.querySelectorAll(".date"))) {
if (element.getAttribute("data-unix")) {
// this allows us to run the function twice on the same page
@ -134,7 +134,7 @@ media_theme_pref();
element.setAttribute("title", then.toLocaleString());
let pretty = $.rel_date(then) || "";
let pretty = (await $.rel_date(then)) || "";
if (
(screen.width < 900 && pretty !== undefined) |
@ -619,7 +619,6 @@ media_theme_pref();
.catch(() => {
// done scrolling, no more pages (http error)
wrapper.removeEventListener("scroll", event);
resolve();
});
}
@ -652,7 +651,7 @@ media_theme_pref();
);
self.define("hooks::check_reactions", async ({ $ }) => {
const observer = $.offload_work_to_client_when_in_view(
const observer = await $.offload_work_to_client_when_in_view(
async (element) => {
const like = element.querySelector(
'[hook_element="reaction.like"]',
@ -1292,7 +1291,7 @@ ${option.input_element_type === "textarea" ? `${option.value}</textarea>` : ""}
}, 150);
// run hooks
const atto = ns("atto");
const atto = await ns("atto");
atto.clean_date_codes();
atto.clean_poll_date_codes();

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);

View file

@ -52,6 +52,17 @@
if (data.method.Forward === "Key") {
$.STREAMS[stream].id = data.data;
return console.info(`${stream} ${data.data}`);
} else if (data.method.Forward === "Javascript") {
const s = document.createElement("script");
s.setAttribute("type", "module");
s.setAttribute("data-received", Date.now().toString());
s.text = JSON.parse(data.data).js;
document.body.appendChild(s).parentNode.removeChild(s);
return console.info(
`${stream} received Forward(PacketType::Javascript) payload of ${data.data.length} bytes`,
);
}
return $.sock(stream).events.message(data);
@ -72,8 +83,8 @@
socket.socket.close();
});
self.define("event", ({ $ }, stream, event, handler) => {
const socket = $.sock(stream);
self.define("event", async ({ $ }, stream, event, handler) => {
const socket = await $.sock(stream);
if (!socket) {
console.warn("no such stream to add event to");
@ -84,7 +95,7 @@
});
self.define("send_packet", async ({ $ }, stream, method, data) => {
await (
return await (
await fetch(`/api/v1/auth/user/${$.USER}/_connect/${stream}/send`, {
method: "POST",
headers: {
@ -97,4 +108,19 @@
})
).json();
});
self.define("send_packet_to", async (_, user, stream, method, data) => {
return await (
await fetch(`/api/v1/auth/user/${user}/_connect/${stream}/send`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
method,
data: JSON.stringify(data),
}),
})
).json();
});
})();