feat: Robust Date Guessing, API Fixes, and Project Modernization#2
Merged
feat: Robust Date Guessing, API Fixes, and Project Modernization#2
Conversation
The `onsen.ag` API has been observed to return a numeric type for the `poster_image_url` field in some cases, instead of the expected string. This caused JSON unmarshaling to fail when the corresponding struct field was strictly typed as `string`.
This commit addresses the issue by:
1. Changing the type of `PosterImageUrl` in the `onsen/nuxt/nuxt.go` `Content` struct to `interface{}`. This allows the JSON to be decoded successfully regardless of whether the value is a string or a number.
2. Updating the `Episode.Poster()` method in `onsen/onsen.go` with a type switch to safely handle the different possible types of `PosterImageUrl`. It now correctly processes both string and numeric values, returning an empty string for any other unexpected types.
This change makes the program more resilient to inconsistencies in the API's data format, preventing crashes and ensuring poster URLs are processed correctly.
The date guessing logic has been significantly improved to correctly handle programs spanning multiple years. The previous implementation led to incorrect year assignments for older episodes. This commit introduces a hybrid, chained chronological guessing mechanism: - For each radio program, it first attempts to find a reliable "anchor" date by parsing the `streaming_url` of the newest episodes. - This anchor (or a global default) is used as a starting point. - A "chained" guessing logic is then applied, where each episode's date is guessed using the previously determined episode's date as a reference, ensuring strict chronological order. Changes include: - The `Episode` struct now holds a `GuessedDate` to store the corrected time. - `Radio.Episodes()` contains the new guessing logic. - `Radio.JstUpdatedAt()` was updated to use the corrected date of the latest episode, ensuring the parent "directory" shows a consistent date. - The test server in `cmd/cmd_test.go` was made more robust with proper error handling and resource cleanup. - A test case for `lsm` was updated to verify the new logic.
This commit modernizes the project's Go toolchain and updates the GitHub Actions workflows to use the latest versions and best practices.
**Go Version Update:**
- The project's Go version in `go.mod` has been updated from `1.16` to `1.22`. This brings the project to a currently supported Go release, benefiting from performance improvements, new language features, and security updates.
- The `go.sum` file has been updated accordingly by `go mod tidy` to reflect the new dependency graph compatible with Go `1.22`.
**GitHub Actions Workflow Updates:**
- Both `.github/workflows/deploy.yml` and `.github/workflows/go.yml` have been updated:
- `actions/checkout` was upgraded from `v2` to `v4`.
- `actions/setup-go` was upgraded from `v2` to `v5`.
- The `go-version` in both workflows was set to `1.22`, aligning with the `go.mod` file.
- For the deployment workflow (`deploy.yml`):
- `softprops/action-gh-release` was upgraded from `v1` to `v2`.
- The explicit `GITHUB_TOKEN` environment variable was removed, as `v2` of the action handles this automatically.
These updates ensure the project's CI/CD pipelines are running on modern, secure, and efficient versions of Go and GitHub Actions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This Pull Request introduces significant improvements to the onsengo CLI tool, focusing on more accurate date handling, enhanced API robustness, and modernization of the project's development infrastructure.
Key Changes Included in this PR:
Robust Chronological Date Guessing (
feat(onsen)):using the previously determined episode's date as a reference. This ensures strict chronological order and correct year assignment.
API Robustness for
poster_image_url(fix(onsen)):and ensuring correct URL extraction.
Project Modernization (
chore(deps, ci)):This Pull Request collectively enhances the onsengo CLI tool's functionality, stability, and maintainability.