Fixed text truncate, req params and css

pull/543/head
ThiemeH 2025-03-31 21:46:19 +07:00
parent 38bdc69e67
commit 7a1fd8acf9
3 changed files with 11 additions and 12 deletions

@ -6,6 +6,7 @@
@import "widget-group.css"; @import "widget-group.css";
@import "widget-markets.css"; @import "widget-markets.css";
@import "widget-monitor.css"; @import "widget-monitor.css";
@import "widget-qbittorrent.css";
@import "widget-reddit.css"; @import "widget-reddit.css";
@import "widget-releases.css"; @import "widget-releases.css";
@import "widget-rss.css"; @import "widget-rss.css";

@ -5,8 +5,8 @@
{{- if .Torrents }} {{- if .Torrents }}
{{- range .Torrents }} {{- range .Torrents }}
<div class="qbittorrent-torrent"> <div class="qbittorrent-torrent">
<div class="qbittorrent-torrent-header"> <div class="qbittorrent-torrent-header text-truncate">
<span class="qbittorrent-torrent-name text-truncate">{{ .Name }}</span> <span class="qbittorrent-torrent-name">{{ .Name }}</span>
</div> </div>
<div class="qbittorrent-torrent-progress flex items-center gap-10"> <div class="qbittorrent-torrent-progress flex items-center gap-10">
<div class="progress-bar flex-1"> <div class="progress-bar flex-1">

@ -10,7 +10,7 @@ import (
"net/http" "net/http"
"net/http/cookiejar" "net/http/cookiejar"
"net/url" "net/url"
"sort" "strconv"
"strings" "strings"
"time" "time"
) )
@ -104,7 +104,13 @@ func (widget *qbittorrentWidget) login() error {
} }
func (widget *qbittorrentWidget) update(ctx context.Context) { func (widget *qbittorrentWidget) update(ctx context.Context) {
req, err := http.NewRequestWithContext(ctx, "GET", widget.URL+qBittorrentTorrentsPath, nil) params := url.Values{}
params.Set("limit", strconv.Itoa(widget.Limit))
params.Set("sort", "dlspeed")
params.Set("reverse", "true")
requestURL := widget.URL + qBittorrentTorrentsPath + "?" + params.Encode()
req, err := http.NewRequestWithContext(ctx, "GET", requestURL, nil)
if err != nil { if err != nil {
widget.withError(fmt.Errorf("creating torrents request: %w", err)) widget.withError(fmt.Errorf("creating torrents request: %w", err))
return return
@ -133,14 +139,6 @@ func (widget *qbittorrentWidget) update(ctx context.Context) {
return return
} }
sort.Slice(torrents, func(i, j int) bool {
return torrents[i].Progress > torrents[j].Progress
})
if len(torrents) > widget.Limit {
torrents = torrents[:widget.Limit]
}
widget.Torrents = torrents widget.Torrents = torrents
widget.withError(nil) widget.withError(nil)
} }