Skip to content

Commit

Permalink
make path/posixPath an option
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-zucker committed Jul 29, 2020
1 parent b14bc94 commit 9e60683
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
17 changes: 10 additions & 7 deletions src/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ async fetch(uri, options = {}) {
options.scheme = url.protocol

let pathname, path
/* mungedPath = USE default path() for file and posix.path for others)
*/
if (options.scheme.startsWith('file')) {
options.url = Url.format(url)
pathname = Url.fileURLToPath(options.url)
Expand All @@ -59,6 +61,7 @@ async fetch(uri, options = {}) {
options.rest_prefix=uri.replace(options.scheme+'//','').replace(/\/.*$/,'')
path = libPath.posix
}
options.mungedPath = path
/**/

if(!self.storage){
Expand Down Expand Up @@ -132,7 +135,7 @@ async fetch(uri, options = {}) {
let link = options.headers.Link || options.headers.link
let slug = options.headers.Slug || options.headers.slug || options.slug
if(slug.match(/\//)) return _response(null, resOptions, 400) // Now returns 400 instead of 404
pathname = path.join(pathname,slug);
pathname = options.mungedPath.join(pathname,slug);
if( pathname.startsWith('\\') ) pathname = pathname.replace(/\\/g,'/')

if( link && link.match("Container") ) {
Expand Down Expand Up @@ -185,7 +188,7 @@ async fetch(uri, options = {}) {
})

// cxRes
if ( !pathname.endsWith(path.sep) ) pathname += path.sep
if ( !pathname.endsWith(options.mungedPath.sep) ) pathname += options.mungedPath.sep
// if (!pathname.endsWith("/")) pathname += "/"

let str2 = ""
Expand Down Expand Up @@ -214,9 +217,9 @@ async fetch(uri, options = {}) {
/* treats filename ".acl" and ".meta" as extensions
*/
function _getExtension(pathname) {
let ext = ( path.basename(pathname).startsWith('.') )
? path.basename(pathname)
: path.extname(pathname)
let ext = ( options.mungedPath.basename(pathname).startsWith('.') )
? options.mungedPath.basename(pathname)
: options.mungedPath.extname(pathname)
return ext
}
function _getContentType(ext,type) {
Expand All @@ -241,8 +244,8 @@ async fetch(uri, options = {}) {
function _getHeaders(pathname,options){

// cxRes
path = path || libPath
const fn = path.basename(pathname)
// path = path || libPath
const fn = options.mungedPath.basename(pathname)
// let fn = encodeURI(pathname.replace(/.*\//,''))

let headers = (typeof self.storage(options).getHeaders != "undefined")
Expand Down
12 changes: 8 additions & 4 deletions tests/browser-test.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script src="../src/localStorage.js"></script>
<script src="../bundles/browserfs.min.js"></script>
<!-- <script src="../src/localStorage.js"></script> -->
<script src="../src/browserFS.js"></script>
<script src="../dist/main.js"></script>
<div id="results"></div>
<script>
Expand All @@ -11,7 +13,8 @@
/* This runs using src/localStorage directly
*/
async function runStorage(file,text){
const storage = new SolidLocalStorage()
// const storage = new SolidLocalStorage()
const storage = new SolidBrowserFS()
let response = await storage.putResource( file,{body:text} )
response = await storage.getResource( file )
show(await response)
Expand All @@ -20,8 +23,9 @@
/* This runs using src/localStorage via transpiled version of src/rest
*/
async function runRest(file,text){
file = "app://ls"+file
const rest = new SolidRest([ new SolidLocalStorage() ])
file = "app://bfs"+file
// const rest = new SolidRest([ new SolidLocalStorage() ])
const rest = new SolidRest([new SolidBrowserFS])
let response = await rest.fetch( file,{method:"PUT",body:text} )
response = await rest.fetch( file )
show(response.status+","+await response.text())
Expand Down

0 comments on commit 9e60683

Please sign in to comment.