repositories_controller.rb revision ac24fe7991ded663db092bd5480ef9c52c14a86f
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallynclass RepositoriesController < ApplicationController
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn inherit_resources
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn defaults finder: :find_by_path!
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn load_and_authorize_resource :except => [:index, :show]
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn def files
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn @path = params[:path]
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn commit_id = @repository.commit_id(params[:oid])
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn @oid = commit_id[:oid]
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn @branch_name = commit_id[:branch_name]
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn @is_head = @repository.is_head?(@oid)
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn @info = @repository.path_info(params[:path], @oid)
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn raise Repository::FileNotFoundError, @path if @info.nil?
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn case @info[:type]
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn when :raw
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn render text: @repository.read_file(@path, params[:oid])[:content],
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn content_type: Mime::Type.lookup('application/force-download')
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn when :file_base
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn @file = @repository.read_file(@info[:entry][:path], params[:oid])
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn end
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallyn end
58a46e06210a6321c530735f15f66eb648c4657dSerge Hallynend
807732062eab6cd44fb033bfbb37fbb38907aa66Serge Hallyn