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/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 4f64abbb6..a79aae425 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: "/preview/#{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/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" #分支 } diff --git a/config/routes.rb b/config/routes.rb index f8b4eec71..40d1546ba 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -31,6 +31,9 @@ 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 end