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