-
Notifications
You must be signed in to change notification settings - Fork 9
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
BrowserFS implementation #24
Comments
...and girls, and men and women and transgender and non-binaries, etc. (or simply "Hey there, running..." / "Running..."). Just a little reminder for inclusiveness :) The problem is in rest.js. There we define a Here's the relevant part of the fetch function: https://github.com/jeff-zucker/solid-rest/blob/9567fb77abed828174c5136f9c82aa46e49d5743/src/rest.js#L48-L60 This should work fine, but the problem is that the other methods don't have access to this local path variable, hence it is undefined for them. For instance here in the getHeaders function: https://github.com/jeff-zucker/solid-rest/blob/9567fb77abed828174c5136f9c82aa46e49d5743/src/rest.js#L240-L243 So a simple solution would be to store the path as a field variable of the SolidRest instance ( |
Sorry @Otto-AA , i don't want to bless anyone.
Thxs all ;-) |
I think @jeff-zucker fixed most of this in this commit: 9e60683 But I don't think that this will work, because options is likely undefined here (as far as I see it's a local variable in the fetch method and it is not passed as parameter to To fix this you can either add the options to the function declaration (e.g. In general to make the code cleaner I'd suggest to split SolidRest into the two classes SolidRest and RequestHandler. The RequestHandler constructor could take the url, storage and options as parameter. The benefit would be, that you could assign the options to So it would look something like this: class SolidRest {
constructor( handlers ) {
this.storageHandlers = {}
if( typeof handlers ==="undefined") return
handlers.forEach( handler => {
console.log(`
Installing Rest Handler ${handler.name} using prefix ${handler.prefix}
`)
this.storageHandlers[handler.prefix] = handler
})
}
getStorage(uri){
const { protocol } = new URL(uri)
const prefix = protocol // TODO
if(!this.storageHandlers[prefix]) throw "Did not recognize prefix "+prefix
return this.storageHandlers[prefix]
}
async fetch(uri, options = {}) {
const storage = this.getStorage(uri)
const requestHandler = new RequestHandler(uri, storage, options)
return requestHandler.fetch()
}
}
class RequestHandler {
constructor(uri, storage, options) {
this.uri = uri
this.storage = storage
this.options = options
}
async fetch() {
switch(this.options.method) {
case 'GET':
return this.get()
case 'POST':
return this.post()
// ...
}
// ...
} If you want a refactor like this I could make a PR for it. It's not necessary, but it should make the code easier to maintain. |
Hi Thxs, in fact I don't really know what I want... I just want to understand how to use solid-rest. 😉 |
@scenaristeur I'm afraid I need to concentrate on the file:/// part of solid-rest and will not be able to even provide adequate examples of browserFS. I will probably mark it as experimental in the documentation. Nevertheless I believe that it can (or with a few tweaks it could) do what you want using either indexedDB or the Native File API, both of which are permenent and can be accessed via BrowserFS. If you run into specific issues, please let me know but I can't promise much response until other module issues are taken care of. |
@Otto-AA wrote : To fix this you can either add the options to the function declaration (e.g. function _getExtension(pathname, options) ) or assign it to this instead of the options object. I went with making options available everywhere it is needed. Using this would probably be cleaner, but will have to wait for another time. Otto and @bourgeoa - I've prioritized the issues as I see them and want to fix the red and orange ones before the green ones. If you would prioritize differently, let me know. |
@scenaristeur - I take it back, IT WORKS!. The fix turned out to be easier than I thought. It involves adding an initBackends call. I've re-written the browser-test.html and included some documentation in it. So you should be able to permanently store resources and containers in your Android browser's Native File API (HTML5FS) or IndexedDB or other storage spaces supported by BrowserFS. I haven't npm'd it yet, but the current 1.22 master has all the changes. @Otto-AA - it was good you caught the path/basename problem but LOL the error was from basename in the BrowserFS package, not in anything in solid-rest or solid-rest's browserFS plugin. It turns out that @CxRes's fix of the path/path.posix issue doesn't work in the browser - path.posix is undefined, so now I default to path if there is no path.posix. |
Thxs , I'll give it a try soon 👍😘😂 |
Hi guys, running opening tests/browser-test.html in the browser, i got a
TypeError: can't access property "basename", u is undefined
and same with my webapp
Do you have any idea where it comes from ?
THxs
The text was updated successfully, but these errors were encountered: