From 89565acd13e6e270b0d2bfe4a9ac1a71bd213394 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 16 Apr 2024 09:41:48 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BB=93=E5=BA=93releases=E6=96=87?= =?UTF-8?q?=E4=BB=B6=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 ed608873..ac245528 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 1ccdbe61..9835db15 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 b5f5c75c..531253fc 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' From 6feb3369c27b497e10d25454c8ff9178ecf16574 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 16 Apr 2024 09:46:45 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BB=93=E5=BA=93releases=E6=96=87?= =?UTF-8?q?=E4=BB=B6=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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index ac245528..37f47463 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -127,9 +127,9 @@ class VersionReleasesController < ApplicationController end def download - tip_exception(404, '您访问的页面不存在或已被删除') if params["tag_name"].blank? || params["file_name"].blank? + 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["file_name"]) + attachment = @version.attachments.find_by(filename: params["filename"]) tip_exception(404, '您访问的页面不存在或已被删除') if attachment.blank? redirect_to "/api/attachments/#{attachment.uuid}" end From d84ebe0f42b63bee721cd770278a907cb3ce1aeb Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 16 Apr 2024 09:46:58 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BB=93=E5=BA=93releases=E6=96=87?= =?UTF-8?q?=E4=BB=B6=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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index 37f47463..ffe51f38 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -129,7 +129,7 @@ class VersionReleasesController < ApplicationController 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"]) + attachment = version.attachments.find_by(filename: params["filename"]) tip_exception(404, '您访问的页面不存在或已被删除') if attachment.blank? redirect_to "/api/attachments/#{attachment.uuid}" end From 5e9621d8d762cdc7a7aeadaa9bb841eaac5e5d36 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 16 Apr 2024 09:56:35 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BB=93=E5=BA=93releases=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8B=E8=BD=BD=E9=93=BE=E6=8E=A5=E6=9E=84=E5=BB=BA?= =?UTF-8?q?,=E6=96=87=E4=BB=B6=E5=90=8E=E7=BC=80=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 531253fc..caba039e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,7 +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 ':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' From 0dc4ecbfb803f8a20b09e0a942e4e6991d56bc6f Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 16 Apr 2024 10:00:44 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BB=93=E5=BA=93releases=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8B=E8=BD=BD=E9=93=BE=E6=8E=A5=E6=9E=84=E5=BB=BA?= =?UTF-8?q?,=E6=96=87=E4=BB=B6=E5=90=8E=E7=BC=80=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=EF=BC=8C=E7=9B=B4=E6=8E=A5=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/version_releases_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index ffe51f38..cae97cbe 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -131,7 +131,9 @@ class VersionReleasesController < ApplicationController 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? - redirect_to "/api/attachments/#{attachment.uuid}" + 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 From 07a43120f24323c9b747793d193a485d6692cd2e Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 16 Apr 2024 10:02:07 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BB=93=E5=BA=93releases=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8B=E8=BD=BD=E9=93=BE=E6=8E=A5=E6=9E=84=E5=BB=BA?= =?UTF-8?q?,=E6=96=87=E4=BB=B6=E5=90=8E=E7=BC=80=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=EF=BC=8C=E7=9B=B4=E6=8E=A5=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/version_releases_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index cae97cbe..2419a1fe 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -1,4 +1,5 @@ class VersionReleasesController < ApplicationController + include ApplicationHelper before_action :load_repository before_action :set_user before_action :require_login, except: [:index, :show]