Http接口加上版本标志

This commit is contained in:
Sydonian 2025-05-15 16:24:57 +08:00
parent cffbd89127
commit b555688baa
27 changed files with 183 additions and 178 deletions

View File

@ -1,37 +1,5 @@
package http
import (
"fmt"
import "gitlink.org.cn/cloudream/jcs-pub/client/internal/http/types"
"gitlink.org.cn/cloudream/common/consts/errorcode"
"gitlink.org.cn/cloudream/common/pkgs/mq"
)
type Response struct {
Code string `json:"code"`
Message string `json:"message"`
Data any `json:"data"`
}
func OK(data any) Response {
return Response{
Code: errorcode.OK,
Message: "",
Data: data,
}
}
func Failed(code string, format string, args ...any) Response {
return Response{
Code: code,
Message: fmt.Sprintf(format, args...),
}
}
func FailedError(err error) Response {
if codeErr, ok := err.(*mq.CodeMessageError); ok {
return Failed(codeErr.Code, codeErr.Message)
}
return Failed(errorcode.OperationFailed, err.Error())
}
type Config = types.Config

View File

@ -7,8 +7,9 @@ import (
"github.com/gin-gonic/gin"
"gitlink.org.cn/cloudream/common/pkgs/async"
"gitlink.org.cn/cloudream/common/pkgs/logger"
"gitlink.org.cn/cloudream/jcs-pub/client/internal/http/types"
v1 "gitlink.org.cn/cloudream/jcs-pub/client/internal/http/v1"
"gitlink.org.cn/cloudream/jcs-pub/client/internal/services"
cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api"
)
type ServerEventChan = async.UnboundChannel[ServerEvent]
@ -23,17 +24,19 @@ type ExitEvent struct {
}
type Server struct {
cfg *Config
cfg *types.Config
httpSrv *http.Server
svc *services.Service
eventChan *ServerEventChan
v1Svr *v1.Server
}
func NewServer(cfg *Config, svc *services.Service) *Server {
func NewServer(cfg *types.Config, svc *services.Service) *Server {
return &Server{
cfg: cfg,
svc: svc,
eventChan: async.NewUnboundChannel[ServerEvent](),
v1Svr: v1.NewServer(cfg, svc),
}
}
@ -49,7 +52,7 @@ func (s *Server) Start() *ServerEventChan {
Handler: engine,
}
s.initRouters(engine)
s.v1Svr.InitRouters(engine.Group("/v1"))
logger.Infof("start serving http at: %s", s.cfg.Listen)
@ -67,100 +70,3 @@ func (s *Server) Stop() {
s.httpSrv.Shutdown(context.Background())
}
func (s *Server) initRouters(engine *gin.Engine) {
rt := engine.Use()
// initTemp(rt, s)
s.routeV1(engine, rt)
rt.GET(cliapi.ObjectListPathByPath, s.Object().ListByPath)
rt.GET(cliapi.ObjectListByIDsPath, s.Object().ListByIDs)
rt.GET(cliapi.ObjectDownloadPath, s.Object().Download)
rt.GET(cliapi.ObjectDownloadByPathPath, s.Object().DownloadByPath)
rt.POST(cliapi.ObjectUploadPath, s.Object().Upload)
rt.GET(cliapi.ObjectGetPackageObjectsPath, s.Object().GetPackageObjects)
rt.POST(cliapi.ObjectUpdateInfoPath, s.Object().UpdateInfo)
rt.POST(cliapi.ObjectUpdateInfoByPathPath, s.Object().UpdateInfoByPath)
rt.POST(cliapi.ObjectMovePath, s.Object().Move)
rt.POST(cliapi.ObjectDeletePath, s.Object().Delete)
rt.POST(cliapi.ObjectDeleteByPathPath, s.Object().DeleteByPath)
rt.POST(cliapi.ObjectClonePath, s.Object().Clone)
rt.GET(cliapi.PackageGetPath, s.Package().Get)
rt.GET(cliapi.PackageGetByFullNamePath, s.Package().GetByFullName)
rt.POST(cliapi.PackageCreatePath, s.Package().Create)
rt.POST(cliapi.PackageCreateUploadPath, s.Package().CreateLoad)
rt.POST(cliapi.PackageDeletePath, s.Package().Delete)
rt.POST(cliapi.PackageClonePath, s.Package().Clone)
rt.GET(cliapi.PackageListBucketPackagesPath, s.Package().ListBucketPackages)
// rt.GET(cdsapi.PackageGetCachedStoragesPath, s.Package().GetCachedStorages)
rt.POST(cliapi.UserSpaceDownloadPackagePath, s.UserSpace().DownloadPackage)
rt.POST(cliapi.UserSpaceCreatePackagePath, s.UserSpace().CreatePackage)
rt.GET(cliapi.UserSpaceGetPath, s.UserSpace().Get)
// rt.POST(cdsapi.CacheMovePackagePath, s.Cache().MovePackage)
rt.GET(cliapi.BucketGetByNamePath, s.Bucket().GetByName)
rt.POST(cliapi.BucketCreatePath, s.Bucket().Create)
rt.POST(cliapi.BucketDeletePath, s.Bucket().Delete)
rt.GET(cliapi.BucketListAllPath, s.Bucket().ListAll)
}
func (s *Server) routeV1(eg *gin.Engine, rt gin.IRoutes) {
v1 := eg.Group("/v1")
awsAuth := NewAWSAuth(s.cfg)
v1.GET(cliapi.ObjectListPathByPath, awsAuth.Auth, s.Object().ListByPath)
v1.GET(cliapi.ObjectListByIDsPath, awsAuth.Auth, s.Object().ListByIDs)
v1.GET(cliapi.ObjectDownloadPath, awsAuth.Auth, s.Object().Download)
v1.GET(cliapi.ObjectDownloadByPathPath, awsAuth.Auth, s.Object().DownloadByPath)
v1.POST(cliapi.ObjectUploadPath, awsAuth.AuthWithoutBody, s.Object().Upload)
v1.GET(cliapi.ObjectGetPackageObjectsPath, awsAuth.Auth, s.Object().GetPackageObjects)
v1.POST(cliapi.ObjectUpdateInfoPath, awsAuth.Auth, s.Object().UpdateInfo)
v1.POST(cliapi.ObjectUpdateInfoByPathPath, awsAuth.Auth, s.Object().UpdateInfoByPath)
v1.POST(cliapi.ObjectMovePath, awsAuth.Auth, s.Object().Move)
v1.POST(cliapi.ObjectDeletePath, awsAuth.Auth, s.Object().Delete)
v1.POST(cliapi.ObjectDeleteByPathPath, awsAuth.Auth, s.Object().DeleteByPath)
v1.POST(cliapi.ObjectClonePath, awsAuth.Auth, s.Object().Clone)
v1.GET(cliapi.PackageGetPath, awsAuth.Auth, s.Package().Get)
v1.GET(cliapi.PackageGetByFullNamePath, awsAuth.Auth, s.Package().GetByFullName)
v1.POST(cliapi.PackageCreatePath, awsAuth.Auth, s.Package().Create)
v1.POST(cliapi.PackageCreateUploadPath, awsAuth.Auth, s.Package().CreateLoad)
v1.POST(cliapi.PackageDeletePath, awsAuth.Auth, s.Package().Delete)
v1.POST(cliapi.PackageClonePath, awsAuth.Auth, s.Package().Clone)
v1.GET(cliapi.PackageListBucketPackagesPath, awsAuth.Auth, s.Package().ListBucketPackages)
// v1.GET(cdsapi.PackageGetCachedStoragesPath, awsAuth.Auth, s.Package().GetCachedStorages)
v1.POST(cliapi.UserSpaceDownloadPackagePath, awsAuth.Auth, s.UserSpace().DownloadPackage)
v1.POST(cliapi.UserSpaceCreatePackagePath, awsAuth.Auth, s.UserSpace().CreatePackage)
v1.GET(cliapi.UserSpaceGetPath, awsAuth.Auth, s.UserSpace().Get)
rt.POST(cliapi.UserSpaceSpaceToSpacePath, s.UserSpace().SpaceToSpace)
// v1.POST(cdsapi.CacheMovePackagePath, awsAuth.Auth, s.Cache().MovePackage)
v1.GET(cliapi.BucketGetByNamePath, awsAuth.Auth, s.Bucket().GetByName)
v1.POST(cliapi.BucketCreatePath, awsAuth.Auth, s.Bucket().Create)
v1.POST(cliapi.BucketDeletePath, awsAuth.Auth, s.Bucket().Delete)
v1.GET(cliapi.BucketListAllPath, awsAuth.Auth, s.Bucket().ListAll)
rt.POST(cliapi.ObjectNewMultipartUploadPath, s.Object().NewMultipartUpload)
rt.POST(cliapi.ObjectUploadPartPath, s.Object().UploadPart)
rt.POST(cliapi.ObjectCompleteMultipartUploadPath, s.Object().CompleteMultipartUpload)
rt.GET(cliapi.PresignedObjectListByPathPath, awsAuth.PresignedAuth, s.Presigned().ObjectListByPath)
rt.GET(cliapi.PresignedObjectDownloadByPathPath, awsAuth.PresignedAuth, s.Presigned().ObjectDownloadByPath)
rt.GET(cliapi.PresignedObjectDownloadPath, awsAuth.PresignedAuth, s.Presigned().ObjectDownload)
rt.POST(cliapi.PresignedObjectUploadPath, awsAuth.PresignedAuth, s.Presigned().ObjectUpload)
rt.POST(cliapi.PresignedObjectNewMultipartUploadPath, awsAuth.PresignedAuth, s.Presigned().ObjectNewMultipartUpload)
rt.POST(cliapi.PresignedObjectUploadPartPath, awsAuth.PresignedAuth, s.Presigned().ObjectUploadPart)
rt.POST(cliapi.PresignedObjectCompleteMultipartUploadPath, awsAuth.PresignedAuth, s.Presigned().ObjectCompleteMultipartUpload)
// 不需要鉴权
rt.GET(cliapi.MountDumpStatusPath, s.Mount().DumpStatus)
}

View File

@ -1,4 +1,4 @@
package http
package types
import "gitlink.org.cn/cloudream/jcs-pub/client/types"

View File

@ -18,6 +18,7 @@ import (
"github.com/gin-gonic/gin"
"gitlink.org.cn/cloudream/common/consts/errorcode"
"gitlink.org.cn/cloudream/common/pkgs/logger"
"gitlink.org.cn/cloudream/jcs-pub/client/internal/http/types"
)
const (
@ -27,12 +28,12 @@ const (
)
type AWSAuth struct {
cfg *Config
cfg *types.Config
cred aws.Credentials
signer *v4.Signer
}
func NewAWSAuth(cfg *Config) *AWSAuth {
func NewAWSAuth(cfg *types.Config) *AWSAuth {
auth := &AWSAuth{
cfg: cfg,
}

View File

@ -8,7 +8,7 @@ import (
"github.com/gin-gonic/gin"
"gitlink.org.cn/cloudream/common/consts/errorcode"
"gitlink.org.cn/cloudream/common/pkgs/logger"
cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api"
cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1"
)
type BucketService struct {

View File

@ -6,7 +6,7 @@ import (
"github.com/gin-gonic/gin"
"gitlink.org.cn/cloudream/common/consts/errorcode"
"gitlink.org.cn/cloudream/common/pkgs/logger"
cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api"
cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1"
)
type MountService struct {

View File

@ -14,7 +14,7 @@ import (
"gitlink.org.cn/cloudream/common/pkgs/logger"
"gitlink.org.cn/cloudream/common/utils/math2"
"gitlink.org.cn/cloudream/jcs-pub/client/internal/downloader"
cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api"
cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1"
clitypes "gitlink.org.cn/cloudream/jcs-pub/client/types"
)

View File

@ -10,7 +10,7 @@ import (
"github.com/gin-gonic/gin"
"gitlink.org.cn/cloudream/common/consts/errorcode"
"gitlink.org.cn/cloudream/common/pkgs/logger"
cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api"
cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1"
clitypes "gitlink.org.cn/cloudream/jcs-pub/client/types"
)

View File

@ -13,7 +13,7 @@ import (
"gitlink.org.cn/cloudream/common/pkgs/logger"
"gitlink.org.cn/cloudream/common/utils/math2"
"gitlink.org.cn/cloudream/jcs-pub/client/internal/downloader"
cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api"
cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1"
)
type PresignedService struct {

View File

@ -0,0 +1,89 @@
package http
import (
"net/http"
"github.com/gin-gonic/gin"
"gitlink.org.cn/cloudream/common/pkgs/async"
"gitlink.org.cn/cloudream/jcs-pub/client/internal/http/types"
"gitlink.org.cn/cloudream/jcs-pub/client/internal/services"
cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1"
)
type ServerEventChan = async.UnboundChannel[ServerEvent]
type ServerEvent interface {
IsServerEvent() bool
}
type ExitEvent struct {
ServerEvent
Err error
}
type Server struct {
svc *services.Service
cfg *types.Config
httpSrv *http.Server
}
func NewServer(cfg *types.Config, svc *services.Service) *Server {
return &Server{
cfg: cfg,
svc: svc,
}
}
func (s *Server) InitRouters(rt gin.IRoutes) {
awsAuth := NewAWSAuth(s.cfg)
rt.GET(cliapi.ObjectListPathByPath, awsAuth.Auth, s.Object().ListByPath)
rt.GET(cliapi.ObjectListByIDsPath, awsAuth.Auth, s.Object().ListByIDs)
rt.GET(cliapi.ObjectDownloadPath, awsAuth.Auth, s.Object().Download)
rt.GET(cliapi.ObjectDownloadByPathPath, awsAuth.Auth, s.Object().DownloadByPath)
rt.POST(cliapi.ObjectUploadPath, awsAuth.AuthWithoutBody, s.Object().Upload)
rt.GET(cliapi.ObjectGetPackageObjectsPath, awsAuth.Auth, s.Object().GetPackageObjects)
rt.POST(cliapi.ObjectUpdateInfoPath, awsAuth.Auth, s.Object().UpdateInfo)
rt.POST(cliapi.ObjectUpdateInfoByPathPath, awsAuth.Auth, s.Object().UpdateInfoByPath)
rt.POST(cliapi.ObjectMovePath, awsAuth.Auth, s.Object().Move)
rt.POST(cliapi.ObjectDeletePath, awsAuth.Auth, s.Object().Delete)
rt.POST(cliapi.ObjectDeleteByPathPath, awsAuth.Auth, s.Object().DeleteByPath)
rt.POST(cliapi.ObjectClonePath, awsAuth.Auth, s.Object().Clone)
rt.GET(cliapi.PackageGetPath, awsAuth.Auth, s.Package().Get)
rt.GET(cliapi.PackageGetByFullNamePath, awsAuth.Auth, s.Package().GetByFullName)
rt.POST(cliapi.PackageCreatePath, awsAuth.Auth, s.Package().Create)
rt.POST(cliapi.PackageCreateUploadPath, awsAuth.Auth, s.Package().CreateLoad)
rt.POST(cliapi.PackageDeletePath, awsAuth.Auth, s.Package().Delete)
rt.POST(cliapi.PackageClonePath, awsAuth.Auth, s.Package().Clone)
rt.GET(cliapi.PackageListBucketPackagesPath, awsAuth.Auth, s.Package().ListBucketPackages)
// v1.GET(cdsapi.PackageGetCachedStoragesPath, awsAuth.Auth, s.Package().GetCachedStorages)
rt.POST(cliapi.UserSpaceDownloadPackagePath, awsAuth.Auth, s.UserSpace().DownloadPackage)
rt.POST(cliapi.UserSpaceCreatePackagePath, awsAuth.Auth, s.UserSpace().CreatePackage)
rt.GET(cliapi.UserSpaceGetPath, awsAuth.Auth, s.UserSpace().Get)
rt.POST(cliapi.UserSpaceSpaceToSpacePath, awsAuth.Auth, s.UserSpace().SpaceToSpace)
// v1.POST(cdsapi.CacheMovePackagePath, awsAuth.Auth, s.Cache().MovePackage)
rt.GET(cliapi.BucketGetByNamePath, awsAuth.Auth, s.Bucket().GetByName)
rt.POST(cliapi.BucketCreatePath, awsAuth.Auth, s.Bucket().Create)
rt.POST(cliapi.BucketDeletePath, awsAuth.Auth, s.Bucket().Delete)
rt.GET(cliapi.BucketListAllPath, awsAuth.Auth, s.Bucket().ListAll)
rt.POST(cliapi.ObjectNewMultipartUploadPath, awsAuth.Auth, s.Object().NewMultipartUpload)
rt.POST(cliapi.ObjectUploadPartPath, awsAuth.AuthWithoutBody, s.Object().UploadPart)
rt.POST(cliapi.ObjectCompleteMultipartUploadPath, awsAuth.Auth, s.Object().CompleteMultipartUpload)
rt.GET(cliapi.PresignedObjectListByPathPath, awsAuth.PresignedAuth, s.Presigned().ObjectListByPath)
rt.GET(cliapi.PresignedObjectDownloadByPathPath, awsAuth.PresignedAuth, s.Presigned().ObjectDownloadByPath)
rt.GET(cliapi.PresignedObjectDownloadPath, awsAuth.PresignedAuth, s.Presigned().ObjectDownload)
rt.POST(cliapi.PresignedObjectUploadPath, awsAuth.PresignedAuth, s.Presigned().ObjectUpload)
rt.POST(cliapi.PresignedObjectNewMultipartUploadPath, awsAuth.PresignedAuth, s.Presigned().ObjectNewMultipartUpload)
rt.POST(cliapi.PresignedObjectUploadPartPath, awsAuth.PresignedAuth, s.Presigned().ObjectUploadPart)
rt.POST(cliapi.PresignedObjectCompleteMultipartUploadPath, awsAuth.PresignedAuth, s.Presigned().ObjectCompleteMultipartUpload)
// 不需要鉴权
rt.GET(cliapi.MountDumpStatusPath, awsAuth.Auth, s.Mount().DumpStatus)
}

View File

@ -7,7 +7,7 @@ import (
"github.com/gin-gonic/gin"
"gitlink.org.cn/cloudream/common/consts/errorcode"
"gitlink.org.cn/cloudream/common/pkgs/logger"
cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api"
cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1"
)
type UserSpaceService struct {

View File

@ -0,0 +1,37 @@
package http
import (
"fmt"
"gitlink.org.cn/cloudream/common/consts/errorcode"
"gitlink.org.cn/cloudream/common/pkgs/mq"
)
type Response struct {
Code string `json:"code"`
Message string `json:"message"`
Data any `json:"data"`
}
func OK(data any) Response {
return Response{
Code: errorcode.OK,
Message: "",
Data: data,
}
}
func Failed(code string, format string, args ...any) Response {
return Response{
Code: code,
Message: fmt.Sprintf(format, args...),
}
}
func FailedError(err error) Response {
if codeErr, ok := err.(*mq.CodeMessageError); ok {
return Failed(codeErr.Code, codeErr.Message)
}
return Failed(errorcode.OperationFailed, err.Error())
}

View File

@ -12,7 +12,7 @@ import (
"gitlink.org.cn/cloudream/common/utils/sort2"
"gitlink.org.cn/cloudream/jcs-pub/client/internal/db"
"gitlink.org.cn/cloudream/jcs-pub/client/internal/downloader"
"gitlink.org.cn/cloudream/jcs-pub/client/sdk/api"
"gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1"
"gitlink.org.cn/cloudream/jcs-pub/client/types"
"gitlink.org.cn/cloudream/jcs-pub/common/models/datamap"
"gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch2/ops2"

View File

@ -2,6 +2,7 @@ package api
import (
"gitlink.org.cn/cloudream/common/sdks"
"gitlink.org.cn/cloudream/jcs-pub/client/sdk/api"
)
type response[T any] struct {
@ -18,10 +19,10 @@ func (r *response[T]) ToError() *sdks.CodeMessageError {
}
type Client struct {
cfg *Config
cfg *api.Config
}
func NewClient(cfg *Config) *Client {
func NewClient(cfg *api.Config) *Client {
return &Client{
cfg: cfg,
}
@ -33,10 +34,10 @@ type Pool interface {
}
type pool struct {
cfg *Config
cfg *api.Config
}
func NewPool(cfg *Config) Pool {
func NewPool(cfg *api.Config) Pool {
return &pool{
cfg: cfg,
}

View File

@ -17,7 +17,7 @@ func (c *Client) Mount() *MountService {
}
}
const MountDumpStatusPath = "/v1/mount/dumpStatus"
const MountDumpStatusPath = "/mount/dumpStatus"
type MountDumpStatus struct{}

View File

@ -455,7 +455,7 @@ func (c *ObjectService) GetPackageObjects(req ObjectGetPackageObjects) (*ObjectG
return JSONAPI(c.cfg, http.DefaultClient, &req, &ObjectGetPackageObjectsResp{})
}
const ObjectNewMultipartUploadPath = "/v1/object/newMultipartUpload"
const ObjectNewMultipartUploadPath = "/object/newMultipartUpload"
type ObjectNewMultipartUpload struct {
PackageID types.PackageID `json:"packageID" binding:"required"`
@ -478,7 +478,7 @@ func (c *ObjectService) NewMultipartUpload(req ObjectNewMultipartUpload) (*Objec
return JSONAPI(c.cfg, http.DefaultClient, &req, &ObjectNewMultipartUploadResp{})
}
const ObjectUploadPartPath = "/v1/object/uploadPart"
const ObjectUploadPartPath = "/object/uploadPart"
type ObjectUploadPart struct {
ObjectUploadPartInfo
@ -532,7 +532,7 @@ func (c *ObjectService) UploadPart(req ObjectUploadPart) (*ObjectUploadPartResp,
return nil, fmt.Errorf("unknow response content type: %s", contType)
}
const ObjectCompleteMultipartUploadPath = "/v1/object/completeMultipartUpload"
const ObjectCompleteMultipartUploadPath = "/object/completeMultipartUpload"
type ObjectCompleteMultipartUpload struct {
ObjectID types.ObjectID `json:"objectID" binding:"required"`

View File

@ -23,7 +23,7 @@ func (c *Client) Presigned() *PresignedService {
}
}
const PresignedObjectListByPathPath = "/v1/presigned/object/listByPath"
const PresignedObjectListByPathPath = "/presigned/object/listByPath"
type PresignedObjectListByPath struct {
ObjectListByPath
@ -33,7 +33,7 @@ func (c *PresignedService) ObjectListByPath(req PresignedObjectListByPath, expir
return c.presign(req, PresignedObjectListByPathPath, http.MethodGet, expireIn)
}
const PresignedObjectDownloadByPathPath = "/v1/presigned/object/downloadByPath"
const PresignedObjectDownloadByPathPath = "/presigned/object/downloadByPath"
type PresignedObjectDownloadByPath struct {
PackageID clitypes.PackageID `form:"packageID" url:"packageID" binding:"required"`
@ -46,7 +46,7 @@ func (c *PresignedService) ObjectDownloadByPath(req PresignedObjectDownloadByPat
return c.presign(req, PresignedObjectDownloadByPathPath, http.MethodGet, expireIn)
}
const PresignedObjectDownloadPath = "/v1/presigned/object/download"
const PresignedObjectDownloadPath = "/presigned/object/download"
type PresignedObjectDownload struct {
ObjectID clitypes.ObjectID `form:"objectID" url:"objectID" binding:"required"`
@ -58,7 +58,7 @@ func (c *PresignedService) ObjectDownload(req PresignedObjectDownload, expireIn
return c.presign(req, PresignedObjectDownloadPath, http.MethodGet, expireIn)
}
const PresignedObjectUploadPath = "/v1/presigned/object/upload"
const PresignedObjectUploadPath = "/presigned/object/upload"
type PresignedObjectUpload struct {
PackageID clitypes.PackageID `form:"packageID" binding:"required" url:"packageID"`
@ -76,7 +76,7 @@ func (c *PresignedService) ObjectUpload(req PresignedObjectUpload, expireIn int)
return c.presign(req, PresignedObjectUploadPath, http.MethodPost, expireIn)
}
const PresignedObjectNewMultipartUploadPath = "/v1/presigned/object/newMultipartUpload"
const PresignedObjectNewMultipartUploadPath = "/presigned/object/newMultipartUpload"
type PresignedObjectNewMultipartUpload struct {
PackageID clitypes.PackageID `form:"packageID" binding:"required" url:"packageID"`
@ -91,7 +91,7 @@ func (c *PresignedService) ObjectNewMultipartUpload(req PresignedObjectNewMultip
return c.presign(req, PresignedObjectNewMultipartUploadPath, http.MethodPost, expireIn)
}
const PresignedObjectUploadPartPath = "/v1/presigned/object/uploadPart"
const PresignedObjectUploadPartPath = "/presigned/object/uploadPart"
type PresignedObjectUploadPart struct {
ObjectID clitypes.ObjectID `form:"objectID" binding:"required" url:"objectID"`
@ -104,7 +104,7 @@ func (c *PresignedService) ObjectUploadPart(req PresignedObjectUploadPart, expir
return c.presign(req, PresignedObjectUploadPartPath, http.MethodPost, expireIn)
}
const PresignedObjectCompleteMultipartUploadPath = "/v1/presigned/object/completeMultipartUpload"
const PresignedObjectCompleteMultipartUploadPath = "/presigned/object/completeMultipartUpload"
type PresignedObjectCompleteMultipartUpload struct {
ObjectID clitypes.ObjectID `form:"objectID" binding:"required" url:"objectID"`

View File

@ -5,10 +5,11 @@ import (
. "github.com/smartystreets/goconvey/convey"
"gitlink.org.cn/cloudream/common/pkgs/types"
"gitlink.org.cn/cloudream/jcs-pub/client/sdk/api"
)
func Test_Presigned(t *testing.T) {
cli := NewClient(&Config{
cli := NewClient(&api.Config{
URL: "http://localhost:7890",
AccessKey: "123456",
SecretKey: "123456",
@ -38,7 +39,7 @@ func Test_Presigned(t *testing.T) {
}
func Test_PresignedObjectListByPath(t *testing.T) {
cli := NewClient(&Config{
cli := NewClient(&api.Config{
URL: "http://localhost:7890",
AccessKey: "123456",
SecretKey: "123456",
@ -62,7 +63,7 @@ func Test_PresignedObjectListByPath(t *testing.T) {
}
func Test_PresignedObjectDownloadByPath(t *testing.T) {
cli := NewClient(&Config{
cli := NewClient(&api.Config{
URL: "http://localhost:7890",
AccessKey: "123456",
SecretKey: "123456",
@ -82,7 +83,7 @@ func Test_PresignedObjectDownloadByPath(t *testing.T) {
}
func Test_PresignedObjectDownload(t *testing.T) {
cli := NewClient(&Config{
cli := NewClient(&api.Config{
URL: "http://localhost:7890",
AccessKey: "123456",
SecretKey: "123456",
@ -101,7 +102,7 @@ func Test_PresignedObjectDownload(t *testing.T) {
}
func Test_PresignedObjectUpload(t *testing.T) {
cli := NewClient(&Config{
cli := NewClient(&api.Config{
URL: "http://localhost:7890",
})
@ -117,7 +118,7 @@ func Test_PresignedObjectUpload(t *testing.T) {
}
func Test_PresignedNewMultipartUpload(t *testing.T) {
cli := NewClient(&Config{
cli := NewClient(&api.Config{
URL: "http://localhost:7890",
})
@ -133,7 +134,7 @@ func Test_PresignedNewMultipartUpload(t *testing.T) {
}
func Test_PresignedObjectUploadPart(t *testing.T) {
cli := NewClient(&Config{
cli := NewClient(&api.Config{
URL: "http://localhost:7890",
AccessKey: "123456",
SecretKey: "123456",
@ -151,7 +152,7 @@ func Test_PresignedObjectUploadPart(t *testing.T) {
}
func Test_PresignedCompleteMultipartUpload(t *testing.T) {
cli := NewClient(&Config{
cli := NewClient(&api.Config{
URL: "http://localhost:7890",
AccessKey: "123456",
SecretKey: "123456",

View File

@ -9,12 +9,13 @@ import (
"github.com/google/uuid"
. "github.com/smartystreets/goconvey/convey"
"gitlink.org.cn/cloudream/common/pkgs/iterator"
"gitlink.org.cn/cloudream/jcs-pub/client/sdk/api"
clitypes "gitlink.org.cn/cloudream/jcs-pub/client/types"
)
func Test_PackageGet(t *testing.T) {
Convey("上传后获取Package信息", t, func() {
cli := NewClient(&Config{
cli := NewClient(&api.Config{
URL: "http://localhost:7890",
})
@ -64,7 +65,7 @@ func Test_PackageGet(t *testing.T) {
func Test_Object(t *testing.T) {
Convey("上传,下载,删除", t, func() {
cli := NewClient(&Config{
cli := NewClient(&api.Config{
URL: "http://localhost:7890",
})
@ -119,7 +120,7 @@ func Test_Object(t *testing.T) {
func Test_ObjectList(t *testing.T) {
Convey("路径查询", t, func() {
cli := NewClient(&Config{
cli := NewClient(&api.Config{
URL: "http://localhost:7890",
})
@ -135,7 +136,7 @@ func Test_ObjectList(t *testing.T) {
func Test_Storage(t *testing.T) {
Convey("上传后调度文件", t, func() {
cli := NewClient(&Config{
cli := NewClient(&api.Config{
URL: "http://localhost:7890",
})
@ -184,7 +185,7 @@ func Test_Storage(t *testing.T) {
/*
func Test_Cache(t *testing.T) {
Convey("上传后移动文件", t, func() {
cli := NewClient(&Config{
cli := NewClient(&api.Config{
URL: "http://localhost:7890",
})
@ -232,7 +233,7 @@ func Test_Storage(t *testing.T) {
*/
func Test_Sign(t *testing.T) {
Convey("签名接口", t, func() {
cli := NewClient(&Config{
cli := NewClient(&api.Config{
URL: "http://localhost:7890/v1",
AccessKey: "123456",
SecretKey: "123456",

View File

@ -77,7 +77,7 @@ func (c *Client) UserSpaceGet(req UserSpaceGet) (*UserSpaceGetResp, error) {
return JSONAPI(c.cfg, http.DefaultClient, &req, &UserSpaceGetResp{})
}
const UserSpaceSpaceToSpacePath = "/v1/userspace/spaceToSpace"
const UserSpaceSpaceToSpacePath = "/userspace/spaceToSpace"
type UserSpaceSpaceToSpace struct {
SrcUserSpaceID clitypes.UserSpaceID `json:"srcUserSpaceID" binding:"required"`

View File

@ -17,6 +17,7 @@ import (
"gitlink.org.cn/cloudream/common/utils/http2"
"gitlink.org.cn/cloudream/common/utils/math2"
"gitlink.org.cn/cloudream/common/utils/serder"
"gitlink.org.cn/cloudream/jcs-pub/client/sdk/api"
)
func MakeIPFSFilePath(fileHash string) string {
@ -44,7 +45,7 @@ func ParseJSONResponse[TBody any](resp *http.Response) (TBody, error) {
return ret, fmt.Errorf("unknow response content type: %s, status: %d, body(prefix): %s", contType, resp.StatusCode, strCont[:math2.Min(len(strCont), 200)])
}
func JSONAPI[Resp sdks.APIResponse, Req sdks.APIRequest](cfg *Config, cli *http.Client, req Req, resp Resp) (Resp, error) {
func JSONAPI[Resp sdks.APIResponse, Req sdks.APIRequest](cfg *api.Config, cli *http.Client, req Req, resp Resp) (Resp, error) {
param := req.MakeParam()
@ -69,7 +70,7 @@ func JSONAPI[Resp sdks.APIResponse, Req sdks.APIRequest](cfg *Config, cli *http.
return resp, err
}
func JSONAPINoData[Req sdks.APIRequest](cfg *Config, cli *http.Client, req Req) error {
func JSONAPINoData[Req sdks.APIRequest](cfg *api.Config, cli *http.Client, req Req) error {
param := req.MakeParam()
httpReq, err := param.MakeRequest(cfg.URL)
@ -112,7 +113,7 @@ func calcSha256(body sdks.RequestBody) string {
}
}
func PostMultiPart(cfg *Config, url string, info any, files http2.MultiPartFileIterator) (*http.Response, error) {
func PostMultiPart(cfg *api.Config, url string, info any, files http2.MultiPartFileIterator) (*http.Response, error) {
req, err := http.NewRequest(http.MethodPost, url, nil)
if err != nil {
return nil, err