gitlab.com/jokerrs1/Sia@v1.3.2/node/api/client/renter.go (about)

     1  package client
     2  
     3  import (
     4  	"fmt"
     5  	"net/url"
     6  	"strconv"
     7  
     8  	"github.com/NebulousLabs/Sia/modules"
     9  	"github.com/NebulousLabs/Sia/node/api"
    10  )
    11  
    12  // RenterContractsGet requests the /renter/contracts resource
    13  func (c *Client) RenterContractsGet() (rc api.RenterContracts, err error) {
    14  	err = c.get("/renter/contracts", &rc)
    15  	return
    16  }
    17  
    18  // RenterDeletePost uses the /renter/delete endpoint to delete a file.
    19  func (c *Client) RenterDeletePost(siaPath string) (err error) {
    20  	err = c.post(fmt.Sprintf("/renter/delete/%s", siaPath), "", nil)
    21  	return err
    22  }
    23  
    24  // RenterDownloadGet uses the /renter/download endpoint to download a file to a
    25  // destination on disk.
    26  func (c *Client) RenterDownloadGet(siaPath, destination string, offset, length uint64, async bool) (err error) {
    27  	query := fmt.Sprintf("%s?destination=%s&offset=%d&length=%d&httpresp=false&async=%v",
    28  		siaPath, destination, offset, length, async)
    29  	err = c.get("/renter/download/"+query, nil)
    30  	return
    31  }
    32  
    33  // RenterDownloadsGet requests the /renter/downloads resource
    34  func (c *Client) RenterDownloadsGet() (rdq api.RenterDownloadQueue, err error) {
    35  	err = c.get("/renter/downloads", &rdq)
    36  	return
    37  }
    38  
    39  // RenterDownloadHTTPResponseGet uses the /renter/download endpoint to download
    40  // a file and return its data.
    41  func (c *Client) RenterDownloadHTTPResponseGet(siaPath string, offset, length uint64) (resp []byte, err error) {
    42  	query := fmt.Sprintf("%s?offset=%d&length=%d&httpresp=true", siaPath, offset, length)
    43  	resp, err = c.getRawResponse("/renter/download/" + query)
    44  	return
    45  }
    46  
    47  // RenterFilesGet requests the /renter/files resource
    48  func (c *Client) RenterFilesGet() (rf api.RenterFiles, err error) {
    49  	err = c.get("/renter/files", &rf)
    50  	return
    51  }
    52  
    53  // RenterPost uses the /renter endpoint to change the renter's allowance
    54  func (c *Client) RenterPost(allowance modules.Allowance) (err error) {
    55  	values := url.Values{}
    56  	values.Set("funds", allowance.Funds.String())
    57  	values.Set("hosts", strconv.FormatUint(allowance.Hosts, 10))
    58  	values.Set("period", strconv.FormatUint(uint64(allowance.Period), 10))
    59  	values.Set("renewwindow", strconv.FormatUint(uint64(allowance.RenewWindow), 10))
    60  	err = c.post("/renter", values.Encode(), nil)
    61  	return
    62  }
    63  
    64  // RenterUploadPost uses the /renter/upload endpoin to upload a file
    65  func (c *Client) RenterUploadPost(path, siaPath string, dataPieces, parityPieces uint64) (err error) {
    66  	values := url.Values{}
    67  	values.Set("source", path)
    68  	values.Set("datapieces", strconv.FormatUint(dataPieces, 10))
    69  	values.Set("paritypieces", strconv.FormatUint(parityPieces, 10))
    70  	err = c.post(fmt.Sprintf("/renter/upload%v", siaPath), values.Encode(), nil)
    71  	return
    72  }