From 89565acd13e6e270b0d2bfe4a9ac1a71bd213394 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 16 Apr 2024 09:41:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=93=E5=BA=93releases=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E9=93=BE=E6=8E=A5=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/version_releases_controller.rb | 8 ++++++++ app/views/version_releases/_version_release.json.jbuilder | 8 +++++++- config/routes.rb | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index ed608873e..ac2455283 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -126,6 +126,14 @@ class VersionReleasesController < ApplicationController end end + def download + tip_exception(404, '您访问的页面不存在或已被删除') if params["tag_name"].blank? || params["file_name"].blank? + version = @repository.version_releases.find_by(tag_name: params["tag_name"]) + attachment = @version.attachments.find_by(filename: params["file_name"]) + tip_exception(404, '您访问的页面不存在或已被删除') if attachment.blank? + redirect_to "/api/attachments/#{attachment.uuid}" + end + private def set_user diff --git a/app/views/version_releases/_version_release.json.jbuilder b/app/views/version_releases/_version_release.json.jbuilder index 1ccdbe617..9835db152 100644 --- a/app/views/version_releases/_version_release.json.jbuilder +++ b/app/views/version_releases/_version_release.json.jbuilder @@ -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 \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index b5f5c75ca..531253fcd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' get 'check_pr_url',to: "settings#check_url" # get 'auth/qq/callback', to: 'oauth/qq#create'