Skip to content

Commit c11defb

Browse files
committed
Fixed TODOs
1 parent 8facb19 commit c11defb

File tree

6 files changed

+104
-89
lines changed

6 files changed

+104
-89
lines changed

release/remotestorage.js

+71-45
Original file line numberDiff line numberDiff line change
@@ -54889,7 +54889,7 @@ class RemoteStorage {
5488954889
case 'pod-not-selected':
5489054890
if ((this.remote instanceof solid_1.default)
5489154891
&& this.remote.getPodURLs().length > 0
54892-
&& this.remote.getPodURL() == null) {
54892+
&& this.remote.getPodURL() === null) {
5489354893
setTimeout(handler, 0);
5489454894
}
5489554895
break;
@@ -55185,16 +55185,6 @@ class RemoteStorage {
5518555185
log(...args) {
5518655186
log_1.default.apply(RemoteStorage, args);
5518755187
}
55188-
setSolidAuthURL(authURL) {
55189-
if (!authURL) {
55190-
return;
55191-
}
55192-
solid_1.default._rs_init(this);
55193-
this.solid.setAuthURL(authURL);
55194-
if (hasLocalStorage) {
55195-
localStorage.setItem('remotestorage:solid-auth-url', authURL); // TODO
55196-
}
55197-
}
5519855188
/**
5519955189
* Set the OAuth key/ID for either GoogleDrive, Dropbox or Solid backend support.
5520055190
*
@@ -56024,16 +56014,13 @@ const baseclient_1 = __importDefault(__webpack_require__(/*! ./baseclient */ "./
5602456014
const eventhandling_1 = __importDefault(__webpack_require__(/*! ./eventhandling */ "./src/eventhandling.ts"));
5602556015
const util_1 = __webpack_require__(/*! ./util */ "./src/util.ts");
5602656016
const remote_1 = __webpack_require__(/*! ./remote */ "./src/remote.ts");
56027-
const solidStorage_1 = __importDefault(__webpack_require__(/*! ./solid/solidStorage */ "./src/solid/solidStorage.ts"));
56017+
const solidStorage_1 = __importDefault(__webpack_require__(/*! ./solidStorage */ "./src/solidStorage.ts"));
5602856018
const blob_1 = __importDefault(__webpack_require__(/*! blob */ "./node_modules/blob/main.js"));
5602956019
const SETTINGS_KEY = 'remotestorage:solid';
5603056020
let hasLocalStorage;
5603156021
/**
5603256022
* Overwrite BaseClient's getItemURL with our own implementation
5603356023
*
56034-
* TODO: Still needs to be implemented. At the moment it just throws
56035-
* and error saying that it's not implemented yet.
56036-
*
5603756024
* @param {object} rs - RemoteStorage instance
5603856025
*
5603956026
* @private
@@ -56043,8 +56030,19 @@ function hookGetItemURL(rs) {
5604356030
return;
5604456031
}
5604556032
rs._origBaseClientGetItemURL = baseclient_1.default.prototype.getItemURL;
56046-
baseclient_1.default.prototype.getItemURL = function ( /* path */) {
56047-
throw new Error('getItemURL is not implemented for Solid yet'); // TODO It actually is. No?
56033+
baseclient_1.default.prototype.getItemURL = function (path) {
56034+
if (typeof path !== 'string') {
56035+
throw 'Argument \'path\' of baseClient.getItemURL must be a string';
56036+
}
56037+
if (this.storage.connected) {
56038+
if (path.startsWith('/')) {
56039+
path = path.substring(1);
56040+
}
56041+
return this.selectedPodURL + (0, util_1.cleanPath)(path);
56042+
}
56043+
else {
56044+
return undefined;
56045+
}
5604856046
};
5604956047
}
5605056048
/**
@@ -56072,14 +56070,18 @@ function unHookGetItemURL(rs) {
5607256070
*/
5607356071
function requestBodyToBlob(body) {
5607456072
if (typeof (body) === 'object') {
56075-
if (body instanceof blob_1.default)
56073+
if (body instanceof blob_1.default) {
5607656074
return body;
56077-
if (body instanceof DataView)
56075+
}
56076+
if (body instanceof DataView) {
5607856077
return new blob_1.default([body], { type: "application/octet-stream" });
56079-
if (body instanceof ArrayBuffer)
56078+
}
56079+
if (body instanceof ArrayBuffer) {
5608056080
return new blob_1.default([new DataView(body)]);
56081-
if (ArrayBuffer.isView(body))
56081+
}
56082+
if (ArrayBuffer.isView(body)) {
5608256083
return new blob_1.default([body], { type: "application/octet-stream" });
56084+
}
5608356085
if (body instanceof FormData) {
5608456086
return new blob_1.default([new URLSearchParams([JSON.parse(JSON.stringify(body.entries()))]).toString()], { type: 'application/x-www-form-urlencoded' });
5608556087
}
@@ -56166,16 +56168,15 @@ class Solid extends remote_1.RemoteBase {
5616656168
* @protected
5616756169
*/
5616856170
configure(settings) {
56169-
// TODO fix comments
5617056171
// We only update this.userAddress if settings.userAddress is set to a string or to null
5617156172
if (typeof settings.userAddress !== 'undefined') {
5617256173
this.userAddress = settings.userAddress;
5617356174
}
56174-
// We only update this.userAddress if settings.userAddress is set to a string or to null
56175+
// We only update this.authURL if settings.href is set to a string or to null
5617556176
if (typeof settings.href !== 'undefined') {
5617656177
this.authURL = settings.href;
5617756178
}
56178-
// Same for this.token. If only one of these two is set, we leave the other one at its existing value
56179+
// Read session properties and pod URL from the properties if it exists
5617956180
if (typeof settings.properties !== 'undefined') {
5618056181
const properties = settings.properties;
5618156182
if (properties) {
@@ -56218,8 +56219,7 @@ class Solid extends remote_1.RemoteBase {
5621856219
};
5621956220
if (this.sessionProperties) {
5622056221
this.configStorage.setConfig(JSON.stringify(this.sessionProperties));
56221-
this.connected = false;
56222-
// TODO this.connect();
56222+
this.connected = this.session.info && this.session.info.isLoggedIn;
5622356223
writeSettingsToCache.apply(this);
5622456224
}
5622556225
else {
@@ -56241,21 +56241,31 @@ class Solid extends remote_1.RemoteBase {
5624156241
return this.podURLs;
5624256242
}
5624356243
setPodURL(podURL) {
56244+
if (this.selectedPodURL === podURL) {
56245+
return;
56246+
}
5624456247
this.selectedPodURL = podURL;
5624556248
if (this.session.info && this.session.info.isLoggedIn) {
56246-
let settings = (0, util_1.getJSONFromLocalStorage)(SETTINGS_KEY);
56247-
if (!settings) {
56248-
settings = {};
56249-
}
56250-
settings.userAddress = this.session.info.webId;
56251-
settings.href = this.authURL;
56252-
settings.properties = {
56253-
sessionProperties: this.sessionProperties,
56254-
podURL: this.selectedPodURL
56255-
};
56256-
localStorage.setItem(SETTINGS_KEY, JSON.stringify(settings));
56249+
if (this.selectedPodURL) {
56250+
let settings = (0, util_1.getJSONFromLocalStorage)(SETTINGS_KEY);
56251+
if (!settings) {
56252+
settings = {};
56253+
}
56254+
settings.userAddress = this.session.info.webId;
56255+
settings.href = this.authURL;
56256+
settings.properties = {
56257+
sessionProperties: this.sessionProperties,
56258+
podURL: this.selectedPodURL
56259+
};
56260+
localStorage.setItem(SETTINGS_KEY, JSON.stringify(settings));
56261+
this.connected = true;
56262+
this._emit('connected');
56263+
}
56264+
else {
56265+
this.connected = false;
56266+
this.rs._emit('pod-not-selected');
56267+
}
5625756268
}
56258-
this._emit('connected');
5625956269
}
5626056270
getPodURL() {
5626156271
return this.selectedPodURL;
@@ -56265,12 +56275,24 @@ class Solid extends remote_1.RemoteBase {
5626556275
*/
5626656276
connect() {
5626756277
this.rs.setBackend('solid');
56278+
if (!this.authURL) {
56279+
this.rs._emit('error', new Error(`No authURL is configured.`));
56280+
return;
56281+
}
5626856282
this.session.login({
5626956283
oidcIssuer: this.authURL,
5627056284
redirectUrl: new URL("/", window.location.href).toString(),
5627156285
clientName: "Remote Storage"
5627256286
});
5627356287
}
56288+
/**
56289+
* Get the connected Solid session
56290+
*
56291+
* @returns {Session} that is being used by this instance
56292+
*/
56293+
getSession() {
56294+
return (this.session.info && this.session.info.isLoggedIn) ? this.session : undefined;
56295+
}
5627456296
/**
5627556297
* Convert path to file URL
5627656298
*
@@ -56284,6 +56306,9 @@ class Solid extends remote_1.RemoteBase {
5628456306
if (path.startsWith('/')) {
5628556307
path = path.substring(1);
5628656308
}
56309+
if (path.length === 0) {
56310+
path = '/';
56311+
}
5628756312
return this.selectedPodURL + path;
5628856313
}
5628956314
/**
@@ -56308,9 +56333,10 @@ class Solid extends remote_1.RemoteBase {
5630856333
map[itemName] = {}; // We are skipping ETag
5630956334
}
5631056335
else {
56336+
const fileDataset = (0, solid_client_1.getThing)(containerDataset, item);
5631156337
map[itemName] = {
56312-
'Content-Length': 1,
56313-
'Last-Modified': 1, // date.toUTCString()
56338+
'Content-Length': (0, solid_client_1.getInteger)(fileDataset, 'http://www.w3.org/ns/posix/stat#size'),
56339+
'Last-Modified': (0, solid_client_1.getDatetime)(fileDataset, 'http://purl.org/dc/terms/modified').toUTCString(), // date.toUTCString()
5631456340
};
5631556341
}
5631656342
return map;
@@ -56477,16 +56503,16 @@ class Solid extends remote_1.RemoteBase {
5647756503
unHookGetItemURL(remoteStorage);
5647856504
}
5647956505
}
56480-
(0, util_1.applyMixins)(Solid, [eventhandling_1.default]); // TODO what is this?
56506+
(0, util_1.applyMixins)(Solid, [eventhandling_1.default]);
5648156507
module.exports = Solid;
5648256508

5648356509

5648456510
/***/ }),
5648556511

56486-
/***/ "./src/solid/solidStorage.ts":
56487-
/*!***********************************!*\
56488-
!*** ./src/solid/solidStorage.ts ***!
56489-
\***********************************/
56512+
/***/ "./src/solidStorage.ts":
56513+
/*!*****************************!*\
56514+
!*** ./src/solidStorage.ts ***!
56515+
\*****************************/
5649056516
/***/ (function(__unused_webpack_module, exports) {
5649156517

5649256518
"use strict";

release/remotestorage.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cachinglayer.ts

-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ abstract class CachingLayer {
135135
// could call sync.queueGetRequest directly instead of needing
136136
// this hacky third parameter as a callback
137137
async get (path: string, maxAge: number, queueGetRequest: (path2: string) => Promise<QueuedRequestResponse>): Promise<QueuedRequestResponse> {
138-
139138
if (typeof (maxAge) === 'number') {
140139
return this.getNodes(pathsFromRoot(path))
141140
.then((objs) => {

src/remotestorage.ts

-13
Original file line numberDiff line numberDiff line change
@@ -527,19 +527,6 @@ class RemoteStorage {
527527
log.apply(RemoteStorage, args);
528528
}
529529

530-
setSolidAuthURL(authURL: string) {
531-
if (!authURL) {
532-
return;
533-
}
534-
535-
Solid._rs_init(this);
536-
this.solid.setAuthURL(authURL);
537-
538-
if (hasLocalStorage) {
539-
localStorage.setItem('remotestorage:solid-auth-url', authURL); // TODO
540-
}
541-
}
542-
543530
/**
544531
* Set the OAuth key/ID for either GoogleDrive, Dropbox or Solid backend support.
545532
*

src/solid.ts

+32-9
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import {
55
import {
66
getFile, overwriteFile, getContentType,
77
getPodUrlAll, deleteFile, getContainedResourceUrlAll, getSolidDataset,
8-
FetchError, UrlString
8+
FetchError, UrlString,
9+
getThing, getInteger, getDatetime
910
} from "@inrupt/solid-client";
1011
import BaseClient from './baseclient';
1112
import EventHandling from './eventhandling';
1213
import {
14+
cleanPath,
1315
applyMixins,
1416
getJSONFromLocalStorage,
1517
localStorageAvailable
@@ -26,18 +28,25 @@ let hasLocalStorage;
2628
/**
2729
* Overwrite BaseClient's getItemURL with our own implementation
2830
*
29-
* TODO: Still needs to be implemented. At the moment it just throws
30-
* and error saying that it's not implemented yet.
31-
*
3231
* @param {object} rs - RemoteStorage instance
3332
*
3433
* @private
3534
*/
3635
function hookGetItemURL (rs): void {
3736
if (rs._origBaseClientGetItemURL) { return; }
3837
rs._origBaseClientGetItemURL = BaseClient.prototype.getItemURL;
39-
BaseClient.prototype.getItemURL = function (/* path */): never {
40-
throw new Error('getItemURL is not implemented for Solid yet'); // TODO It actually is. No?
38+
BaseClient.prototype.getItemURL = function (path: string): string {
39+
if (typeof path !== 'string') {
40+
throw 'Argument \'path\' of baseClient.getItemURL must be a string';
41+
}
42+
if (this.storage.connected) {
43+
if (path.startsWith('/')) {
44+
path = path.substring(1);
45+
}
46+
return this.selectedPodURL + cleanPath(path);
47+
} else {
48+
return undefined;
49+
}
4150
};
4251
}
4352

@@ -312,6 +321,15 @@ class Solid extends RemoteBase implements Remote, ConfigObserver {
312321
});
313322
}
314323

324+
/**
325+
* Get the connected Solid session
326+
*
327+
* @returns {Session} that is being used by this instance
328+
*/
329+
getSession(): Session {
330+
return (this.session.info && this.session.info.isLoggedIn)?this.session:undefined;
331+
}
332+
315333
/**
316334
* Convert path to file URL
317335
*
@@ -325,6 +343,9 @@ class Solid extends RemoteBase implements Remote, ConfigObserver {
325343
if (path.startsWith('/')) {
326344
path = path.substring(1);
327345
}
346+
if (path.length === 0) {
347+
path = '/';
348+
}
328349
return this.selectedPodURL + path;
329350
}
330351

@@ -352,9 +373,11 @@ class Solid extends RemoteBase implements Remote, ConfigObserver {
352373
map[itemName] = { }; // We are skipping ETag
353374
}
354375
else {
376+
const fileDataset = getThing(containerDataset, item);
377+
355378
map[itemName] = {
356-
'Content-Length': 1, // TODO FIX THESE
357-
'Last-Modified': 1, // date.toUTCString()
379+
'Content-Length': getInteger(fileDataset, 'http://www.w3.org/ns/posix/stat#size'),
380+
'Last-Modified': getDatetime(fileDataset, 'http://purl.org/dc/terms/modified').toUTCString(), // date.toUTCString()
358381
};
359382
}
360383

@@ -544,6 +567,6 @@ class Solid extends RemoteBase implements Remote, ConfigObserver {
544567
}
545568
}
546569

547-
applyMixins(Solid, [EventHandling]); // TODO what is this?
570+
applyMixins(Solid, [EventHandling]);
548571

549572
export = Solid;

test/unit/solid-suite.js

-20
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,6 @@ define(['util', 'require', './build/eventhandling', './build/solid',
3535
env.connectedClient = new Solid(env.rs);
3636
util.localStorageAvailable = oldLocalStorageAvailable;
3737

38-
/*
39-
{
40-
"href": "https://solidcommunity.net",
41-
"userAddress": "https://yasharpm.solidcommunity.net/profile/ca"
42-
"properties": {
43-
"sessionProperties": {
44-
"clientId": "f3746db1ad9c6e83ec2c3ef76fd7dba5",
45-
"clientSecret": "43ef2f966cbd1d6a974a9af590847daf",
46-
"idTokenSignedResponseAlg": "RS256",
47-
"sessionId": "any",
48-
"codeVerifier": "3099e5e6e8d14a1c9a0ad328a2421d5a6f8f30f7c7b648c48326dd987df5ccf4c285700f206c4f4d8d24aacf664e1823",
49-
"issuer": "https://solidcommunity.net",
50-
"redirectUrl": "https://8080-pondersource-devstock-73mdx98iw45.ws-eu115.gitpod.io/",
51-
"dpop": "true"
52-
},
53-
"podURL": "https://yasharpm.solidcommunity.net/"
54-
}
55-
}
56-
*/
57-
5838
env.baseURI = 'https://example.com/storage/test';
5939
env.connectedClient.configure({
6040
userAddress: 'soliduser',

0 commit comments

Comments
 (0)