mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
Refactor irc client (#19)
* refactor: update http handlers * feat: add trace log level * refactir: irc handler * refactor(definitions): add irc settings and invite cmd: * feat: add dft values to inputs * refactor: indexer irc forms * refactor(definitions): fix nickserv.password var: * feat: pre fill indexer name field * refactor: handle stopping and updates
This commit is contained in:
parent
5f69ae9380
commit
4d40d41628
48 changed files with 1380 additions and 943 deletions
|
@ -1,133 +0,0 @@
|
|||
package http
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/autobrr/autobrr/internal/config"
|
||||
"github.com/autobrr/autobrr/web"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
address string
|
||||
baseUrl string
|
||||
actionService actionService
|
||||
authService authService
|
||||
downloadClientService downloadClientService
|
||||
filterService filterService
|
||||
indexerService indexerService
|
||||
ircService ircService
|
||||
}
|
||||
|
||||
func NewServer(address string, baseUrl string, actionService actionService, authService authService, downloadClientSvc downloadClientService, filterSvc filterService, indexerSvc indexerService, ircSvc ircService) Server {
|
||||
return Server{
|
||||
address: address,
|
||||
baseUrl: baseUrl,
|
||||
actionService: actionService,
|
||||
authService: authService,
|
||||
downloadClientService: downloadClientSvc,
|
||||
filterService: filterSvc,
|
||||
indexerService: indexerSvc,
|
||||
ircService: ircSvc,
|
||||
}
|
||||
}
|
||||
|
||||
func (s Server) Open() error {
|
||||
listener, err := net.Listen("tcp", s.address)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
server := http.Server{
|
||||
Handler: s.Handler(),
|
||||
}
|
||||
|
||||
return server.Serve(listener)
|
||||
}
|
||||
|
||||
func (s Server) Handler() http.Handler {
|
||||
r := chi.NewRouter()
|
||||
|
||||
//r.Get("/", index)
|
||||
//r.Get("/dashboard", dashboard)
|
||||
|
||||
//handler := web.AssetHandler("/", "build")
|
||||
|
||||
encoder := encoder{}
|
||||
|
||||
assets, _ := fs.Sub(web.Assets, "build/static")
|
||||
r.HandleFunc("/static/*", func(w http.ResponseWriter, r *http.Request) {
|
||||
fileSystem := http.StripPrefix("/static/", http.FileServer(http.FS(assets)))
|
||||
fileSystem.ServeHTTP(w, r)
|
||||
})
|
||||
|
||||
authHandler := authHandler{
|
||||
encoder: encoder,
|
||||
authService: s.authService,
|
||||
}
|
||||
|
||||
r.Route("/api/auth", authHandler.Routes)
|
||||
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(IsAuthenticated)
|
||||
|
||||
actionHandler := actionHandler{
|
||||
encoder: encoder,
|
||||
actionService: s.actionService,
|
||||
}
|
||||
|
||||
r.Route("/api/actions", actionHandler.Routes)
|
||||
|
||||
downloadClientHandler := downloadClientHandler{
|
||||
encoder: encoder,
|
||||
downloadClientService: s.downloadClientService,
|
||||
}
|
||||
|
||||
r.Route("/api/download_clients", downloadClientHandler.Routes)
|
||||
|
||||
filterHandler := filterHandler{
|
||||
encoder: encoder,
|
||||
filterService: s.filterService,
|
||||
}
|
||||
|
||||
r.Route("/api/filters", filterHandler.Routes)
|
||||
|
||||
ircHandler := ircHandler{
|
||||
encoder: encoder,
|
||||
ircService: s.ircService,
|
||||
}
|
||||
|
||||
r.Route("/api/irc", ircHandler.Routes)
|
||||
|
||||
indexerHandler := indexerHandler{
|
||||
encoder: encoder,
|
||||
indexerService: s.indexerService,
|
||||
}
|
||||
|
||||
r.Route("/api/indexer", indexerHandler.Routes)
|
||||
|
||||
configHandler := configHandler{
|
||||
encoder: encoder,
|
||||
}
|
||||
|
||||
r.Route("/api/config", configHandler.Routes)
|
||||
})
|
||||
|
||||
//r.HandleFunc("/*", handler.ServeHTTP)
|
||||
r.Get("/", index)
|
||||
r.Get("/*", index)
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func index(w http.ResponseWriter, r *http.Request) {
|
||||
p := web.IndexParams{
|
||||
Title: "Dashboard",
|
||||
Version: "thisistheversion",
|
||||
BaseUrl: config.Config.BaseURL,
|
||||
}
|
||||
web.Index(w, p)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue