sync: Implement writable importer
This commit is contained in:
parent
8ed9415c68
commit
aab66bf612
4 changed files with 55 additions and 0 deletions
|
@ -3,6 +3,7 @@ package sync
|
|||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
@ -103,6 +104,29 @@ func (i CloudImporter) getFile(filename string, writer *bufio.Writer) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (i CloudImporter) writeFile(filename string, reader io.Reader) error {
|
||||
fullURL := i.baseDAV
|
||||
fullURL.Path = path.Join(fullURL.Path, filename)
|
||||
|
||||
client := http.Client{}
|
||||
if req, err := http.NewRequest("PUT", fullURL.String(), reader); err != nil {
|
||||
return err
|
||||
} else {
|
||||
req.SetBasicAuth(i.username, i.password)
|
||||
if resp, err := client.Do(req); err != nil {
|
||||
return err
|
||||
} else {
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return errors.New(resp.Status)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i CloudImporter) listDir(filename string) ([]string, error) {
|
||||
client := gowebdav.NewClient(i.baseDAV.String(), i.username, i.password)
|
||||
|
||||
|
|
Reference in a new issue