Files
playlet-piped/playlet-lib/src/components/Web/PlayletWebServer/Middleware/SearchHistoryRouter.bs
T
Brahim Hadricheandgithub-action linter d70a07049a Add Job System (#656)
* Add Job System

* Remove testing stuff

* changelog

* plugin work

* Convert a couple more jobs

* simplify callback

* assert

* Logging changes and rendezvous perf

* changelog

* sb segment viewed job

* clear cache, and few changes

* Lint fix

* a couple more jobs

* reduce rendezvous in web server

* refactor

* Lint fix

* no message

* test shutdown

* comment

* free fields

---------

Co-authored-by: github-action linter <githubaction@githubaction.com>
2025-06-17 20:13:48 -04:00

56 lines
1.6 KiB
Plaintext

import "pkg:/components/Services/SearchHistory/SearchHistoryUtils.bs"
import "pkg:/components/Web/WebServer/Http/HttpRouter.bs"
namespace Http
class SearchHistoryRouter extends HttpRouter
function new(server as object)
super()
m.preferencesNode = server.sceneNodes.preferences
end function
@get("/api/search-history")
function GetSearchHistory(context as object) as boolean
response = context.response
response.Json(SearchHistoryUtils.GetAllSaved(m.preferencesNode))
return true
end function
@post("/api/search-history")
function AddSearchHistory(context as object) as boolean
request = context.request
response = context.response
payload = request.Json()
if payload = invalid
response.Default(400, `Invalid JSON payload`)
return true
end if
query = payload.query
if query = invalid
response.Default(400, `missing "query" property in JSON payload`)
return true
end if
SearchHistoryUtils.Save(m.preferencesNode, query)
response.Json(SearchHistoryUtils.GetAllSaved(m.preferencesNode))
return true
end function
@delete("/api/search-history")
function ClearSearchHistory(context as object) as boolean
response = context.response
SearchHistoryUtils.Clear()
response.Default(204, "OK")
return true
end function
end class
end namespace