Skip to content

Upload media referenced in note type templates/CSS on publish#1245

Merged
RisingOrange merged 2 commits intomainfrom
upload-notetype-media
Feb 13, 2026
Merged

Upload media referenced in note type templates/CSS on publish#1245
RisingOrange merged 2 commits intomainfrom
upload-notetype-media

Conversation

@RisingOrange
Copy link
Collaborator

@RisingOrange RisingOrange commented Feb 12, 2026

When deck owners publish a new note type or update templates/styles via the decks dialog, media files referenced in templates and CSS (e.g. background images, sounds) were not being uploaded. Subscribers would receive broken media references until a separate full media upload was triggered.

This adds media upload calls after note type publish operations, following the same pattern used in deck creation.

Related issues

https://ankihub.atlassian.net/browse/ACTV-270

  • Follows up on d2619e4 which added get_media_names_from_notetype() for media download/sync, as well as media upload on deck creation, but missed to add media upload on note type creation/update

Proposed changes

  • ankihub/gui/decks_dialog.py: After add_note_type() and update_note_type_templates_and_styles(), extract media names from the note type's templates/CSS and trigger a background media upload via media_sync.start_media_upload()
  • tests/addon/test_integration.py: Add parametrized tests (test_publish_note_type_media_upload and test_update_templates_media_upload) to verify media upload is triggered correctly when publishing note types with media, and not triggered when no media is present

How to reproduce

  1. As a deck owner, add a note type with media references in templates (e.g. <img src="image.png">) or CSS (e.g. background: url("bg.jpg"))
  2. Publish the note type via the decks dialog
  3. Previously: media files were not uploaded. Now: media upload starts automatically in the background

Further comments

The add_note_type_fields flow was intentionally excluded — it only updates "flds", not templates/CSS, so no new media is introduced.

🤖 Generated with Claude Code

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @RisingOrange, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical issue where media files embedded in Anki note type templates or CSS were not being uploaded to AnkiHub when a deck owner published or updated note types. This oversight led to broken media links for subscribers. The changes ensure that any media referenced within these components is automatically detected and uploaded, providing a seamless experience for users and maintaining data integrity across shared decks.

Highlights

  • Media Upload on Note Type Publish: Implemented automatic uploading of media files referenced in note type templates and CSS when a deck owner publishes a new note type or updates existing templates/styles via the decks dialog. This resolves an issue where subscribers would receive broken media references.
  • Integration of Media Sync: Integrated get_media_names_from_notetype to extract media references and media_sync.start_media_upload to initiate background media uploads after add_note_type and update_note_type_templates_and_styles operations.
  • New Integration Tests: Added two new integration tests to validate that get_media_names_from_notetype correctly extracts media names from note types after both creation and template/style updates.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • ankihub/gui/decks_dialog.py
    • Imported get_media_names_from_notetype and media_sync modules.
    • Modified on_note_type_selected to extract media names from newly added note types and trigger a media upload.
    • Modified on_templates_selected to extract media names from updated note type templates/styles and trigger a media upload.
  • tests/addon/test_integration.py
    • Added test_get_media_names_from_notetype_after_add_note_type to verify media extraction from newly added note types.
    • Added test_get_media_names_from_notetype_after_update_templates to verify media extraction from updated note type templates/styles.
Activity
  • The pull request was created by RisingOrange to address media synchronization issues during note type publishing.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

When publishing a new note type or updating templates/styles via the
decks dialog, extract media names from templates and CSS and trigger
a background media upload so subscribers receive the referenced files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@abdnh
Copy link
Contributor

abdnh commented Feb 13, 2026

Thank you for catching that so quickly!

Added two tests validating that get_media_names_from_notetype() correctly extracts media from note types created/updated via the business logic functions

Did you mean to add tests?

Add two parametrized tests to verify media upload behavior when
publishing note types:

- test_publish_note_type_media_upload: Tests media upload when
  publishing a new note type via "Publish note type" button
- test_update_templates_media_upload: Tests media upload when
  publishing template/style updates via "Publish style/template
  updates" button

Both tests verify that media_sync.start_media_upload is called with
correct parameters when media is present, and not called when no
media is present.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@RisingOrange
Copy link
Collaborator Author

@abdnh Right, I forgot to add them. Added them now

@RisingOrange RisingOrange merged commit 6fbfced into main Feb 13, 2026
8 checks passed
@RisingOrange RisingOrange deleted the upload-notetype-media branch February 13, 2026 11:35
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.

2 participants