Merge branches 'dev_aliyun' and 'dev_jupyter' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_new_shixunsrepository
杨树明 5 years ago
commit c23bfb4852

@ -41,7 +41,8 @@ module GitHelper
# 更新文件代码
# content 文件内容message提交描述
def update_file_content(content, repo_path, path, mail, username, message)
GitService.update_file(repo_path: repo_path, file_path: path, message: message,
content = Base64.encode64(content)
GitService.update_file_base64(repo_path: repo_path, file_path: path, message: message,
content: content, author_name: username, author_email: mail)
end

@ -2,16 +2,30 @@
#
# 文档在 https://www.showdoc.cc/127895880302646?page_id=1077512172693249
#
require 'faraday'
class GitService
class << self
['add_repository', 'fork_repository', 'delete_repository', 'file_tree', 'update_file', 'file_content', 'commits', 'add_tree', 'delete_file'].each do |method|
['add_repository', 'fork_repository', 'delete_repository', 'file_tree', 'update_file', 'file_content', 'commits',
'add_tree', 'delete_file', 'update_file_base64'].each do |method|
define_method method do |params|
post(method, params)
end
end
def make_new_multipar_file(full_file_path)
Faraday::FilePart.new(full_file_path, 'application/octet-stream')
end
#上传二进制文件
#参数构造形式
# {a: 'a', file: make_new_multipar_file('1.txt') }
def update_file_binary(params)
post_form('update_file', params)
end
private
def root_url
@ -24,6 +38,19 @@ class GitService
Rails.logger
end
def post_form(action,params)
conn = Faraday.new(root_url) do |f|
f.request :multipart
f.request :url_encoded
f.adapter :net_http
end
resp = conn.post("/api/#{action}", params)
body = resp.body
parse_return(body)
end
def post(action, params)
uri = URI.parse("#{root_url}/api/#{action}")
https = Net::HTTP.new(uri.host, uri.port)
@ -32,6 +59,11 @@ class GitService
req.body = params.to_json
res = https.request(req)
body = res.body
parse_return(body)
end
def parse_return(body)
logger.info("--uri_exec: .....res is #{body}")
content = JSON.parse(body)

Loading…
Cancel
Save