mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-06 08:30:29 +00:00
feat: direct call download api by cgo
This commit is contained in:
1 parent
85fe92a378
commit
467ada5500
22 files changed
+1040
-709
No files matched your search
@@ -0,0 +1,58 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"github.com/GopeedLab/gopeed/pkg/base"
|
||||
"io/fs"
|
||||
)
|
||||
|
||||
type Storage string
|
||||
|
||||
const (
|
||||
StorageMem Storage = "mem"
|
||||
StorageBolt Storage = "bolt"
|
||||
)
|
||||
|
||||
type StartConfig struct {
|
||||
RefreshInterval int `json:"refreshInterval"`
|
||||
Storage Storage `json:"storage"`
|
||||
StorageDir string `json:"storageDir"`
|
||||
WhiteDownloadDirs []string `json:"whiteDownloadDirs"`
|
||||
DownloadConfig *base.DownloaderStoreConfig `json:"downloadConfig"`
|
||||
|
||||
ProductionMode bool
|
||||
|
||||
WebEnable bool
|
||||
WebFS fs.FS
|
||||
WebBasicAuth *WebBasicAuth
|
||||
}
|
||||
|
||||
func (cfg *StartConfig) Init() *StartConfig {
|
||||
if cfg.RefreshInterval == 0 {
|
||||
cfg.RefreshInterval = 350
|
||||
}
|
||||
if cfg.Storage == "" {
|
||||
cfg.Storage = StorageBolt
|
||||
}
|
||||
if cfg.StorageDir == "" {
|
||||
cfg.StorageDir = "./"
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
type WebBasicAuth struct {
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
// Authorization returns the value of the Authorization header to be used in HTTP requests.
|
||||
func (cfg *WebBasicAuth) Authorization() string {
|
||||
userId := cfg.Username + ":" + cfg.Password
|
||||
return "Basic " + base64.StdEncoding.EncodeToString([]byte(userId))
|
||||
}
|
||||
|
||||
type StartResult struct {
|
||||
Host string `json:"host"`
|
||||
// Port is the http server real listen port.
|
||||
Port int `json:"port"`
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package model
|
||||
|
||||
type InstallExtension struct {
|
||||
DevMode bool `json:"devMode"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
type UpdateExtensionSettings struct {
|
||||
Settings map[string]any `json:"settings"`
|
||||
}
|
||||
|
||||
type SwitchExtension struct {
|
||||
Status bool `json:"status"`
|
||||
}
|
||||
|
||||
type UpgradeCheckExtensionResp struct {
|
||||
NewVersion string `json:"newVersion"`
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package model
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type RespCode int
|
||||
|
||||
const (
|
||||
CodeOk RespCode = 0
|
||||
// CodeError is the common error code
|
||||
CodeError RespCode = 1000
|
||||
// CodeUnauthorized is the error code for unauthorized
|
||||
CodeUnauthorized RespCode = 1001
|
||||
// CodeInvalidParam is the error code for invalid parameter
|
||||
CodeInvalidParam RespCode = 1002
|
||||
// CodeTaskNotFound is the error code for task not found
|
||||
CodeTaskNotFound RespCode = 2001
|
||||
)
|
||||
|
||||
type Result[T any] struct {
|
||||
Code RespCode `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data T `json:"data"`
|
||||
}
|
||||
|
||||
func (r *Result[T]) Json() string {
|
||||
buf, _ := json.Marshal(r)
|
||||
return string(buf)
|
||||
}
|
||||
|
||||
func (r *Result[T]) HasError() bool {
|
||||
return r.Code != CodeOk
|
||||
}
|
||||
|
||||
func NewOkResult[T any](data T) *Result[T] {
|
||||
return &Result[T]{
|
||||
Code: CodeOk,
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
func NewNilResult() *Result[any] {
|
||||
return &Result[any]{
|
||||
Code: CodeOk,
|
||||
}
|
||||
}
|
||||
|
||||
func NewErrorResult[T any](msg string, code ...RespCode) *Result[T] {
|
||||
// if code is not provided, the default code is CodeError
|
||||
c := CodeError
|
||||
if len(code) > 0 {
|
||||
c = code[0]
|
||||
}
|
||||
|
||||
return &Result[T]{
|
||||
Code: c,
|
||||
Msg: msg,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package model
|
||||
|
||||
import "github.com/GopeedLab/gopeed/pkg/base"
|
||||
|
||||
type CreateTask struct {
|
||||
Rid string `json:"rid"`
|
||||
Req *base.Request `json:"req"`
|
||||
Opt *base.Options `json:"opt"`
|
||||
}
|
||||
|
||||
type CreateTaskBatch struct {
|
||||
Reqs []*base.Request `json:"reqs"`
|
||||
Opt *base.Options `json:"opt"`
|
||||
}
|
||||
Reference in new issue
Block a user