chore: update getCurrentDomain to return undefined when not allowing localhost
This commit is contained in:
@@ -1,10 +1,30 @@
|
|||||||
import type { HonoRequest } from "hono";
|
import type { HonoRequest } from "hono";
|
||||||
|
|
||||||
export function getCurrentDomain(req: HonoRequest) {
|
export function getCurrentDomain(req: HonoRequest): string | undefined;
|
||||||
|
export function getCurrentDomain(
|
||||||
|
req: HonoRequest,
|
||||||
|
avoidLocalhost: false,
|
||||||
|
): string;
|
||||||
|
export function getCurrentDomain(
|
||||||
|
req: HonoRequest,
|
||||||
|
avoidLocalhost: true,
|
||||||
|
): string | undefined;
|
||||||
|
export function getCurrentDomain(req: HonoRequest, avoidLocalhost = true) {
|
||||||
let domain = req.url.replace(req.path, "");
|
let domain = req.url.replace(req.path, "");
|
||||||
if (domain.includes("?")) {
|
if (domain.includes("?")) {
|
||||||
domain = domain.split("?")[0];
|
domain = domain.split("?")[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (avoidLocalhost) {
|
||||||
|
if (
|
||||||
|
domain.includes("localhost") ||
|
||||||
|
domain.includes("127.0.0.1") ||
|
||||||
|
domain.includes("192.168.1")
|
||||||
|
) {
|
||||||
|
console.log("Domain is localhost, returning undefined");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return domain;
|
return domain;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,7 @@ export async function maybeScheduleNextAiringEpisode(
|
|||||||
aniListId: number,
|
aniListId: number,
|
||||||
) {
|
) {
|
||||||
const domain = getCurrentDomain(req);
|
const domain = getCurrentDomain(req);
|
||||||
if (
|
if (!domain) {
|
||||||
domain.includes("localhost") ||
|
|
||||||
domain.includes("127.0.0.1") ||
|
|
||||||
domain.includes("192.168.1")
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user