You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
2.2 KiB
56 lines
2.2 KiB
import type { H3Event } from "h3";
|
|
import fs from "fs/promises";
|
|
import { resolve } from "node:path";
|
|
|
|
const handler = eventHandler(async (event: H3Event) => {
|
|
const query = getQuery(event);
|
|
|
|
if (Reflect.has(query, "auto")) {
|
|
try {
|
|
return await $fetch("https://api.miaomc.cn/image/get", { method: "get", mode: "cors" })
|
|
} catch (error) {}
|
|
try {
|
|
return await sendRedirect(
|
|
event,
|
|
encodeURI("https://api.r10086.com/樱道随机图片api接口.php?图片系列=动漫综合1"),
|
|
302
|
|
);
|
|
} catch (error) {}
|
|
return "error"
|
|
}
|
|
if (Reflect.has(query, "miaomc")) {
|
|
// return await $fetch("https://api.miaomc.cn/image/get", { method: "get", mode: "cors" })
|
|
event.node.res.statusCode = 302;
|
|
event.node.res.setHeader("location", "https://api.miaomc.cn/image/get");
|
|
return;
|
|
}
|
|
if (Reflect.has(query, "r10086")) {
|
|
// return `<!DOCTYPE html><html lang="zh"><head><meta charset="utf-8"><title>选择</title></head>
|
|
// <body><script>location.href="https://api.r10086.com/樱道随机图片api接口.php?图片系列=动漫综合1"</script></body>
|
|
// </html>`;
|
|
return await sendRedirect(
|
|
event,
|
|
encodeURI("https://api.r10086.com/樱道随机图片api接口.php?图片系列=动漫综合1"),
|
|
302
|
|
);
|
|
}
|
|
if (Reflect.has(query, "favicon")) {
|
|
const avatarPath = resolve("public", "favicon.ico")
|
|
event.node.res.setHeader("Content-Type", "image/jpeg");
|
|
return fs.readFile(avatarPath) //fs.createReadStream(avatarPath);
|
|
}
|
|
return `<!DOCTYPE html><html lang="zh"><head><meta charset="utf-8"><title>选择</title></head>
|
|
<body>
|
|
<h1>选择图片路径</h1>
|
|
<ol>
|
|
<li><a href="/api/pic/random?auto">auto(同时支持以下两种方式)</a></li>
|
|
<li><a href="/api/pic/random?miaomc">api.miaomc.cn</a></li>
|
|
<li><a href="/api/pic/random?r10086">r10086</a></li>
|
|
<li><a href="/api/pic/random?favicon">favicon</a></li>
|
|
</ol>
|
|
</body>
|
|
</html>`;
|
|
});
|
|
|
|
export type ReturnData = Awaited<ReturnType<typeof handler>>;
|
|
export default handler;
|
|
|