Skip to content

Commit

Permalink
readme & other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-zucker committed Feb 17, 2021
1 parent 185a7cc commit a6e438c
Show file tree
Hide file tree
Showing 17 changed files with 226 additions and 94 deletions.
17 changes: 4 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,8 @@ Treat any storage backend as a Solid pod

Solid-Rest translates Solid requests into backend requests and backend responses into Solid responses. This means that any storage system that has a Solid-Rest plugin may be treated as a pod. Currently there are plugins for file and dropbox which means that any app that uses Solid-Rest can address file:// and dropbox:// URIs the same way as a Solid pod https:// URI and expect the same responses with some exceptions : permissions are not handled by Solid .acls, they are based on the underlying file or cloud permissions; collaborative tools such as chat are not available. These backends can now be addressed with most Solid libraries (e.g. rdflib) and apps (e.g. the databrowser).

Plugins for ssh, in-memory storage, in-browser storage (indexedDB, localStorage, Native File API) are almost ready and will be released soon.
Plugins for ssh, in-memory storage, in-browser storage (indexedDB, localStorage, Native File API) are in development.

Although Solid-Rest can be used stand-alone, it is best used in conjunction with other libraries, especially [Solid-Node-Client](), a nodejs client for Solid. Solid-Node-Client comes preloaded with the Solid-Rest-File plugin and you may add the dropbox and other plugins as shown below:
```javascript
import { SolidNodeClient } from 'SolidNodeClient';
import { SolidRestDropbox } from 'SolidRestDropbox';
const client = new SolidNodeClient({
handlers : { dropbox : new SolidRestDropbox() }
});
await client.login( your_dropbox_credentials, {protocol:'dropbox'} );
await client.login( your_pod_credentials, {protocol:'https'} );
// you may now use client.fetch() as per the [Solid Rest Spec]() with
// dropbox://, file://, and authenticated https:// URIs.
```
Although Solid-Rest can be used stand-alone, it is best used in conjunction with other libraries, especially [Solid-Node-Client](), a nodejs client for Solid.
Solid-Node-Client comes preloaded with the Solid-Rest-File plugin, so it will be transparently included in anything using that library.

4 changes: 0 additions & 4 deletions core/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@
.#*
drafts
node_modules
dist
coverage
lib
test-folder
log.txt
8 changes: 5 additions & 3 deletions core/src/handleRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const methods = {
PATCH: {
requiresWrite: 1,
requiresContentType: 1
},
LOGIN: {
}
};
export async function handleRequest(uri, originalRequest) {
Expand All @@ -41,7 +43,7 @@ export async function handleRequest(uri, originalRequest) {
if (request.method === 'POST' && !request.headers.link) return 400;
const item = this.item = await this.getItem(uri, request); //
// Errors we find by comparing the request & the itemRequested

if(item.isContainer && !item.contentType) item.contentType="text/turtle";
if (item.folderFileConfusion) return 400; // can't have both /foo and /foo/

if (item.patchOnNonRdf) return 400;
Expand Down Expand Up @@ -73,7 +75,7 @@ export async function handleRequest(uri, originalRequest) {


if (request.method === 'PUT' || request.method === 'PATCH') {
if (item.isContainer) return 405;
// if (item.isContainer) return 405;
let okDir = await this.perform('CREATE_INTERMEDIATE_CONTAINERS');
if (!okDir) return 500;
}
Expand All @@ -88,4 +90,4 @@ export async function handleRequest(uri, originalRequest) {
// SUCCESS !!!

return response;
} // ENDS
} // ENDS
10 changes: 8 additions & 2 deletions core/src/handleResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,26 @@ export async function handleResponse(response, originalRequest) {

const body = finalResponse.body || this.response.body || ""; // Now we merge headers we created with response headers, prefering response



Object.assign(headers, finalResponse.headers);
headers.status = headers.status || this.response.headers.status || 500;
headers.statusText = headers.statusText || statusText[headers.status]; //console.log(headers)
headers.statusText = headers.statusText || statusText[headers.status];
// Now we create & return the Response object

if (originalRequest.plainResponse) {
// from a server that wants to munge
return {
status:headers.status,
statusText:headers.statusText,
body: body,
headers: headers
};
}

headers = wrapHeaders ? {
status:headers.status,
statusText:headers.statusText,
headers: headers
} : headers;
let responseObject;
Expand Down Expand Up @@ -126,4 +132,4 @@ function createLinkHeader(item) {
return;
`<${fn}.meta>; rel="describedBy", <${fn}.acl>; rel="acl",` + `<http://www.w3.org/ns/ldp#Resource>; rel="type"`;
}
} // THE END!
} // THE END!
6 changes: 4 additions & 2 deletions core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export default class SolidRest {
}

async login(options) {
return await this.perform('LOGIN', options);
options = {loginOptions:options,method:'login'};
let response = await this.handleRequest('http://example.org/', options);
return await this.handleResponse(response, options );
}

async itemExists(pathname) {
Expand All @@ -52,4 +54,4 @@ export default class SolidRest {
if (response === 401) return true;
}

} // THE END
} // THE END
15 changes: 6 additions & 9 deletions core/src/performRequestedMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default async function perform(method, pathname, content, ctype) {
break;

case 'LOGIN':
return await this.storage.login(pathname);
return await this.storage.login(this.request.loginoptions);
break;

case 'ITEM_TYPE':
Expand Down Expand Up @@ -132,17 +132,14 @@ export default async function perform(method, pathname, content, ctype) {

if (patchStatus !== 200) {
return {
headers: {
status: patchStatus
}
status: patchStatus,
statusText: newContent
};
}
} catch (e) {
return {
headers: {
status: parseInt(e),
statusText: e
}
status: parseInt(e),
statusText: e
};
}

Expand All @@ -153,4 +150,4 @@ export default async function perform(method, pathname, content, ctype) {
return putStatus;
break;
}
} // ENDS
} // ENDS
10 changes: 9 additions & 1 deletion dropbox/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Solid-Rest-Dropbox

A Solid-Rest plugin for Dropbox
Treat your Dropbox storage as a Solid pod

**Warning** This library is in development and should be considered experimental at this time. If you run into problems, contact me on the Solid forum (@jeffz) or Gitter channel. (@jeff-zucker).

This library treats a Dropbox host as a serverless Solid Pod, accepting Solid requests (GET, PUT, etc.) and returning Solid responses (wac-allow headers, turtle representation of folders, etc.).

The library may be used stand-alone (see [tests](./tests/all.js) for examples).<!-- , or as a plugin to [Solid-Node-Client](https://github.com/solid/solid-node-client) from where it can be integrated into almost any Solid library or app. Simply import Solid-Node-Client and thereafter use file:// URLs almost anywhere that https:// URLs work. See the Solid-Node-Client documentation for details. -->

&copy; 2021, Jeff Zucker, may be freely used with an MIT license.

36 changes: 36 additions & 0 deletions dropbox/examples/dropbox-read.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {SolidRestDropbox} from '../';
import {credentials} from '/home/jeff/.solid-identities.js';
const client = new SolidRestDropbox();

const access_token = credentials.dropbox.access_token;
const testFolder = 'dropbox:///';
const testFile = 'dropbox:///x.txt';

async function main(){
await login({access_token:access_token});
await readFolder( testFolder );
await readFile( testFile );
}
main();

async function login(init){
console.log("logging in ...");
let response = await client.login(init);
console.log("got status : ",response.status,response.statusText,"\n");
}
async function readFile(file){
console.log("reading file ",file);
let response = await client.fetch(file);
console.log("got content : ",await response.text(),"\n");
console.log("got status : ",response.status,response.statusText,"\n");
}
async function readFolder(folder){
console.log("reading folder ",folder);
let response = await client.fetch(folder);
let content = await response.text();
console.log("got container turtle : ",content.length,"\n");
console.log("got status : ",response.status,response.statusText,"\n");
}



2 changes: 1 addition & 1 deletion dropbox/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@solid-rest/dropbox",
"author": "Jeff Zucker",
"version": "1.0.5",
"version": "1.0.6",
"license": "MIT",
"description": "Solid-Rest plugin for Dropbox",
"main": "dist/cjs/index.js",
Expand Down
Loading

0 comments on commit a6e438c

Please sign in to comment.