platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func handleTransportSingBoxProfileHistory(w http.ResponseWriter, r *http.Request, id string) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
limit := 50
|
||||
if s := strings.TrimSpace(r.URL.Query().Get("limit")); s != "" {
|
||||
if n, err := strconv.Atoi(s); err == nil && n > 0 {
|
||||
if n > 500 {
|
||||
n = 500
|
||||
}
|
||||
limit = n
|
||||
}
|
||||
}
|
||||
|
||||
records, err := loadSingBoxHistoryRecords(id, limit)
|
||||
if err != nil {
|
||||
writeJSON(w, http.StatusInternalServerError, SingBoxProfileHistoryResponse{
|
||||
OK: false,
|
||||
Code: singBoxProfileCodeRollbackFailed,
|
||||
Message: "history read failed: " + err.Error(),
|
||||
ProfileID: id,
|
||||
})
|
||||
return
|
||||
}
|
||||
items := make([]SingBoxProfileHistoryEntry, 0, len(records))
|
||||
for _, it := range records {
|
||||
items = append(items, it.Public())
|
||||
}
|
||||
writeJSON(w, http.StatusOK, SingBoxProfileHistoryResponse{
|
||||
OK: true,
|
||||
Message: "ok",
|
||||
ProfileID: id,
|
||||
Count: len(items),
|
||||
Items: items,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user