Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: support remote file paths #35

Merged
merged 1 commit into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/parts/GetResponse/GetResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { fileURLToPath } from 'node:url'
import * as HandleIndexHtml from '../HandleIndexHtml/HandleIndexHtml.ts'
import * as HandleOther from '../HandleOther/HandleOther.ts'
import * as HandlePreviewInjected from '../HandlePreviewInjected/HandlePreviewInjected.ts'
import * as ResolveFilePath from '../ResolveFilePath/ResolveFilePath.ts'

export const getResponse = async (pathName: string, frameAncestors: string, webViewRoot: string): Promise<Response> => {
const filePath = fileURLToPath(`file://${webViewRoot}${pathName}`)
const filePath = ResolveFilePath.resolveFilePath(pathName, webViewRoot)
const isHtml = filePath.endsWith('index.html')
if (isHtml) {
return HandleIndexHtml.handleIndexHtml(filePath, frameAncestors)
Expand Down
16 changes: 16 additions & 0 deletions src/parts/ResolveFilePath/ResolveFilePath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { fileURLToPath } from 'node:url'

export const resolveFilePath = (pathName: string, webViewRoot: string) => {
// TODO remove this, double slash should not be allowed
// TODO use path.resolve and verify that file path is in allowed roots
if (pathName.startsWith('/remote//')) {
const filePath = pathName.slice('/remote/'.length)
return fileURLToPath(`file://${filePath}`)
}
if (pathName.startsWith('/remote/')) {
const filePath = pathName.slice('/remote'.length)
return fileURLToPath(`file://${filePath}`)
}
const filePath = fileURLToPath(`file://${webViewRoot}${pathName}`)
return filePath
}