Add Dun Check For Project
This commit is contained in:
parent
fc9588fb63
commit
c9a263e03c
|
@ -33,6 +33,7 @@ class AttachmentsController < ApplicationController
|
|||
# 2. 上传到云
|
||||
begin
|
||||
upload_file = params["file"] || params["#{params[:file_param_name]}"]# 这里的file_param_name是为了方便其他插件名称
|
||||
dun_check_file = upload_file.dup
|
||||
uid_logger("#########################file_params####{params["#{params[:file_param_name]}"]}")
|
||||
raise "未上传文件" unless upload_file
|
||||
|
||||
|
@ -71,7 +72,15 @@ class AttachmentsController < ApplicationController
|
|||
@attachment.author_id = current_user.id
|
||||
@attachment.disk_directory = month_folder
|
||||
@attachment.cloud_url = remote_path
|
||||
@attachment.save!
|
||||
# @attachment.save!
|
||||
if @attachment.save!
|
||||
check_result = Attachment.check_image_able(dun_check_file)
|
||||
if check_result[:status].to_i == -1
|
||||
@attachment.destroy
|
||||
raise "上传失败,#{check_result[:message]}"
|
||||
# return render json: {status: -1, message: "上传失败,#{check_result[:message]}" }
|
||||
end
|
||||
end
|
||||
else
|
||||
logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}"
|
||||
end
|
||||
|
|
|
@ -1,13 +1,24 @@
|
|||
class Contents::CreateForm < BaseForm
|
||||
attr_accessor :filepath, :branch, :new_branch
|
||||
attr_accessor :filepath, :branch, :new_branch, :content
|
||||
|
||||
validates :filepath, presence: true
|
||||
|
||||
validate :check_branch
|
||||
|
||||
validate :dun_content_check
|
||||
|
||||
def check_branch
|
||||
raise "branch和new_branch必须存在一个 " if branch.blank? && new_branch.blank?
|
||||
# raise "branch和new_branch只能存在一个" if !branch.blank? && !new_branch.blank?
|
||||
end
|
||||
|
||||
def dun_content_check
|
||||
if content.present?
|
||||
check_result = DunCheck::TextCheck.new({title: "", content: content}).call
|
||||
if check_result[:status].to_i == -1
|
||||
raise "内容含有:#{check_result[:extra_params][:infos]},请修改"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -47,7 +47,8 @@ module Gitea
|
|||
{
|
||||
filepath: @params[:filepath],
|
||||
branch: @params[:branch],
|
||||
new_branch: @params[:new_branch]
|
||||
new_branch: @params[:new_branch],
|
||||
content: @params[:content]
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ class DunCheck::ImageCheck
|
|||
Rails.logger.info("==========@image_params===========#{@image_params}")
|
||||
dun_params = check_dun_params(@image_params)
|
||||
|
||||
api_url = Redmine::Configuration['dun']['image_api']
|
||||
api_url = EduSetting.get("dun_image_api")
|
||||
|
||||
uri = URI.parse(api_url)
|
||||
|
|
@ -6,8 +6,8 @@ class DunCheck::PublicParams
|
|||
def call
|
||||
|
||||
public_params = {
|
||||
secretId: Redmine::Configuration['dun']['secretId'],
|
||||
businessId: Redmine::Configuration['dun']["#{@type}_businessId"],
|
||||
secretId: EduSetting.get("dun_secret_id"),
|
||||
businessId: EduSetting.get("dun_#{@type}_businessId"),
|
||||
timestamp: DateTime.current.strftime('%Q').to_i,
|
||||
nonce: rand(10 ** 11).to_i
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ class DunCheck::PublicParams
|
|||
end
|
||||
|
||||
def generate_sign(params)
|
||||
secretkey = Redmine::Configuration['dun']['secretKey']
|
||||
secretkey = EduSetting.get("dun_secrect_key")
|
||||
sort_params = params.sort.to_h
|
||||
sign_str = ""
|
||||
sort_params.each do |k,v|
|
|
@ -44,8 +44,8 @@ class DunCheck::TextCheck
|
|||
begin
|
||||
dun_params = check_dun_params(text_params)
|
||||
|
||||
api_url = Redmine::Configuration['dun']['text_api']
|
||||
|
||||
# api_url = Redmine::Configuration['dun']['text_api']
|
||||
api_url = EduSetting.get("dun_text_api")
|
||||
uri = URI.parse(api_url)
|
||||
|
||||
http = Net::HTTP.new(uri.hostname, uri.port)
|
|
@ -3,7 +3,7 @@ class Attachment < ApplicationRecord
|
|||
include Publicable
|
||||
include Publishable
|
||||
include Lockable
|
||||
|
||||
include DunCheckImageAble
|
||||
belongs_to :container, polymorphic: true, optional: true
|
||||
belongs_to :author, class_name: "User", foreign_key: :author_id
|
||||
# belongs_to :course, foreign_key: :container_id, optional: true
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
json.status 0
|
||||
json.id @attachment.id
|
||||
json.filesize @attachment.filesize
|
||||
|
|
Loading…
Reference in New Issue