Skip to content

Commit

Permalink
Separate the browser file functions from their interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
curiousdannii committed Dec 12, 2024
1 parent eecdc17 commit bef7f5a
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 28 deletions.
22 changes: 3 additions & 19 deletions src/common/file.ts → src/common/file/browser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Common file processing functions
================================
File processing functions for the browser
=========================================
Copyright (c) 2024 Dannii Willis
MIT licenced
Expand All @@ -11,23 +11,7 @@ https://github.com/curiousdannii/asyncglk

import {gunzipSync} from 'fflate'

export type ProgressCallback = (bytes: number) => void

export type TruthyOption = boolean | number

export interface DownloadOptions {
/** Domains to access directly: should always have both Access-Control-Allow-Origin and compression headers */
direct_domains?: string[],
/** Path to resources */
lib_path?: string,
/** URL of Proxy */
proxy_url?: string,
/** Whether to load embedded resources in single file mode */
single_file?: TruthyOption,
/** Use the file proxy; if disabled may mean that some files can't be loaded */
// We could just say to exclude proxy_url instead?
use_proxy?: boolean | number,
}
import type {DownloadOptions, ProgressCallback} from './interface.js'

/** Fetch a resource */
const resource_map: Map<string, any> = new Map()
Expand Down
28 changes: 28 additions & 0 deletions src/common/file/interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
File processing functions
=========================
Copyright (c) 2024 Dannii Willis
MIT licenced
https://github.com/curiousdannii/asyncglk
*/

export type ProgressCallback = (bytes: number) => void

export type TruthyOption = boolean | number

export interface DownloadOptions {
/** Domains to access directly: should always have both Access-Control-Allow-Origin and compression headers */
direct_domains?: string[],
/** Path to resources */
lib_path?: string,
/** URL of Proxy */
proxy_url?: string,
/** Whether to load embedded resources in single file mode */
single_file?: TruthyOption,
/** Use the file proxy; if disabled may mean that some files can't be loaded */
// We could just say to exclude proxy_url instead?
use_proxy?: boolean | number,
}
2 changes: 1 addition & 1 deletion src/dialog/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ https://github.com/curiousdannii/asyncglk
import {saveAs as filesave_saveAs} from 'file-saver'
import path from 'path-browserify-esm'

import type {DownloadOptions, ProgressCallback} from '../../common/file.js'
import type {DownloadOptions, ProgressCallback} from '../../common/file/interface.js'
import type {DialogDirectories, DialogOptions} from '../common/interface.js'
import {show_alert} from './common.js'
import {DownloadProvider, read_uploaded_file} from './download.js'
Expand Down
4 changes: 2 additions & 2 deletions src/dialog/browser/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ https://github.com/curiousdannii/asyncglk

import {gunzipSync} from 'fflate'

import type {DownloadOptions, ProgressCallback} from '../../common/file.js'
import type {DownloadOptions, ProgressCallback} from '../../common/file/interface.js'
import {parse_base64, read_response} from '../../common/file/browser.js'
import {NullProvider} from './common.js'
import type {Provider} from './interface.js'
import {parse_base64, read_response} from '../../common/file.js'
import {utf8decoder} from '../../common/misc.js'

export class DownloadProvider implements Provider {
Expand Down
2 changes: 1 addition & 1 deletion src/dialog/browser/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ https://github.com/curiousdannii/asyncglk
*/

import type {ProgressCallback} from '../../common/file.js'
import type {ProgressCallback} from '../../common/file/interface.js'
import type {AsyncDialog} from '../common/interface.js'

export interface BrowserDialog extends AsyncDialog {
Expand Down
2 changes: 1 addition & 1 deletion src/glkote/common/glkote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ https://github.com/curiousdannii/asyncglk

import {Blorb} from '../../blorb/blorb.js'
import * as Constants from '../../common/constants.js'
import type {DownloadOptions} from '../../common/file.js'
import type {DownloadOptions} from '../../common/file/interface.js'
import * as protocol from '../../common/protocol.js'
import {filetype_to_extension} from '../../dialog/common/common.js'
import type {Dialog} from '../../dialog/common/interface.js'
Expand Down
2 changes: 1 addition & 1 deletion src/glkote/web/schannels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ https://github.com/curiousdannii/asyncglk
*/

import {fetch_resource} from '../../common/file.js'
import {fetch_resource} from '../../common/file/browser.js'
import * as protocol from '../../common/protocol.js'
import WebGlkOte from './web.js'

Expand Down
2 changes: 1 addition & 1 deletion src/index-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ https://github.com/curiousdannii/asyncglk

export * from './index-common.js'

export {fetch_resource} from './common/file.js'
export {fetch_resource, parse_base64, read_response} from './common/file/browser.js'

export {ProviderBasedBrowserDialog} from './dialog/browser/browser.js'

Expand Down
3 changes: 1 addition & 2 deletions src/index-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ export type {BlorbChunk, BlorbDataChunk, ImageInfo, ImageSize, InfoMap, InfoMapR
export {IFF} from './blorb/iff.js'

export * as constants from './common/constants.js'
export {parse_base64, read_response} from './common/file.js'
export type {DownloadOptions, ProgressCallback, TruthyOption} from './common/file.js'
export type {DownloadOptions, ProgressCallback, TruthyOption} from './common/file/interface.js'
export {FileView} from './common/misc.js'
export * as protocol from './common/protocol.js'

Expand Down

0 comments on commit bef7f5a

Please sign in to comment.