forked from Trustie/forgeplus
FIX merge dev_trustie branch
This commit is contained in:
commit
705ae1020b
59
README.md
59
README.md
|
@ -1363,6 +1363,65 @@ http://localhost:3000/api/projects | jq
|
||||||
```
|
```
|
||||||
---
|
---
|
||||||
|
|
||||||
|
#### 推荐项目
|
||||||
|
```
|
||||||
|
GET api/projects/recommend
|
||||||
|
```
|
||||||
|
*示例*
|
||||||
|
```
|
||||||
|
curl -X GET \
|
||||||
|
http://localhost:3000/api/projects/recommend | jq
|
||||||
|
```
|
||||||
|
|
||||||
|
*返回参数说明:*
|
||||||
|
|
||||||
|
|参数名|类型|说明|
|
||||||
|
|-|-|-|
|
||||||
|
|total_count |int |项目总条数 |
|
||||||
|
|id |string |项目id |
|
||||||
|
|name |string|项目名称|
|
||||||
|
|description |string|项目简介|
|
||||||
|
|visits |int|流量数|
|
||||||
|
|forked_count |int|被fork的数量|
|
||||||
|
|praises_count |int|star数量|
|
||||||
|
|is_public |boolean|是否公开, true:公开,false:未公开|
|
||||||
|
|mirror_url |string|镜像url|
|
||||||
|
|last_update_time|int|最后更新时间,为UNIX格式的时间戳|
|
||||||
|
|author |object|项目创建者|
|
||||||
|
|-- name |string|用户名,也是用户标识|
|
||||||
|
|category |object|项目类别|
|
||||||
|
|-- id |int|项目类型id|
|
||||||
|
|-- name |string|项目类型名称|
|
||||||
|
|language |object|项目语言|
|
||||||
|
|-- id |int|项目语言id|
|
||||||
|
|-- name |string|项目语言名称|
|
||||||
|
|
||||||
|
|
||||||
|
返回值
|
||||||
|
```
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": 20,
|
||||||
|
"repo_id": null,
|
||||||
|
"identifier": "PNAekinmH",
|
||||||
|
"name": "FNILL",
|
||||||
|
"visits": 13567,
|
||||||
|
"author": {
|
||||||
|
"name": "王一达",
|
||||||
|
"login": "wangyida",
|
||||||
|
"image_url": "avatars/User/b"
|
||||||
|
},
|
||||||
|
"category": {
|
||||||
|
"id": 8,
|
||||||
|
"name": "其他"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
...
|
||||||
|
]
|
||||||
|
|
||||||
|
```
|
||||||
|
---
|
||||||
|
|
||||||
### 获取分支列表
|
### 获取分支列表
|
||||||
```
|
```
|
||||||
GET /api/:namespace_id/:id/branches
|
GET /api/:namespace_id/:id/branches
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#
|
#
|
||||||
# 文件上传
|
# 文件上传
|
||||||
class AttachmentsController < ApplicationController
|
class AttachmentsController < ApplicationController
|
||||||
before_action :require_login, :check_auth, except: [:show, :preview_attachment]
|
before_action :require_login, :check_auth, except: [:show, :preview_attachment, :get_file]
|
||||||
before_action :find_file, only: %i[show destroy]
|
before_action :find_file, only: %i[show destroy]
|
||||||
before_action :attachment_candown, only: [:show]
|
before_action :attachment_candown, only: [:show]
|
||||||
skip_before_action :check_sign, only: [:show, :create]
|
skip_before_action :check_sign, only: [:show, :create]
|
||||||
|
@ -28,6 +28,15 @@ class AttachmentsController < ApplicationController
|
||||||
update_downloads(@file)
|
update_downloads(@file)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def get_file
|
||||||
|
normal_status(-1, "参数缺失") if params[:download_url].blank?
|
||||||
|
url = URI.encode(params[:download_url].to_s.gsub("http:", "https:"))
|
||||||
|
response = Faraday.get(url)
|
||||||
|
filename = params[:download_url].to_s.split("/").pop()
|
||||||
|
send_data(response.body.force_encoding("UTF-8"), filename: filename, type: "application/octet-stream", disposition: 'attachment')
|
||||||
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
# 1. 本地存储
|
# 1. 本地存储
|
||||||
# 2. 上传到云
|
# 2. 上传到云
|
||||||
|
|
|
@ -2,9 +2,8 @@ class ProjectsController < ApplicationController
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
include OperateProjectAbilityAble
|
include OperateProjectAbilityAble
|
||||||
include ProjectsHelper
|
include ProjectsHelper
|
||||||
|
before_action :require_login, except: %i[index branches group_type_list simple show fork_users praise_users watch_users recommend]
|
||||||
before_action :require_login, except: %i[index branches group_type_list simple show fork_users praise_users watch_users]
|
before_action :load_project, except: %i[index group_type_list migrate create recommend]
|
||||||
before_action :load_project, except: %i[index group_type_list migrate create]
|
|
||||||
before_action :authorizate_user_can_edit_project!, only: %i[update]
|
before_action :authorizate_user_can_edit_project!, only: %i[update]
|
||||||
before_action :project_public?, only: %i[fork_users praise_users watch_users]
|
before_action :project_public?, only: %i[fork_users praise_users watch_users]
|
||||||
|
|
||||||
|
@ -104,6 +103,10 @@ class ProjectsController < ApplicationController
|
||||||
json_response(@project, current_user)
|
json_response(@project, current_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def recommend
|
||||||
|
@projects = Project.recommend.includes(:repository, :project_category, owner: :user_extension).limit(5)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
def project_params
|
def project_params
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
module RepositoriesHelper
|
module RepositoriesHelper
|
||||||
def render_decode64_content(str)
|
def render_decode64_content(str)
|
||||||
return nil if str.blank?
|
return nil if str.blank?
|
||||||
Base64.decode64(str).force_encoding('UTF-8')
|
Base64.decode64(str).force_encoding("UTF-8")
|
||||||
end
|
end
|
||||||
|
|
||||||
def download_type(str)
|
def download_type(str)
|
||||||
default_type = %w(xlsx xls ppt pptx pdf zip 7z rar exe pdb obj idb png jpg gif tif psd svg RData rdata)
|
default_type = %w(xlsx xls ppt pptx pdf zip 7z rar exe pdb obj idb png jpg gif tif psd svg RData rdata doc docx mpp vsdx)
|
||||||
default_type.include?(str&.downcase)
|
default_type.include?(str&.downcase)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,8 @@ class Project < ApplicationRecord
|
||||||
after_save :check_project_members
|
after_save :check_project_members
|
||||||
scope :project_statics_select, -> {select(:id,:name, :is_public, :identifier, :status, :project_type, :user_id, :forked_count, :visits, :project_category_id, :project_language_id, :license_id, :ignore_id, :watchers_count, :created_on)}
|
scope :project_statics_select, -> {select(:id,:name, :is_public, :identifier, :status, :project_type, :user_id, :forked_count, :visits, :project_category_id, :project_language_id, :license_id, :ignore_id, :watchers_count, :created_on)}
|
||||||
scope :no_anomory_projects, -> {where("projects.user_id is not null and projects.user_id != ?", 2)}
|
scope :no_anomory_projects, -> {where("projects.user_id is not null and projects.user_id != ?", 2)}
|
||||||
|
scope :recommend, -> { visible.project_statics_select.where(recommend: true) }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def self.search_project(search)
|
def self.search_project(search)
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
json.array! @projects do |project|
|
||||||
|
owner = project.owner
|
||||||
|
json.id project.id
|
||||||
|
json.repo_id project&.repository&.id
|
||||||
|
json.identifier project.identifier
|
||||||
|
json.name project.name
|
||||||
|
json.visits project.visits
|
||||||
|
json.author do
|
||||||
|
json.name owner.try(:show_real_name)
|
||||||
|
json.login owner.login
|
||||||
|
json.image_url url_to_avatar(owner)
|
||||||
|
end
|
||||||
|
|
||||||
|
json.category do
|
||||||
|
if project.project_category.blank?
|
||||||
|
json.nil!
|
||||||
|
else
|
||||||
|
json.id project.project_category.id
|
||||||
|
json.name project.project_category.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -7,7 +7,7 @@ json.sha entry['sha']
|
||||||
json.path entry['path']
|
json.path entry['path']
|
||||||
json.type entry['type']
|
json.type entry['type']
|
||||||
json.size entry['size']
|
json.size entry['size']
|
||||||
json.content entry['content'].present? && !direct_download ? render_decode64_content(entry['content']).force_encoding('UTF-8') : ""
|
json.content entry['content'].present? && !direct_download ? render_decode64_content(entry['content']) : ""
|
||||||
json.target entry['target']
|
json.target entry['target']
|
||||||
json.download_url entry['download_url']
|
json.download_url entry['download_url']
|
||||||
json.direct_download direct_download
|
json.direct_download direct_download
|
||||||
|
|
|
@ -8,8 +8,10 @@ Rails.application.routes.draw do
|
||||||
# Serve websocket cable requests in-process
|
# Serve websocket cable requests in-process
|
||||||
mount ActionCable.server => '/cable'
|
mount ActionCable.server => '/cable'
|
||||||
|
|
||||||
|
get 'attachments/entries/get_file', to: 'attachments#get_file'
|
||||||
get 'attachments/download/:id', to: 'attachments#show'
|
get 'attachments/download/:id', to: 'attachments#show'
|
||||||
get 'attachments/download/:id/:filename', to: 'attachments#show'
|
get 'attachments/download/:id/:filename', to: 'attachments#show'
|
||||||
|
|
||||||
get 'auth/qq/callback', to: 'oauth/qq#create'
|
get 'auth/qq/callback', to: 'oauth/qq#create'
|
||||||
get 'auth/failure', to: 'oauth/base#auth_failure'
|
get 'auth/failure', to: 'oauth/base#auth_failure'
|
||||||
get 'auth/cas/callback', to: 'oauth/cas#create'
|
get 'auth/cas/callback', to: 'oauth/cas#create'
|
||||||
|
@ -18,6 +20,8 @@ Rails.application.routes.draw do
|
||||||
get 'oauth/register', to: 'oauth#register'
|
get 'oauth/register', to: 'oauth#register'
|
||||||
post 'oauth/auto_register', to: 'oauth#auto_register'
|
post 'oauth/auto_register', to: 'oauth#auto_register'
|
||||||
|
|
||||||
|
resources :edu_settings
|
||||||
|
|
||||||
resources :edu_settings
|
resources :edu_settings
|
||||||
scope '/api' do
|
scope '/api' do
|
||||||
namespace :ci do
|
namespace :ci do
|
||||||
|
@ -48,7 +52,7 @@ Rails.application.routes.draw do
|
||||||
resources :compose_projects, only: [:create, :destroy]
|
resources :compose_projects, only: [:create, :destroy]
|
||||||
end
|
end
|
||||||
resources :attachments do
|
resources :attachments do
|
||||||
member do
|
member do
|
||||||
post :preview_attachment
|
post :preview_attachment
|
||||||
end
|
end
|
||||||
collection do
|
collection do
|
||||||
|
@ -104,6 +108,7 @@ Rails.application.routes.draw do
|
||||||
collection do
|
collection do
|
||||||
post :migrate
|
post :migrate
|
||||||
get :group_type_list
|
get :group_type_list
|
||||||
|
get :recommend
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddIndexToUsersType < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_index :users, :type
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddRecommendToProjects < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :projects, :recommend, :boolean, default: false
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue