fix: raw html links and engine
This commit is contained in:
parent
739d029339
commit
a3567cfb34
@ -19,7 +19,8 @@ import {
|
||||
export default async function handlePage(
|
||||
url: string, // remote URL
|
||||
requestUrl: URL, // proxy URL
|
||||
engine?: string
|
||||
engine?: string,
|
||||
redirect_path: string = "get"
|
||||
): Promise<IHandlerOutput> {
|
||||
const urlObj = new URL(url);
|
||||
|
||||
@ -38,7 +39,7 @@ export default async function handlePage(
|
||||
|
||||
[...window.document.getElementsByTagName("a")].forEach((link) => {
|
||||
try {
|
||||
link.href = generateProxyUrl(requestUrl, link.href, engine);
|
||||
link.href = generateProxyUrl(requestUrl, link.href, engine, redirect_path);
|
||||
} catch (_err) {
|
||||
// ignore TypeError: Invalid URL
|
||||
}
|
||||
|
@ -9,7 +9,8 @@ export default async function rawHtml(fastify: FastifyInstance) {
|
||||
fastify.get<IParseSchema>(
|
||||
"/api/raw-html",
|
||||
{ schema: rawHtmlSchema },
|
||||
async (request) => {
|
||||
async (request, reply) => {
|
||||
reply.type("text/html; charset=utf-8");
|
||||
return (
|
||||
await handlePage(
|
||||
request.query.url,
|
||||
@ -17,7 +18,9 @@ export default async function rawHtml(fastify: FastifyInstance) {
|
||||
request.protocol,
|
||||
request.hostname,
|
||||
request.originalUrl
|
||||
)
|
||||
),
|
||||
request.query.engine,
|
||||
"api/raw-html"
|
||||
)
|
||||
).content;
|
||||
}
|
||||
|
@ -9,7 +9,8 @@ export function generateRequestUrl(
|
||||
export function generateProxyUrl(
|
||||
requestUrl: URL,
|
||||
href: string,
|
||||
engine?: string
|
||||
engine?: string,
|
||||
redirect_url: string = "get"
|
||||
): string {
|
||||
const parsedHref = new URL(href);
|
||||
|
||||
@ -19,5 +20,5 @@ export function generateProxyUrl(
|
||||
const urlParam = `?url=${encodeURIComponent(parsedHref.toString())}`;
|
||||
const engineParam = engine ? `&engine=${engine}` : "";
|
||||
|
||||
return `${requestUrl.origin}/get${urlParam}${engineParam}${hash}`;
|
||||
return `${requestUrl.origin}/${redirect_url}${urlParam}${engineParam}${hash}`;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user