Feat/content maintenance tools#26
Open
Z4phxr wants to merge 3 commits into
Open
Conversation
…enhance media usage tracking - Introduced `MediaDeleteUnusedButton` component for bulk deletion of unused media files. - Implemented `countUnusedMedia` and `deleteAllUnusedMedia` functions to facilitate media management. - Enhanced media usage tracking by adding `flashcardsCount` to the `MediaUsage` interface and updating related logic. - Updated `AdminMediaPage` to utilize new media usage functions for improved performance. - Added scripts for wiping content in Docker and Prisma, ensuring a clean state for development.
…s, tags, and flashcards - Added new export scripts for courses, tags, and flashcards, enabling users to back up and migrate content. - Introduced helper functions for exporting course structures and flashcard decks, ensuring compatibility with import processes. - Updated documentation to include new export commands and usage instructions. - Enhanced existing scripts to support dry-run and output directory options for better user control during exports.
There was a problem hiding this comment.
Pull request overview
This PR expands the LearningPlatform’s content maintenance and admin tooling by adding export/wipe scripts, improving flashcard deck deletion consistency, and refactoring admin media usage analysis into shared utilities (including flashcard media usage).
Changes:
- Added content maintenance scripts: export runners (tags/courses/flashcards + export-all) and destructive wipe tooling (TS/SQL + Docker helper), with documentation updates.
- Refactored admin media usage analysis into
lib/media-usage.ts, added flashcard media usage counting, and introduced “delete all unused media” admin UI/action. - Improved flashcard deck deletion behavior (DB cascade for flashcards, API cache revalidation, and client-side state cleanup when deleting main decks).
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| LearningPlatform/test/api/flashcard-decks-and-summary.test.ts | Updates tests to mock/assert cache revalidation on deck deletion. |
| LearningPlatform/scripts/wipe-content.ts | Adds a TS runner to wipe CMS course content + Prisma flashcards/progress (guarded by confirmation). |
| LearningPlatform/scripts/wipe-content.sql | Adds SQL wipe script for Docker/Postgres to truncate content-related tables. |
| LearningPlatform/scripts/wipe-content-docker.ps1 | Adds a PowerShell helper to run the SQL wipe against the Docker DB container. |
| LearningPlatform/scripts/imports/runners/export-tags.js | Adds tag export runner (supports “used tags only”). |
| LearningPlatform/scripts/imports/runners/export-flashcards.js | Adds flashcard decks/cards export runner. |
| LearningPlatform/scripts/imports/runners/export-courses.js | Adds course export runner from Payload, including structure/media references. |
| LearningPlatform/scripts/imports/runners/export-all.js | Adds a convenience runner to export tags → courses → flashcards. |
| LearningPlatform/scripts/imports/helpers/flashcard-export.js | Adds helper to build import-shaped flashcard export payloads and used-tag collection. |
| LearningPlatform/scripts/imports/helpers/export-utils.js | Adds shared export utilities (arg parsing, safe filenames, JS export writer, media mapping, etc.). |
| LearningPlatform/scripts/imports/helpers/course-export.js | Adds course structure exporter (subjects/course/modules/lessons/tasks) from Payload. |
| LearningPlatform/prisma/schema.prisma | Changes Flashcard→Deck FK to onDelete: Cascade. |
| LearningPlatform/prisma/migrations/20260517120000_flashcard_deck_cascade_delete/migration.sql | Adds migration to enforce DB-level cascade delete for flashcards by deck. |
| LearningPlatform/package.json | Adds npm scripts for content export and wipe workflows. |
| LearningPlatform/lib/media-usage.ts | Introduces shared media usage utilities (including flashcard media references) with caching. |
| LearningPlatform/documentation/CONTENT_IMPORTS.md | Documents export workflows and re-import steps. |
| LearningPlatform/components/admin/media-delete-unused-button.tsx | Adds UI button to count and bulk-delete unused media. |
| LearningPlatform/app/api/flashcard-decks/[id]/route.ts | Adds cache tag revalidation after deck deletion. |
| LearningPlatform/app/(admin)/admin/media/page.tsx | Refactors to use shared media-usage helpers; adds “delete unused” button; shows flashcard usage count. |
| LearningPlatform/app/(admin)/admin/flashcards/admin-flashcards-client.tsx | Improves client state cleanup when deleting a main deck (also removes subdecks/cards from UI state). |
| LearningPlatform/app/(admin)/admin/actions/media.ts | Adds countUnusedMedia + deleteAllUnusedMedia admin actions and supporting media ID enumeration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+51
to
+60
| const payload = tags.map((t) => ({ | ||
| name: t.name, | ||
| slug: t.slug, | ||
| ...(t.main ? { main: true } : {}), | ||
| })) | ||
|
|
||
| writeJsExport(path.join(tagsDir, 'exported-tags.js'), payload, { dryRun: opts.dryRun }) | ||
| console.log(`[INFO] Exported ${payload.length} tag(s)`) | ||
| await disconnect() | ||
| return 0 |
Comment on lines
+55
to
+67
| const getCachedLessonsTasksCourses = unstable_cache( | ||
| async () => { | ||
| const payload = await getPayload({ config }) | ||
| const [lessonsResult, tasksResult, coursesResult] = await Promise.all([ | ||
| payload.find({ collection: 'lessons', limit: 1000, depth: 0 }), | ||
| payload.find({ collection: 'tasks', limit: 5000, depth: 1 }), | ||
| payload.find({ collection: 'courses', limit: 500, depth: 0 }), | ||
| ]) | ||
| return { lessons: lessonsResult.docs, tasks: tasksResult.docs, courses: coursesResult.docs } | ||
| }, | ||
| ['admin-media-usage-data-v2'], | ||
| { revalidate: 30 }, | ||
| ) |
…dles - Introduced `ContentBundleImportPanel` component for importing course bundles, allowing users to manage course content more efficiently. - Added `CourseExportButton` component for exporting courses as bundles, including associated media and metadata. - Implemented backend logic for zipping and importing course bundles, enhancing content sharing capabilities. - Updated documentation to include instructions for using the new import/export features and bundle structure.
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 several improvements and new features to the admin media management functionality, enhances flashcard deck deletion handling, and refactors media usage logic for better performance and maintainability. The most important changes are grouped below:
Media Usage Analysis and Management Enhancements:
admin/media/page.tsxand delegating it to shared utilities in@/lib/media-usage, improving maintainability and performance. Now, usage stats (including a newflashcardsCount) are fetched for all visible media at once usinggetMediaUsageForIds, and utility functions likeisMediaInUseandmediaUsageTotalare used throughout the UI. [1] [2] [3] [4] [5] [6] [7] [8]deleteAllUnusedMedia) and a corresponding UI button (MediaDeleteUnusedButton), allowing admins to efficiently clean up unused uploads. [1] [2]countUnusedMedia) to count unused media files, supporting bulk deletion and reporting.Flashcard Deck Deletion Improvements:
API and Performance Improvements:
revalidateTag) to the flashcard deck API route after deletion, ensuring that API consumers see up-to-date data. (LearningPlatform/app/api/flashcard-decks/[id]/route.tsR2, LearningPlatform/app/api/flashcard-decks/[id]/route.tsR47-R52)admin/media/page.tsx, such as removing theunstable_cacheimport and cleaning up comments and formatting. [1] [2] [3] [4] [5] [6] [7]These changes collectively improve the admin experience for managing media, ensure data consistency, and streamline code for future maintenance.