From f0732b69fec8f163c1bd0b209c982fffa012b93c Mon Sep 17 00:00:00 2001 From: Mickael KERJEAN Date: Wed, 6 Feb 2019 23:16:51 +1100 Subject: [PATCH] improvement (metadata): add new metadatas for better display control from the backend handler --- client/pages/connectpage/form.js | 10 +++++++--- client/pages/filespage.js | 9 ++++++++- client/pages/filespage/thing-existing.js | 19 +++++++++++++++++-- config/mime.json | 2 ++ server/common/cache.go | 5 +++++ server/common/error.go | 1 + server/common/types.go | 7 ++++++- server/plugin/plg_backend_ldap/index.go | 6 ++---- 8 files changed, 48 insertions(+), 11 deletions(-) diff --git a/client/pages/connectpage/form.js b/client/pages/connectpage/form.js index 80c4ceb0..60936b95 100644 --- a/client/pages/connectpage/form.js +++ b/client/pages/connectpage/form.js @@ -30,9 +30,13 @@ export class Form extends React.Component { this.props.onLoadingChange(false); this.setState({ backends_available: backend, - backends_enabled: window.CONFIG["connections"].map((conn) => { - return createFormBackend(backend, conn); - }) + backends_enabled: window.CONFIG["connections"].reduce((acc, conn) => { + const f = createFormBackend(backend, conn); + if(Object.keys(f).length > 0){ + acc.push(f); + } + return acc; + }, []) }, () => this.publishState(this.props)); }).catch((err) => this.props.onError(err)); } diff --git a/client/pages/filespage.js b/client/pages/filespage.js index ff0abc5c..a2d8d044 100644 --- a/client/pages/filespage.js +++ b/client/pages/filespage.js @@ -52,8 +52,15 @@ export class FilesPage extends React.Component { this.onRefresh(this.state.path, 'directory'); // subscriptions + this.props.subscribe('file.create', function(){ + return onCreate.apply(this, arguments).then(() => { + if(this.state.metadata && this.state.metadata.refresh_on_create === true){ + this.onRefresh(this.state.path, 'directory') + } + return Promise.resolve() + }); + }.bind(this)); this.props.subscribe('file.upload', onUpload.bind(this)); - this.props.subscribe('file.create', onCreate.bind(this)); this.props.subscribe('file.rename', onRename.bind(this)); this.props.subscribe('file.delete', onDelete.bind(this)); this.props.subscribe('file.refresh', this.onRefresh.bind(this)); diff --git a/client/pages/filespage/thing-existing.js b/client/pages/filespage/thing-existing.js index 9e7ca9a3..fce75cc2 100644 --- a/client/pages/filespage/thing-existing.js +++ b/client/pages/filespage/thing-existing.js @@ -217,7 +217,13 @@ export class ExistingThing extends React.Component { - + @@ -270,11 +276,20 @@ class Filename extends React.Component { } render(){ + const [fileWithoutExtension, fileExtension] = function(filename){ + const fname = filename.split("."); + const ext = fname.pop(); + if(window.CONFIG.mime[ext] === undefined){ + return [filename, ""]; + } + return [fname.join("."), "." + ext]; + }(this.state.filename); return ( - {this.state.filename} + { fileWithoutExtension }{ this.props.hide_extension ? null : {fileExtension} } +
diff --git a/config/mime.json b/config/mime.json index 1c0d7ff4..2bf1be05 100644 --- a/config/mime.json +++ b/config/mime.json @@ -47,6 +47,7 @@ "htm": "text/html", "html": "text/html", "ico": "image/x-icon", + "ics": "text/calendar", "img": "application/octet-stream", "ini": "text/x-ini", "iso": "application/octet-stream", @@ -132,6 +133,7 @@ "tk": "application/x-tcl", "ts": "video/mp2t", "txt": "text/plain", + "vcf": "text/vcard", "vrml": "application/x-vrml", "war": "application/java-archive", "wav": "audio/wave", diff --git a/server/common/cache.go b/server/common/cache.go index 397bd72c..814b82fd 100644 --- a/server/common/cache.go +++ b/server/common/cache.go @@ -31,6 +31,11 @@ func (a *AppCache) Set(key map[string]string, value interface{}) { a.Cache.Set(fmt.Sprint(hash), value, cache.DefaultExpiration) } +func (a *AppCache) Del(key map[string]string) { + hash, _ := hashstructure.Hash(key, nil) + a.Cache.Delete(fmt.Sprint(hash)) +} + func (a *AppCache) OnEvict(fn func(string, interface{})) { a.Cache.OnEvicted(fn) } diff --git a/server/common/error.go b/server/common/error.go index dafda0be..c36b3b79 100644 --- a/server/common/error.go +++ b/server/common/error.go @@ -13,6 +13,7 @@ var ( ErrNotAllowed error = NewError("Not Allowed", 403) ErrPermissionDenied error = NewError("Permission Denied", 403) ErrNotValid error = NewError("Not Valid", 405) + ErrConflict error = NewError("Already exist", 409) ErrNotReachable error = NewError("Cannot Reach Destination", 502) ErrInvalidPassword = NewError("Invalid Password", 403) ErrNotImplemented = NewError("Not Implemented", 501) diff --git a/server/common/types.go b/server/common/types.go index 43410596..55cdefae 100644 --- a/server/common/types.go +++ b/server/common/types.go @@ -39,7 +39,10 @@ func (f File) Mode() os.FileMode { return 0 } func (f File) ModTime() time.Time { - return time.Now() + if f.FTime == 0 { + return time.Now() + } + return time.Unix(f.FTime, 0) } func (f File) IsDir() bool { if f.FType != "directory" { @@ -60,6 +63,8 @@ type Metadata struct { CanUpload *bool `json:"can_upload,omitempty"` CanDelete *bool `json:"can_delete,omitempty"` CanShare *bool `json:"can_share,omitempty"` + HideExtension *bool `json:"hide_extension,omitempty"` + RefreshOnCreate *bool `json:"refresh_on_create"` Expire *time.Time `json:"-"` } diff --git a/server/plugin/plg_backend_ldap/index.go b/server/plugin/plg_backend_ldap/index.go index 97138d98..0a25f07b 100644 --- a/server/plugin/plg_backend_ldap/index.go +++ b/server/plugin/plg_backend_ldap/index.go @@ -433,11 +433,9 @@ func (this LDAP) Save(path string, file io.Reader) error { func (this LDAP) Meta(path string) Metadata { return Metadata{ - CanCreateFile: NewBool(true), - CanCreateDirectory: NewBool(true), - CanRename: NewBool(true), - CanMove: NewBool(true), CanUpload: NewBool(false), + HideExtension: NewBool(true), + RefreshOnCreate: NewBool(true), } }