Report traffic for all download tokens

This commit is contained in:
Ben Adrian Sarmiento
2024-07-04 04:14:39 +02:00
parent 49432dd810
commit 38a1a9e096
5 changed files with 59 additions and 33 deletions

View File

@@ -129,7 +129,7 @@ func NewHTTPClient(
}
func (r *HTTPClient) Do(req *http.Request) (*http.Response, error) {
if r.token != "" {
if r.token != "" && req.Header.Get("Authorization") == "" {
req.Header.Set("Authorization", "Bearer "+r.token)
}

View File

@@ -338,12 +338,12 @@ func (rd *RealDebrid) GetUserInformation() (*User, error) {
// TrafficDetails represents the structure of the traffic details response
type TrafficDetails map[string]struct {
Host map[string]int64 `json:"host"`
Bytes int64 `json:"bytes"`
Host map[string]uint64 `json:"host"`
Bytes int64 `json:"bytes"`
}
// GetTrafficDetails gets the traffic details from the Real-Debrid API
func (rd *RealDebrid) GetTrafficDetails() (map[string]int64, error) {
func (rd *RealDebrid) GetTrafficDetails(token string) (map[string]uint64, error) {
// Construct request URL
reqURL := "https://api.real-debrid.com/rest/1.0/traffic/details"
req, err := http.NewRequest(http.MethodGet, reqURL, nil)
@@ -352,6 +352,8 @@ func (rd *RealDebrid) GetTrafficDetails() (map[string]int64, error) {
return nil, err
}
req.Header.Set("Authorization", "Bearer "+token)
// Send the request
resp, err := rd.apiClient.Do(req)
if err != nil {

View File

@@ -102,3 +102,11 @@ func (dtm *DownloadTokenManager) GetExpiredTokens() []string {
}
return tokens
}
func (dtm *DownloadTokenManager) GetAllTokens() []string {
var tokens []string
for _, t := range dtm.tokens {
tokens = append(tokens, t.value)
}
return tokens
}