Files
console-dev/app/lib/oauth.js
T
2026-11-06 00:04:38 +08:00

68 lines
1.6 KiB
JavaScript

import { o as backend_menu_o } from "~/lib/backend-menu.js";
function t(t) {
return Array.isArray(t)
? t.flatMap((t) => {
if (
!t ||
typeof t != `object` ||
typeof t.name != `string` ||
!/^[a-z][a-z0-9_]*$/i.test(t.name)
)
return [];
let n = typeof t.img == `string` ? t.img : ``,
r =
/^\/(?!\/)/.test(n) && !/[\\\u0000-\u0020]/.test(n)
? n
: backend_menu_o(n);
return [
{
name: t.name,
title: typeof t.title == `string` ? t.title : t.name,
image: r,
linked: t.link === !0 || t.link === 1 || t.link === `1`,
},
];
})
: [];
}
function n(t, n) {
return typeof t == `string`
? /^\/(?!\/)/.test(t) && !/[\\\u0000-\u0020]/.test(t)
? new URL(t, n).href
: backend_menu_o(t)
: ``;
}
function r(e, t, r = t) {
if (!e || typeof e != `object` || Array.isArray(e))
return {
kind: `expired`,
};
let i = e;
if (typeof i.jwt == `string` && i.jwt.trim())
return {
kind: `login`,
jwt: i.jwt.trim(),
};
let a = n(i.url, t);
if (a) {
let e = new URL(a);
if (e.pathname === `/oauth.htm` && [t, r].includes(e.origin))
return (
(e.pathname = `/oauth/bind`),
{
kind: `bind`,
url: t + e.pathname + e.search + e.hash,
}
);
if (e.origin === t && e.pathname === `/oauth/bind`)
return {
kind: `bind`,
url: a,
};
}
return {
kind: `expired`,
};
}
export { r as n, n as r, t };