(urlOrPath)
| 58 | * @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). |
| 59 | */ |
| 60 | export async function getFile(urlOrPath) { |
| 61 | if (env.useFS && !isValidUrl(urlOrPath, ['http:', 'https:', 'blob:'])) { |
| 62 | return new FileResponse( |
| 63 | urlOrPath instanceof URL |
| 64 | ? urlOrPath.protocol === 'file:' |
| 65 | ? urlOrPath.pathname |
| 66 | : urlOrPath.toString() |
| 67 | : urlOrPath, |
| 68 | ); |
| 69 | } else { |
| 70 | return env.fetch(urlOrPath, { |
| 71 | headers: getFetchHeaders(urlOrPath), |
| 72 | }); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Generates appropriate HTTP headers for fetching resources. |
no test coverage detected