Merge branch 'standalone_develop' into pre_trustie_server

This commit is contained in:
xxq250 2024-04-16 10:04:42 +08:00
commit 3762515207
3 changed files with 19 additions and 1 deletions

View File

@ -1,4 +1,5 @@
class VersionReleasesController < ApplicationController
include ApplicationHelper
before_action :load_repository
before_action :set_user
before_action :require_login, except: [:index, :show]
@ -126,6 +127,16 @@ class VersionReleasesController < ApplicationController
end
end
def download
tip_exception(404, '您访问的页面不存在或已被删除') if params["tag_name"].blank? || params["filename"].blank?
version = @repository.version_releases.find_by(tag_name: params["tag_name"])
attachment = version.attachments.find_by(filename: params["filename"])
tip_exception(404, '您访问的页面不存在或已被删除') if attachment.blank?
send_file(absolute_path(local_path(attachment)), filename: attachment.title, stream: false, type: attachment.content_type.presence || 'application/octet-stream')
update_downloads(attachment)
# redirect_to "/api/attachments/#{attachment.uuid}"
end
private
def set_user

View File

@ -16,6 +16,12 @@ json.user_login user&.login
json.image_url user.present? ? url_to_avatar(user) : ""
json.attachments do
json.array! version.try(:attachments) do |attachment|
json.partial! "attachments/attachment_simple", locals: {attachment: attachment}
# json.partial! "attachments/attachment_simple", locals: {attachment: attachment}
json.id attachment.id
json.title attachment.title
json.filesize number_to_human_size attachment.filesize
json.description attachment.description
json.is_pdf attachment.is_pdf?
json.url "/#{@owner.login}/#{@repository.identifier}/releases/download/#{version&.tag_name}/#{attachment.filename}"
end
end

View File

@ -19,6 +19,7 @@ Rails.application.routes.draw do
get 'attachments/entries/get_file', to: 'attachments#get_file'
get 'attachments/download/:id', to: 'attachments#show'
get 'attachments/download/:id/:filename', to: 'attachments#show'
get ':owner/:repo/releases/download/:tag_name/:filename', to: 'version_releases#download', constraints: { repo: /[^\/]+/, filename: /[^\/]+/ }
get 'check_pr_url',to: "settings#check_url"
# get 'auth/qq/callback', to: 'oauth/qq#create'