Skip to content

Commit

Permalink
Merge pull request #19 from rokoucha/fix-local-file-path
Browse files Browse the repository at this point in the history
ローカルファイルのパスをどの環境でも動くように組み立てる・ファイル名に # が入っていても壊れないようにする
  • Loading branch information
ci7lus authored Jan 15, 2023
2 parents 42b4304 + 1e41d41 commit fe7b7fb
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/miraktest-local/components/FileSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,20 @@ export const FileSelector: React.VFC<{
if (dialog.canceled) {
return
}
const path = dialog.filePaths.slice(0).shift()
const path = dialog.filePaths.at(0)
if (!path) {
return
}
setFilePath("file://" + path)
// Windows なら file:///C:\path\to\file.m2ts、Linux / Mac なら file:///path/to/file.m2ts になるように加工する。パスの要素それぞれに対してパーセントエンコードをする
const url =
"file:///" +
path
.replaceAll(/\\/g, "/")
.split("/")
.filter((p) => p !== "")
.map((p) => encodeURIComponent(p))
.join("/")
setFilePath(url)
}}
>
<File className="pointer-events-none" size="1.75rem" />
Expand Down

0 comments on commit fe7b7fb

Please sign in to comment.