Skip to content

Commit

Permalink
Mark all properties of DownloadOptions as optional
Browse files Browse the repository at this point in the history
  • Loading branch information
curiousdannii committed Dec 10, 2024
1 parent 7a932df commit 261a7c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
12 changes: 7 additions & 5 deletions src/common/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ 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[],
direct_domains?: string[],
/** Path to resources */
lib_path: string,
lib_path?: string,
/** URL of Proxy */
proxy_url: string,
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,
}

Expand Down Expand Up @@ -66,12 +67,13 @@ async function fetch_resource_inner(options: DownloadOptions, path: string, prog
}

// Handle when lib_path is a proper URL (such as import.meta.url), as well as the old style path fragment
const lib_path = options.lib_path ?? import.meta.url
let url: URL | string
try {
url = new URL(path, options.lib_path)
url = new URL(path, lib_path)
}
catch {
url = options.lib_path + path
url = lib_path + path
}

if (path.endsWith('.js')) {
Expand Down
10 changes: 5 additions & 5 deletions src/dialog/browser/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export async function fetch_storyfile(options: DownloadOptions, url: string, pro
const story_domain = story_url.hostname
const same_protocol = story_url.protocol === document.location.protocol
const same_domain = story_domain === document.location.hostname
const proxy_url = `${options.proxy_url}?url=${story_url}`
let response: Response

// Load an embedded storyfile
Expand All @@ -92,8 +91,9 @@ export async function fetch_storyfile(options: DownloadOptions, url: string, pro

// Only directly access files same origin files or those from the list of reliable domains
let direct_access = (same_protocol && same_domain) || story_url.protocol === 'data:'
if (!direct_access) {
for (const domain of options.direct_domains) {
const direct_domains = options.direct_domains
if (!direct_access && direct_domains) {
for (const domain of direct_domains) {
if (story_domain.endsWith(domain)) {
// all direct domains require HTTPS
story_url.protocol = 'https:'
Expand All @@ -115,8 +115,8 @@ export async function fetch_storyfile(options: DownloadOptions, url: string, pro

// Otherwise use the proxy
else {
if (options.use_proxy) {
response = await fetch(proxy_url)
if (options.use_proxy && options.proxy_url) {
response = await fetch(`${options.proxy_url}?url=${story_url}`)
}
else {
throw new Error('Storyfile not in list of direct domains and proxy disabled')
Expand Down

0 comments on commit 261a7c6

Please sign in to comment.