Skip to content

Commit

Permalink
Support uploaded storyfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
curiousdannii committed Oct 4, 2024
1 parent b838bb1 commit 91ee9ac
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/dialog/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ export class ProviderBasedBrowserDialog implements BrowserDialog {

async download(url: string, progress_callback?: ProgressCallback): Promise<string> {
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
}

Expand All @@ -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)
}
Expand All @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions src/dialog/browser/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DirBrowser> {
return this.next.browse()
}
Expand Down
1 change: 1 addition & 0 deletions src/dialog/browser/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type ProgressCallback = (bytes: number) => void

export interface BrowserDialog extends AsyncDialog {
download(url: string, progress_callback?: ProgressCallback): Promise<string>
upload(file: File): Promise<string>
}

export interface DownloadOptions {
Expand Down

0 comments on commit 91ee9ac

Please sign in to comment.