github.com/cloudreve/Cloudreve/v3@v3.0.0-20240224133659-3edb00a6484c/pkg/serializer/slave.go (about)

     1  package serializer
     2  
     3  import (
     4  	"crypto/sha1"
     5  	"encoding/gob"
     6  	"fmt"
     7  
     8  	model "github.com/cloudreve/Cloudreve/v3/models"
     9  )
    10  
    11  // RemoteDeleteRequest 远程策略删除接口请求正文
    12  type RemoteDeleteRequest struct {
    13  	Files []string `json:"files"`
    14  }
    15  
    16  // ListRequest 远程策略列文件请求正文
    17  type ListRequest struct {
    18  	Path      string `json:"path"`
    19  	Recursive bool   `json:"recursive"`
    20  }
    21  
    22  // NodePingReq 从机节点Ping请求
    23  type NodePingReq struct {
    24  	SiteURL       string      `json:"site_url"`
    25  	SiteID        string      `json:"site_id"`
    26  	IsUpdate      bool        `json:"is_update"`
    27  	CredentialTTL int         `json:"credential_ttl"`
    28  	Node          *model.Node `json:"node"`
    29  }
    30  
    31  // NodePingResp 从机节点Ping响应
    32  type NodePingResp struct {
    33  }
    34  
    35  // SlaveAria2Call 从机有关Aria2的请求正文
    36  type SlaveAria2Call struct {
    37  	Task         *model.Download        `json:"task"`
    38  	GroupOptions map[string]interface{} `json:"group_options"`
    39  	Files        []int                  `json:"files"`
    40  }
    41  
    42  // SlaveTransferReq 从机中转任务创建请求
    43  type SlaveTransferReq struct {
    44  	Src    string        `json:"src"`
    45  	Dst    string        `json:"dst"`
    46  	Policy *model.Policy `json:"policy"`
    47  }
    48  
    49  // Hash 返回创建请求的唯一标识,保持创建请求幂等
    50  func (s *SlaveTransferReq) Hash(id string) string {
    51  	h := sha1.New()
    52  	h.Write([]byte(fmt.Sprintf("transfer-%s-%s-%s-%d", id, s.Src, s.Dst, s.Policy.ID)))
    53  	bs := h.Sum(nil)
    54  	return fmt.Sprintf("%x", bs)
    55  }
    56  
    57  const (
    58  	SlaveTransferSuccess = "success"
    59  	SlaveTransferFailed  = "failed"
    60  )
    61  
    62  type SlaveTransferResult struct {
    63  	Error string
    64  }
    65  
    66  func init() {
    67  	gob.Register(SlaveTransferResult{})
    68  }