first commit
This commit is contained in:
commit
db5762abd4
687 files changed
+171307
No files matched your search
@@ -0,0 +1,86 @@
|
||||
function e(e) {
|
||||
if (
|
||||
!/^(?:https?:\/\/|\/(?!\/)|\.\.?\/)/i.test(e) ||
|
||||
/[\u0000-\u001f\u007f\\]/.test(e)
|
||||
)
|
||||
return !1;
|
||||
try {
|
||||
let t = new URL(e, `https://attachment.invalid/`);
|
||||
return t.protocol === `http:` || t.protocol === `https:`;
|
||||
} catch {
|
||||
return !1;
|
||||
}
|
||||
}
|
||||
function t(t) {
|
||||
return (
|
||||
!!t.href &&
|
||||
e(t.href) &&
|
||||
/\.(?:avif|bmp|gif|ico|jpe?g|png|webp)$/i.test(t.name)
|
||||
);
|
||||
}
|
||||
function n(e, t) {
|
||||
let n =
|
||||
e
|
||||
.split(`/`)
|
||||
.at(-1)
|
||||
?.split(/\^|%5e/i)
|
||||
.at(-1) || t;
|
||||
try {
|
||||
n = decodeURIComponent(n);
|
||||
} catch {}
|
||||
return n.split(`^`).at(-1) || t;
|
||||
}
|
||||
function r(t) {
|
||||
return Array.isArray(t)
|
||||
? t.map((t, r) => {
|
||||
let i = `附件 ${r + 1}`,
|
||||
a = t && typeof t == `object` && !Array.isArray(t) ? t : null;
|
||||
if (
|
||||
typeof t != `string` &&
|
||||
(!a ||
|
||||
![`url`, `name`, `save_name`].some((e) => typeof a[e] == `string`))
|
||||
)
|
||||
return {
|
||||
name: `${i}(格式暂不支持)`,
|
||||
href: null,
|
||||
};
|
||||
let o = typeof t == `string` ? t : a?.url,
|
||||
s = typeof o == `string` ? o.trim() : ``,
|
||||
c = typeof a?.name == `string` ? a.name.trim() : ``,
|
||||
l = typeof a?.save_name == `string` ? a.save_name.trim() : ``,
|
||||
u = c || (l ? n(l, i) : ``),
|
||||
d =
|
||||
l ||
|
||||
(typeof o == `string` && !e(o) && !/[\\/:\u0000-\u001f]/.test(o)
|
||||
? o
|
||||
: ``),
|
||||
f = {
|
||||
name: u || (d ? n(d, i) : `${i}(地址不可用)`),
|
||||
href: null,
|
||||
...(d
|
||||
? {
|
||||
storageName: d,
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
if (!e(s)) return f;
|
||||
try {
|
||||
let e = new URL(s, `https://attachment.invalid/`);
|
||||
return e.protocol !== `http:` && e.protocol !== `https:`
|
||||
? f
|
||||
: {
|
||||
name: u || n(e.pathname, i),
|
||||
href: s,
|
||||
...(d
|
||||
? {
|
||||
storageName: d,
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
} catch {
|
||||
return f;
|
||||
}
|
||||
})
|
||||
: [];
|
||||
}
|
||||
export { r as n, t };
|
||||
Reference in new issue
Block a user