Support JNC Nina via dynamic domain, add optional Suffix for Series (used for language separation)

This commit is contained in:
Neshura 2025-02-19 23:20:24 +01:00
parent d828532239
commit 741eed00ac
Signed by: Neshura
GPG key ID: 4E2D47B1374C297D
2 changed files with 64 additions and 46 deletions

View file

@ -15,11 +15,6 @@ import (
"time"
)
const BaseUrl = "https://labs.j-novel.club/"
const ApiV1Url = BaseUrl + "app/v1/"
const ApiV2Url = BaseUrl + "app/v2/"
const FeedUrl = BaseUrl + "feed/"
type ApiFormat int
const (
@ -56,6 +51,8 @@ type Api struct {
_format ApiFormat
_library Library
_series map[string]SerieAugmented
_apiUrl string
_feedUrl string
}
type Auth struct {
@ -202,7 +199,8 @@ type Pagination struct {
LastPage bool `json:"lastPage"`
}
func NewJNC() Api {
func NewJNC(domain string) Api {
baseUrl := fmt.Sprintf("https://%s/", domain)
jncApi := Api{
_auth: Auth{
_username: "",
@ -211,6 +209,8 @@ func NewJNC() Api {
},
_library: Library{},
_series: map[string]SerieAugmented{},
_apiUrl: baseUrl + "app/v2/",
_feedUrl: baseUrl + "feed/",
}
return jncApi
}
@ -240,7 +240,7 @@ func (jncApi *Api) Login() error {
return err
}
res, err := http.Post(ApiV2Url+"auth/login?"+jncApi.ReturnFormat(), "application/json", bytes.NewBuffer(jsonAuthBody))
res, err := http.Post(jncApi._apiUrl+"auth/login?"+jncApi.ReturnFormat(), "application/json", bytes.NewBuffer(jsonAuthBody))
if err != nil {
return err
}
@ -275,7 +275,7 @@ func (jncApi *Api) AuthParam() string {
// Logout invalidates the auth token and resets the jnc instance to a blank slate. No information remains after calling.
func (jncApi *Api) Logout() error {
fmt.Println("Logging out...")
res, err := http.Post(ApiV2Url+"auth/logout?"+jncApi.ReturnFormat()+"&"+jncApi.AuthParam(), "application/json", nil)
res, err := http.Post(jncApi._apiUrl+"auth/logout?"+jncApi.ReturnFormat()+"&"+jncApi.AuthParam(), "application/json", nil)
if err != nil {
panic(err)
}
@ -305,7 +305,7 @@ func (jncApi *Api) SetUsername(username string) {
// FetchLibrary retrieves the list of Book's in the logged-in User's J-Novel Club library
func (jncApi *Api) FetchLibrary() error {
fmt.Println("Fetching library contents...")
res, err := http.Get(ApiV2Url + "me/library?" + jncApi.ReturnFormat() + "&" + jncApi.AuthParam())
res, err := http.Get(jncApi._apiUrl + "me/library?" + jncApi.ReturnFormat() + "&" + jncApi.AuthParam())
if err != nil {
return err
}
@ -364,7 +364,7 @@ func (jncApi *Api) FetchLibrarySeries() error {
fmt.Printf("\rFetching Series Info: %s/%s - %s%%", strconv.Itoa(progress), strconv.Itoa(len(jncApi._series)), strconv.FormatFloat(float64(progress)/float64(len(jncApi._series))*float64(100), 'f', 2, 32))
serie := jncApi._series[i]
res, err := http.Get(ApiV2Url + "series/" + serie.Info.Id + "?" + jncApi.ReturnFormat() + "&" + jncApi.AuthParam())
res, err := http.Get(jncApi._apiUrl + "series/" + serie.Info.Id + "?" + jncApi.ReturnFormat() + "&" + jncApi.AuthParam())
if err != nil {
return err
@ -394,7 +394,7 @@ func (jncApi *Api) FetchLibrarySeries() error {
// FetchVolumeInfo retrieves additional Volume Info that was not returned when retrieving the entire Library
func (jncApi *Api) FetchVolumeInfo(volume Volume) (Volume, error) {
fmt.Println("Fetching Volume details...")
res, err := http.Get(ApiV2Url + "volumes/" + volume.Id + "?" + jncApi.ReturnFormat() + "&" + jncApi.AuthParam())
res, err := http.Get(jncApi._apiUrl + "volumes/" + volume.Id + "?" + jncApi.ReturnFormat() + "&" + jncApi.AuthParam())
if err != nil {
return volume, err
}