mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-10 23:10:32 +00:00
Infinite scroll (#28)
* no message * infinite scroll + new ws implementation * no message * scrolling top * fetch button * more Backend changes * fix go mod and sum * mire fixes against develop * unused code * small ui refactor Co-authored-by: Roee Gadot <roee.gadot@up9.com>
This commit is contained in:
@@ -2,26 +2,59 @@ package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/google/martian/har"
|
||||
"mizuserver/pkg/database"
|
||||
"mizuserver/pkg/models"
|
||||
"mizuserver/pkg/utils"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
HardLimit = 200
|
||||
)
|
||||
|
||||
func GetEntries(c *fiber.Ctx) error {
|
||||
limit, e := strconv.Atoi(c.Query("limit", "100"))
|
||||
limit, e := strconv.Atoi(c.Query("limit", "200"))
|
||||
utils.CheckErr(e)
|
||||
if limit > HardLimit {
|
||||
limit = HardLimit
|
||||
}
|
||||
|
||||
sortOption := c.Query("operator", "lt")
|
||||
var sortingOperator string
|
||||
var ordering string
|
||||
if strings.ToLower(sortOption) == "gt" {
|
||||
sortingOperator = ">"
|
||||
ordering = "asc"
|
||||
} else if strings.ToLower(sortOption) == "lt" {
|
||||
sortingOperator = "<"
|
||||
ordering = "desc"
|
||||
} else {
|
||||
fmt.Println("Unsupported")
|
||||
return nil
|
||||
}
|
||||
|
||||
timestamp, e := strconv.Atoi(c.Query("timestamp", "-1"))
|
||||
utils.CheckErr(e)
|
||||
|
||||
var entries []models.MizuEntry
|
||||
|
||||
database.GetEntriesTable().
|
||||
Order(fmt.Sprintf("timestamp %s", ordering)).
|
||||
Where(fmt.Sprintf("timestamp %s %v",sortingOperator, timestamp)).
|
||||
Omit("entry"). // remove the "big" entry field
|
||||
Limit(limit).
|
||||
Find(&entries)
|
||||
|
||||
if len(entries) > 0 && ordering == "desc"{
|
||||
utils.ReverseSlice(entries)
|
||||
}
|
||||
|
||||
// Convert to base entries
|
||||
baseEntries := make([]models.BaseEntryDetails, 0)
|
||||
baseEntries := make([]models.BaseEntryDetails, 0, limit)
|
||||
for _, entry := range entries {
|
||||
baseEntries = append(baseEntries, models.BaseEntryDetails{
|
||||
Id: entry.EntryId,
|
||||
@@ -51,7 +84,6 @@ func GetEntry(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fullEntry)
|
||||
}
|
||||
|
||||
|
||||
func DeleteAllEntries(c *fiber.Ctx) error {
|
||||
database.GetEntriesTable().
|
||||
Where("1 = 1").
|
||||
|
@@ -76,7 +76,7 @@ func SaveHarToDb(entry har.Entry, source string) {
|
||||
Method: entry.Request.Method,
|
||||
Status: entry.Response.Status,
|
||||
Source: source,
|
||||
Timestamp: entry.StartedDateTime.Unix(),
|
||||
Timestamp: entry.StartedDateTime.UnixNano() / int64(time.Millisecond),
|
||||
}
|
||||
database.GetEntriesTable().Create(&mizuEntry)
|
||||
|
||||
@@ -87,7 +87,7 @@ func SaveHarToDb(entry har.Entry, source string) {
|
||||
Path: urlPath,
|
||||
StatusCode: entry.Response.Status,
|
||||
Method: entry.Request.Method,
|
||||
Timestamp: entry.StartedDateTime.Unix(),
|
||||
Timestamp: entry.StartedDateTime.UnixNano() / int64(time.Millisecond),
|
||||
}
|
||||
baseEntryBytes, _ := json.Marshal(&baseEntry)
|
||||
ikisocket.Broadcast(baseEntryBytes)
|
||||
|
@@ -13,5 +13,4 @@ func EntriesRoutes(fiberApp *fiber.App) {
|
||||
routeGroup.Get("/entries/:entryId", controllers.GetEntry) // get single (full) entry
|
||||
|
||||
routeGroup.Get("/resetDB", controllers.DeleteAllEntries) // get single (full) entry
|
||||
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"reflect"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
@@ -29,6 +30,17 @@ func StartServer(app *fiber.App) {
|
||||
}
|
||||
}
|
||||
|
||||
func ReverseSlice(data interface{}) {
|
||||
value := reflect.ValueOf(data)
|
||||
valueLen := value.Len()
|
||||
for i := 0; i <= int((valueLen-1)/2); i++ {
|
||||
reverseIndex := valueLen - 1 - i
|
||||
tmp := value.Index(reverseIndex).Interface()
|
||||
value.Index(reverseIndex).Set(value.Index(i))
|
||||
value.Index(i).Set(reflect.ValueOf(tmp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func CheckErr(e error) {
|
||||
if e != nil {
|
||||
|
Reference in New Issue
Block a user