Features:

- Add file logging, server
- Fix minor repair bug
- Wrap up beta
This commit is contained in:
Mukhtar Akere
2025-01-23 00:27:12 +01:00
parent cfb0051b04
commit 74a55149fc
13 changed files with 113 additions and 11 deletions

View File

@@ -45,9 +45,6 @@ func (q *qbitHandler) Routes(r chi.Router) http.Handler {
func (u *uiHandler) Routes(r chi.Router) http.Handler {
r.Group(func(r chi.Router) {
//if u.debug {
// r.Use(middleware.Logger)
//}
r.Get("/", u.IndexHandler)
r.Get("/download", u.DownloadHandler)
r.Get("/repair", u.RepairHandler)

View File

@@ -11,6 +11,7 @@ import (
"github.com/sirrobot01/debrid-blackhole/pkg/arr"
"github.com/sirrobot01/debrid-blackhole/pkg/debrid"
"github.com/sirrobot01/debrid-blackhole/pkg/qbit/shared"
"io"
"net/http"
"os"
"os/signal"
@@ -41,6 +42,7 @@ func (s *Server) Start(ctx context.Context) error {
ui := uiHandler{qbit: s.qbit, logger: common.NewLogger("UI", s.logger.GetLevel().String(), os.Stdout), debug: debug}
// Register routes
r.Get("/logs", s.GetLogs)
q.Routes(r)
ui.Routes(r)
@@ -67,3 +69,29 @@ func (s *Server) Start(ctx context.Context) error {
s.logger.Info().Msg("Shutting down gracefully...")
return srv.Shutdown(context.Background())
}
func (s *Server) GetLogs(w http.ResponseWriter, r *http.Request) {
logFile := common.GetLogPath()
// Open and read the file
file, err := os.Open(logFile)
if err != nil {
http.Error(w, "Error reading log file", http.StatusInternalServerError)
return
}
defer file.Close()
// Set headers
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.Header().Set("Content-Disposition", "inline; filename=application.log")
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
w.Header().Set("Pragma", "no-cache")
w.Header().Set("Expires", "0")
// Stream the file
_, err = io.Copy(w, file)
if err != nil {
http.Error(w, "Error streaming log file", http.StatusInternalServerError)
return
}
}

View File

@@ -22,12 +22,12 @@
<th>Progress</th>
<th>Speed</th>
<th>Category</th>
<th>Debrid</th>
<th>State</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="torrentsList">
<!-- Will be populated by JavaScript -->
</tbody>
</table>
</div>
@@ -51,6 +51,7 @@
</td>
<td>${formatSpeed(torrent.dlspeed)}</td>
<td><span class="badge bg-secondary">${torrent.category || 'None'}</span></td>
<td><span class="badge bg-secondary">${torrent.debrid || 'None'}</span></td>
<td><span class="badge ${getStateColor(torrent.state)}">${torrent.state}</span></td>
<td>
<button class="btn btn-sm btn-outline-danger" onclick="deleteTorrent('${torrent.hash}')">

View File

@@ -87,6 +87,11 @@
<i class="bi bi-gear me-1"></i>Config
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/logs" target="_blank">
<i class="bi bi-journal me-1"></i>Logs
</a>
</li>
</ul>
<div class="d-flex align-items-center">
<span class="badge me-2" id="channel-badge">Loading...</span>