mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-06-20 02:44:16 +08:00
Add og:image support
This commit is contained in:
@@ -11,6 +11,10 @@ import { i18n_get_lang } from "../server/i18ns.ts";
|
||||
import { SharedTokenType } from "../db.ts";
|
||||
import { initDOMParser } from "../utils.ts";
|
||||
import { DOMParser } from "deno_dom/wasm-noinit";
|
||||
import pbkdf2Hmac from "pbkdf2-hmac";
|
||||
import { encodeBase64 } from "@std/encoding/base64";
|
||||
import { extname } from "@std/path";
|
||||
import { get_host } from "../server/utils.ts";
|
||||
|
||||
const STATIC_FILES = ["/common.css", "/scrollBar.css", "/sw.js", "/sw.js.map"];
|
||||
|
||||
@@ -94,6 +98,42 @@ export async function handler(req: Request, ctx: FreshContext) {
|
||||
)?.setAttribute("content", title);
|
||||
doc.querySelector('meta[name="description"]')
|
||||
?.setAttribute("content", desc);
|
||||
if (m.cfg.img_verify_secret && doc) {
|
||||
const p = m.db.get_pmeta_by_index(st.info.gid, 1);
|
||||
if (p) {
|
||||
const t = m.db.get_files(p.token);
|
||||
if (t.length) {
|
||||
const tverify = encodeBase64(
|
||||
new Uint8Array(
|
||||
await pbkdf2Hmac(
|
||||
`${t[0].id}`,
|
||||
m.cfg.img_verify_secret,
|
||||
1000,
|
||||
64,
|
||||
"SHA-512",
|
||||
),
|
||||
),
|
||||
);
|
||||
let url: string | undefined;
|
||||
if (m.cfg.use_path_based_img_url) {
|
||||
const ext = extname(t[0].path);
|
||||
url = `${get_host(req)}/file/${
|
||||
encodeURIComponent(tverify)
|
||||
}/${t[0].id}${ext}`;
|
||||
} else {
|
||||
const b = new URLSearchParams();
|
||||
b.append("verify", tverify);
|
||||
url = `${get_host(req)}/file/${
|
||||
t[0].id
|
||||
}?${b}`;
|
||||
}
|
||||
const me = dom.createElement("meta");
|
||||
me.setAttribute("name", "og:image");
|
||||
me.setAttribute("content", url);
|
||||
doc.querySelector("head")?.append(me);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Response(
|
||||
"<!DOCTYPE html>\n" + doc.outerHTML,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user