Browse Source

新增ipfs pin测试

gitlink
JeshuaRen 1 year ago
parent
commit
eab7b49141
2 changed files with 45 additions and 2 deletions
  1. +9
    -2
      common/pkgs/downloader/downloader.go
  2. +36
    -0
      common/pkgs/downloader/ipfs_pin.go

+ 9
- 2
common/pkgs/downloader/downloader.go View File

@@ -2,14 +2,13 @@ package downloader

import (
"fmt"
"io"

lru "github.com/hashicorp/golang-lru/v2"
"gitlink.org.cn/cloudream/common/pkgs/iterator"
cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
stgglb "gitlink.org.cn/cloudream/storage/common/globals"
stgmod "gitlink.org.cn/cloudream/storage/common/models"
coormq "gitlink.org.cn/cloudream/storage/common/pkgs/mq/coordinator"
"io"
)

const (
@@ -71,6 +70,14 @@ func (d *Downloader) DownloadObjects(reqs []DownloadReqeust) DownloadIterator {
return iterator.FuseError[*Downloading](fmt.Errorf("request to coordinator: %w", err))
}

// 测试使用:将文件pin到ipfs
go func() {
err := PinFileToIPFS(*objDetails)
if err != nil {
print(err)
}
}()

req2s := make([]downloadReqeust2, len(reqs))
for i, req := range reqs {
req2s[i] = downloadReqeust2{


+ 36
- 0
common/pkgs/downloader/ipfs_pin.go View File

@@ -0,0 +1,36 @@
package downloader

import (
stgglb "gitlink.org.cn/cloudream/storage/common/globals"
coormq "gitlink.org.cn/cloudream/storage/common/pkgs/mq/coordinator"
)

type PinConfig struct {
IpfsPin IpfsConfig
}

type IpfsConfig struct {
IpfsUrl string `json:"ipfsUrl"`
}

// PinFileToIPFS pin file to IPFS
func PinFileToIPFS(objDetails coormq.GetObjectDetailsResp) error {

client, err := stgglb.IPFSPool.Acquire()
if err != nil {
print(err)
}

objs := objDetails.Objects
// 遍历objDetails
for _, obj := range objs {
cid := obj.Object.FileHash
err := client.Pin(cid)
if err != nil {
return err
}
print("IPFS pin success, filehash: " + cid)
}

return nil
}

Loading…
Cancel
Save