Retire old API routes
This commit is contained in:
@@ -83,43 +83,6 @@ func (s *Server) handleIndex(w http.ResponseWriter, r *http.Request) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type limitsJSON struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Remembered bool `json:"remembered"`
|
|
||||||
MaxSize *int64 `json:"max_size"` // null means unlimited
|
|
||||||
MaxExpiry string `json:"max_expiry"`
|
|
||||||
DefaultExpiry string `json:"default_expiry"`
|
|
||||||
AllowVanity bool `json:"allow_vanity"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// handleLimits reports the permissions belonging to the presented credential,
|
|
||||||
// so the page can show what the caller may actually do.
|
|
||||||
func (s *Server) handleLimits(w http.ResponseWriter, r *http.Request) {
|
|
||||||
// Rate-limited like an upload: this is the one endpoint that reports
|
|
||||||
// whether a token is valid, and it should not be a free oracle.
|
|
||||||
if !s.limiter.allow(clientIP(r, s.cfg), s.now()) {
|
|
||||||
s.fail(w, r, http.StatusTooManyRequests, "Too many requests; try again shortly.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
lim, err := s.limitsFor(r, credential(r))
|
|
||||||
if err != nil {
|
|
||||||
s.fail(w, r, http.StatusUnauthorized, "Unrecognised token.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
out := limitsJSON{
|
|
||||||
Name: lim.Name,
|
|
||||||
Remembered: lim.Name != "" && bearer(r) == "",
|
|
||||||
MaxExpiry: config.FormatDuration(lim.MaxExpiry),
|
|
||||||
DefaultExpiry: config.FormatDuration(lim.DefaultExpiry),
|
|
||||||
AllowVanity: lim.AllowVanity,
|
|
||||||
}
|
|
||||||
if lim.MaxSize != config.Unlimited {
|
|
||||||
n := lim.MaxSize
|
|
||||||
out.MaxSize = &n
|
|
||||||
}
|
|
||||||
writeJSON(w, http.StatusOK, out)
|
|
||||||
}
|
|
||||||
|
|
||||||
type objectPage struct {
|
type objectPage struct {
|
||||||
page
|
page
|
||||||
Meta *store.Meta
|
Meta *store.Meta
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ func (s *Server) routes() http.Handler {
|
|||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("GET /{$}", s.handleIndex)
|
mux.HandleFunc("GET /{$}", s.handleIndex)
|
||||||
mux.HandleFunc("POST /upload", s.handleUpload)
|
mux.HandleFunc("POST /upload", s.handleUpload)
|
||||||
mux.HandleFunc("GET /api/limits", s.handleLimits)
|
|
||||||
mux.HandleFunc("GET /admin", s.handleAdmin)
|
mux.HandleFunc("GET /admin", s.handleAdmin)
|
||||||
mux.HandleFunc("GET /d/{id}", s.handleDownload)
|
mux.HandleFunc("GET /d/{id}", s.handleDownload)
|
||||||
mux.HandleFunc("GET /i/{id}", s.handleInfo)
|
mux.HandleFunc("GET /i/{id}", s.handleInfo)
|
||||||
|
|||||||
Reference in New Issue
Block a user