闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
779 B

  1. # frozen_string_literal: true
  2. class MediaController < ApplicationController
  3. include Authorization
  4. before_action :set_media_attachment
  5. before_action :verify_permitted_status!
  6. def show
  7. redirect_to @media_attachment.file.url(:original)
  8. end
  9. def player
  10. @body_classes = 'player'
  11. raise ActiveRecord::RecordNotFound unless @media_attachment.video? || @media_attachment.gifv?
  12. end
  13. private
  14. def set_media_attachment
  15. @media_attachment = MediaAttachment.attached.find_by!(shortcode: params[:id] || params[:medium_id])
  16. end
  17. def verify_permitted_status!
  18. authorize @media_attachment.status, :show?
  19. rescue Mastodon::NotPermittedError
  20. # Reraise in order to get a 404 instead of a 403 error code
  21. raise ActiveRecord::RecordNotFound
  22. end
  23. end