diff --git a/src/dialog/browser/browser.ts b/src/dialog/browser/browser.ts index 2e908a9..7d217c3 100644 --- a/src/dialog/browser/browser.ts +++ b/src/dialog/browser/browser.ts @@ -57,10 +57,7 @@ export class ProviderBasedBrowserDialog implements BrowserDialog { async download(url: string, progress_callback?: ProgressCallback): Promise { const file_path = await this.downloader!.download(url, progress_callback) - const parsed_path = path.parse(file_path) - this.dirs.storyfile = parsed_path.dir - this.dirs.working = '/usr/' + parsed_path.name.toLowerCase().trim() - this.dialog!.update_direntry(this.dirs.working) + this.setup(file_path) return file_path } @@ -84,6 +81,12 @@ export class ProviderBasedBrowserDialog implements BrowserDialog { } } + async upload(file: File) { + const file_path = await this.downloader!.upload(file) + this.setup(file_path) + return file_path + } + delete(path: string): void { this.providers[0].delete(path) } @@ -99,6 +102,13 @@ export class ProviderBasedBrowserDialog implements BrowserDialog { write(path: string, data: Uint8Array): void { this.providers[0].write(path, data) } + + private setup(file_path: string) { + const parsed_path = path.parse(file_path) + this.dirs.storyfile = parsed_path.dir + this.dirs.working = '/usr/' + parsed_path.name.toLowerCase().trim() + this.dialog!.update_direntry(this.dirs.working) + } } export interface Filter { diff --git a/src/dialog/browser/download.ts b/src/dialog/browser/download.ts index e5adeda..fa1dc51 100644 --- a/src/dialog/browser/download.ts +++ b/src/dialog/browser/download.ts @@ -31,6 +31,13 @@ export class DownloadProvider implements Provider { return path } + async upload(file: File) { + const data = await read_uploaded_file(file) + const path = '/upload/' + file.name + this.store.set(path, data) + return path + } + async browse(): Promise { return this.next.browse() } diff --git a/src/dialog/browser/interface.ts b/src/dialog/browser/interface.ts index 71caa03..da68333 100644 --- a/src/dialog/browser/interface.ts +++ b/src/dialog/browser/interface.ts @@ -17,6 +17,7 @@ export type ProgressCallback = (bytes: number) => void export interface BrowserDialog extends AsyncDialog { download(url: string, progress_callback?: ProgressCallback): Promise + upload(file: File): Promise } export interface DownloadOptions {