Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading assets from the filesystem directly? #102

Closed
zkat opened this issue Jun 14, 2024 · 3 comments
Closed

Loading assets from the filesystem directly? #102

zkat opened this issue Jun 14, 2024 · 3 comments

Comments

@zkat
Copy link

zkat commented Jun 14, 2024

I have a situation where I can't make network requests and everything has to be bundled. I can do some juggling of things to write all the assets back into the filesystem somewhere that the application can read them, but I can't actually get dice-box to read from the filesystem itself, given a file:// path.

Is this a thing that's possible at all?

@frankieali
Copy link
Contributor

As far as I know, fetching from file:// is not allowed as it is a security problem.
The base path to assets is set here:

const basePath = `${this.config.origin}${this.config.assetPath}themes/${theme}`

It uses the config options origin and assetPath. origin defaults to window.location.origin
My only suggestion would be to try setting the config option origin to your file:// root path if you haven't tried that already.

@frankieali
Copy link
Contributor

This example shows how origin was set to point to enable loading files from a different url. Not sure that it will work with file:// though.
https://codesandbox.io/p/sandbox/dice-es6-module-cdn-lhbs99?file=%2Fsrc%2Findex.js

@zkat
Copy link
Author

zkat commented Jun 14, 2024

I figured it out!

For anyone curious in the future about how to get this working with something like Obsidian: Electron apps often provide something like an app:// protocol, which is good enough for serving URLs that won't count as "local". So I just needed to find out how to grab the one for Obsidian, which is through plugin.app.vault.adapter.getResourcePath. Once I did the work of spitting out all the files from my bundle back into the filesystem, I just set the origin to a path based on getResourcePath and everything just worked! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants