Info command update

This commit is contained in:
2025-07-23 17:55:12 +03:00
parent 06db684c43
commit b8d6934025
3 changed files with 65 additions and 24 deletions

View File

@@ -21,22 +21,22 @@ type AlbumStatsResponse struct {
// Album represents a Bunkkr album.
type Album struct {
Title string `json:"title"`
Views int `json:"views"`
Files []File `json:"files"`
ID string `json:"id"`
URL *url.URL `json:"url"`
SizeKB int64 `json:"size_kb"`
Title string `json:"title"`
Views int `json:"views"`
Files []File `json:"files"`
ID string `json:"id"`
URL *URLString `json:"url"`
SizeKB int64 `json:"size_kb"`
}
// File represents a single file within a Bunkkr album.
type File struct {
Title string `json:"title"`
SizeKB int64 `json:"size_kb"`
DateUploaded time.Time `json:"date_uploaded"`
URL *url.URL `json:"url"`
Filename string `json:"filename"`
Format string `json:"format"`
Title string `json:"title"`
SizeKB int64 `json:"size_kb"`
DateUploaded time.Time `json:"date_uploaded"`
URL *URLString `json:"url"`
Filename string `json:"filename"`
Format string `json:"format"`
}
func (a *Album) GetSize() string {
@@ -161,3 +161,30 @@ func (f *File) ToString() string {
return builder.String()
}
// ### WRAPPERS ###
type URLString struct {
*url.URL
}
func (u URLString) MarshalJSON() ([]byte, error) {
if u.URL == nil {
return []byte(`""`), nil
}
return []byte(`"` + u.String() + `"`), nil
}
func (u *URLString) UnmarshalJSON(data []byte) error {
s := strings.Trim(string(data), `"`)
if s == "" {
u.URL = nil
return nil
}
parsed, err := url.Parse(s)
if err != nil {
return err
}
u.URL = parsed
return nil
}