47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
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,
|
|
})
|
|
}
|