From b9a3a86b38297e5607b39e9ac978ba3a6de77e48 Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Wed, 23 Sep 2020 17:40:48 +0800 Subject: [PATCH 1/6] Change VersionRelease Default False --- 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 bc6f03037..a9e7fa63a 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -139,7 +139,7 @@ class VersionReleasesController < ApplicationController body: params[:body], draft: params[:draft] || false, name: params[:name], - prerelease: params[:prerelease], + prerelease: params[:prerelease] || false, tag_name: params[:tag_name], target_commitish: params[:target_commitish] || "master" #分支 } From e698efb14f74335e929ca56c7aa0d3f7302487ab Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Thu, 24 Sep 2020 14:57:36 +0800 Subject: [PATCH 2/6] Add Attachment Video --- app/controllers/application_controller.rb | 2 +- app/views/attachments/_attachment_simple.json.jbuilder | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bcf42ccbc..5a706e38a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -385,7 +385,7 @@ class ApplicationController < ActionController::Base def current_user if Rails.env.development? - User.current = User.find 36480 + User.current = User.find 1 else User.current end diff --git a/app/views/attachments/_attachment_simple.json.jbuilder b/app/views/attachments/_attachment_simple.json.jbuilder index 6737838d1..46250489f 100644 --- a/app/views/attachments/_attachment_simple.json.jbuilder +++ b/app/views/attachments/_attachment_simple.json.jbuilder @@ -3,6 +3,7 @@ json.title attachment.title json.filesize number_to_human_size attachment.filesize json.description attachment.description json.is_pdf attachment.is_pdf? +json.absolute_path absolute_path(local_path(attachment)) json.url attachment.is_pdf? ? download_url(attachment,disposition:"inline") : download_url(attachment) # json.url download_url(attachment) json.set! :delete, delete.nil? ? true : delete if defined? delete \ No newline at end of file From 09d382ab8f6a8702831c14cbc99e0a98f796585c Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Thu, 24 Sep 2020 15:33:30 +0800 Subject: [PATCH 3/6] Add Attachment Video1 --- app/views/attachments/_attachment_simple.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/attachments/_attachment_simple.json.jbuilder b/app/views/attachments/_attachment_simple.json.jbuilder index 46250489f..0681d6022 100644 --- a/app/views/attachments/_attachment_simple.json.jbuilder +++ b/app/views/attachments/_attachment_simple.json.jbuilder @@ -3,7 +3,7 @@ json.title attachment.title json.filesize number_to_human_size attachment.filesize json.description attachment.description json.is_pdf attachment.is_pdf? -json.absolute_path absolute_path(local_path(attachment)) +json.absolute_path "https://forgeplus.trustie.net/#{absolute_path(local_path(attachment))}" json.url attachment.is_pdf? ? download_url(attachment,disposition:"inline") : download_url(attachment) # json.url download_url(attachment) json.set! :delete, delete.nil? ? true : delete if defined? delete \ No newline at end of file From 1fcf540dfcccef28d7daea72ed7b0390a61ff894 Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Fri, 25 Sep 2020 09:49:42 +0800 Subject: [PATCH 4/6] Add Attachment --- app/controllers/attachments_controller.rb | 22 ++++++++++++++++++- .../_attachment_simple.json.jbuilder | 1 - config/routes.rb | 1 + 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 4f64abbb6..b592bb3f9 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -2,7 +2,7 @@ # # 文件上传 class AttachmentsController < ApplicationController - before_action :require_login, :check_auth, except: [:show] + before_action :require_login, :check_auth, except: [:show, :preview_attachment] before_action :find_file, only: %i[show destroy] before_action :attachment_candown, only: [:show] skip_before_action :check_sign, only: [:show, :create] @@ -98,6 +98,26 @@ class AttachmentsController < ApplicationController end end + # 附件为视频时,点击播放 + def preview_attachment + attachment = Attachment.find_by(id: params[:id]) + dir_path = "#{Rails.root}/public/preview" + Dir.mkdir(dir_path) unless Dir.exist?(dir_path) + if params[:status] == "preview" + if system("cp -r #{absolute_path(local_path(attachment))} #{dir_path}/") + render json: {status: 1, url: "#{dir_path}/#{attachment.disk_filename}"} + else + normal_status(-1, "出现错误,请稍后重试") + end + else + if system("rm -rf #{dir_path}/#{attachment.disk_filename}") + normal_status(1, "操作成功") + else + normal_status(-1, "出现错误,请稍后重试") + end + end + end + private def find_file @file = diff --git a/app/views/attachments/_attachment_simple.json.jbuilder b/app/views/attachments/_attachment_simple.json.jbuilder index 0681d6022..6737838d1 100644 --- a/app/views/attachments/_attachment_simple.json.jbuilder +++ b/app/views/attachments/_attachment_simple.json.jbuilder @@ -3,7 +3,6 @@ json.title attachment.title json.filesize number_to_human_size attachment.filesize json.description attachment.description json.is_pdf attachment.is_pdf? -json.absolute_path "https://forgeplus.trustie.net/#{absolute_path(local_path(attachment))}" json.url attachment.is_pdf? ? download_url(attachment,disposition:"inline") : download_url(attachment) # json.url download_url(attachment) json.set! :delete, delete.nil? ? true : delete if defined? delete \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index f8b4eec71..0af147919 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,6 +33,7 @@ Rails.application.routes.draw do resources :attachments do collection do delete :destroy_files + post :preview_attachment end end get 'home/index' From 47c147c263300210ab37c0160e57f0e57687208d Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Fri, 25 Sep 2020 09:50:57 +0800 Subject: [PATCH 5/6] Add Attachment1 --- config/routes.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 0af147919..40d1546ba 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -31,9 +31,11 @@ Rails.application.routes.draw do resources :compose_projects, only: [:create, :destroy] end resources :attachments do + member do + post :preview_attachment + end collection do delete :destroy_files - post :preview_attachment end end get 'home/index' From d9f6750797fa005d93c6cb6c337007645110dfa9 Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Fri, 25 Sep 2020 10:26:51 +0800 Subject: [PATCH 6/6] Add Attachment2 --- app/controllers/attachments_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index b592bb3f9..a79aae425 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -105,7 +105,7 @@ class AttachmentsController < ApplicationController Dir.mkdir(dir_path) unless Dir.exist?(dir_path) if params[:status] == "preview" if system("cp -r #{absolute_path(local_path(attachment))} #{dir_path}/") - render json: {status: 1, url: "#{dir_path}/#{attachment.disk_filename}"} + render json: {status: 1, url: "/preview/#{attachment.disk_filename}"} else normal_status(-1, "出现错误,请稍后重试") end