Skip to content

Commit

Permalink
単一ファイルはaタグでダウンロードさせる
Browse files Browse the repository at this point in the history
Chromeだと認可を得ることが出来れば複数ダウンロードみたいのが出来るのでなんとかなる…
  • Loading branch information
yamachu committed Jul 4, 2023
1 parent 04084e8 commit 50bd37c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/browser/fileImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,15 @@ export const writeFileImpl: typeof window[typeof SandboxKey]["writeFile"] =
const path = obj.filePath;

if (path.indexOf(sep) === -1) {
return Promise.resolve({
code: undefined,
message:
"フォルダへのアクセス許可がありません、ブラウザ版ではファイル単体の書き出しをサポートしていません",
});
const aTag = document.createElement("a");
const blob = URL.createObjectURL(new Blob([obj.buffer]));
aTag.href = blob;
aTag.download = path;
document.body.appendChild(aTag);
aTag.click();
document.body.removeChild(aTag);
URL.revokeObjectURL(blob);
return;
}

const fileName = resolveFileName(path);
Expand Down Expand Up @@ -273,9 +277,7 @@ export const checkFileExistsImpl: typeof window[typeof SandboxKey]["checkFileExi
const path = file;

if (path.indexOf(sep) === -1) {
throw new Error(
"ブラウザ版ではフォルダを固定しないファイルへのアクセスをサポートしていません"
);
return Promise.resolve(false);
}

const fileName = resolveFileName(path);
Expand Down

0 comments on commit 50bd37c

Please sign in to comment.