From ff34ec6de84ad296df70fc7150f9608805706699 Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 20 Dec 2016 16:33:26 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=BA=93=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=20=20=E5=8F=82=E6=95=B0=E5=8A=A0=E5=AF=86=20gitlab=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=A7=A3=E5=AF=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 22 ++++++++++++++++------ app/helpers/application_helper.rb | 17 +++++++++++++++++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 82cbde56f..7f2e834cd 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -35,7 +35,7 @@ class RepositoriesController < ApplicationController before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo, :stats, :quality_analysis] before_filter :find_repository, :only => [:edit, :update, :destroy, :committers] - before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked, :project_archive, :export_rep_static] + before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked, :export_rep_static] # 连接gitlab # before_filter :connect_gitlab, :only => [:quality_analysis, :commit_diff] @@ -121,9 +121,15 @@ class RepositoriesController < ApplicationController # 一键ZIP下载 def project_archive - g = Gitlab.client - g.get() - # g.project_archive(params[:gpid].to_i, params[:rev]) + token = Gitlab.private_token + token = aes_encrypt(token, "abcd") + # g = Gitlab.client + # g.project_archive(@project.gpid, @rev) + # 'git archive --format zip --output /path/to/file.zip master' # 将 master 以zip格式打包到指定文件 + # + # zip_path = Gitlab.endpoint.to_s + "/projects/" + @project.gpid.to_s + "/repository/archive?&private_token=" + Gitlab.private_token + # f = open(zip_path).read + # send_file "/path/to/file.zip" end # 判断用户是否已经fork过该项目 @@ -409,8 +415,12 @@ update @creator = @project.owner.to_s gitlab_address = Redmine::Configuration['gitlab_address'] - # REDO:需优化,仅测试用 - @zip_path = Gitlab.endpoint.to_s + "/projects/" + @project.gpid.to_s + "/repository/archive?&private_token=" + Gitlab.private_token + gitlab_token = Gitlab.private_token + # token值加密解密 + token = aes_encrypt("priEn3UwXfJs3Pmy", gitlab_token) + # token值解密 + # gitlab_token = aes_dicrypt("priEn3UwXfJs3Pmy", token) + @zip_path = Gitlab.endpoint.to_s + "/projects/" + @project.gpid.to_s + "/repository/archive?&private_token=" + token end @creator = @project.owner.to_s diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index aef32f714..542823dc9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -37,6 +37,23 @@ module ApplicationHelper # super # end + # 字符串加密 + def aes_encrypt(key, encrypted_string) + aes = OpenSSL::Cipher::Cipher.new("AES-128-ECB") + aes.encrypt + aes.key = key + txt = aes.update(encrypted_string) << aes.final + txt.unpack('H*')[0].upcase + end + + # 字符串解密 + def aes_dicrypt(key, dicrypted_string) + aes = OpenSSL::Cipher::Cipher.new("AES-128-ECB") + aes.decrypt + aes.key = key + aes.update([dicrypted_string].pack('H*')) << aes.final + end + # 获取多种类型的user用户名 def user_message_username user user.try(:show_name)