From 48846a7e31810a6d9cb631701c7902023358965d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Wed, 10 Aug 2022 16:07:20 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20=E5=B7=B2=E8=AF=BB=E6=9C=AA=E8=AF=BB?= =?UTF-8?q?=E6=A0=87=E8=AE=B0=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/mark_files_controller.rb | 41 ++++++++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/app/controllers/mark_files_controller.rb b/app/controllers/mark_files_controller.rb index 88856c35a..a7ec304fd 100644 --- a/app/controllers/mark_files_controller.rb +++ b/app/controllers/mark_files_controller.rb @@ -4,17 +4,44 @@ class MarkFilesController < ApplicationController before_action :load_pull_request def index - @files_result = Gitea::PullRequest::FilesService.call(@owner.login, @project.identifier, @pull_request.gitea_number, current_user&.gitea_token) - - MarkFile.bulk_insert(*%i[pull_request_id, file_path_sha file_path created_at updated_at]) do |worker| - @files_result['Files'].echo do |file| - worker.add(pull_request_id: @pull_request.id, file_path_sha: SecureRandom.uuid.gsub("-", ""), file_path: file['Name']) - end - end + @files_result = Gitea::PullRequest::FilesService.call(@owner.login, @project.identifier, @pull_request.gitea_number, current_user&.gitea_token, { "only-file-name": true }) @mark_files = MarkFile.where(pull_request_id: @pull_request.id) end def create + # unless @pull_request.mark_files.present? + # MarkFile.bulk_insert(*%i[pull_request_id, file_path_sha file_path created_at updated_at]) do |worker| + # @files_result['Files'].each do |file| + # worker.add(pull_request_id: @pull_request.id, file_path_sha: SecureRandom.uuid.gsub("-", ""), file_path: file['Name']) + # end + # end + # end + end + + def mark_file_as_unread + tip_exception "参数错误" if params[:file_path_sha].blank? + file_path = Base64.strict_decode64(params[:file_path_sha].to_s) + mark_file = @pull_request.mark_files.find_or_initialize_by(file_path_sha: params[:file_path_sha]) + mark_file.file_path = file_path + mark_file.user_id = current_user.id + mark_file.mark_as_read = false + mark_file.save + render_ok + rescue Exception => e + tip_exception "参数解析错误" + end + + def mark_file_as_read + tip_exception "参数错误" if params[:file_path_sha].blank? + file_path = Base64.strict_decode64(params[:file_path_sha].to_s) + mark_file = @pull_request.mark_files.find_or_initialize_by(file_path_sha: params[:file_path_sha]) + mark_file.file_path = file_path + mark_file.user_id = current_user.id + mark_file.mark_as_read = true + mark_file.save + render_ok + rescue Exception => e + tip_exception "参数解析错误" end private