Skip to content

Commit

Permalink
Fixed TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
yasharpm committed Aug 21, 2024
1 parent 8facb19 commit c11defb
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 89 deletions.
116 changes: 71 additions & 45 deletions release/remotestorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -54889,7 +54889,7 @@ class RemoteStorage {
case 'pod-not-selected':
if ((this.remote instanceof solid_1.default)
&& this.remote.getPodURLs().length > 0
&& this.remote.getPodURL() == null) {
&& this.remote.getPodURL() === null) {
setTimeout(handler, 0);
}
break;
Expand Down Expand Up @@ -55185,16 +55185,6 @@ class RemoteStorage {
log(...args) {
log_1.default.apply(RemoteStorage, args);
}
setSolidAuthURL(authURL) {
if (!authURL) {
return;
}
solid_1.default._rs_init(this);
this.solid.setAuthURL(authURL);
if (hasLocalStorage) {
localStorage.setItem('remotestorage:solid-auth-url', authURL); // TODO
}
}
/**
* Set the OAuth key/ID for either GoogleDrive, Dropbox or Solid backend support.
*
Expand Down Expand Up @@ -56024,16 +56014,13 @@ const baseclient_1 = __importDefault(__webpack_require__(/*! ./baseclient */ "./
const eventhandling_1 = __importDefault(__webpack_require__(/*! ./eventhandling */ "./src/eventhandling.ts"));
const util_1 = __webpack_require__(/*! ./util */ "./src/util.ts");
const remote_1 = __webpack_require__(/*! ./remote */ "./src/remote.ts");
const solidStorage_1 = __importDefault(__webpack_require__(/*! ./solid/solidStorage */ "./src/solid/solidStorage.ts"));
const solidStorage_1 = __importDefault(__webpack_require__(/*! ./solidStorage */ "./src/solidStorage.ts"));
const blob_1 = __importDefault(__webpack_require__(/*! blob */ "./node_modules/blob/main.js"));
const SETTINGS_KEY = 'remotestorage:solid';
let hasLocalStorage;
/**
* Overwrite BaseClient's getItemURL with our own implementation
*
* TODO: Still needs to be implemented. At the moment it just throws
* and error saying that it's not implemented yet.
*
* @param {object} rs - RemoteStorage instance
*
* @private
Expand All @@ -56043,8 +56030,19 @@ function hookGetItemURL(rs) {
return;
}
rs._origBaseClientGetItemURL = baseclient_1.default.prototype.getItemURL;
baseclient_1.default.prototype.getItemURL = function ( /* path */) {
throw new Error('getItemURL is not implemented for Solid yet'); // TODO It actually is. No?
baseclient_1.default.prototype.getItemURL = function (path) {
if (typeof path !== 'string') {
throw 'Argument \'path\' of baseClient.getItemURL must be a string';
}
if (this.storage.connected) {
if (path.startsWith('/')) {
path = path.substring(1);
}
return this.selectedPodURL + (0, util_1.cleanPath)(path);
}
else {
return undefined;
}
};
}
/**
Expand Down Expand Up @@ -56072,14 +56070,18 @@ function unHookGetItemURL(rs) {
*/
function requestBodyToBlob(body) {
if (typeof (body) === 'object') {
if (body instanceof blob_1.default)
if (body instanceof blob_1.default) {
return body;
if (body instanceof DataView)
}
if (body instanceof DataView) {
return new blob_1.default([body], { type: "application/octet-stream" });
if (body instanceof ArrayBuffer)
}
if (body instanceof ArrayBuffer) {
return new blob_1.default([new DataView(body)]);
if (ArrayBuffer.isView(body))
}
if (ArrayBuffer.isView(body)) {
return new blob_1.default([body], { type: "application/octet-stream" });
}
if (body instanceof FormData) {
return new blob_1.default([new URLSearchParams([JSON.parse(JSON.stringify(body.entries()))]).toString()], { type: 'application/x-www-form-urlencoded' });
}
Expand Down Expand Up @@ -56166,16 +56168,15 @@ class Solid extends remote_1.RemoteBase {
* @protected
*/
configure(settings) {
// TODO fix comments
// We only update this.userAddress if settings.userAddress is set to a string or to null
if (typeof settings.userAddress !== 'undefined') {
this.userAddress = settings.userAddress;
}
// We only update this.userAddress if settings.userAddress is set to a string or to null
// We only update this.authURL if settings.href is set to a string or to null
if (typeof settings.href !== 'undefined') {
this.authURL = settings.href;
}
// Same for this.token. If only one of these two is set, we leave the other one at its existing value
// Read session properties and pod URL from the properties if it exists
if (typeof settings.properties !== 'undefined') {
const properties = settings.properties;
if (properties) {
Expand Down Expand Up @@ -56218,8 +56219,7 @@ class Solid extends remote_1.RemoteBase {
};
if (this.sessionProperties) {
this.configStorage.setConfig(JSON.stringify(this.sessionProperties));
this.connected = false;
// TODO this.connect();
this.connected = this.session.info && this.session.info.isLoggedIn;
writeSettingsToCache.apply(this);
}
else {
Expand All @@ -56241,21 +56241,31 @@ class Solid extends remote_1.RemoteBase {
return this.podURLs;
}
setPodURL(podURL) {
if (this.selectedPodURL === podURL) {
return;
}
this.selectedPodURL = podURL;
if (this.session.info && this.session.info.isLoggedIn) {
let settings = (0, util_1.getJSONFromLocalStorage)(SETTINGS_KEY);
if (!settings) {
settings = {};
}
settings.userAddress = this.session.info.webId;
settings.href = this.authURL;
settings.properties = {
sessionProperties: this.sessionProperties,
podURL: this.selectedPodURL
};
localStorage.setItem(SETTINGS_KEY, JSON.stringify(settings));
if (this.selectedPodURL) {
let settings = (0, util_1.getJSONFromLocalStorage)(SETTINGS_KEY);
if (!settings) {
settings = {};
}
settings.userAddress = this.session.info.webId;
settings.href = this.authURL;
settings.properties = {
sessionProperties: this.sessionProperties,
podURL: this.selectedPodURL
};
localStorage.setItem(SETTINGS_KEY, JSON.stringify(settings));
this.connected = true;
this._emit('connected');
}
else {
this.connected = false;
this.rs._emit('pod-not-selected');
}
}
this._emit('connected');
}
getPodURL() {
return this.selectedPodURL;
Expand All @@ -56265,12 +56275,24 @@ class Solid extends remote_1.RemoteBase {
*/
connect() {
this.rs.setBackend('solid');
if (!this.authURL) {
this.rs._emit('error', new Error(`No authURL is configured.`));
return;
}
this.session.login({
oidcIssuer: this.authURL,
redirectUrl: new URL("/", window.location.href).toString(),
clientName: "Remote Storage"
});
}
/**
* Get the connected Solid session
*
* @returns {Session} that is being used by this instance
*/
getSession() {
return (this.session.info && this.session.info.isLoggedIn) ? this.session : undefined;
}
/**
* Convert path to file URL
*
Expand All @@ -56284,6 +56306,9 @@ class Solid extends remote_1.RemoteBase {
if (path.startsWith('/')) {
path = path.substring(1);
}
if (path.length === 0) {
path = '/';
}
return this.selectedPodURL + path;
}
/**
Expand All @@ -56308,9 +56333,10 @@ class Solid extends remote_1.RemoteBase {
map[itemName] = {}; // We are skipping ETag
}
else {
const fileDataset = (0, solid_client_1.getThing)(containerDataset, item);
map[itemName] = {
'Content-Length': 1,
'Last-Modified': 1, // date.toUTCString()
'Content-Length': (0, solid_client_1.getInteger)(fileDataset, 'http://www.w3.org/ns/posix/stat#size'),
'Last-Modified': (0, solid_client_1.getDatetime)(fileDataset, 'http://purl.org/dc/terms/modified').toUTCString(), // date.toUTCString()
};
}
return map;
Expand Down Expand Up @@ -56477,16 +56503,16 @@ class Solid extends remote_1.RemoteBase {
unHookGetItemURL(remoteStorage);
}
}
(0, util_1.applyMixins)(Solid, [eventhandling_1.default]); // TODO what is this?
(0, util_1.applyMixins)(Solid, [eventhandling_1.default]);
module.exports = Solid;


/***/ }),

/***/ "./src/solid/solidStorage.ts":
/*!***********************************!*\
!*** ./src/solid/solidStorage.ts ***!
\***********************************/
/***/ "./src/solidStorage.ts":
/*!*****************************!*\
!*** ./src/solidStorage.ts ***!
\*****************************/
/***/ (function(__unused_webpack_module, exports) {

"use strict";
Expand Down
2 changes: 1 addition & 1 deletion release/remotestorage.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/cachinglayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ abstract class CachingLayer {
// could call sync.queueGetRequest directly instead of needing
// this hacky third parameter as a callback
async get (path: string, maxAge: number, queueGetRequest: (path2: string) => Promise<QueuedRequestResponse>): Promise<QueuedRequestResponse> {

if (typeof (maxAge) === 'number') {
return this.getNodes(pathsFromRoot(path))
.then((objs) => {
Expand Down
13 changes: 0 additions & 13 deletions src/remotestorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,19 +527,6 @@ class RemoteStorage {
log.apply(RemoteStorage, args);
}

setSolidAuthURL(authURL: string) {
if (!authURL) {
return;
}

Solid._rs_init(this);
this.solid.setAuthURL(authURL);

if (hasLocalStorage) {
localStorage.setItem('remotestorage:solid-auth-url', authURL); // TODO
}
}

/**
* Set the OAuth key/ID for either GoogleDrive, Dropbox or Solid backend support.
*
Expand Down
41 changes: 32 additions & 9 deletions src/solid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import {
import {
getFile, overwriteFile, getContentType,
getPodUrlAll, deleteFile, getContainedResourceUrlAll, getSolidDataset,
FetchError, UrlString
FetchError, UrlString,
getThing, getInteger, getDatetime
} from "@inrupt/solid-client";
import BaseClient from './baseclient';
import EventHandling from './eventhandling';
import {
cleanPath,
applyMixins,
getJSONFromLocalStorage,
localStorageAvailable
Expand All @@ -26,18 +28,25 @@ let hasLocalStorage;
/**
* Overwrite BaseClient's getItemURL with our own implementation
*
* TODO: Still needs to be implemented. At the moment it just throws
* and error saying that it's not implemented yet.
*
* @param {object} rs - RemoteStorage instance
*
* @private
*/
function hookGetItemURL (rs): void {
if (rs._origBaseClientGetItemURL) { return; }
rs._origBaseClientGetItemURL = BaseClient.prototype.getItemURL;
BaseClient.prototype.getItemURL = function (/* path */): never {
throw new Error('getItemURL is not implemented for Solid yet'); // TODO It actually is. No?
BaseClient.prototype.getItemURL = function (path: string): string {
if (typeof path !== 'string') {
throw 'Argument \'path\' of baseClient.getItemURL must be a string';
}
if (this.storage.connected) {
if (path.startsWith('/')) {
path = path.substring(1);
}
return this.selectedPodURL + cleanPath(path);
} else {
return undefined;
}
};
}

Expand Down Expand Up @@ -312,6 +321,15 @@ class Solid extends RemoteBase implements Remote, ConfigObserver {
});
}

/**
* Get the connected Solid session
*
* @returns {Session} that is being used by this instance
*/
getSession(): Session {
return (this.session.info && this.session.info.isLoggedIn)?this.session:undefined;
}

/**
* Convert path to file URL
*
Expand All @@ -325,6 +343,9 @@ class Solid extends RemoteBase implements Remote, ConfigObserver {
if (path.startsWith('/')) {
path = path.substring(1);
}
if (path.length === 0) {
path = '/';
}
return this.selectedPodURL + path;
}

Expand Down Expand Up @@ -352,9 +373,11 @@ class Solid extends RemoteBase implements Remote, ConfigObserver {
map[itemName] = { }; // We are skipping ETag
}
else {
const fileDataset = getThing(containerDataset, item);

map[itemName] = {
'Content-Length': 1, // TODO FIX THESE
'Last-Modified': 1, // date.toUTCString()
'Content-Length': getInteger(fileDataset, 'http://www.w3.org/ns/posix/stat#size'),
'Last-Modified': getDatetime(fileDataset, 'http://purl.org/dc/terms/modified').toUTCString(), // date.toUTCString()
};
}

Expand Down Expand Up @@ -544,6 +567,6 @@ class Solid extends RemoteBase implements Remote, ConfigObserver {
}
}

applyMixins(Solid, [EventHandling]); // TODO what is this?
applyMixins(Solid, [EventHandling]);

export = Solid;
20 changes: 0 additions & 20 deletions test/unit/solid-suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,6 @@ define(['util', 'require', './build/eventhandling', './build/solid',
env.connectedClient = new Solid(env.rs);
util.localStorageAvailable = oldLocalStorageAvailable;

/*
{
"href": "https://solidcommunity.net",
"userAddress": "https://yasharpm.solidcommunity.net/profile/ca"
"properties": {
"sessionProperties": {
"clientId": "f3746db1ad9c6e83ec2c3ef76fd7dba5",
"clientSecret": "43ef2f966cbd1d6a974a9af590847daf",
"idTokenSignedResponseAlg": "RS256",
"sessionId": "any",
"codeVerifier": "3099e5e6e8d14a1c9a0ad328a2421d5a6f8f30f7c7b648c48326dd987df5ccf4c285700f206c4f4d8d24aacf664e1823",
"issuer": "https://solidcommunity.net",
"redirectUrl": "https://8080-pondersource-devstock-73mdx98iw45.ws-eu115.gitpod.io/",
"dpop": "true"
},
"podURL": "https://yasharpm.solidcommunity.net/"
}
}
*/

env.baseURI = 'https://example.com/storage/test';
env.connectedClient.configure({
userAddress: 'soliduser',
Expand Down

0 comments on commit c11defb

Please sign in to comment.