Skip to content

Commit

Permalink
Merge pull request #143 from waifuvault/fix-localhost
Browse files Browse the repository at this point in the history
Fix isLocalhost to handle both protocol and non protocol URLs
  • Loading branch information
nakedmcse authored Mar 31, 2024
2 parents 708c7f2 + dd5e087 commit 280febe
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/services/FileUrlService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { BadRequest, Forbidden, HTTPException, RequestURITooLong } from "@tsed/e
import path from "node:path";
import fs from "node:fs";
import { filesDir } from "../utils/Utils.js";
import isLocalhost from "is-localhost-ip";
import Module from "node:module";
import { Logger } from "@tsed/logger";
import { Readable } from "node:stream";
import { finished } from "node:stream/promises";
import { ReadableStream } from "node:stream/web";
import isLocalhost from "is-localhost-ip";

const require = Module.createRequire(import.meta.url);

Expand Down Expand Up @@ -113,6 +113,8 @@ export class FileUrlService {
}

private isLocalhost(url: string): Promise<boolean> {
return isLocalhost(punycode.toASCII(url).split("/")[0].split(":")[0]);
return url.includes("://")
? isLocalhost(punycode.toASCII(url).split("://")[1].split("/")[0])
: isLocalhost(punycode.toASCII(url).split("/")[0]);
}
}

0 comments on commit 280febe

Please sign in to comment.