From b28191a79f26106ba54705c6e5aa176175c9b6f4 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 10 Oct 2022 18:08:02 +0300 Subject: [PATCH] fixed root page access issues... Signed-off-by: Alex A. Naanou --- pwiki/path.js | 6 ++--- pwiki/store/base.js | 63 +++++++++++++++++++-------------------------- pwiki2.js | 6 ++--- 3 files changed, 32 insertions(+), 43 deletions(-) diff --git a/pwiki/path.js b/pwiki/path.js index 0ea7903..bd11364 100755 --- a/pwiki/path.js +++ b/pwiki/path.js @@ -351,11 +351,11 @@ module = { : path path = this.normalize(path, 'string') var name = path == '/' ? - this.ROOT_PAGE - : this.basename(path) + ['', this.ROOT_PAGE] + : [this.basename(path)] return name == '' ? this.ALTERNATIVE_PAGES.slice() - : [name, ...this.ALTERNATIVE_PAGES] }, + : [...name, ...this.ALTERNATIVE_PAGES] }, // diff --git a/pwiki/store/base.js b/pwiki/store/base.js index 56e3343..d14e8b7 100755 --- a/pwiki/store/base.js +++ b/pwiki/store/base.js @@ -239,39 +239,28 @@ module.BaseStore = { return path in this.data && path }, exists: async function(path){ - // XXX SANITIZE... - path = pwpath.sanitize(path, 'string') - /*/ - path = pwpath.normalize(path, 'string') - //*/ - var {path, args} = pwpath.splitArgs(path) - var res = (await this.__exists__(path)) - // NOTE: all paths at this point and in store are - // absolute, so we check both with the leading - // '/' and without it to make things a bit more - // relaxed and return the actual matching path... - // XXX SANITIZE... - || (await this.__exists__('/'+ path)) - /*/ - || (await this.__exists__( - path[0] == '/' ? - path.slice(1) - : ('/'+ path))) - //*/ - // delegate to .next... - || ((this.next || {}).__exists__ - && (await this.next.__exists__(path) - // XXX SANITIZE... - || await this.next.__exists__('/'+path))) - /*/ - || await this.next.__exists__( - path[0] == '/' ? - path.slice(1) - : ('/'+ path)))) - //*/ - // normalize the output... - || false - if(!res){ + var {path, args} = + pwpath.splitArgs( + pwpath.sanitize(path, 'string')) + + // NOTE: all paths at this point and in store are + // absolute, so we check both with the leading + // '/' and without it to make things a bit more + // relaxed and return the actual matching path... + var res = await this.__exists__(path) + // NOTE: res can be '' and thus we can't simply chain via || here... + typeof(res) != 'string' + && (res = await this.__exists__('/'+ path)) + + // delegate to .next... + typeof(res) != 'string' + && (this.next || {}).__exists__ + && (res = await this.next.__exists__(path)) + typeof(res) != 'string' + && (this.next || {}).__exists__ + && (res = await this.next.__exists__('/'+path)) + + if(typeof(res) != 'string'){ return false } return pwpath.joinArgs(res, args) }, // find the closest existing alternative path... @@ -555,7 +544,7 @@ module.BaseStore = { return this } path = pwpath.splitArgs(path).path path = await this.exists(path) - if(path){ + if(typeof(path) == 'string'){ await this.__delete__(path) // XXX CACHED this.__cache_remove(path) @@ -743,7 +732,7 @@ module.MetaStore = { null, function(res, path){ var s = this.substore(path) - return res == false ? + return typeof(res) != 'string' ? (this.next ? this.next.exists(path) : res) @@ -865,8 +854,8 @@ module.CachedStore = { var Store = module.Store = - //MetaStore - CachedStore + MetaStore + //CachedStore diff --git a/pwiki2.js b/pwiki2.js index 5b3744a..d8751ab 100755 --- a/pwiki2.js +++ b/pwiki2.js @@ -15,16 +15,16 @@ * - images * * +* XXX BUG: can't .get(..) data from substore root... * XXX IndexedDB: after editing a page for some reason we do not see the * final version until a full refresh -- cache??? +* ...this seems to disappeared after moving external stores +* from / to /Stores... * XXX Chrome started spamming CORS error: * Access to manifest at 'file:///L:/work/pWiki/manifest.json' * from origin 'null' ... * not sure why... * XXX test: can we store the file handler with permissions in a ServiceWorker?? -* XXX store: add an indexedDB backend -- save on serialization... -* - idb-keyval -* - native??? * XXX might be a good idea to wrap the wysiwig editor into a separate template * and use it in the main edit template to make it user-selectable... * XXX generalize html/dom api...