Compare commits
2 Commits
fa47c328cc
...
b5de8af9d1
| Author | SHA1 | Date | |
|---|---|---|---|
| b5de8af9d1 | |||
| d231f9a79e |
66
main.go
66
main.go
@@ -7,6 +7,7 @@ import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
@@ -176,6 +177,71 @@ func main() {
|
||||
}
|
||||
})
|
||||
|
||||
mux.HandleFunc("GET /glance", func(w http.ResponseWriter, r *http.Request) {
|
||||
type glanceTorrent struct {
|
||||
Title string
|
||||
}
|
||||
|
||||
type glanceItem struct {
|
||||
Query string
|
||||
Link string
|
||||
Torrents []glanceTorrent
|
||||
}
|
||||
|
||||
glanceItems := []glanceItem{}
|
||||
|
||||
items, err := m.GetItems()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
|
||||
baseUrl := r.URL.Query().Get("base_url")
|
||||
|
||||
for _, item := range items {
|
||||
gItem := glanceItem{
|
||||
Query: item.Query,
|
||||
Link: fmt.Sprintf("%s?item=%d", baseUrl, item.ID),
|
||||
Torrents: []glanceTorrent{},
|
||||
}
|
||||
torrents, err := m.GetItemTorrents(item.ID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, torrent := range torrents {
|
||||
gItem.Torrents = append(gItem.Torrents, glanceTorrent{
|
||||
Title: torrent.Title,
|
||||
})
|
||||
}
|
||||
|
||||
glanceItems = append(glanceItems, gItem)
|
||||
}
|
||||
|
||||
tmpl := `
|
||||
<ul class="list list-gap-2">
|
||||
{{range .Items}}
|
||||
<li class="size-h5">[{{len .Torrents}}] <a href="{{.Link}}" target="_blank">{{.Query}}</a></li>
|
||||
{{end}}
|
||||
</ul>
|
||||
`
|
||||
|
||||
t, err := template.New("glance").Parse(tmpl)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Widget-Title", "tvqueue")
|
||||
w.Header().Set("Widget-Content-Type", "html")
|
||||
|
||||
t.ExecuteTemplate(w, "glance", struct {
|
||||
Items []glanceItem
|
||||
}{
|
||||
Items: glanceItems,
|
||||
})
|
||||
})
|
||||
|
||||
mux.HandleFunc("POST /api/items", func(w http.ResponseWriter, r *http.Request) {
|
||||
var body struct {
|
||||
Query string
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import type { ItemDetails } from "../api/useItemsQuery";
|
||||
import { useItemTorrentsQuery } from "../api/useItemTorrentsQuery";
|
||||
import {
|
||||
@@ -39,6 +39,16 @@ export const Item = ({ item }: ItemProps) => {
|
||||
|
||||
const Icon = open ? CaretUpIcon : CaretDownIcon;
|
||||
|
||||
useEffect(() => {
|
||||
const params = new URLSearchParams(location.search);
|
||||
const itemId = params.get("item");
|
||||
if (itemId && parseInt(itemId) === item.id) {
|
||||
// fuck this stupid rule
|
||||
// eslint-disable-next-line
|
||||
setOpen(true);
|
||||
}
|
||||
}, [item]);
|
||||
|
||||
const handleDownloadTorrent = (torrentId: number) => {
|
||||
downloadMutation.mutate({ torrentId });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user