mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 06:40:54 +03:00
REST API: add events search
This commit is contained in:
@@ -7,12 +7,14 @@ import (
|
||||
"io"
|
||||
"mime"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/render"
|
||||
"github.com/klauspost/compress/zip"
|
||||
|
||||
@@ -20,6 +22,7 @@ import (
|
||||
"github.com/drakkan/sftpgo/v2/dataprovider"
|
||||
"github.com/drakkan/sftpgo/v2/logger"
|
||||
"github.com/drakkan/sftpgo/v2/metric"
|
||||
"github.com/drakkan/sftpgo/v2/sdk/plugin"
|
||||
"github.com/drakkan/sftpgo/v2/util"
|
||||
)
|
||||
|
||||
@@ -74,6 +77,9 @@ func getRespStatus(err error) int {
|
||||
if os.IsPermission(err) {
|
||||
return http.StatusForbidden
|
||||
}
|
||||
if errors.Is(err, plugin.ErrNoSearcher) {
|
||||
return http.StatusNotImplemented
|
||||
}
|
||||
return http.StatusInternalServerError
|
||||
}
|
||||
|
||||
@@ -90,6 +96,28 @@ func getMappedStatusCode(err error) int {
|
||||
return statusCode
|
||||
}
|
||||
|
||||
func getURLParam(r *http.Request, key string) string {
|
||||
v := chi.URLParam(r, key)
|
||||
unescaped, err := url.PathUnescape(v)
|
||||
if err != nil {
|
||||
return v
|
||||
}
|
||||
return unescaped
|
||||
}
|
||||
|
||||
func getCommaSeparatedQueryParam(r *http.Request, key string) []string {
|
||||
var result []string
|
||||
|
||||
for _, val := range strings.Split(r.URL.Query().Get(key), ",") {
|
||||
val = strings.TrimSpace(val)
|
||||
if val != "" {
|
||||
result = append(result, val)
|
||||
}
|
||||
}
|
||||
|
||||
return util.RemoveDuplicates(result)
|
||||
}
|
||||
|
||||
func handleCloseConnection(w http.ResponseWriter, r *http.Request) {
|
||||
r.Body = http.MaxBytesReader(w, r.Body, maxRequestSize)
|
||||
connectionID := getURLParam(r, "connectionID")
|
||||
|
||||
Reference in New Issue
Block a user