Fix queue & warn about queued or cancelled search
Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
@@ -11,6 +11,8 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var cancelled = make(map[string]struct{})
|
||||
|
||||
func searchWorker(s *server.Server, cache *map[string]*search.Result, searchQueue chan string, limiter chan struct{}) {
|
||||
for id := range searchQueue {
|
||||
s.Mu.RLock()
|
||||
@@ -21,6 +23,16 @@ func searchWorker(s *server.Server, cache *map[string]*search.Result, searchQueu
|
||||
continue
|
||||
}
|
||||
|
||||
s.Mu.RLock()
|
||||
_, isCancelled := cancelled[id]
|
||||
s.Mu.RUnlock()
|
||||
if isCancelled {
|
||||
s.Mu.Lock()
|
||||
r.Status = "cancelled"
|
||||
s.Mu.Unlock()
|
||||
continue
|
||||
}
|
||||
|
||||
limiter <- struct{}{}
|
||||
search.Search(s, r.Query, r, s.Mu)
|
||||
<-limiter
|
||||
@@ -130,30 +142,14 @@ func routes(s *server.Server, cache *map[string]*search.Result, searchQueue chan
|
||||
return
|
||||
}
|
||||
|
||||
if r.Status == "queued" {
|
||||
newQueue := make(chan string, cap(searchQueue))
|
||||
for {
|
||||
select {
|
||||
case queuedId := <-searchQueue:
|
||||
if queuedId != id {
|
||||
newQueue <- queuedId
|
||||
}
|
||||
default:
|
||||
goto Done
|
||||
}
|
||||
}
|
||||
Done:
|
||||
searchQueue = newQueue
|
||||
|
||||
s.Mu.Lock()
|
||||
cancelled[id] = struct{}{}
|
||||
if r.Status == "queued" {
|
||||
r.Status = "cancelled"
|
||||
}
|
||||
s.Mu.Unlock()
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"Status": "Cancelled"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusBadRequest, gin.H{"Error": "Cannot cancel running or finished search"})
|
||||
})
|
||||
|
||||
s.Router.GET("/dataleak/sample", func(c *gin.Context) {
|
||||
|
||||
@@ -43,7 +43,11 @@
|
||||
.then((r) => {
|
||||
result = r.data;
|
||||
console.log(result);
|
||||
if (result && result.Status !== "pending") {
|
||||
if (
|
||||
result &&
|
||||
result.Status !== "pending" &&
|
||||
result.Status !== "queued"
|
||||
) {
|
||||
clearInterval(intervalId);
|
||||
}
|
||||
})
|
||||
@@ -71,7 +75,7 @@
|
||||
elapsedTime += pollingInterval;
|
||||
|
||||
// Check for status change inside the interval
|
||||
if (result && result.Status !== "pending") {
|
||||
if (result && result.Status !== "pending" && result.Status !== "queued") {
|
||||
clearInterval(intervalId);
|
||||
return;
|
||||
}
|
||||
@@ -122,6 +126,17 @@
|
||||
<Stats {result} />
|
||||
</div>
|
||||
|
||||
{#if result.Status === "queued"}
|
||||
<div class="my-10 m-auto flex gap-5 flex-col">
|
||||
<h2 class="text-center font-bold text-8xl">(o^^)o</h2>
|
||||
<h2 class="text-center font-semibold text-4xl">Search queued...</h2>
|
||||
</div>
|
||||
{:else if result.Status === "cancelled"}
|
||||
<div class="my-10 m-auto flex gap-5 flex-col">
|
||||
<h2 class="text-center font-bold text-8xl">(^-^*)</h2>
|
||||
<h2 class="text-center font-semibold text-4xl">Search cancelled</h2>
|
||||
</div>
|
||||
{:else}
|
||||
{#if !result.LeakResult.Inactive}
|
||||
<div class="collapse collapse-arrow bg-base-100 border">
|
||||
<input type="radio" name="my-accordion-2" checked={true} />
|
||||
@@ -299,6 +314,7 @@
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user