-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Load local file requested using file protocol in reviewer (json & text file) #11564
Conversation
Have you looked at the issues surrounding #10213 |
One approach worth considering in the future is switching mViewerUrl away from a file:// scheme, and using a fake https URL instead. Android appears to provide a helper class to make it easier to serve file content from shouldInterceptRequest: https://developer.android.com/reference/androidx/webkit/WebViewAssetLoader |
I have tested by adding following card template and it seems, it is working.
I created a issues, and implement the suggested option in next PR. |
Hello 👋, this PR has been opened for more than 2 months with no activity on it. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically |
No pressure at all here @krmanik - I'm just going through the whole PR queue oldest to newest and I'm curious what the plan here is? I have looked in your repo with you at PR 23 over there, and I know you've got the TS files working in the backend (but maybe we need a change there?). Let me know what you need to move this forward and I'll do my best to collaborate. In the meantime, I'm catching up again and now that summer travel is over I hope to get through the JS add-on work you've done |
Hi, If this issue fixed #11570 then the current PR will be closed. So, it needs work on the issues. |
Hello 👋, this PR has been opened for more than 2 months with no activity on it. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically |
scoped storage will finish, one of these days, and I can hopefully turn attention back to all the javascript work + crowdin API updates |
There is an already existing undocumented facility for loading files from the media folder: #7764 (comment). It works on Android 10+ as is; older Androids require a fix for correct MIME type identification (critical for JS modules, but not necessarily critical for a Wouldn't the following be already sufficient for JSON fetching: const mediaRoot = globalThis.AnkiDroidJS ? 'https://appassets.androidplatform.net'
: globalThis.ankiPlatform === 'desktop' ? '' : '.';
await fetch(`${mediaRoot}/file.json`); |
This PR can be closed now because latest version of AnkiDroid contains http server which can be used to fetch the json/files from collection.media. |
Pull Request template
Purpose / Description
I use Anki-Xiehanzi deck to study Chinese language and always want it to be offline, but json files in the deck need to be served over localhost because
file:///
protocol gives error when loading file other thanjs
.Anki desktop load this file because it uses localhost so all files in
collection.media
are accessible overhttp://127.0.0.1:<port>
.Fixes
Fixes #8525
Approach
When file (json & text) requested over
file:///
protocol then implementation in this PR will return the web response with file content.file:///
AbstractFlashcardViewer
decoded url passed toAnkiLoadLocalFile
AnkiLoadLocalFile
the url split with/
and last string used as filenameHow Has This Been Tested?
test.json
file incollection.media
dirNote: fetch will not return the file, but XMLHttpRequest will get the file.
Learning (optional, can help others)
krmanik#23
Checklist
Please, go through these checks before submitting the PR.
if
statements)