diff --git a/config.yaml.sample b/config.yaml.sample index de0a720..616cbe6 100644 --- a/config.yaml.sample +++ b/config.yaml.sample @@ -23,17 +23,12 @@ Dirs: # DontHash: false ## If true, will pin the root directory # Pin: false -## If true, and EstuaryAPIKey is set, will attempt to pin the CID via Estuary as well -# Estuary: false # - ID: Example2 # Dir: /home/user/Pictures/ # Nocopy: false # DontHash: false # Pin: false -# API key for Estuary (optional, find out more at https://estuary.tech) -EstuaryAPIKey: - # Relative MFS directory path (default "/ipfs-sync/") BasePath: /ipfs-sync/ diff --git a/configuration.go b/configuration.go index 55a21c8..7847d10 100644 --- a/configuration.go +++ b/configuration.go @@ -36,7 +36,6 @@ var ( VersionFlag = flag.Bool("version", false, "display version and exit") VerboseFlag = flag.Bool("v", false, "display verbose output") Verbose bool - EstuaryAPIKey string // don't make this a flag VerifyFilestoreFlag = flag.Bool("verify", false, "verify filestore on startup (not recommended unless you're having issues)") VerifyFilestore bool @@ -64,7 +63,6 @@ type DirKey struct { Nocopy bool `yaml:"Nocopy"` DontHash bool `yaml:"DontHash"` Pin bool `yaml:"Pin"` - Estuary bool `yaml:"Estuary"` // probably best to let this be managed automatically CID string @@ -117,7 +115,6 @@ type ConfigFileStruct struct { DB string `yaml:"DB"` IgnoreHidden bool `yaml:"IgnoreHidden"` Timeout string `yaml:"Timeout"` - EstuaryAPIKey string `yaml:"EstuaryAPIKey"` VerifyFilestore bool `yaml:"VerifyFilestore"` } @@ -179,7 +176,6 @@ func loadConfig(path string) { DBPath = cfg.DB } IgnoreHidden = cfg.IgnoreHidden - EstuaryAPIKey = cfg.EstuaryAPIKey VerifyFilestore = cfg.VerifyFilestore } diff --git a/main.go b/main.go index ef639c1..4364c00 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,6 @@ package main import ( - "bytes" "context" "encoding/json" "errors" @@ -122,7 +121,7 @@ func filePathWalkDir(root string) ([]string, error) { } // AddDir adds a directory, and returns CID. -func AddDir(path string, nocopy bool, pin bool, estuary bool) (string, error) { +func AddDir(path string, nocopy bool, pin bool) (string, error) { pathSplit := strings.Split(path, string(os.PathSeparator)) dirName := pathSplit[len(pathSplit)-2] files, err := filePathWalkDir(path) @@ -158,11 +157,6 @@ func AddDir(path string, nocopy bool, pin bool, estuary bool) (string, error) { err := Pin(cid) log.Println("Error pinning", dirName, ":", err) } - if estuary { - if err := PinEstuary(cid, dirName); err != nil { - log.Println("Error pinning to Estuary:", err) - } - } return cid, err } @@ -567,11 +561,6 @@ func Publish(cid, key string) error { return err } -type EstuaryFile struct { - Cid string - Name string -} - type IPFSRemotePinningResponse struct { Count int Results []*IPFSRemotePinResult @@ -586,98 +575,6 @@ type IPFSRemotePin struct { Cid string } -func doEstuaryRequest(reqType, cmd string, jsonData []byte) (string, error) { - if EstuaryAPIKey == "" { - return "", errors.New("Estuary API key is blank.") - } - var cancel context.CancelFunc - ctx := context.Background() - if TimeoutTime > 0 { - ctx, cancel = context.WithTimeout(ctx, TimeoutTime) - defer cancel() - } - c := &http.Client{} - - var ( - req *http.Request - err error - ) - if jsonData != nil { - req, err = http.NewRequestWithContext(ctx, reqType, "https://api.estuary.tech/"+cmd, bytes.NewBuffer(jsonData)) - } else { - req, err = http.NewRequestWithContext(ctx, reqType, "https://api.estuary.tech/"+cmd, nil) - } - if err != nil { - return "", err - } - - req.Header.Add("Authorization", "Bearer "+EstuaryAPIKey) - req.Header.Add("Content-Type", "application/json") - resp, err := c.Do(req) - if err != nil { - return "", err - } - defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - return "", err - } - - errStruct := new(ErrorStruct) - err = json.Unmarshal(body, errStruct) - if err == nil { - if errStruct.Error() != "" { - return string(body), errStruct - } - } - - return string(body), nil -} - -func PinEstuary(cid, name string) error { - jsonData, _ := json.Marshal(&EstuaryFile{Cid: cid, Name: name}) - _, err := doEstuaryRequest("POST", "pinning/pins", jsonData) - return err -} - -func UpdatePinEstuary(oldcid, newcid, name string) { - resp, err := doEstuaryRequest("GET", "pinning/pins?cid="+oldcid, nil) - if err != nil { - log.Println("Error getting Estuary pin:", err) - return - } - pinResp := new(IPFSRemotePinningResponse) - err = json.Unmarshal([]byte(resp), pinResp) - if err != nil { - log.Println("Error decoding Estuary pin list:", err) - return - } - // FIXME Estuary doesn't seem to support `cid` GET field yet, this code can be removed when it does: - var reqId string - pinResp.Count = 0 - for _, pinResult := range pinResp.Results { - if pinResult.Pin.Cid == oldcid { - reqId = pinResult.RequestId - pinResp.Count = 1 - break - } - } - // END OF FIXME - jsonData, _ := json.Marshal(&EstuaryFile{Cid: newcid, Name: name}) - if pinResp.Count > 0 { - _, err := doEstuaryRequest("POST", "pinning/pins/"+reqId, jsonData) - if err != nil { - log.Println("Error updating Estuary pin:", err) - } else { - return - } - } - err = PinEstuary(newcid, name) - if err != nil { - log.Println("Error pinning to Estuary:", err) - } -} - // WatchDog watches for directory updates, periodically updates IPNS records, and updates recursive pins. func WatchDog() { // Init WatchDog @@ -754,7 +651,7 @@ func WatchDog() { log.Println(dk.ID, "not found, generating...") ik := GenerateKey(dk.ID) var err error - dk.CID, err = AddDir(dk.Dir, dk.Nocopy, dk.Pin, dk.Estuary) + dk.CID, err = AddDir(dk.Dir, dk.Nocopy, dk.Pin) if err != nil { log.Panicln("[ERROR] Failed to add directory:", err) } @@ -772,9 +669,6 @@ func WatchDog() { if dk.Pin { UpdatePin(dk.CID, fCID, dk.Nocopy) } - if dk.Estuary { - UpdatePinEstuary(dk.CID, fCID, strings.Split(dk.MFSPath, "/")[0]) - } Publish(fCID, dk.ID) dk.CID = fCID log.Println(dk.MFSPath, "updated...")