feature (share): reflect different share params on UI and fix share viewpage

This commit is contained in:
Mickael KERJEAN 2018-11-02 04:42:01 +11:00
parent 6c195b7297
commit f87fddbb32
8 changed files with 32 additions and 20 deletions

View file

@ -190,9 +190,11 @@ export class ShareComponent extends React.Component {
<h2>Create a New Link</h2>
<div className="share--content link-type no-select">
<div onClick={this.updateState.bind(this, 'role', 'uploader')} className={this.state.role === "uploader" ? "active" : ""}>
Uploader
</div>
<NgIf cond={this.props.type !== "file"}>
<div onClick={this.updateState.bind(this, 'role', 'uploader')} className={this.state.role === "uploader" ? "active" : ""}>
Uploader
</div>
</NgIf>
<div onClick={this.updateState.bind(this, 'role', 'viewer')} className={this.state.role === "viewer" ? "active" : ""}>
Viewer
</div>
@ -236,10 +238,12 @@ export class ShareComponent extends React.Component {
<div className="share--content advanced-settings no-select">
<NgIf cond={false}>
<SuperCheckbox value={this.state.can_manage_own} label="Can Manage Own" onChange={this.updateState.bind(this, 'can_manage_own')}/>
<SuperCheckbox value={this.state.can_share} label="Can Share" onChange={this.updateState.bind(this, 'can_share')}/>
</NgIf>
<NgIf cond={this.state.show_advanced === true}>
<SuperCheckbox value={datify(this.state.expire)} label="Expiration" placeholder="The link won't be valid after" onChange={this.updateState.bind(this, 'expire')} inputType="date"/>
<NgIf cond={this.state.role === "editor" && this.props.type !== "file"}>
<SuperCheckbox value={this.state.can_share} label="Can Reshare" onChange={this.updateState.bind(this, 'can_share')}/>
</NgIf>
<SuperCheckbox value={this.state.url} label="Custom Link url" placeholder="beautiful_url" onChange={(val) => this.updateState('url', urlify(val))} inputType="text"/>
</NgIf>
</div>

View file

@ -183,7 +183,7 @@ export class ExistingThing extends React.Component {
onShareRequest(filename){
alert.now(
<ShareComponent path={this.props.file.path}/>,
<ShareComponent path={this.props.file.path} type={this.props.file.type} />,
(ok) => {}
);
}

View file

@ -39,7 +39,6 @@ export class SharePage extends React.Component {
if(this.refs.$input) {
this.refs.$input.ref.value = "";
}
let st = {
key: res.key,
path: res.path || null,

View file

@ -132,11 +132,11 @@ export class Pager extends React.Component {
let inputWidth = this.state.n === undefined ? 12 : ((this.state.n + 1).toString().length) * 12;
const nextLink = () => {
const l = this.state.files[this.calculateNextPageNumber(this.state.n)];
return (l && l.link) || '#';
return (((l && l.link) || "") + window.location.search) || '#';
};
const prevLink = () => {
const l = this.state.files[this.calculatePrevPageNumber(this.state.n)];
return (l && l.link) || '#';
return (((l && l.link) || "") + window.location.search) || '#';
};
const current_page_number = this.state.n === undefined ? "" : this.state.n + 1;
return (

View file

@ -57,7 +57,11 @@ func FileLs(ctx App, res http.ResponseWriter, req *http.Request) {
files = append(files, f)
}
var perms *Metadata = &Metadata{}
var perms Metadata = Metadata{}
if obj, ok := ctx.Backend.(interface{ Meta(path string) Metadata }); ok {
perms = obj.Meta(path)
}
if model.CanEdit(&ctx) == false {
perms.CanCreateFile = NewBool(false)
perms.CanCreateDirectory = NewBool(false)
@ -75,10 +79,6 @@ func FileLs(ctx App, res http.ResponseWriter, req *http.Request) {
perms.CanShare = NewBool(false)
}
if obj, ok := ctx.Backend.(interface{ Meta(path string) *Metadata }); ok {
perms = obj.Meta(path)
}
SendSuccessResultsWithMetadata(res, files, perms)
}

View file

@ -34,8 +34,7 @@ func ShareGet(ctx App, res http.ResponseWriter, req *http.Request) {
Path string `json:"path"`
}{
Id: s.Id,
//Path: s.Path,
Path: "/",
Path: s.Path,
})
}
@ -202,11 +201,12 @@ func ShareVerifyProof(ctx App, res http.ResponseWriter, req *http.Request) {
return
}
Log.Info("SHAREGET('%+v')", s)
SendSuccessResult(res, struct {
Id string `json:"id"`
Path string `json:"path"`
}{
Id: s.Id,
Path: "/",
Path: s.Path,
})
}

View file

@ -112,7 +112,16 @@ func ExtractSession(req *http.Request, ctx *App) (map[string]string, error) {
str = ctx.Share.Auth
str, _ = DecryptString(SECRET_KEY, str)
err := json.Unmarshal([]byte(str), &res)
res["path"] = ctx.Share.Path
if ctx.Share.Path[len(ctx.Share.Path)-1:] == "/" {
res["path"] = ctx.Share.Path
} else {
path := req.URL.Query().Get("path")
if strings.HasSuffix(ctx.Share.Path, path) == false {
return res, ErrPermissionDenied
}
res["path"] = strings.TrimSuffix(ctx.Share.Path, path) + "/"
}
return res, err
} else {
cookie, err := req.Cookie(COOKIE_NAME_AUTH)

View file

@ -57,16 +57,16 @@ func (s S3Backend) Info() string {
return "s3"
}
func (s S3Backend) Meta(path string) *Metadata {
func (s S3Backend) Meta(path string) Metadata {
if path == "/" {
return &Metadata{
return Metadata{
CanCreateFile: NewBool(false),
CanRename: NewBool(false),
CanMove: NewBool(false),
CanUpload: NewBool(false),
}
}
return nil
return Metadata{}
}
func (s S3Backend) Ls(path string) ([]os.FileInfo, error) {