diff --git a/src/common/file.ts b/src/common/file/browser.ts similarity index 84% rename from src/common/file.ts rename to src/common/file/browser.ts index 9365725..529f7a3 100644 --- a/src/common/file.ts +++ b/src/common/file/browser.ts @@ -1,7 +1,7 @@ /* -Common file processing functions -================================ +File processing functions for the browser +========================================= Copyright (c) 2024 Dannii Willis MIT licenced @@ -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 = new Map() diff --git a/src/common/file/interface.ts b/src/common/file/interface.ts new file mode 100644 index 0000000..ea49e68 --- /dev/null +++ b/src/common/file/interface.ts @@ -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, +} \ No newline at end of file diff --git a/src/dialog/browser/browser.ts b/src/dialog/browser/browser.ts index 4d5d953..5c6db11 100644 --- a/src/dialog/browser/browser.ts +++ b/src/dialog/browser/browser.ts @@ -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' diff --git a/src/dialog/browser/download.ts b/src/dialog/browser/download.ts index 41c6cc4..8d86b9d 100644 --- a/src/dialog/browser/download.ts +++ b/src/dialog/browser/download.ts @@ -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 { diff --git a/src/dialog/browser/interface.ts b/src/dialog/browser/interface.ts index 68fdc9b..d6f8184 100644 --- a/src/dialog/browser/interface.ts +++ b/src/dialog/browser/interface.ts @@ -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 { diff --git a/src/glkote/common/glkote.ts b/src/glkote/common/glkote.ts index 127cc43..23f8e16 100644 --- a/src/glkote/common/glkote.ts +++ b/src/glkote/common/glkote.ts @@ -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' diff --git a/src/glkote/web/schannels.ts b/src/glkote/web/schannels.ts index 050f2e7..445d0bb 100644 --- a/src/glkote/web/schannels.ts +++ b/src/glkote/web/schannels.ts @@ -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' diff --git a/src/index-browser.ts b/src/index-browser.ts index 413cc7e..da07d16 100644 --- a/src/index-browser.ts +++ b/src/index-browser.ts @@ -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' diff --git a/src/index-common.ts b/src/index-common.ts index 0e2b50d..6c2a211 100644 --- a/src/index-common.ts +++ b/src/index-common.ts @@ -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'