Skip to content

Commit c6f5f16

Browse files
committed
Allow filePath to be a URL
1 parent b1162f3 commit c6f5f16

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/utils.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { env } = require('./env.js');
55

66
if (global.ReadableStream === undefined && typeof process !== 'undefined') {
77
try {
8+
// @ts-ignore
89
global.ReadableStream = require('node:stream/web').ReadableStream; // ReadableStream is not a global with Node 16
910
} catch(err) {
1011
console.warn("ReadableStream not defined and unable to import from node:stream/web");
@@ -14,7 +15,7 @@ if (global.ReadableStream === undefined && typeof process !== 'undefined') {
1415
class FileResponse {
1516
/**
1617
* Creates a new `FileResponse` object.
17-
* @param {string} filePath
18+
* @param {string|URL} filePath
1819
*/
1920
constructor(filePath) {
2021
this.filePath = filePath;
@@ -55,7 +56,7 @@ class FileResponse {
5556
*/
5657
updateContentType() {
5758
// Set content-type header based on file extension
58-
const extension = this.filePath.split('.').pop().toLowerCase();
59+
const extension = this.filePath.toString().split('.').pop().toLowerCase();
5960
switch (extension) {
6061
case 'txt':
6162
this.headers['content-type'] = 'text/plain';
@@ -156,7 +157,7 @@ class FileResponse {
156157
/**
157158
* Determines whether the given string is a valid HTTP or HTTPS URL.
158159
* @function
159-
* @param {string} string - The string to test for validity as an HTTP or HTTPS URL.
160+
* @param {string|URL} string - The string to test for validity as an HTTP or HTTPS URL.
160161
* @returns {boolean} - True if the string is a valid HTTP or HTTPS URL, false otherwise.
161162
*/
162163
function isValidHttpUrl(string) {
@@ -175,7 +176,7 @@ function isValidHttpUrl(string) {
175176
*
176177
* @async
177178
* @function getFile
178-
* @param {string} url - The URL of the file to get.
179+
* @param {string|URL} url - The URL of the file to get.
179180
* @returns {Promise<FileResponse|Response>} A promise that resolves to a FileResponse object (if the file is retrieved using the FileSystem API), or a Response object (if the file is retrieved using the Fetch API).
180181
*/
181182
async function getFile(url) {

0 commit comments

Comments
 (0)