Merge branch 'master' into v0.12
* master: Report versioning usage in usage report Swap the corsMiddleware and the csrfMiddleware to the unauthenticated OPTIONS requests are first processed. Return "No such object in the index" when /rest/db/file gets called on something that doesn't exist Revert "Add .arcconfig to project root" Add .arcconfig to project root
This commit is contained in:
+16
-6
@@ -236,12 +236,12 @@ func (s *apiService) Serve() {
|
|||||||
|
|
||||||
guiCfg := s.cfg.GUI()
|
guiCfg := s.cfg.GUI()
|
||||||
|
|
||||||
|
// Add the CORS handling
|
||||||
|
handler := corsMiddleware(mux)
|
||||||
|
|
||||||
// Wrap everything in CSRF protection. The /rest prefix should be
|
// Wrap everything in CSRF protection. The /rest prefix should be
|
||||||
// protected, other requests will grant cookies.
|
// protected, other requests will grant cookies.
|
||||||
handler := csrfMiddleware(s.id.String()[:5], "/rest", guiCfg, mux)
|
handler = csrfMiddleware(s.id.String()[:5], "/rest", guiCfg, handler)
|
||||||
|
|
||||||
// Add the CORS handling
|
|
||||||
handler = corsMiddleware(handler)
|
|
||||||
|
|
||||||
// Add our version and ID as a header to responses
|
// Add our version and ID as a header to responses
|
||||||
handler = withDetailsMiddleware(s.id, handler)
|
handler = withDetailsMiddleware(s.id, handler)
|
||||||
@@ -382,6 +382,10 @@ func corsMiddleware(next http.Handler) http.Handler {
|
|||||||
// Handle CORS headers and CORS OPTIONS request.
|
// Handle CORS headers and CORS OPTIONS request.
|
||||||
// CORS OPTIONS request are typically sent by browser during AJAX preflight
|
// CORS OPTIONS request are typically sent by browser during AJAX preflight
|
||||||
// when the browser initiate a POST request.
|
// when the browser initiate a POST request.
|
||||||
|
//
|
||||||
|
// As the OPTIONS request is unauthorized, this handler must be the first
|
||||||
|
// of the chain.
|
||||||
|
//
|
||||||
// See https://www.w3.org/TR/cors/ for details.
|
// See https://www.w3.org/TR/cors/ for details.
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
// Add a generous access-control-allow-origin header since we may be
|
// Add a generous access-control-allow-origin header since we may be
|
||||||
@@ -615,8 +619,14 @@ func (s *apiService) getDBFile(w http.ResponseWriter, r *http.Request) {
|
|||||||
qs := r.URL.Query()
|
qs := r.URL.Query()
|
||||||
folder := qs.Get("folder")
|
folder := qs.Get("folder")
|
||||||
file := qs.Get("file")
|
file := qs.Get("file")
|
||||||
gf, _ := s.model.CurrentGlobalFile(folder, file)
|
gf, gfOk := s.model.CurrentGlobalFile(folder, file)
|
||||||
lf, _ := s.model.CurrentFolderFile(folder, file)
|
lf, lfOk := s.model.CurrentFolderFile(folder, file)
|
||||||
|
|
||||||
|
if !(gfOk || lfOk) {
|
||||||
|
// This file for sure does not exist.
|
||||||
|
http.Error(w, "No such object in the index", http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
av := s.model.Availability(folder, file)
|
av := s.model.Availability(folder, file)
|
||||||
sendJSON(w, map[string]interface{}{
|
sendJSON(w, map[string]interface{}{
|
||||||
|
|||||||
@@ -121,10 +121,14 @@ func reportData(cfg *config.Wrapper, m *model.Model) map[string]interface{} {
|
|||||||
|
|
||||||
var rescanIntvs []int
|
var rescanIntvs []int
|
||||||
folderUses := map[string]int{
|
folderUses := map[string]int{
|
||||||
"readonly": 0,
|
"readonly": 0,
|
||||||
"ignorePerms": 0,
|
"ignorePerms": 0,
|
||||||
"ignoreDelete": 0,
|
"ignoreDelete": 0,
|
||||||
"autoNormalize": 0,
|
"autoNormalize": 0,
|
||||||
|
"simpleVersioning": 0,
|
||||||
|
"externalVersioning": 0,
|
||||||
|
"staggeredVersioning": 0,
|
||||||
|
"trashcanVersioning": 0,
|
||||||
}
|
}
|
||||||
for _, cfg := range cfg.Folders() {
|
for _, cfg := range cfg.Folders() {
|
||||||
rescanIntvs = append(rescanIntvs, cfg.RescanIntervalS)
|
rescanIntvs = append(rescanIntvs, cfg.RescanIntervalS)
|
||||||
@@ -141,6 +145,9 @@ func reportData(cfg *config.Wrapper, m *model.Model) map[string]interface{} {
|
|||||||
if cfg.AutoNormalize {
|
if cfg.AutoNormalize {
|
||||||
folderUses["autoNormalize"]++
|
folderUses["autoNormalize"]++
|
||||||
}
|
}
|
||||||
|
if cfg.Versioning.Type != "" {
|
||||||
|
folderUses[cfg.Versioning.Type+"Versioning"]++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sort.Ints(rescanIntvs)
|
sort.Ints(rescanIntvs)
|
||||||
res["rescanIntvs"] = rescanIntvs
|
res["rescanIntvs"] = rescanIntvs
|
||||||
|
|||||||
Reference in New Issue
Block a user