Skip to content

fix(onsen): Handle numeric delivery_date from API#3

Merged
Adios merged 1 commit intomainfrom
fix/numeric-delivery-date
Nov 10, 2025
Merged

fix(onsen): Handle numeric delivery_date from API#3
Adios merged 1 commit intomainfrom
fix/numeric-delivery-date

Conversation

@Adios
Copy link
Copy Markdown
Owner

@Adios Adios commented Nov 10, 2025

The application crashes with a JSON unmarshaling error when processing data from a paid member session. This is caused by the delivery_date field, which is expected to be a "MM/DD" string, sometimes being sent as a number (e.g., 23744) for older episodes accessible to paid members.

This commit fixes the crash and correctly handles both data types by implementing a prioritized date-finding strategy, preserving the original logic's structure.

  1. The delivery_date field in the nuxt.Content struct is changed to interface{} to accept both strings and numbers, preventing the initial crash.

  2. The Episodes() method is augmented to be type-aware, following a strict priority for determining an episode's date:

    • Priority 1: If delivery_date is a string, the original, preferred GuessTime logic is used.
    • Last Resort: If delivery_date is a number, a new helper function, dateFromURL, is called to parse the full date from the episode's streaming_url filename. This is only used when the string date is not present.
  3. The initial "anchor-finding" loop is also made type-safe to avoid errors when processing episodes with numeric dates.

This resolves the bug for paid sessions by correctly parsing dates from the streaming URL as a fallback, while ensuring the original guessing logic is preserved for all other cases, preventing regressions.

The application crashes with a JSON unmarshaling error when processing
data from a paid member session. This is caused by the `delivery_date`
field, which is expected to be a "MM/DD" string, sometimes being sent
as a number (e.g., 23744) for older episodes accessible to paid members.

This commit fixes the crash and correctly handles both data types by
implementing a prioritized date-finding strategy, preserving the
original logic's structure.

1.  The `delivery_date` field in the `nuxt.Content` struct is changed to
    `interface{}` to accept both strings and numbers, preventing the
    initial crash.

2.  The `Episodes()` method is augmented to be type-aware, following a
    strict priority for determining an episode's date:
    - **Priority 1**: If `delivery_date` is a string, the original,
      preferred `GuessTime` logic is used.
    - **Last Resort**: If `delivery_date` is a number, a new helper
      function, `dateFromURL`, is called to parse the full date from
      the episode's `streaming_url` filename. This is only used when
      the string date is not present.

3.  The initial "anchor-finding" loop is also made type-safe to avoid
    errors when processing episodes with numeric dates.

This resolves the bug for paid sessions by correctly parsing dates from
the streaming URL as a fallback, while ensuring the original guessing
logic is preserved for all other cases, preventing regressions.
@Adios Adios merged commit 5e7570c into main Nov 10, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant