Skip to content

feat(web): add media API endpoints for admin#2953

Merged
ComputelessComputer merged 6 commits intomainfrom
devin/1768030903-media-api-endpoints
Jan 11, 2026
Merged

feat(web): add media API endpoints for admin#2953
ComputelessComputer merged 6 commits intomainfrom
devin/1768030903-media-api-endpoints

Conversation

@devin-ai-integration
Copy link
Contributor

Summary

This PR adds backend API endpoints for managing media files in the admin interface. It builds on PR #1 which added the admin authentication foundation.

New files:

  • src/functions/github-media.ts - Utility functions for GitHub API operations (list, upload, delete, move, create folder)
  • src/routes/api/admin/media/list.ts - GET endpoint to list media files in a directory
  • src/routes/api/admin/media/upload.ts - POST endpoint to upload new files
  • src/routes/api/admin/media/delete.ts - POST endpoint to batch delete files
  • src/routes/api/admin/media/move.ts - POST endpoint to move/rename files
  • src/routes/api/admin/media/create-folder.ts - POST endpoint to create folders

All endpoints are protected by admin authentication via fetchAdminUser().

Review & Testing Checklist for Human

  • Test admin auth protection: Try calling /api/admin/media/list without authentication and with a non-admin user - both should return 401
  • Verify GitHub token: Ensure YUJONGLEE_GITHUB_TOKEN_REPO env var is configured and has repo write permissions
  • Test path handling edge cases: The getFullPath() function handles paths like /images/blog, images/blog, and blog differently - verify these all resolve correctly
  • Test move operation failure mode: The move operation copies then deletes. If you interrupt after copy but before delete, you'll have duplicate files. Consider if this is acceptable.
  • Test batch delete: Try deleting multiple files at once and verify partial failures are handled correctly (returns 207 status with details)

Recommended test plan:

  1. Deploy to preview environment
  2. Log in as admin and call GET /api/admin/media/list to verify listing works
  3. Upload a test image via POST /api/admin/media/upload
  4. Move the image to a subfolder via POST /api/admin/media/move
  5. Delete the image via POST /api/admin/media/delete
  6. Verify all operations created appropriate commits in the repo

Notes

This is PR #2 in a stacked PR series implementing issue #2948. The UI for the media library will come in PR #3.

The move operation is not atomic - it copies the file first, then deletes the original. This matches how GitHub's API works (no native move operation).

Requested by: @ComputelessComputer
Devin session: https://app.devin.ai/sessions/5c615647f58c421dabccc0cdd5b4270c

devin-ai-integration bot and others added 3 commits January 10, 2026 07:40
- Remove Decap CMS files (config.yml, index.html, media-library.js, etc.)
- Remove netlify-identity-redirect.js and its reference in __root.tsx
- Move mdx-format-core.js to scripts/ folder (still used by format-mdx.js)
- Add admin authentication with email whitelist
- Add admin layout route with auth guard
- Add admin dashboard and media library placeholder pages
- Update handbook documentation to reflect new admin system

Co-Authored-By: john@hyprnote.com <john@hyprnote.com>
The _admin prefix creates a pathless layout route which conflicts with
_view's index.tsx since both resolve to '/'. Renaming to 'admin' creates
routes at /admin/* which don't conflict.

Co-Authored-By: john@hyprnote.com <john@hyprnote.com>
- Add github-media.ts with utilities for listing, uploading, deleting,
  moving files and creating folders via GitHub API
- Add /api/admin/media/list endpoint for listing media files
- Add /api/admin/media/upload endpoint for uploading files
- Add /api/admin/media/delete endpoint for batch deleting files
- Add /api/admin/media/move endpoint for moving/renaming files
- Add /api/admin/media/create-folder endpoint for creating folders
- All endpoints protected with admin authentication check

Co-Authored-By: john@hyprnote.com <john@hyprnote.com>
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Base automatically changed from devin/1768030596-remove-decap-admin-auth to main January 11, 2026 14:31
@netlify
Copy link

netlify bot commented Jan 11, 2026

Deploy Preview for hyprnote-storybook canceled.

Name Link
🔨 Latest commit f449cee
🔍 Latest deploy log https://app.netlify.com/projects/hyprnote-storybook/deploys/6963bffe8b12910008159011

@netlify
Copy link

netlify bot commented Jan 11, 2026

Deploy Preview for hyprnote ready!

Name Link
🔨 Latest commit f449cee
🔍 Latest deploy log https://app.netlify.com/projects/hyprnote/deploys/6963bffe6c2b0f0008e95908
😎 Deploy Preview https://deploy-preview-2953--hyprnote.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Jan 11, 2026

Deploy Preview for howto-fix-macos-audio-selection canceled.

Name Link
🔨 Latest commit f449cee
🔍 Latest deploy log https://app.netlify.com/projects/howto-fix-macos-audio-selection/deploys/6963bffe3c67a90008dd76ba

ComputelessComputer and others added 2 commits January 11, 2026 23:43
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Removed unnecessary blank lines in github-media.ts
@ComputelessComputer ComputelessComputer force-pushed the devin/1768030903-media-api-endpoints branch from 21f8de5 to f449cee Compare January 11, 2026 15:21
@ComputelessComputer ComputelessComputer merged commit 00c7ffd into main Jan 11, 2026
19 checks passed
@ComputelessComputer ComputelessComputer deleted the devin/1768030903-media-api-endpoints branch January 11, 2026 15:28
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

Comments