Compare commits

..

5 Commits

Author SHA1 Message Date
jasder cb11a5c8e9 发布v3.1.1版本
* FIX 修复pulls、issues 搜索数量统计问题
* FIX 解决在线创建文件错误提示信息不准确的问题
* FIX table name bug
* FIX 解决applied_projects相关表操作的问题
* FIX 解决排序参数的判断预防SQL注入
* FIX 项目导航栏数量改为开启中的数量
* FIX 解决项目邀请码的索引查询问题
* FIX FIX get readme file bug
* FIX sql attack
* FIX projects load by invite code slowly
2021-06-18 17:09:57 +08:00
jasder c5d73b7cf8 v3.1.0
* 改版升级个人主页
* 修复bug
* 更改license
2021-06-09 09:52:57 +08:00
jasder 8a10a183e0 Merge branch 'develop' 2021-05-24 10:18:03 +08:00
jasder 6d1bcabd51 Merge branch 'master' of https://git.trustie.net/jasder/forgeplus 2021-05-24 10:10:24 +08:00
jasder 86f03ffafc Merge OK 2021-05-08 17:46:22 +08:00
10 changed files with 18 additions and 102 deletions

View File

@ -5,7 +5,7 @@ class ProjectsController < ApplicationController
include Acceleratorable
before_action :require_login, except: %i[index branches group_type_list simple show fork_users praise_users watch_users recommend about menu_list]
before_action :load_repository, except: %i[index group_type_list migrate create recommend]
before_action :load_project, except: %i[index group_type_list migrate create recommend]
before_action :authorizate_user_can_edit_project!, only: %i[update]
before_action :project_public?, only: %i[fork_users praise_users watch_users]

View File

@ -5,9 +5,9 @@ class RepositoriesController < ApplicationController
before_action :require_login, only: %i[edit update create_file update_file delete_file sync_mirror]
before_action :load_repository
before_action :authorizate!, except: [:sync_mirror, :tags, :commit, :archive]
before_action :authorizate!, except: [:sync_mirror, :tags, :commit]
before_action :authorizate_user_can_edit_repo!, only: %i[sync_mirror]
before_action :get_ref, only: %i[entries sub_entries top_counts file archive]
before_action :get_ref, only: %i[entries sub_entries top_counts file]
before_action :get_latest_commit, only: %i[entries sub_entries top_counts]
before_action :get_statistics, only: %i[top_counts]
@ -192,19 +192,6 @@ class RepositoriesController < ApplicationController
render json: languages_precentagable
end
def archive
domain = Gitea.gitea_config[:domain]
api_url = Gitea.gitea_config[:base_url]
archive_url = "/repos/#{@owner.login}/#{@repository.identifier}/archive/#{params[:archive]}"
file_path = [domain, api_url, archive_url].join
file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("?") if @repository.hidden?
return render_not_found if !request.format.zip? && !request.format.gzip?
redirect_to file_path
end
private
def find_project
@ -279,7 +266,7 @@ class RepositoriesController < ApplicationController
# uploadPushInfo
end
def create_new_pr(params)
if params[:new_branch].present? && params[:new_branch] != params[:branch]
local_params = {

View File

@ -13,12 +13,12 @@ module ProjectsHelper
end
end
def render_zip_url(owner, repository, archive)
[base_url, archive_repositories_path(owner&.login, repository, "#{archive}.zip")].join
def render_zip_url(project, archive_name)
[gitea_domain, project.owner.login, project.identifier, "archive", "#{archive_name}.zip"].join('/')
end
def render_tar_url(owner, repository, archive)
[base_url, archive_repositories_path(owner&.login, repository, "#{archive}.tar.gz")].join
def render_tar_url(project, archive_name)
[gitea_domain, project.owner.login, project.identifier, "archive", "#{archive_name}.tar.gz"].join('/')
end
def render_http_url(project)

View File

@ -24,14 +24,8 @@ module Gitea
def run
Contents::CreateForm.new(valid_params).validate!
result = Gitea::Repository::Entries::CreateService.call(token,
owner, @params[:identifier], @params[:filepath], file_params)
if result[:status] == :success
@result = result[:body]
else
fail!(result[:message])
end
response = Gitea::Repository::Entries::CreateService.new(token, owner, @params[:identifier], @params[:filepath], file_params).call
render_result(response)
rescue Exception => exception
Rails.logger.info "Exception ===========> #{exception.message}"
fail!(exception.message)
@ -62,7 +56,7 @@ module Gitea
file_params = {}
file_params = file_params.merge(branch: @params[:branch]) unless @params[:branch].blank?
file_params = file_params.merge(new_branch: @params[:new_branch]) unless @params[:new_branch].blank?
file_params = file_params.merge(content: Base64.encode64(@params[:content] || ""))
file_params = file_params.merge(content: Base64.encode64(@params[:content]))
file_params = file_params.merge(message: @params[:message]) unless @params[:message].blank?
file_params = file_params.merge(committer: @params[:committer])
file_params

View File

@ -214,14 +214,6 @@ class Gitea::ClientService < ApplicationService
[body, message]
end
def json_parse!(body)
return nil unless body.present?
body = JSON.parse(body)
body, message = fix_body(body)
body
end
def log_error(status, body)
puts "[gitea] status: #{status}"
puts "[gitea] body: #{body&.force_encoding('UTF-8')}"

View File

@ -1,40 +0,0 @@
class Gitea::Repository::ArchiveService < Gitea::ClientService
attr_reader :owner, :repo, :archive, :token
def initialize(owner, repo, archive, token=nil)
@owner = owner
@repo = repo
@archive = archive
@token = token
end
def call
response = get(url, params)
response_payload(response)
end
private
def params
Hash.new.merge(token: token)
end
def url
"/repos/#{owner}/#{repo}/archive/#{archive}".freeze
end
def response_payload(response)
status = response.status
body = response&.body
log_error(status, body)
status_payload(status, body)
end
def status_payload(status, body)
case status
when 200 then success
when 404 then error("你操作的链接不存在!")
else error("系统错误!")
end
end
end

View File

@ -30,7 +30,8 @@ class Gitea::Repository::Entries::CreateService < Gitea::ClientService
def call
response = post(url, params)
response_payload(response)
render_201_response(response)
end
private
@ -42,21 +43,4 @@ class Gitea::Repository::Entries::CreateService < Gitea::ClientService
"/repos/#{owner}/#{repo_name}/contents/#{filepath}".freeze
end
def response_payload(response)
status = response.status
body = response&.body
log_error(status, body)
status_payload(status, body)
end
def status_payload(status, body)
case status
when 201 then success(json_parse!(body))
when 403 then error("你没有权限操作!")
when 404 then error("你操作的链接不存在!")
when 422 then error("#{filepath}文件已存在,不能重复创建!")
else error("系统错误!")
end
end
end

View File

@ -4,8 +4,8 @@ json.array! @branches do |branch|
json.user_can_merge branch['user_can_merge']
json.protected branch['protected']
json.http_url render_http_url(@project)
json.zip_url render_zip_url(@owner, @repository, branch['name'])
json.tar_url render_tar_url(@owner, @repository, branch['name'])
json.zip_url render_zip_url(@project, branch['name'])
json.tar_url render_tar_url(@project, branch['name'])
json.last_commit do
json.sha branch['commit']['id']
json.message branch['commit']['message']

View File

@ -42,9 +42,8 @@ if @project.forge?
#json.tags_count @tags_count
#json.branches_count @branches_count
json.commits_count @commits_count
# json.zip_url archive_repositories_path(@owner&.login, @repository, @ref)
json.zip_url render_zip_url(@owner, @repository, @ref)
json.tar_url render_tar_url(@owner, @repository, @ref)
json.zip_url render_zip_url(@project, @ref)
json.tar_url render_tar_url(@project, @ref)
json.entries do
json.array! @entries do |entry|
json.name entry['name']

View File

@ -416,6 +416,7 @@ Rails.application.routes.draw do
member do
get :files
get :detail
get :archive
get :entries
match :sub_entries, :via => [:get, :put]
get :commits
@ -430,7 +431,6 @@ Rails.application.routes.draw do
get 'commits/:sha', to: 'repositories#commit', as: 'commit'
get 'readme'
get 'languages'
get 'archive/:archive', to: 'repositories#archive', as: "archive", constraints: { archive: /.+/, format: /(zip|gzip)/ }
end
end