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

@@ -34,12 +34,14 @@ func FetchAlbumInfo(rawURL string) (*strux.Album, error) {
var album *strux.Album = &strux.Album{}
fmt.Println(rawURL)
album.URL, err = url.Parse(rawURL)
newUrl, err := url.Parse(rawURL)
if err != nil {
return nil, fmt.Errorf("failed to parse URL: %w", err)
} else {
album.URL = &strux.URLString{URL: newUrl}
}
album.ID = helper.GetLastPathElement(album.URL)
album.ID = helper.GetLastPathElement(album.URL.URL)
// Title
album.Title = strings.TrimSpace(doc.Find("h1.truncate").First().Text())
@@ -75,7 +77,7 @@ func FetchAlbumInfo(rawURL string) (*strux.Album, error) {
file := strux.File{
Title: fileTitle,
URL: fileURL,
URL: &strux.URLString{URL: fileURL},
Filename: fileTitle,
SizeKB: fileSize,
Format: helper.GetMimeTypeFromFilename(fileTitle),

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
}