Add API to delete media attachments that are not in use (#33991)
This commit is contained in:
		
					parent
					
						
							
								e71fb450e0
							
						
					
				
			
			
				commit
				
					
						4960193ed0
					
				
			
		
					 3 changed files with 69 additions and 3 deletions
				
			
		|  | @ -3,8 +3,8 @@ | |||
| class Api::V1::MediaController < Api::BaseController | ||||
|   before_action -> { doorkeeper_authorize! :write, :'write:media' } | ||||
|   before_action :require_user! | ||||
|   before_action :set_media_attachment, except: [:create] | ||||
|   before_action :check_processing, except: [:create] | ||||
|   before_action :set_media_attachment, except: [:create, :destroy] | ||||
|   before_action :check_processing, except: [:create, :destroy] | ||||
| 
 | ||||
|   def show | ||||
|     render json: @media_attachment, serializer: REST::MediaAttachmentSerializer, status: status_code_for_media_attachment | ||||
|  | @ -25,6 +25,15 @@ class Api::V1::MediaController < Api::BaseController | |||
|     render json: @media_attachment, serializer: REST::MediaAttachmentSerializer, status: status_code_for_media_attachment | ||||
|   end | ||||
| 
 | ||||
|   def destroy | ||||
|     @media_attachment = current_account.media_attachments.find(params[:id]) | ||||
| 
 | ||||
|     return render json: in_usage_error, status: 422 unless @media_attachment.status_id.nil? | ||||
| 
 | ||||
|     @media_attachment.destroy | ||||
|     render_empty | ||||
|   end | ||||
| 
 | ||||
|   private | ||||
| 
 | ||||
|   def status_code_for_media_attachment | ||||
|  | @ -54,4 +63,8 @@ class Api::V1::MediaController < Api::BaseController | |||
|   def processing_error | ||||
|     { error: 'Error processing thumbnail for uploaded media' } | ||||
|   end | ||||
| 
 | ||||
|   def in_usage_error | ||||
|     { error: 'Media attachment is currently used by a status' } | ||||
|   end | ||||
| end | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue