From f87fddbb32d350d05ce2e1f47467a3af80ef6d29 Mon Sep 17 00:00:00 2001 From: Mickael KERJEAN Date: Fri, 2 Nov 2018 04:42:01 +1100 Subject: [PATCH] feature (share): reflect different share params on UI and fix share viewpage --- client/pages/filespage/share.js | 12 ++++++++---- client/pages/filespage/thing-existing.js | 2 +- client/pages/sharepage.js | 1 - client/pages/viewerpage/pager.js | 4 ++-- server/ctrl/files.go | 10 +++++----- server/ctrl/share.go | 6 +++--- server/middleware/http.go | 11 ++++++++++- server/model/backend/s3.go | 6 +++--- 8 files changed, 32 insertions(+), 20 deletions(-) diff --git a/client/pages/filespage/share.js b/client/pages/filespage/share.js index 209b04f3..6bcc4f25 100644 --- a/client/pages/filespage/share.js +++ b/client/pages/filespage/share.js @@ -190,9 +190,11 @@ export class ShareComponent extends React.Component {

Create a New Link

-
- Uploader -
+ +
+ Uploader +
+
Viewer
@@ -236,10 +238,12 @@ export class ShareComponent extends React.Component {
- + + + this.updateState('url', urlify(val))} inputType="text"/>
diff --git a/client/pages/filespage/thing-existing.js b/client/pages/filespage/thing-existing.js index c0754908..8f307a16 100644 --- a/client/pages/filespage/thing-existing.js +++ b/client/pages/filespage/thing-existing.js @@ -183,7 +183,7 @@ export class ExistingThing extends React.Component { onShareRequest(filename){ alert.now( - , + , (ok) => {} ); } diff --git a/client/pages/sharepage.js b/client/pages/sharepage.js index 6c4386ca..6636ffcc 100644 --- a/client/pages/sharepage.js +++ b/client/pages/sharepage.js @@ -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, diff --git a/client/pages/viewerpage/pager.js b/client/pages/viewerpage/pager.js index f7634a57..a981be85 100644 --- a/client/pages/viewerpage/pager.js +++ b/client/pages/viewerpage/pager.js @@ -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 ( diff --git a/server/ctrl/files.go b/server/ctrl/files.go index d9fca993..21961afa 100644 --- a/server/ctrl/files.go +++ b/server/ctrl/files.go @@ -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) } diff --git a/server/ctrl/share.go b/server/ctrl/share.go index 779b7798..bb3f66be 100644 --- a/server/ctrl/share.go +++ b/server/ctrl/share.go @@ -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, }) } diff --git a/server/middleware/http.go b/server/middleware/http.go index 62e9939d..0f4f1e51 100644 --- a/server/middleware/http.go +++ b/server/middleware/http.go @@ -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) diff --git a/server/model/backend/s3.go b/server/model/backend/s3.go index 09485354..fdd9d75e 100644 --- a/server/model/backend/s3.go +++ b/server/model/backend/s3.go @@ -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) {