improvement (metadata): add new metadatas for better display control from the backend handler

This commit is contained in:
Mickael KERJEAN 2019-02-06 23:16:51 +11:00
parent 464abe07b1
commit f0732b69fe
8 changed files with 48 additions and 11 deletions

View file

@ -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));
}

View file

@ -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));

View file

@ -217,7 +217,13 @@ export class ExistingThing extends React.Component {
<Link to={this.props.file.link + window.location.search}>
<Card ref="$card"className={this.state.hover} className={className}>
<Image preview={this.state.preview} icon={this.props.file.icon || this.props.file.type} view={this.props.view} path={path.join(this.props.path, this.props.file.name)} />
<Filename filename={this.props.file.name} filesize={this.props.file.size} filetype={this.props.file.type} onRename={this.onRename.bind(this)} is_renaming={this.state.is_renaming} onRenameCancel={this.onRenameRequest.bind(this, false)}/>
<Filename filename={this.props.file.name}
filesize={this.props.file.size}
filetype={this.props.file.type}
hide_extension={this.props.metadata.hide_extension}
onRename={this.onRename.bind(this)}
is_renaming={this.state.is_renaming}
onRenameCancel={this.onRenameRequest.bind(this, false)}/>
<DateTime show={this.state.icon !== 'loading'} timestamp={this.props.file.time} />
<ActionButton onClickRename={this.onRenameRequest.bind(this)} onClickDelete={this.onDeleteRequest.bind(this)} onClickShare={this.onShareRequest.bind(this)} is_renaming={this.state.is_renaming}
can_rename={this.props.metadata.can_rename !== false} can_delete={this.props.metadata.can_delete !== false} can_share={this.props.metadata.can_share !== false && window.CONFIG.enable_share === true} />
@ -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 (
<span className="component_filename">
<span className="file-details">
<NgIf cond={this.props.is_renaming === false} type='inline'>
{this.state.filename} <FileSize type={this.props.filetype} size={this.props.filesize} />
{ fileWithoutExtension }{ this.props.hide_extension ? null : <span className="extension">{fileExtension}</span> }
<FileSize type={this.props.filetype} size={this.props.filesize} />
</NgIf>
<NgIf cond={this.props.is_renaming === true} type='inline'>
<form onClick={this.preventSelect} onSubmit={this.onRename.bind(this)}>

View file

@ -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",

View file

@ -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)
}

View file

@ -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)

View file

@ -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:"-"`
}

View file

@ -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),
}
}