package ctrl import ( "encoding/json" "fmt" "github.com/gorilla/mux" . "github.com/mickael-kerjean/filestash/server/common" "github.com/mickael-kerjean/filestash/server/model" "net/http" "strings" ) func ShareList(ctx App, res http.ResponseWriter, req *http.Request) { path, err := pathBuilder(ctx, req.URL.Query().Get("path")) if err != nil { SendErrorResult(res, err) return } listOfSharedLinks, err := model.ShareList( GenerateID(&ctx), path, ) if err != nil { SendErrorResult(res, err) return } for i:=0; i 20 || len(requiredProof) > 20 { http.SetCookie(res, &http.Cookie{ Name: COOKIE_NAME_PROOF, Value: "", MaxAge: -1, Path: COOKIE_PATH, }) SendErrorResult(res, ErrNotValid) return } if err := s.IsValid(); err != nil { SendErrorResult(res, err) return } // 3) process the proof sent by the user submittedProof, err = model.ShareProofVerifier(s, submittedProof); if err != nil { submittedProof.Error = NewString(err.Error()) SendSuccessResult(res, submittedProof) return } if submittedProof.Key == "code" { submittedProof.Value = "" submittedProof.Message = NewString("We've sent you a message with a verification code") SendSuccessResult(res, submittedProof) return } if submittedProof.Key != "" { submittedProof.Id = Hash(submittedProof.Key + "::" + submittedProof.Value, 20) verifiedProof = append(verifiedProof, submittedProof) } // 4) Find remaining proofs: requiredProof - verifiedProof remainingProof = model.ShareProofCalculateRemainings(requiredProof, verifiedProof) // 5) persist proofs in client cookie cookie := http.Cookie{ Name: COOKIE_NAME_PROOF, Value: func(p []model.Proof) string { j, _ := json.Marshal(p) str, _ := EncryptString(SECRET_KEY_DERIVATE_FOR_PROOF, string(j)) return str }(verifiedProof), Path: COOKIE_PATH, MaxAge: 60 * 60 * 24 * 30, HttpOnly: true, SameSite: http.SameSiteStrictMode, } http.SetCookie(res, &cookie) if len(remainingProof) > 0 { SendSuccessResult(res, remainingProof[0]) return } SendSuccessResult(res, struct { Id string `json:"id"` Path string `json:"path"` }{ Id: s.Id, Path: s.Path, }) }