From 2921d3117b46ad332277c7f3732d32f404b4b252 Mon Sep 17 00:00:00 2001 From: AdiosF6F <62105+Adios@users.noreply.github.com> Date: Mon, 22 Dec 2025 06:59:02 +0800 Subject: [PATCH] fix(onsen): handle numeric 'updated' field from API The Onsen.ag API has started returning numeric values (e.g., 23111) for the 'updated' field in the programs list, which previously only contained date strings (e.g., "10/22") or null. This caused a JSON unmarshaling error because the field was hardcoded as *string. This change: - Updates nuxt.Program.Updated to interface{} to accept both strings and numbers. - Safely handles type assertions in onsen.Radio.JstUpdatedAt(). - Updates associated tests to reflect the change from pointer to interface. Analysis of current API data suggests that even when 'updated' is numeric and unusable for date parsing, the application can still successfully derive the correct JST update time from episode streaming URLs. --- onsen/nuxt/nuxt.go | 2 +- onsen/nuxt/nuxt_test.go | 4 ++-- onsen/onsen.go | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/onsen/nuxt/nuxt.go b/onsen/nuxt/nuxt.go index 1f195f6..f62c656 100644 --- a/onsen/nuxt/nuxt.go +++ b/onsen/nuxt/nuxt.go @@ -41,7 +41,7 @@ type Program struct { DirectoryName string `json:"directory_name"` Title string `json:"title"` New bool `json:"new"` - Updated *string `json:"updated"` + Updated interface{} `json:"updated"` Performers []Performer `json:"performers"` Contents []Content `json:"contents"` } diff --git a/onsen/nuxt/nuxt_test.go b/onsen/nuxt/nuxt_test.go index 9eb18c8..17fd7bb 100644 --- a/onsen/nuxt/nuxt_test.go +++ b/onsen/nuxt/nuxt_test.go @@ -50,7 +50,7 @@ func TestCreateWithAnonymousUser(t *testing.T) { {chosen.DirectoryName, "radionyan"}, {chosen.Title, "月とライカと吸血姫 ~アーニャ・シモニャン・ラジオニャン!~"}, {chosen.New, false}, - {*chosen.Updated, "10/22"}, + {chosen.Updated, "10/22"}, {len(chosen.Contents), 6}, { chosen.Performers, @@ -98,7 +98,7 @@ func TestCreateWithLogined(t *testing.T) { {chosen.DirectoryName, "radionyan"}, {chosen.Title, "月とライカと吸血姫 ~アーニャ・シモニャン・ラジオニャン!~"}, {chosen.New, false}, - {*chosen.Updated, "10/22"}, + {chosen.Updated, "10/22"}, {len(chosen.Contents), 6}, // Preimum user can access this content {*chosen.Contents[1].StreamingUrl, "HAS_BEEN_SCREENED"}, diff --git a/onsen/onsen.go b/onsen/onsen.go index 03ae230..0e51f42 100644 --- a/onsen/onsen.go +++ b/onsen/onsen.go @@ -209,7 +209,9 @@ func (r Radio) JstUpdatedAt() (res time.Time, ok bool) { // Fallback for radios with no episodes, using the old logic. if r.Raw.Updated != nil { - return GuessJstTimeWithNow(*r.Raw.Updated) + if s, ok := r.Raw.Updated.(string); ok { + return GuessJstTimeWithNow(s) + } } return time.Time{}, false