mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-17 08:31:38 +00:00
cleaning up FileStore...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
188bdfe131
commit
56013209f2
54
pwiki2.js
54
pwiki2.js
@ -18,7 +18,6 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* TODO:
|
* TODO:
|
||||||
* - async parser does not work...
|
|
||||||
* - .load(..) / .json(..) -- for most stores...
|
* - .load(..) / .json(..) -- for most stores...
|
||||||
* might be a good idea to keep a unified format...
|
* might be a good idea to keep a unified format...
|
||||||
* - <page>.then() -- resolve when all pending write operations done ???
|
* - <page>.then() -- resolve when all pending write operations done ???
|
||||||
@ -571,7 +570,8 @@ function(meth, drop_cache=false, post){
|
|||||||
return async function(path, ...args){
|
return async function(path, ...args){
|
||||||
var store = this.substore(path)
|
var store = this.substore(path)
|
||||||
|
|
||||||
var res = store == null ?
|
var res =
|
||||||
|
store == null ?
|
||||||
object.parentCall(MetaStore, meth, this, path, ...args)
|
object.parentCall(MetaStore, meth, this, path, ...args)
|
||||||
//: this.data[store][meth](path.slice(store.length), ...args)
|
//: this.data[store][meth](path.slice(store.length), ...args)
|
||||||
: this.data[store][target](path.slice(store.length), ...args)
|
: this.data[store][target](path.slice(store.length), ...args)
|
||||||
@ -629,7 +629,7 @@ module.MetaStore = {
|
|||||||
// XXX revise...
|
// XXX revise...
|
||||||
__exists__: metaProxy('__exists__',
|
__exists__: metaProxy('__exists__',
|
||||||
function(res, store, path){
|
function(res, store, path){
|
||||||
return store ?
|
return (res && store) ?
|
||||||
// XXX which way should we go???
|
// XXX which way should we go???
|
||||||
//module.path.join(store, res)
|
//module.path.join(store, res)
|
||||||
path
|
path
|
||||||
@ -722,6 +722,8 @@ module.FileStore = {
|
|||||||
// XXX
|
// XXX
|
||||||
__path__: 'store/fs',
|
__path__: 'store/fs',
|
||||||
|
|
||||||
|
__directory_text__: '.text',
|
||||||
|
|
||||||
// XXX do we remove the extension???
|
// XXX do we remove the extension???
|
||||||
// XXX cache???
|
// XXX cache???
|
||||||
__paths__: async function(){
|
__paths__: async function(){
|
||||||
@ -735,18 +737,32 @@ module.FileStore = {
|
|||||||
return path
|
return path
|
||||||
.slice(that.__path__.length) })) }) }) },
|
.slice(that.__path__.length) })) }) }) },
|
||||||
__exists__: async function(path){
|
__exists__: async function(path){
|
||||||
return !!fs.existsSync(module.path.join(this.__path__, path)) ?
|
var p = module.path.join(this.__path__, path)
|
||||||
|
try {
|
||||||
|
var stat = await fs.promises.stat(p)
|
||||||
|
// NOTE: we consider a directory as "existing" iff we can
|
||||||
|
// produce text for it...
|
||||||
|
return stat.isDirectory() ?
|
||||||
|
(!!fs.existsSync(p +'/'+ this.__directory_text__)
|
||||||
|
&& path)
|
||||||
|
: !!fs.existsSync(p) ?
|
||||||
path
|
path
|
||||||
: false },
|
: false
|
||||||
|
} catch(err){
|
||||||
|
return false } },
|
||||||
__get__: async function(path){
|
__get__: async function(path){
|
||||||
var p = module.path.join(this.__path__, path)
|
var p = module.path.join(this.__path__, path)
|
||||||
var {atimeMs, mtimeMs, ctimeMs, birthtimeMs} = await fs.promises.stat(p)
|
var stat = await fs.promises.stat(p)
|
||||||
|
var {atimeMs, mtimeMs, ctimeMs, birthtimeMs} = stat
|
||||||
return {
|
return {
|
||||||
atime: atimeMs,
|
atime: atimeMs,
|
||||||
mtime: mtimeMs,
|
mtime: mtimeMs,
|
||||||
ctime: ctimeMs,
|
ctime: ctimeMs,
|
||||||
text: fs.readFileSync(p).toString(),
|
text: stat.isDirectory() ?
|
||||||
|
fs.readFileSync(p +'/'+ this.__directory_text__).toString()
|
||||||
|
: fs.readFileSync(p).toString(),
|
||||||
} },
|
} },
|
||||||
|
// XXX handle writing to directories...
|
||||||
// XXX do we write all the data or only the .text???
|
// XXX do we write all the data or only the .text???
|
||||||
__update__: async function(path, data, mode='update'){
|
__update__: async function(path, data, mode='update'){
|
||||||
var p = module.path.join(this.__path__, path)
|
var p = module.path.join(this.__path__, path)
|
||||||
@ -779,6 +795,8 @@ var PouchDBStore =
|
|||||||
module.PouchDBStore = {
|
module.PouchDBStore = {
|
||||||
__proto__: BaseStore,
|
__proto__: BaseStore,
|
||||||
|
|
||||||
|
// XXX should this be __path__???
|
||||||
|
// ...this sets the path where the store is created...
|
||||||
__name__: 'pWiki-test-store',
|
__name__: 'pWiki-test-store',
|
||||||
__key_prefix__: 'pwiki:',
|
__key_prefix__: 'pwiki:',
|
||||||
|
|
||||||
@ -831,8 +849,10 @@ module.PouchDBStore = {
|
|||||||
&& (await this.data.remove(doc))
|
&& (await this.data.remove(doc))
|
||||||
return this },
|
return this },
|
||||||
|
|
||||||
// XXX overload...
|
// XXX
|
||||||
// .load(..)
|
load: function(){
|
||||||
|
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1911,7 +1931,8 @@ object.Constructor('Page', BasePage, {
|
|||||||
return async function(state){
|
return async function(state){
|
||||||
var outer_filters = state.filters
|
var outer_filters = state.filters
|
||||||
state.filters = this.__parser__.normalizeFilters(filters)
|
state.filters = this.__parser__.normalizeFilters(filters)
|
||||||
var res = this.parse(ast, state)
|
var res =
|
||||||
|
this.parse(ast, state)
|
||||||
.iter()
|
.iter()
|
||||||
.flat()
|
.flat()
|
||||||
.join('')
|
.join('')
|
||||||
@ -2478,6 +2499,19 @@ store.next.load(
|
|||||||
return res }, {}))
|
return res }, {}))
|
||||||
//*/
|
//*/
|
||||||
|
|
||||||
|
store.update('@file',
|
||||||
|
Object.create(FileStore))
|
||||||
|
|
||||||
|
// XXX writing to pages in here does not work yet...
|
||||||
|
// p.pwiki.path = '/@pouch/README'
|
||||||
|
// p.pwiki.text = 'PouchDB Store'
|
||||||
|
store.update('@pouch',
|
||||||
|
Object.assign(
|
||||||
|
Object.create(PouchDBStore),
|
||||||
|
{
|
||||||
|
__name__: 'store/pouch',
|
||||||
|
}))
|
||||||
|
|
||||||
|
|
||||||
// NOTE: in general the root wiki api is simply a page instance.
|
// NOTE: in general the root wiki api is simply a page instance.
|
||||||
// XXX not yet sure how to organize the actual client -- UI, hooks, .. etc
|
// XXX not yet sure how to organize the actual client -- UI, hooks, .. etc
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user