stash/internal/api/urlbuilders/audio.go
Bob bb76aff557 Able to Generate
Lots of errors to fix and TODO notes
2026-04-22 21:43:27 -07:00

68 lines
1.5 KiB
Go

// TODO(audio): updaqte this file
package urlbuilders
import (
"fmt"
"net/url"
"strconv"
"github.com/stashapp/stash/pkg/models"
)
type AudioURLBuilder struct {
BaseURL string
AudioID string
UpdatedAt string
}
func NewAudioURLBuilder(baseURL string, audio *models.Audio) AudioURLBuilder {
return AudioURLBuilder{
BaseURL: baseURL,
AudioID: strconv.Itoa(audio.ID),
UpdatedAt: strconv.FormatInt(audio.UpdatedAt.Unix(), 10),
}
}
func (b AudioURLBuilder) GetStreamURL(apiKey string) *url.URL {
u, err := url.Parse(fmt.Sprintf("%s/audio/%s/stream", b.BaseURL, b.AudioID))
if err != nil {
// shouldn't happen
panic(err)
}
if apiKey != "" {
v := u.Query()
v.Set("apikey", apiKey)
u.RawQuery = v.Encode()
}
return u
}
func (b AudioURLBuilder) GetStreamPreviewURL() string {
return b.BaseURL + "/audio/" + b.AudioID + "/preview"
}
func (b AudioURLBuilder) GetStreamPreviewImageURL() string {
return b.BaseURL + "/audio/" + b.AudioID + "/webp"
}
func (b AudioURLBuilder) GetSpriteVTTURL(checksum string) string {
return b.BaseURL + "/audio/" + checksum + "_thumbs.vtt"
}
func (b AudioURLBuilder) GetSpriteURL(checksum string) string {
return b.BaseURL + "/audio/" + checksum + "_sprite.jpg"
}
func (b AudioURLBuilder) GetScreenshotURL() string {
return b.BaseURL + "/audio/" + b.AudioID + "/screenshot?t=" + b.UpdatedAt
}
func (b AudioURLBuilder) GetFunscriptURL() string {
return b.BaseURL + "/audio/" + b.AudioID + "/funscript"
}
func (b AudioURLBuilder) GetCaptionURL() string {
return b.BaseURL + "/audio/" + b.AudioID + "/caption"
}