summaryrefslogtreecommitdiff
path: root/app/controllers/projects/avatars_controller.rb
blob: a6bebc46b061225c6799958d2679f155e9c04f12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Projects::AvatarsController < Projects::ApplicationController
  include BlobHelper

  before_action :project

  def show
    @blob = @repository.blob_at_branch('master', @project.avatar_in_git)
    if @blob
      headers['X-Content-Type-Options'] = 'nosniff'

      return if cached_blob?

      headers.store(*Gitlab::Workhorse.send_git_blob(@repository, @blob))
      headers['Content-Disposition'] = 'inline'
      headers['Content-Type'] = safe_content_type(@blob)
      head :ok # 'render nothing: true' messes up the Content-Type
    else
      render_404
    end
  end

  def destroy
    @project.remove_avatar!

    @project.save
    @project.reset_events_cache

    redirect_to edit_project_path(@project)
  end
end