jottacloud: Implement optional about interface.

This commit is contained in:
Sebastian Bünger 2018-08-15 01:12:20 +02:00 committed by Nick Craig-Wood
parent 86e3436d55
commit 2d7c5ebc7a

View File

@ -87,6 +87,7 @@ type Options struct {
type Fs struct { type Fs struct {
name string name string
root string root string
user string
opt Options opt Options
features *fs.Features features *fs.Features
endpointURL string endpointURL string
@ -180,24 +181,32 @@ func (f *Fs) readMetaDataForPath(path string) (info *api.JottaFile, err error) {
return &result, nil return &result, nil
} }
// setEndpointUrl reads the account id and generates the API endpoint URL // getAccountInfo retrieves account information
func (f *Fs) setEndpointURL(user, mountpoint string) (err error) { func (f *Fs) getAccountInfo() (info *api.AccountInfo, err error) {
opts := rest.Opts{ opts := rest.Opts{
Method: "GET", Method: "GET",
Path: rest.URLPathEscape(user), Path: rest.URLPathEscape(f.user),
} }
var result api.AccountInfo
var resp *http.Response var resp *http.Response
err = f.pacer.Call(func() (bool, error) { err = f.pacer.Call(func() (bool, error) {
resp, err = f.srv.CallXML(&opts, nil, &result) resp, err = f.srv.CallXML(&opts, nil, &info)
return shouldRetry(resp, err) return shouldRetry(resp, err)
}) })
if err != nil { if err != nil {
return err return nil, err
} }
f.endpointURL = rest.URLPathEscape(path.Join(result.Username, defaultDevice, mountpoint)) return info, nil
}
// setEndpointUrl reads the account id and generates the API endpoint URL
func (f *Fs) setEndpointURL(mountpoint string) (err error) {
info, err := f.getAccountInfo()
if err != nil {
return errors.Wrap(err, "failed to get endpoint url")
}
f.endpointURL = rest.URLPathEscape(path.Join(info.Username, defaultDevice, mountpoint))
return nil return nil
} }
@ -254,6 +263,7 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) {
f := &Fs{ f := &Fs{
name: name, name: name,
root: root, root: root,
user: opt.User,
opt: *opt, opt: *opt,
//endpointURL: rest.URLPathEscape(path.Join(user, defaultDevice, opt.Mountpoint)), //endpointURL: rest.URLPathEscape(path.Join(user, defaultDevice, opt.Mountpoint)),
srv: rest.NewClient(fshttp.NewClient(fs.Config)).SetRoot(rootURL), srv: rest.NewClient(fshttp.NewClient(fs.Config)).SetRoot(rootURL),
@ -262,6 +272,8 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) {
f.features = (&fs.Features{ f.features = (&fs.Features{
CaseInsensitive: true, CaseInsensitive: true,
CanHaveEmptyDirectories: true, CanHaveEmptyDirectories: true,
ReadMimeType: true,
WriteMimeType: true,
}).Fill(f) }).Fill(f)
if user == "" || pass == "" { if user == "" || pass == "" {
@ -271,7 +283,7 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) {
f.srv.SetUserPass(opt.User, opt.Pass) f.srv.SetUserPass(opt.User, opt.Pass)
f.srv.SetErrorHandler(errorHandler) f.srv.SetErrorHandler(errorHandler)
err = f.setEndpointURL(opt.User, opt.Mountpoint) err = f.setEndpointURL(opt.Mountpoint)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "couldn't get account info") return nil, errors.Wrap(err, "couldn't get account info")
} }
@ -646,6 +658,20 @@ func (f *Fs) DirMove(src fs.Fs, srcRemote, dstRemote string) error {
return nil return nil
} }
// About gets quota information
func (f *Fs) About() (*fs.Usage, error) {
info, err := f.getAccountInfo()
if err != nil {
return nil, err
}
usage := &fs.Usage{
Total: fs.NewUsageValue(info.Capacity),
Used: fs.NewUsageValue(info.Usage),
}
return usage, nil
}
// Hashes returns the supported hash sets. // Hashes returns the supported hash sets.
func (f *Fs) Hashes() hash.Set { func (f *Fs) Hashes() hash.Set {
return hash.Set(hash.MD5) return hash.Set(hash.MD5)
@ -903,6 +929,7 @@ var (
_ fs.Copier = (*Fs)(nil) _ fs.Copier = (*Fs)(nil)
_ fs.Mover = (*Fs)(nil) _ fs.Mover = (*Fs)(nil)
_ fs.DirMover = (*Fs)(nil) _ fs.DirMover = (*Fs)(nil)
_ fs.Abouter = (*Fs)(nil)
_ fs.Object = (*Object)(nil) _ fs.Object = (*Object)(nil)
_ fs.MimeTyper = (*Object)(nil) _ fs.MimeTyper = (*Object)(nil)
) )