-
Couldn't load subscription status.
- Fork 84
Use direct file storage for ActivityPub inbox attachments #2375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
Implements a dual storage strategy where Mastodon imports continue using
WordPress attachment posts while ActivityPub inbox items use direct file
storage in uploads/activitypub/{post_id}/.
New methods added:
- import_files(): Public method for direct file import (used by ap_posts)
- save_file(): Downloads and saves files to uploads/activitypub/{post_id}/
Returns array with 'url', 'mime_type', and 'alt' keys
- import_inline_files(): Processes inline images for file storage
- append_files_to_content(): Appends file-based media to content
- generate_files_markup(): Creates block markup from file data
- get_files_gallery_block(): Gallery block for file-based attachments
- delete_files_directory(): Public helper to delete post's file directory
Existing methods preserved:
- import(): Still used for Mastodon imports (creates attachment posts)
- All attachment-related helper methods remain unchanged
Key improvements:
- Uses WP_Filesystem API exclusively for all file operations
- Only handles remote URLs (no local file logic needed for inbox items)
- Reusable delete_files_directory() helper used in multiple places
- Removed unused function parameters (author_id, path key)
- Well-documented return types with hash notation for array keys
- Comprehensive parameter documentation for file data arrays
- Simple folder-per-post structure for easy cleanup
Benefits:
- No attachment posts for inbox items (cleaner database)
- Clear separation between import types
- Consistent use of WordPress filesystem abstractions
- Mastodon imports unaffected (backward compatible)
Tests updated to verify file creation and cleanup.
All 1212 tests passing.
Refactored the logic for assigning the separator before updating post content by using a ternary operator instead of an if statement. This improves code readability and conciseness.
pfefferle
reviewed
Oct 27, 2025
pfefferle
reviewed
Oct 27, 2025
pfefferle
reviewed
Oct 27, 2025
Refactored Attachments class to rename the delete_files_directory method to delete_directory for clarity and consistency. Updated all references to the method in related files.
Changed the directory for storing ap_post media files from 'uploads/activitypub/{post_id}/' to 'uploads/activitypub/ap_posts/{post_id}/'. Introduced a static property for the directory path and updated all relevant references to improve organization and clarity.
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.
Summary
Implements a dual storage strategy where Mastodon imports continue using WordPress attachment posts while ActivityPub inbox items use direct file storage in
uploads/activitypub/{post_id}/.Changes
New methods added:
import_files(): Public method for direct file import (used by ap_posts)save_file(): Downloads and saves files touploads/activitypub/{post_id}/url,mime_type, andaltkeysimport_inline_files(): Processes inline images for file storageappend_files_to_content(): Appends file-based media to contentgenerate_files_markup(): Creates block markup from file dataget_files_gallery_block(): Gallery block for file-based attachmentsdelete_files_directory(): Public helper to delete post's file directoryExisting methods preserved:
import(): Still used for Mastodon imports (creates attachment posts)Key improvements
delete_files_directory()helper used in multiple placesauthor_id,pathkey)Benefits
Test plan
Technical details
The implementation uses a simple folder-per-post structure where each
ap_postgets its own directory atuploads/activitypub/{post_id}/. When a post is deleted, the entire directory is recursively removed usingWP_Filesystem::delete().Files are tracked by the directory structure itself rather than post meta, keeping the implementation simple and avoiding the need for complex deduplication logic.