76 lines
2.2 KiB
Go
76 lines
2.2 KiB
Go
package service
|
|
|
|
import (
|
|
"code.gitea.io/gitea/modules/structs"
|
|
"github.com/go-resty/resty/v2"
|
|
"gitlink.org.cn/JointCloud/pcm-openi/common"
|
|
"gitlink.org.cn/JointCloud/pcm-openi/model"
|
|
"net/http"
|
|
)
|
|
|
|
type RepoService struct {
|
|
}
|
|
|
|
func NewRepoService() *RepoService {
|
|
return &RepoService{}
|
|
}
|
|
|
|
func (r RepoService) UploadFile(token string, param model.RepoUploadFileParam) (resp *structs.FileResponse, err error) {
|
|
for _, content := range param.FileContents {
|
|
respErr := &model.FileContentErr{}
|
|
body := structs.CreateFileOptions{}
|
|
//Base64编码后的文件内容
|
|
body.Content = content.Content
|
|
_, err = common.Request(common.RepoFile, http.MethodPost, func(req *resty.Request) {
|
|
req.SetPathParam("username", param.UserName).
|
|
SetPathParam("reponame", param.RepoName).
|
|
SetPathParam("filepath", content.FilePath).
|
|
SetQueryParam(common.ACCESSTOKEN, token).
|
|
SetBody(&body).SetResult(&resp).SetError(&respErr)
|
|
})
|
|
}
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return
|
|
}
|
|
|
|
func (r RepoService) UpdateFile(token string, param model.RepoUpdateFileParam) (resp *structs.FileResponse, err error) {
|
|
for _, content := range param.FileContents {
|
|
respErr := &model.FileContentErr{}
|
|
resp := &structs.FileResponse{}
|
|
body := structs.UpdateFileOptions{}
|
|
//Base64编码后的文件内容
|
|
body.Content = content.Content
|
|
body.SHA = content.FileSha
|
|
_, err = common.Request(common.RepoFile, http.MethodPut, func(req *resty.Request) {
|
|
req.SetPathParam("username", param.UserName).
|
|
SetPathParam("reponame", param.RepoName).
|
|
SetPathParam("filepath", content.FilePath).
|
|
SetQueryParam(common.ACCESSTOKEN, token).
|
|
SetBody(&body).SetResult(&resp).SetError(&respErr)
|
|
})
|
|
}
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return
|
|
}
|
|
|
|
func (r RepoService) QueryFilesContent(token string, param *model.QueryFilesContentParam) (resp interface{}, err error) {
|
|
var respErr interface{}
|
|
_, err = common.Request(common.RepoFile, http.MethodGet, func(req *resty.Request) {
|
|
req.SetPathParam("username", param.UserName).
|
|
SetPathParam("reponame", param.RepoName).
|
|
SetPathParam("filepath", param.FilePath).
|
|
SetQueryParam(common.ACCESSTOKEN, token).
|
|
SetResult(&resp).SetError(&respErr)
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return
|
|
}
|