vendor: add github.com/koofr/go-koofrclient
* added koofr client SDK dep for koofr backend
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
||||
/bin
|
||||
/pkg
|
||||
|
||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# developer specific
|
||||
*.sublime-workspace
|
||||
*.sublime-project
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Koofr
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
go-koofrclient
|
||||
===========
|
||||
|
||||
Go Koofr client.
|
||||
|
||||
[](https://godoc.org/github.com/koofr/go-koofrclient)
|
||||
|
||||
## Install
|
||||
|
||||
go get github.com/koofr/go-koofrclient
|
||||
|
||||
## Testing
|
||||
|
||||
go get -t
|
||||
KOOFR_APIBASE="https://app.koofr.net" KOOFR_EMAIL="email@example.com" KOOFR_PASSWORD="yourpassword" go test
|
||||
+217
@@ -0,0 +1,217 @@
|
||||
package koofrclient
|
||||
|
||||
import (
|
||||
"path"
|
||||
)
|
||||
|
||||
type TokenRequest struct {
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type Token struct {
|
||||
Token string
|
||||
}
|
||||
|
||||
type MountType string
|
||||
|
||||
const (
|
||||
MountDeviceType = "device"
|
||||
MountExportType = "export"
|
||||
MountImportType = "import"
|
||||
)
|
||||
|
||||
type Mount struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type MountType `json:"type"`
|
||||
Origin string `json:"origin"`
|
||||
SpaceTotal int64 `json:"spaceTotal"`
|
||||
SpaceUsed int64 `json:"spaceUsed"`
|
||||
Online bool `json:"online"`
|
||||
Owner MountUser `json:"owner"`
|
||||
Users []MountUser `json:"users"`
|
||||
Groups []MountGroup `json:"groups"`
|
||||
Version int `json:"version"`
|
||||
Permissions MountPermissions `json:"permissions"`
|
||||
IsPrimary bool `json:"isPrimary"`
|
||||
IsShared bool `json:"isShared"`
|
||||
}
|
||||
|
||||
type MountUser struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Permissions MountPermissions `json:"permissions"`
|
||||
}
|
||||
|
||||
type MountGroup struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Permissions MountPermissions `json:"permissions"`
|
||||
}
|
||||
|
||||
type MountPermissions struct {
|
||||
Read bool `json:"READ"`
|
||||
Write bool `json:"write"`
|
||||
Owner bool `json:"OWNER"`
|
||||
Mount bool `json:"MOUNT"`
|
||||
CreateReceiver bool `json:"CREATE_RECEIVER"`
|
||||
CreateLink bool `json:"CREATE_LINK"`
|
||||
CreateAction bool `json:"CREATE_ACTION"`
|
||||
Comment bool `json:"COMMENT"`
|
||||
}
|
||||
|
||||
type DeviceProvider string
|
||||
|
||||
const (
|
||||
StorageHubProvider = "storagehub"
|
||||
StorageBlobProvider = "storageblob"
|
||||
)
|
||||
|
||||
type Device struct {
|
||||
Id string `json:"id"`
|
||||
ApiKey string `json:"apiKey"`
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
SpaceTotal int64 `json:"spaceTotal"`
|
||||
SpaceUsed int64 `json:"spaceUsed"`
|
||||
SpaceFree int64 `json:"spaceFree"`
|
||||
Version int `json:"version"`
|
||||
Provider struct {
|
||||
Name string `json:"name"`
|
||||
Data interface{} `json:"data"`
|
||||
} `json:"provider"`
|
||||
ReadOnly bool `json:"readonly"`
|
||||
RootMountId string `json:"rootMountId"`
|
||||
}
|
||||
|
||||
type DeviceCreate struct {
|
||||
Name string `json:"name"`
|
||||
ProviderName DeviceProvider `json:"providerName"`
|
||||
}
|
||||
|
||||
type DeviceUpdate struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type FolderCreate struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type FileCopy struct {
|
||||
ToMountId string `json:"toMountId"`
|
||||
TPath string `json:"toPath"`
|
||||
}
|
||||
|
||||
type FileMove struct {
|
||||
ToMountId string `json:"toMountId"`
|
||||
TPath string `json:"toPath"`
|
||||
}
|
||||
|
||||
type FileSpan struct {
|
||||
Start int64
|
||||
End int64
|
||||
}
|
||||
|
||||
type FileUpload struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type PutFilter struct {
|
||||
Modified *int64
|
||||
Size *int64
|
||||
Hash *string
|
||||
IgnoreNonExisting bool
|
||||
NoRename bool
|
||||
ForceOverwrite bool
|
||||
}
|
||||
|
||||
type DeleteFilter struct {
|
||||
Modified *int64
|
||||
Size *int64
|
||||
Hash *string
|
||||
IfEmpty bool
|
||||
}
|
||||
|
||||
type FileInfo struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Modified int64 `json:"modified"`
|
||||
Size int64 `json:"size"`
|
||||
ContentType string `json:"contentType"`
|
||||
Path string `json:"path"`
|
||||
Hash string `json:"hash"`
|
||||
}
|
||||
|
||||
type FileTree struct {
|
||||
FileInfo
|
||||
Children []*FileTree `json:"children"`
|
||||
}
|
||||
|
||||
func (tree *FileTree) Flatten() []FileInfo {
|
||||
trees := []*FileTree{tree}
|
||||
for i := 0; i < len(trees); i++ {
|
||||
tree := trees[i]
|
||||
for _, child := range tree.Children {
|
||||
child.Name = path.Join(tree.Name, child.Name)
|
||||
trees = append(trees, child)
|
||||
}
|
||||
}
|
||||
infos := make([]FileInfo, len(trees))
|
||||
for i, tree := range trees {
|
||||
infos[i] = tree.FileInfo
|
||||
}
|
||||
return infos
|
||||
}
|
||||
|
||||
type User struct {
|
||||
Id string `json:"id"`
|
||||
FirstName string `json:"firstName"`
|
||||
LastName string `json:"lastName"`
|
||||
Email string `json:"email"`
|
||||
}
|
||||
|
||||
type Shared struct {
|
||||
Name string `json:name`
|
||||
Type MountType `json:type`
|
||||
Modified int64 `json:modified`
|
||||
Size int64 `json:size`
|
||||
ContentType string `json:contentType`
|
||||
Hash string `json:hash`
|
||||
Mount Mount `json:mount`
|
||||
Link Link `json:link`
|
||||
Receiver Receiver `json:receiver`
|
||||
}
|
||||
|
||||
type Link struct {
|
||||
Id string `json:id`
|
||||
Name string `json:name`
|
||||
Path string `json:path`
|
||||
Counter int64 `json:counter`
|
||||
Url string `json:url`
|
||||
ShortUrl string `json:shortUrl`
|
||||
Hash string `json:hash`
|
||||
Host string `json:host`
|
||||
HasPassword bool `json:hasPassword`
|
||||
Password string `json:password`
|
||||
ValidFrom int64 `json:validFrom`
|
||||
ValidTo int64 `json:validTo`
|
||||
PasswordRequired bool `json:passwordRequired`
|
||||
}
|
||||
|
||||
type Receiver struct {
|
||||
Id string `json:id`
|
||||
Name string `json:name`
|
||||
Path string `json:path`
|
||||
Counter int64 `json:counter`
|
||||
Url string `json:url`
|
||||
ShortUrl string `json:shortUrl`
|
||||
Hash string `json:hash`
|
||||
Host string `json:host`
|
||||
HasPassword bool `json:hasPassword`
|
||||
Password string `json:password`
|
||||
ValidFrom int64 `json:validFrom`
|
||||
ValidTo int64 `json:validTo`
|
||||
Alert bool `json:alert`
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
package koofrclient
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/koofr/go-httpclient"
|
||||
)
|
||||
|
||||
type KoofrClient struct {
|
||||
*httpclient.HTTPClient
|
||||
token string
|
||||
userID string
|
||||
}
|
||||
|
||||
func NewKoofrClient(baseUrl string, disableSecurity bool) *KoofrClient {
|
||||
var httpClient *httpclient.HTTPClient
|
||||
|
||||
if disableSecurity {
|
||||
httpClient = httpclient.Insecure()
|
||||
} else {
|
||||
httpClient = httpclient.New()
|
||||
}
|
||||
|
||||
apiBaseUrl, _ := url.Parse(baseUrl)
|
||||
|
||||
httpClient.BaseURL = apiBaseUrl
|
||||
|
||||
httpClient.Headers.Set("User-Agent", "go koofrclient")
|
||||
|
||||
return &KoofrClient{
|
||||
HTTPClient: httpClient,
|
||||
token: "",
|
||||
userID: "",
|
||||
}
|
||||
}
|
||||
|
||||
func (c *KoofrClient) SetUserAgent(ua string) {
|
||||
c.Headers.Set("User-Agent", ua)
|
||||
}
|
||||
|
||||
func (c *KoofrClient) SetToken(token string) {
|
||||
c.token = token
|
||||
c.HTTPClient.Headers.Set("Authorization", fmt.Sprintf("Token token=%s", token))
|
||||
}
|
||||
|
||||
func (c *KoofrClient) GetToken() string {
|
||||
return c.token
|
||||
}
|
||||
|
||||
func (c *KoofrClient) SetUserID(userID string) {
|
||||
c.userID = userID
|
||||
}
|
||||
|
||||
func (c *KoofrClient) GetUserID() string {
|
||||
return c.userID
|
||||
}
|
||||
|
||||
func (c *KoofrClient) Authenticate(email string, password string) (err error) {
|
||||
var tokenResponse Token
|
||||
|
||||
tokenRequest := TokenRequest{
|
||||
Email: email,
|
||||
Password: password,
|
||||
}
|
||||
|
||||
request := httpclient.RequestData{
|
||||
Method: "POST",
|
||||
Path: "/token",
|
||||
Headers: make(http.Header),
|
||||
ExpectedStatus: []int{http.StatusOK},
|
||||
ReqEncoding: httpclient.EncodingJSON,
|
||||
ReqValue: tokenRequest,
|
||||
RespEncoding: httpclient.EncodingJSON,
|
||||
RespValue: &tokenResponse,
|
||||
}
|
||||
|
||||
res, err := c.Request(&request)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
c.SetToken(tokenResponse.Token)
|
||||
c.SetUserID(res.Header.Get("X-User-ID"))
|
||||
|
||||
return
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
package koofrclient
|
||||
|
||||
import (
|
||||
"github.com/koofr/go-httpclient"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (c *KoofrClient) Devices() (devices []Device, err error) {
|
||||
d := &struct {
|
||||
Devices *[]Device
|
||||
}{&devices}
|
||||
|
||||
request := httpclient.RequestData{
|
||||
Method: "GET",
|
||||
Path: "/api/v2/devices",
|
||||
ExpectedStatus: []int{http.StatusOK},
|
||||
RespEncoding: httpclient.EncodingJSON,
|
||||
RespValue: &d,
|
||||
}
|
||||
|
||||
_, err = c.Request(&request)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *KoofrClient) DevicesCreate(name string, provider DeviceProvider) (device Device, err error) {
|
||||
deviceCreate := DeviceCreate{name, provider}
|
||||
|
||||
request := httpclient.RequestData{
|
||||
Method: "POST",
|
||||
Path: "/api/v2/devices",
|
||||
ExpectedStatus: []int{http.StatusCreated},
|
||||
ReqEncoding: httpclient.EncodingJSON,
|
||||
ReqValue: deviceCreate,
|
||||
RespEncoding: httpclient.EncodingJSON,
|
||||
RespValue: &device,
|
||||
}
|
||||
|
||||
_, err = c.Request(&request)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *KoofrClient) DevicesDetails(deviceId string) (device Device, err error) {
|
||||
request := httpclient.RequestData{
|
||||
Method: "GET",
|
||||
Path: "/api/v2/devices/" + deviceId,
|
||||
ExpectedStatus: []int{http.StatusOK},
|
||||
RespEncoding: httpclient.EncodingJSON,
|
||||
RespValue: &device,
|
||||
}
|
||||
|
||||
_, err = c.Request(&request)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *KoofrClient) DevicesUpdate(deviceId string, deviceUpdate DeviceUpdate) (err error) {
|
||||
request := httpclient.RequestData{
|
||||
Method: "PUT",
|
||||
Path: "/api/v2/devices/" + deviceId,
|
||||
ExpectedStatus: []int{http.StatusNoContent},
|
||||
ReqEncoding: httpclient.EncodingJSON,
|
||||
ReqValue: deviceUpdate,
|
||||
RespConsume: true,
|
||||
}
|
||||
|
||||
_, err = c.Request(&request)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *KoofrClient) DevicesDelete(deviceId string) (err error) {
|
||||
request := httpclient.RequestData{
|
||||
Method: "DELETE",
|
||||
Path: "/api/v2/devices/" + deviceId,
|
||||
ExpectedStatus: []int{http.StatusNoContent},
|
||||
RespConsume: true,
|
||||
}
|
||||
|
||||
_, err = c.Request(&request)
|
||||
|
||||
return
|
||||
}
|
||||
+294
@@ -0,0 +1,294 @@
|
||||
package koofrclient
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
|
||||
"github.com/koofr/go-httpclient"
|
||||
)
|
||||
|
||||
var ErrCannotOverwrite = fmt.Errorf("Can not overwrite (filter constraint fails)")
|
||||
var ErrCannotRemove = fmt.Errorf("Can not remove (filter constraint fails)")
|
||||
|
||||
func (c *KoofrClient) FilesInfo(mountId string, path string) (info FileInfo, err error) {
|
||||
params := url.Values{}
|
||||
params.Set("path", path)
|
||||
|
||||
request := httpclient.RequestData{
|
||||
Method: "GET",
|
||||
Path: "/api/v2/mounts/" + mountId + "/files/info",
|
||||
Params: params,
|
||||
ExpectedStatus: []int{http.StatusOK},
|
||||
RespEncoding: httpclient.EncodingJSON,
|
||||
RespValue: &info,
|
||||
}
|
||||
|
||||
_, err = c.Request(&request)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *KoofrClient) FilesList(mountId string, basePath string) (files []FileInfo, err error) {
|
||||
f := &struct {
|
||||
Files *[]FileInfo
|
||||
}{&files}
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("path", basePath)
|
||||
|
||||
request := httpclient.RequestData{
|
||||
Method: "GET",
|
||||
Path: "/api/v2/mounts/" + mountId + "/files/list",
|
||||
Params: params,
|
||||
ExpectedStatus: []int{http.StatusOK},
|
||||
RespEncoding: httpclient.EncodingJSON,
|
||||
RespValue: &f,
|
||||
}
|
||||
|
||||
_, err = c.Request(&request)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for i := range files {
|
||||
files[i].Path = path.Join(basePath, files[i].Name)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *KoofrClient) FilesTree(mountId string, path string) (tree FileTree, err error) {
|
||||
params := url.Values{}
|
||||
params.Set("path", path)
|
||||
|
||||
request := httpclient.RequestData{
|
||||
Method: "GET",
|
||||
Path: "/api/v2/mounts/" + mountId + "/files/tree",
|
||||
Params: params,
|
||||
ExpectedStatus: []int{http.StatusOK},
|
||||
RespEncoding: httpclient.EncodingJSON,
|
||||
RespValue: &tree,
|
||||
}
|
||||
|
||||
_, err = c.Request(&request)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *KoofrClient) FilesDelete(mountId string, path string) (err error) {
|
||||
return c.filesDelete(mountId, path, nil)
|
||||
}
|
||||
|
||||
func (c *KoofrClient) FilesDeleteIf(mountId string, path string, deleteFilter *DeleteFilter) (err error) {
|
||||
return c.filesDelete(mountId, path, deleteFilter)
|
||||
}
|
||||
|
||||
func (c *KoofrClient) filesDelete(mountId string, path string, deleteFilter *DeleteFilter) (err error) {
|
||||
params := url.Values{}
|
||||
params.Set("path", path)
|
||||
|
||||
if deleteFilter != nil {
|
||||
if deleteFilter.Size != nil {
|
||||
params.Set("removeIfSize", fmt.Sprintf("%d", *deleteFilter.Size))
|
||||
}
|
||||
if deleteFilter.Modified != nil {
|
||||
params.Set("removeIfModified", fmt.Sprintf("%d", *deleteFilter.Modified))
|
||||
}
|
||||
if deleteFilter.Hash != nil {
|
||||
params.Set("removeIfHash", fmt.Sprintf("%s", *deleteFilter.Hash))
|
||||
}
|
||||
if deleteFilter.IfEmpty {
|
||||
params.Set("removeIfEmpty", "")
|
||||
}
|
||||
}
|
||||
|
||||
request := httpclient.RequestData{
|
||||
Method: "DELETE",
|
||||
Path: "/api/v2/mounts/" + mountId + "/files/remove",
|
||||
Params: params,
|
||||
ExpectedStatus: []int{http.StatusOK},
|
||||
RespConsume: true,
|
||||
}
|
||||
|
||||
_, err = c.Request(&request)
|
||||
|
||||
if err != nil {
|
||||
switch err := err.(type) {
|
||||
case httpclient.InvalidStatusError:
|
||||
if err.Got == http.StatusConflict {
|
||||
return ErrCannotRemove
|
||||
}
|
||||
default:
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *KoofrClient) FilesNewFolder(mountId string, path string, name string) (err error) {
|
||||
reqData := FolderCreate{name}
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("path", path)
|
||||
|
||||
request := httpclient.RequestData{
|
||||
Method: "POST",
|
||||
Path: "/api/v2/mounts/" + mountId + "/files/folder",
|
||||
Params: params,
|
||||
ExpectedStatus: []int{http.StatusOK, http.StatusCreated},
|
||||
ReqEncoding: httpclient.EncodingJSON,
|
||||
ReqValue: reqData,
|
||||
RespConsume: true,
|
||||
}
|
||||
|
||||
_, err = c.Request(&request)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *KoofrClient) FilesCopy(mountId string, path string, toMountId string, toPath string) (err error) {
|
||||
reqData := FileCopy{toMountId, toPath}
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("path", path)
|
||||
|
||||
request := httpclient.RequestData{
|
||||
Method: "PUT",
|
||||
Path: "/api/v2/mounts/" + mountId + "/files/copy",
|
||||
Params: params,
|
||||
ExpectedStatus: []int{http.StatusOK},
|
||||
ReqEncoding: httpclient.EncodingJSON,
|
||||
ReqValue: reqData,
|
||||
RespConsume: true,
|
||||
}
|
||||
|
||||
_, err = c.Request(&request)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *KoofrClient) FilesMove(mountId string, path string, toMountId string, toPath string) (err error) {
|
||||
reqData := FileMove{toMountId, toPath}
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("path", path)
|
||||
|
||||
request := httpclient.RequestData{
|
||||
Method: "PUT",
|
||||
Path: "/api/v2/mounts/" + mountId + "/files/move",
|
||||
Params: params,
|
||||
ExpectedStatus: []int{http.StatusOK},
|
||||
ReqEncoding: httpclient.EncodingJSON,
|
||||
ReqValue: reqData,
|
||||
RespConsume: true,
|
||||
}
|
||||
|
||||
_, err = c.Request(&request)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *KoofrClient) FilesGetRange(mountId string, path string, span *FileSpan) (reader io.ReadCloser, err error) {
|
||||
params := url.Values{}
|
||||
params.Set("path", path)
|
||||
|
||||
request := httpclient.RequestData{
|
||||
Method: "GET",
|
||||
Path: "/content/api/v2/mounts/" + mountId + "/files/get",
|
||||
Params: params,
|
||||
Headers: make(http.Header),
|
||||
ExpectedStatus: []int{http.StatusOK, http.StatusPartialContent},
|
||||
}
|
||||
|
||||
if span != nil {
|
||||
if span.End == -1 {
|
||||
request.Headers.Set("Range", fmt.Sprintf("bytes=%d-", span.Start))
|
||||
} else {
|
||||
request.Headers.Set("Range", fmt.Sprintf("bytes=%d-%d", span.Start, span.End))
|
||||
}
|
||||
}
|
||||
|
||||
res, err := c.Request(&request)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
reader = res.Body
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *KoofrClient) FilesGet(mountId string, path string) (reader io.ReadCloser, err error) {
|
||||
return c.FilesGetRange(mountId, path, nil)
|
||||
}
|
||||
|
||||
func (c *KoofrClient) FilesPut(mountId string, path string, name string, reader io.Reader) (newName string, err error) {
|
||||
info, err := c.FilesPutOptions(mountId, path, name, reader, nil)
|
||||
return info.Name, err
|
||||
}
|
||||
|
||||
func (c *KoofrClient) FilesPutOptions(mountId string, path string, name string, reader io.Reader, putFilter *PutFilter) (fileInfo *FileInfo, err error) {
|
||||
params := url.Values{}
|
||||
params.Set("path", path)
|
||||
params.Set("filename", name)
|
||||
params.Set("info", "true")
|
||||
|
||||
if putFilter != nil {
|
||||
if putFilter.Size != nil {
|
||||
params.Set("overwriteIfSize", fmt.Sprintf("%d", *putFilter.Size))
|
||||
}
|
||||
if putFilter.Modified != nil {
|
||||
params.Set("overwriteIfModified", fmt.Sprintf("%d", *putFilter.Modified))
|
||||
}
|
||||
if putFilter.Hash != nil {
|
||||
params.Set("overwriteIfHash", fmt.Sprintf("%s", *putFilter.Hash))
|
||||
}
|
||||
if putFilter.IgnoreNonExisting {
|
||||
params.Set("overwriteIgnoreNonexisting", "")
|
||||
}
|
||||
if putFilter.NoRename {
|
||||
params.Set("autorename", "false")
|
||||
}
|
||||
if putFilter.ForceOverwrite {
|
||||
params.Set("overwrite", "true")
|
||||
}
|
||||
}
|
||||
|
||||
request := httpclient.RequestData{
|
||||
Method: "POST",
|
||||
Path: "/content/api/v2/mounts/" + mountId + "/files/put",
|
||||
Params: params,
|
||||
ExpectedStatus: []int{http.StatusOK},
|
||||
RespEncoding: httpclient.EncodingJSON,
|
||||
RespValue: &fileInfo,
|
||||
}
|
||||
|
||||
err = request.UploadFile("file", "dummy", reader)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = c.Request(&request)
|
||||
|
||||
if err != nil {
|
||||
|
||||
switch err := err.(type) {
|
||||
case httpclient.InvalidStatusError:
|
||||
if err.Got == http.StatusConflict {
|
||||
return nil, ErrCannotOverwrite
|
||||
}
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package koofrclient
|
||||
|
||||
import (
|
||||
"github.com/koofr/go-httpclient"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (c *KoofrClient) Mounts() (mounts []Mount, err error) {
|
||||
d := &struct {
|
||||
Mounts *[]Mount
|
||||
}{&mounts}
|
||||
|
||||
request := httpclient.RequestData{
|
||||
Method: "GET",
|
||||
Path: "/api/v2/mounts",
|
||||
ExpectedStatus: []int{http.StatusOK},
|
||||
RespEncoding: httpclient.EncodingJSON,
|
||||
RespValue: &d,
|
||||
}
|
||||
|
||||
_, err = c.Request(&request)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *KoofrClient) MountsDetails(mountId string) (mount Mount, err error) {
|
||||
request := httpclient.RequestData{
|
||||
Method: "GET",
|
||||
Path: "/api/v2/mounts/" + mountId,
|
||||
ExpectedStatus: []int{http.StatusOK},
|
||||
RespEncoding: httpclient.EncodingJSON,
|
||||
RespValue: &mount,
|
||||
}
|
||||
|
||||
_, err = c.Request(&request)
|
||||
|
||||
return
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package koofrclient
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/koofr/go-httpclient"
|
||||
)
|
||||
|
||||
func (c *KoofrClient) Shared() (shared []Shared, err error) {
|
||||
d := &struct {
|
||||
Files *[]Shared
|
||||
}{&shared}
|
||||
|
||||
request := httpclient.RequestData{
|
||||
Method: "GET",
|
||||
Path: "/api/v2/shared",
|
||||
ExpectedStatus: []int{http.StatusOK},
|
||||
RespEncoding: httpclient.EncodingJSON,
|
||||
RespValue: &d,
|
||||
}
|
||||
|
||||
_, err = c.Request(&request)
|
||||
|
||||
return
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package koofrclient
|
||||
|
||||
import (
|
||||
"github.com/koofr/go-httpclient"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (c *KoofrClient) UserInfo() (user User, err error) {
|
||||
request := httpclient.RequestData{
|
||||
Method: "GET",
|
||||
Path: "/api/v2/user",
|
||||
ExpectedStatus: []int{http.StatusOK},
|
||||
RespEncoding: httpclient.EncodingJSON,
|
||||
RespValue: &user,
|
||||
}
|
||||
|
||||
_, err = c.Request(&request)
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user