feature (orgmode): use emacs to export org documents

This commit is contained in:
Mickael KERJEAN
2019-01-08 23:51:11 +11:00
parent f87a58c0ba
commit 43f00e12d6
20 changed files with 328 additions and 58 deletions

View File

@ -2,6 +2,7 @@ package middleware
import (
"encoding/json"
"fmt"
. "github.com/mickael-kerjean/filestash/server/common"
"github.com/mickael-kerjean/filestash/server/model"
"github.com/gorilla/mux"
@ -46,45 +47,18 @@ func AdminOnly(fn func(App, http.ResponseWriter, *http.Request)) func(ctx App, r
}
func SessionStart (fn func(App, http.ResponseWriter, *http.Request)) func(ctx App, res http.ResponseWriter, req *http.Request) {
extractShare := func(req *http.Request, ctx *App, share_id string) (Share, error) {
if share_id == "" {
return Share{}, nil
}
if Config.Get("features.share.enable").Bool() == false {
Log.Debug("Share feature isn't enable, contact your administrator")
return Share{}, NewError("Feature isn't enable, contact your administrator", 405)
}
s, err := model.ShareGet(share_id)
if err != nil {
return Share{}, nil
}
if err = s.IsValid(); err != nil {
return Share{}, err
}
return s, nil
}
extractSession := func(req *http.Request, ctx *App) (map[string]string, error) {
var str string
var err error
var res map[string]string = make(map[string]string)
if ctx.Share.Id != "" {
var verifiedProof []model.Proof = model.ShareProofGetAlreadyVerified(req, ctx)
var requiredProof []model.Proof = model.ShareProofGetRequired(ctx.Share)
var remainingProof []model.Proof = model.ShareProofCalculateRemainings(requiredProof, verifiedProof)
if len(remainingProof) != 0 {
return res, NewError("Unauthorized Shared space", 400)
}
str = ctx.Share.Auth
str, err = DecryptString(SECRET_KEY, str)
str, err = DecryptString(SECRET_KEY, ctx.Share.Auth)
if err != nil {
// This typically happen when changing the secret key
return res, nil
}
err = json.Unmarshal([]byte(str), &res)
if ctx.Share.Path[len(ctx.Share.Path)-1:] == "/" {
res["path"] = ctx.Share.Path
} else {
@ -116,14 +90,7 @@ func SessionStart (fn func(App, http.ResponseWriter, *http.Request)) func(ctx Ap
return func(ctx App, res http.ResponseWriter, req *http.Request) {
var err error
share_id := func() string {
if len(req.URL.Path) > 3 && req.URL.Path[:3] == "/s/" {
// this runs while using a link as a webdav server
return mux.Vars(req)["share"]
}
return req.URL.Query().Get("share")
}()
if ctx.Share, err = extractShare(req, &ctx, share_id); err != nil {
if ctx.Share, err = _findShare(req, _extractShareId(req)); err != nil {
SendErrorResult(res, err)
return
}
@ -138,3 +105,60 @@ func SessionStart (fn func(App, http.ResponseWriter, *http.Request)) func(ctx Ap
fn(ctx, res, req)
}
}
func RedirectSharedLoginIfNeeded(fn func(App, http.ResponseWriter, *http.Request)) func(ctx App, res http.ResponseWriter, req *http.Request) {
return func(ctx App, res http.ResponseWriter, req *http.Request) {
share_id := _extractShareId(req)
if share_id == "" {
SendErrorResult(res, ErrNotValid)
return
}
share, err := _findShare(req, share_id);
if err != nil || share_id != share.Id {
http.Redirect(res, req, fmt.Sprintf("/s/%s?next=%s", share_id, req.URL.Path), http.StatusTemporaryRedirect)
return
}
fn(ctx, res, req)
}
}
func _extractShareId(req *http.Request) string {
share := req.URL.Query().Get("share")
if share != "" {
return share
}
m := mux.Vars(req)["share"]
if m == "me" {
return ""
}
return m
}
func _findShare(req *http.Request, share_id string) (Share, error) {
var err error
if share_id == "" {
return Share{}, nil
}
if Config.Get("features.share.enable").Bool() == false {
Log.Debug("Share feature isn't enable, contact your administrator")
return Share{}, NewError("Feature isn't enable, contact your administrator", 405)
}
s, err := model.ShareGet(share_id)
if err != nil {
return Share{}, nil
}
if err = s.IsValid(); err != nil {
return Share{}, err
}
var verifiedProof []model.Proof = model.ShareProofGetAlreadyVerified(req)
var requiredProof []model.Proof = model.ShareProofGetRequired(s)
var remainingProof []model.Proof = model.ShareProofCalculateRemainings(requiredProof, verifiedProof)
if len(remainingProof) != 0 {
return Share{}, NewError("Unauthorized Shared space", 400)
}
return s, nil
}