diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 0cdba3847..4949946c0 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -38,12 +38,13 @@ class AttachmentsController < ApplicationController url = ("/repos"+url.split(base_url + "/api")[1]) filepath, ref = url.split("/")[-1].split("?") url.gsub!(url.split("/")[-1], '') - puts filepath - request_url = [domain, api_url, url, CGI.escape(filepath), "?ref=#{CGI.escape(ref.split('ref=')[1])}&access_token=#{User.where(admin: true).take&.gitea_token}"].join + Rails.logger.info("url===#{url}") + request_url = [domain, api_url, URI.encode(url), CGI.escape(filepath), "?ref=#{CGI.escape(ref.split('ref=')[1])}&access_token=#{User.where(admin: true).take&.gitea_token}"].join + Rails.logger.info("request_url===#{request_url}") response = Faraday.get(request_url) filename = filepath else - response = Faraday.get(url) + response = Faraday.get(URI.encode(url)) filename = params[:download_url].to_s.split("/").pop() end send_data(response.body.force_encoding("UTF-8"), filename: filename, type: "application/octet-stream", disposition: 'attachment') diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 6b2d2437a..1fd61f438 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -263,8 +263,9 @@ class RepositoriesController < ApplicationController end @path = GiteaService.gitea_config[:domain]+"/#{@owner.login}/#{@repository.identifier}/raw/branch/#{params[:ref]}/" @readme = result[:status] === :success ? result[:body] : nil - @readme['content'] = decode64_content(@readme, @owner, @repository, params[:ref], @path) + # replace_content 前置,防止被content改写 @readme['replace_content'] = readme_decode64_content(@readme, @owner, @repository, params[:ref], @path) + @readme['content'] = decode64_content(@readme, @owner, @repository, params[:ref], @path) render json: @readme.slice("type", "encoding", "size", "name", "path", "content", "sha", "replace_content") rescue render json: nil diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 4ccaa7d36..1c1e1aa95 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -55,7 +55,7 @@ module RepositoriesHelper def readme_render_decode64_content(str, owner, repo, ref, path) return nil if str.blank? begin - content = Base64.decode64(str).force_encoding('UTF-8') + content = Base64.decode64(content).force_encoding('UTF-8').valid_encoding? ? Base64.decode64(str).force_encoding('UTF-8') : Base64.decode64(str).force_encoding("GBK").encode("UTF-8") c_regex = /\!\[.*?\]\((.*?)\)/ src_regex = /src=\"(.*?)\"/ @@ -115,7 +115,7 @@ module RepositoriesHelper def new_readme_render_decode64_content(str, owner, repo, ref, readme_path, readme_name) file_path = readme_path.include?('/') ? readme_path.gsub("/#{readme_name}", '') : readme_path.gsub("#{readme_name}", '') return nil if str.blank? - content = Base64.decode64(str).force_encoding('UTF-8') + content = Base64.decode64(str).force_encoding('UTF-8').valid_encoding? ? Base64.decode64(str).force_encoding('UTF-8') : Base64.decode64(str).force_encoding("GBK").encode("UTF-8") # s_regex = /\s\!\[.*?\]\((.*?)\)\s/ s_regex_c = /`{1,2}[^`](.*?)`{1,2}/ s_regex = /```([\s\S]*?)```[\s]?/ @@ -178,9 +178,10 @@ module RepositoriesHelper after_ss_c_souces.each_with_index do |s, index| content = content.gsub("#{s[0]}","#{total_sources[:ss_c][index][0]}") end - return content - rescue + rescue Exception => e + Rails.logger.error("===================#{readme_path}:#{readme_name}:error:#{e}") + # e.backtrace.each { |msg| Rails.logger.error(msg) } return str end @@ -196,8 +197,7 @@ module RepositoriesHelper def readme_decode64_content(entry, owner, repo, ref, path=nil) Rails.logger.info("entry===#{entry["type"]} #{entry["name"]}") - content = Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content'] - # Rails.logger.info("content===#{content}") + content = entry['content'].present? ? entry['content'] : Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content'] # readme_render_decode64_content(content, owner, repo, ref) new_readme_render_decode64_content(content, owner, repo, ref, entry['path'], entry['name']) end @@ -205,9 +205,9 @@ module RepositoriesHelper def decode64_content(entry, owner, repo, ref, path=nil) if is_readme?(entry['type'], entry['name']) Rails.logger.info("entry===#{entry["type"]} #{entry["name"]}") - content = Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content'] + content = entry['content'].present? ? entry['content'] : Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content'] # Rails.logger.info("content===#{content}") - # readme_render_decode64_content(content, owner, repo, ref) + return Base64.decode64(content).force_encoding("GBK").encode("UTF-8") unless Base64.decode64(content).force_encoding('UTF-8').valid_encoding? return Base64.decode64(content).force_encoding('UTF-8') else file_type = File.extname(entry['name'].to_s)[1..-1] diff --git a/app/queries/admins/organization_query.rb b/app/queries/admins/organization_query.rb index 09dbab9e3..ff3f301be 100644 --- a/app/queries/admins/organization_query.rb +++ b/app/queries/admins/organization_query.rb @@ -9,6 +9,8 @@ class Admins::OrganizationQuery < ApplicationQuery def call orgs = Organization.all + + orgs = orgs.where(enabling_cla: params[:enabling_cla]) if params[:enabling_cla].present? # 关键字检索 keyword = params[:keyword].to_s.strip.presence if keyword diff --git a/app/views/admins/feedbacks/_list.html.erb b/app/views/admins/feedbacks/_list.html.erb index 1b7b045ed..a630837f1 100644 --- a/app/views/admins/feedbacks/_list.html.erb +++ b/app/views/admins/feedbacks/_list.html.erb @@ -17,12 +17,8 @@ <%= feedback&.user&.login%> <%= feedback&.user&.mail%> <%= feedback.created_at&.strftime('%Y-%m-%d %H:%M') %> - - - - <%= feedback.content.truncate(20) %> - - + + <%= feedback.content %> <%= link_to "发送邮件", new_history_admins_feedback_path(feedback), remote: true, class: "action" %> diff --git a/app/views/admins/organizations/index.html.erb b/app/views/admins/organizations/index.html.erb index 7cd2ba8fa..2444d87f3 100644 --- a/app/views/admins/organizations/index.html.erb +++ b/app/views/admins/organizations/index.html.erb @@ -5,6 +5,10 @@ <%= form_tag(admins_organizations_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %> <%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: 'login/昵称') %> + + <%= check_box_tag("enabling_cla", true, false, id: "user_enabling_cla", style: 'margin-left: 2px;') %> <%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %> <% end %>