| @@ -92,18 +92,19 @@ class ProjectsController < ApplicationController | |||||
| def update | def update | ||||
| ActiveRecord::Base.transaction do | ActiveRecord::Base.transaction do | ||||
| # Projects::CreateForm.new(project_params).validate! | # Projects::CreateForm.new(project_params).validate! | ||||
| private = params[:private] | |||||
| private = params[:private] || false | |||||
| new_project_params = project_params.except(:private).merge(is_public: !private) | |||||
| @project.update_attributes!(new_project_params) | |||||
| gitea_params = { | gitea_params = { | ||||
| private: private, | private: private, | ||||
| default_branch: params[:default_branch], | |||||
| website: params[:website] | |||||
| default_branch: @project.default_branch, | |||||
| website: @project.website | |||||
| } | } | ||||
| if [true, false].include? private | if [true, false].include? private | ||||
| new_project_params = project_params.except(:private).merge(is_public: !private) | |||||
| Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params) | Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params) | ||||
| @project.repository.update_column(:hidden, private) | @project.repository.update_column(:hidden, private) | ||||
| end | end | ||||
| @project.update_attributes!(new_project_params) | |||||
| end | end | ||||
| rescue Exception => e | rescue Exception => e | ||||
| uid_logger_error(e.message) | uid_logger_error(e.message) | ||||
| @@ -33,34 +33,38 @@ module RepositoriesHelper | |||||
| def readme_render_decode64_content(str, path) | def readme_render_decode64_content(str, path) | ||||
| return nil if str.blank? | return nil if str.blank? | ||||
| content = Base64.decode64(str).force_encoding('UTF-8') | |||||
| begin | |||||
| content = Base64.decode64(str).force_encoding('UTF-8') | |||||
| c_regex = /\!\[.*?\]\((.*?)\)/ | |||||
| src_regex = /src=\"(.*?)\"/ | |||||
| ss = content.to_s.scan(c_regex) | |||||
| ss_src = content.to_s.scan(src_regex) | |||||
| total_images = ss + ss_src | |||||
| if total_images.length > 0 | |||||
| total_images.each do |s| | |||||
| image_title = /\"(.*?)\"/ | |||||
| r_content = s[0] | |||||
| remove_title = r_content.to_s.scan(image_title) | |||||
| if remove_title.length > 0 | |||||
| r_content = r_content.gsub(/#{remove_title[0]}/, "").strip | |||||
| c_regex = /\!\[.*?\]\((.*?)\)/ | |||||
| src_regex = /src=\"(.*?)\"/ | |||||
| ss = content.to_s.scan(c_regex) | |||||
| ss_src = content.to_s.scan(src_regex) | |||||
| total_images = ss + ss_src | |||||
| if total_images.length > 0 | |||||
| total_images.each do |s| | |||||
| image_title = /\"(.*?)\"/ | |||||
| r_content = s[0] | |||||
| remove_title = r_content.to_s.scan(image_title) | |||||
| if remove_title.length > 0 | |||||
| r_content = r_content.gsub(/#{remove_title[0]}/, "").strip | |||||
| end | |||||
| if r_content.include?("?") | |||||
| new_r_content = r_content + "&raw=true" | |||||
| else | |||||
| new_r_content = r_content + "?raw=true" | |||||
| end | |||||
| unless r_content.include?("http://") || r_content.include?("https://") || r_content.include?("mailto:") | |||||
| new_r_content = "#{path}" + new_r_content | |||||
| end | |||||
| content = content.gsub(/#{r_content}/, new_r_content) | |||||
| end | end | ||||
| if r_content.include?("?") | |||||
| new_r_content = r_content + "&raw=true" | |||||
| else | |||||
| new_r_content = r_content + "?raw=true" | |||||
| end | |||||
| unless r_content.include?("http://") || r_content.include?("https://") || r_content.include?("mailto:") | |||||
| new_r_content = "#{path}" + new_r_content | |||||
| end | |||||
| content = content.gsub(/#{r_content}/, new_r_content) | |||||
| end | end | ||||
| return content | |||||
| rescue | |||||
| return str | |||||
| end | end | ||||
| return content | |||||
| end | end | ||||
| # unix_time values for example: 1604382982 | # unix_time values for example: 1604382982 | ||||
| @@ -5,3 +5,4 @@ json.description @project.description | |||||
| json.project_category_id @project.project_category_id | json.project_category_id @project.project_category_id | ||||
| json.project_language_id @project.project_language_id | json.project_language_id @project.project_language_id | ||||
| json.is_public @project.is_public | json.is_public @project.is_public | ||||
| json.website @project.website | |||||
| @@ -7,6 +7,7 @@ else | |||||
| end | end | ||||
| json.identifier render_identifier(@project) | json.identifier render_identifier(@project) | ||||
| json.name @project.name | json.name @project.name | ||||
| json.description @project.description | |||||
| json.project_id @project.id | json.project_id @project.id | ||||
| json.repo_id @repository.id | json.repo_id @repository.id | ||||
| json.issues_count @project.issues_count.to_i - @project.pull_requests_count.to_i | json.issues_count @project.issues_count.to_i - @project.pull_requests_count.to_i | ||||
| @@ -5,4 +5,5 @@ json.project_description @project.description | |||||
| json.project_category_id @project.project_category_id | json.project_category_id @project.project_category_id | ||||
| json.project_language_id @project.project_language_id | json.project_language_id @project.project_language_id | ||||
| json.private !@project.is_public | json.private !@project.is_public | ||||
| json.website @project.website | |||||
| json.project_units @project.project_units.pluck(:unit_type) | json.project_units @project.project_units.pluck(:unit_type) | ||||
| @@ -0,0 +1,15 @@ | |||||
| namespace :sync_count_cache do | |||||
| desc "更新项目自动计数字段" | |||||
| task projects: :environment do | |||||
| Project.includes(:praise_treads, :fork_users, :issues, :watchers, :issues, :pull_requests, :versions, :issue_tags).find_each do |project| | |||||
| project.update(forked_count: project.fork_users.size, closed_issues_count: project.issues.where(status_id: 5).size) | |||||
| Project.reset_counters(project.id, :praise_treads) | |||||
| Project.reset_counters(project.id, :watchers) | |||||
| Project.reset_counters(project.id, :issues) | |||||
| Project.reset_counters(project.id, :pull_requests) | |||||
| Project.reset_counters(project.id, :versions) | |||||
| Project.reset_counters(project.id, :issue_tags) | |||||
| end | |||||
| end | |||||
| end | |||||