From bd3a0d1cab6afe6012c666199ecf7281a3d95149 Mon Sep 17 00:00:00 2001 From: chenjing Date: Mon, 26 Jun 2023 09:29:53 +0800 Subject: [PATCH 01/16] admins org index search enabling_cla --- app/queries/admins/organization_query.rb | 2 ++ app/views/admins/organizations/index.html.erb | 4 ++++ 2 files changed, 6 insertions(+) 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/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 %> From 58abe470511ddb5c726666b567bc0b9694ce123c Mon Sep 17 00:00:00 2001 From: chenjing Date: Mon, 26 Jun 2023 10:58:51 +0800 Subject: [PATCH 02/16] fix bug --- app/views/projects/_detail.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/projects/_detail.json.jbuilder b/app/views/projects/_detail.json.jbuilder index e60aaed8a..e6f17924d 100644 --- a/app/views/projects/_detail.json.jbuilder +++ b/app/views/projects/_detail.json.jbuilder @@ -3,7 +3,7 @@ json.identifier project.identifier json.name project.name json.description project.description json.is_public project.is_public -json.pr_need @project.owner&.cla.try(:pr_need) +json.pr_need @project.owner.class == User ? false : @project.owner&.cla.try(:pr_need) json.owner do json.partial! "/users/user_simple", locals: {user: project.owner} end \ No newline at end of file From 53906590f76a4954910b112bb452e06b068a8151 Mon Sep 17 00:00:00 2001 From: chenjing Date: Tue, 27 Jun 2023 11:54:37 +0800 Subject: [PATCH 03/16] change admins feedback list --- app/views/admins/feedbacks/_list.html.erb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) 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" %> From 64e85397f31631df94b5cf5f1bb40c81bd888d39 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 28 Jun 2023 11:14:58 +0800 Subject: [PATCH 04/16] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E9=93=BE=E6=8E=A5encode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 0cdba3847..99346d2db 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -40,10 +40,10 @@ class AttachmentsController < ApplicationController 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 - response = Faraday.get(request_url) + response = Faraday.get(URI.encode(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') From cf46deb21ac60bb19d8e6563524a3eaf41382fb7 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 28 Jun 2023 11:30:52 +0800 Subject: [PATCH 05/16] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E9=93=BE=E6=8E=A5encode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 99346d2db..447e28bf1 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -38,9 +38,9 @@ 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 - response = Faraday.get(URI.encode(request_url)) + Rails.logger.info("url===#{url}") + request_url = [domain, api_url, CGI.escape(url), CGI.escape(filepath), "?ref=#{CGI.escape(ref.split('ref=')[1])}&access_token=#{User.where(admin: true).take&.gitea_token}"].join + response = Faraday.get(request_url) filename = filepath else response = Faraday.get(URI.encode(url)) From be9185543ba6e025f65384e98f550bf3d26a393d Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 28 Jun 2023 11:35:29 +0800 Subject: [PATCH 06/16] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E9=93=BE=E6=8E=A5encode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 447e28bf1..4949946c0 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -39,7 +39,8 @@ class AttachmentsController < ApplicationController filepath, ref = url.split("/")[-1].split("?") url.gsub!(url.split("/")[-1], '') Rails.logger.info("url===#{url}") - request_url = [domain, api_url, CGI.escape(url), CGI.escape(filepath), "?ref=#{CGI.escape(ref.split('ref=')[1])}&access_token=#{User.where(admin: true).take&.gitea_token}"].join + 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 From 7e66c1349708b4f973125d3b53ea725014ad7696 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 30 Jun 2023 11:45:03 +0800 Subject: [PATCH 07/16] =?UTF-8?q?readme=20GBK=E7=BC=96=E7=A0=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/repositories_helper.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 4ccaa7d36..4ddae72d5 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -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).encoding == Encoding::ASCII_8BIT ? Base64.decode64(str).force_encoding("GBK").encode("UTF-8"): Base64.decode64(str).force_encoding('UTF-8') # s_regex = /\s\!\[.*?\]\((.*?)\)\s/ s_regex_c = /`{1,2}[^`](.*?)`{1,2}/ s_regex = /```([\s\S]*?)```[\s]?/ @@ -180,7 +180,9 @@ module RepositoriesHelper 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,7 +198,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'] + 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) new_readme_render_decode64_content(content, owner, repo, ref, entry['path'], entry['name']) @@ -205,9 +207,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") if Base64.decode64(content).encoding == Encoding::ASCII_8BIT return Base64.decode64(content).force_encoding('UTF-8') else file_type = File.extname(entry['name'].to_s)[1..-1] From de095953cc8ba041d1074e3512a84ac879b653b5 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 30 Jun 2023 14:07:10 +0800 Subject: [PATCH 08/16] =?UTF-8?q?readme=20GBK=E7=BC=96=E7=A0=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/repositories_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 4ddae72d5..dbdc8fc79 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -208,7 +208,7 @@ module RepositoriesHelper if is_readme?(entry['type'], entry['name']) Rails.logger.info("entry===#{entry["type"]} #{entry["name"]}") 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}") + Rails.logger.info("Base64.decode64(content).encoding===#{Base64.decode64(content).encoding}") return Base64.decode64(content).force_encoding("GBK").encode("UTF-8") if Base64.decode64(content).encoding == Encoding::ASCII_8BIT return Base64.decode64(content).force_encoding('UTF-8') else From aff64187c01dce1f3d50b73768e21ed21a3da6e2 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 30 Jun 2023 14:10:31 +0800 Subject: [PATCH 09/16] =?UTF-8?q?readme=20GBK=E7=BC=96=E7=A0=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/repositories_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index dbdc8fc79..11955206d 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -208,8 +208,8 @@ module RepositoriesHelper if is_readme?(entry['type'], entry['name']) Rails.logger.info("entry===#{entry["type"]} #{entry["name"]}") content = entry['content'].present? ? entry['content'] : Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content'] - Rails.logger.info("Base64.decode64(content).encoding===#{Base64.decode64(content).encoding}") - return Base64.decode64(content).force_encoding("GBK").encode("UTF-8") if Base64.decode64(content).encoding == Encoding::ASCII_8BIT + # Rails.logger.info("Base64.decode64(content).encoding===#{Base64.decode64(content).encoding}") + # return Base64.decode64(content).force_encoding("GBK").encode("UTF-8") if Base64.decode64(content).encoding == Encoding::ASCII_8BIT return Base64.decode64(content).force_encoding('UTF-8') else file_type = File.extname(entry['name'].to_s)[1..-1] From 956531e8f174872a7e10f505c253e5235163133d Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 30 Jun 2023 14:12:25 +0800 Subject: [PATCH 10/16] =?UTF-8?q?readme=20GBK=E7=BC=96=E7=A0=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/repositories_helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 11955206d..cf710f69d 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -115,7 +115,8 @@ 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).encoding == Encoding::ASCII_8BIT ? Base64.decode64(str).force_encoding("GBK").encode("UTF-8"): Base64.decode64(str).force_encoding('UTF-8') + # content = Base64.decode64(str).encoding == Encoding::ASCII_8BIT ? Base64.decode64(str).force_encoding("GBK").encode("UTF-8"): Base64.decode64(str).force_encoding('UTF-8') + content = Base64.decode64(str).force_encoding('UTF-8') # s_regex = /\s\!\[.*?\]\((.*?)\)\s/ s_regex_c = /`{1,2}[^`](.*?)`{1,2}/ s_regex = /```([\s\S]*?)```[\s]?/ From 1a0de3752e2723c8786fd18ef901c458a7cdb7b9 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 30 Jun 2023 14:40:38 +0800 Subject: [PATCH 11/16] =?UTF-8?q?readme=20GBK=E7=BC=96=E7=A0=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/repositories_helper.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index cf710f69d..a21cbaf09 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,8 +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).encoding == Encoding::ASCII_8BIT ? Base64.decode64(str).force_encoding("GBK").encode("UTF-8"): Base64.decode64(str).force_encoding('UTF-8') - 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") # s_regex = /\s\!\[.*?\]\((.*?)\)\s/ s_regex_c = /`{1,2}[^`](.*?)`{1,2}/ s_regex = /```([\s\S]*?)```[\s]?/ @@ -209,8 +208,8 @@ module RepositoriesHelper if is_readme?(entry['type'], entry['name']) Rails.logger.info("entry===#{entry["type"]} #{entry["name"]}") content = entry['content'].present? ? entry['content'] : Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content'] - # Rails.logger.info("Base64.decode64(content).encoding===#{Base64.decode64(content).encoding}") - # return Base64.decode64(content).force_encoding("GBK").encode("UTF-8") if Base64.decode64(content).encoding == Encoding::ASCII_8BIT + # Rails.logger.info("content===#{content}") + 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] From daf498d6b5175241f4663170fdb131b52bb2cacd Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 30 Jun 2023 14:46:36 +0800 Subject: [PATCH 12/16] =?UTF-8?q?readme=20GBK=E7=BC=96=E7=A0=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/repositories_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index a21cbaf09..f1e594327 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -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(content).force_encoding('UTF-8').valid_encoding? ? Base64.decode64(str).force_encoding('UTF-8') : Base64.decode64(str).force_encoding("GBK").encode("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]?/ From 0b10f1bceea4ea34b22b7e1e48d58905a9ef8638 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 30 Jun 2023 16:24:32 +0800 Subject: [PATCH 13/16] =?UTF-8?q?readme=20GBK=E7=BC=96=E7=A0=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 6b2d2437a..8427cd262 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -265,6 +265,7 @@ class RepositoriesController < ApplicationController @readme = result[:status] === :success ? result[:body] : nil @readme['content'] = decode64_content(@readme, @owner, @repository, params[:ref], @path) @readme['replace_content'] = readme_decode64_content(@readme, @owner, @repository, params[:ref], @path) + Rails.logger.info("readme['replace_content']=================#{@readme['replace_content']}") render json: @readme.slice("type", "encoding", "size", "name", "path", "content", "sha", "replace_content") rescue render json: nil From 8dc1c7f48c34afc354b444220dc21d181307b141 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 30 Jun 2023 16:34:06 +0800 Subject: [PATCH 14/16] =?UTF-8?q?readme=20GBK=E7=BC=96=E7=A0=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/repositories_helper.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index f1e594327..39eee2cf4 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -116,6 +116,7 @@ module RepositoriesHelper 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').valid_encoding? ? Base64.decode64(str).force_encoding('UTF-8') : Base64.decode64(str).force_encoding("GBK").encode("UTF-8") + Rails.logger.info("content2===#{content}") # s_regex = /\s\!\[.*?\]\((.*?)\)\s/ s_regex_c = /`{1,2}[^`](.*?)`{1,2}/ s_regex = /```([\s\S]*?)```[\s]?/ @@ -178,7 +179,7 @@ module RepositoriesHelper after_ss_c_souces.each_with_index do |s, index| content = content.gsub("#{s[0]}","#{total_sources[:ss_c][index][0]}") end - + Rails.logger.info("content3===#{content}") return content rescue Exception => e Rails.logger.error("===================#{readme_path}:#{readme_name}:error:#{e}") @@ -199,7 +200,7 @@ module RepositoriesHelper def readme_decode64_content(entry, owner, repo, ref, path=nil) Rails.logger.info("entry===#{entry["type"]} #{entry["name"]}") 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}") + Rails.logger.info("content1===#{content}") # readme_render_decode64_content(content, owner, repo, ref) new_readme_render_decode64_content(content, owner, repo, ref, entry['path'], entry['name']) end From 2f411e3421178d6801a467b8cf6602a254299546 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 30 Jun 2023 16:58:35 +0800 Subject: [PATCH 15/16] =?UTF-8?q?readme=20GBK=E7=BC=96=E7=A0=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20=E6=89=A7=E8=A1=8C=E9=A1=BA=E5=BA=8F=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 3 ++- app/helpers/repositories_helper.rb | 3 --- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 8427cd262..e613c6407 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) Rails.logger.info("readme['replace_content']=================#{@readme['replace_content']}") render json: @readme.slice("type", "encoding", "size", "name", "path", "content", "sha", "replace_content") rescue diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 39eee2cf4..1c1e1aa95 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -116,7 +116,6 @@ module RepositoriesHelper 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').valid_encoding? ? Base64.decode64(str).force_encoding('UTF-8') : Base64.decode64(str).force_encoding("GBK").encode("UTF-8") - Rails.logger.info("content2===#{content}") # s_regex = /\s\!\[.*?\]\((.*?)\)\s/ s_regex_c = /`{1,2}[^`](.*?)`{1,2}/ s_regex = /```([\s\S]*?)```[\s]?/ @@ -179,7 +178,6 @@ module RepositoriesHelper after_ss_c_souces.each_with_index do |s, index| content = content.gsub("#{s[0]}","#{total_sources[:ss_c][index][0]}") end - Rails.logger.info("content3===#{content}") return content rescue Exception => e Rails.logger.error("===================#{readme_path}:#{readme_name}:error:#{e}") @@ -200,7 +198,6 @@ module RepositoriesHelper def readme_decode64_content(entry, owner, repo, ref, path=nil) Rails.logger.info("entry===#{entry["type"]} #{entry["name"]}") content = entry['content'].present? ? entry['content'] : Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content'] - Rails.logger.info("content1===#{content}") # readme_render_decode64_content(content, owner, repo, ref) new_readme_render_decode64_content(content, owner, repo, ref, entry['path'], entry['name']) end From 3f63181b4f8d98af58af61158667e5f6e08d191d Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 30 Jun 2023 17:01:11 +0800 Subject: [PATCH 16/16] =?UTF-8?q?readme=20GBK=E7=BC=96=E7=A0=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20=E6=89=A7=E8=A1=8C=E9=A1=BA=E5=BA=8F=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index e613c6407..1fd61f438 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -266,7 +266,6 @@ class RepositoriesController < ApplicationController # 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) - Rails.logger.info("readme['replace_content']=================#{@readme['replace_content']}") render json: @readme.slice("type", "encoding", "size", "name", "path", "content", "sha", "replace_content") rescue render json: nil