itd/api/fs.go

97 lines
1.5 KiB
Go
Raw Normal View History

2021-11-23 19:12:16 +00:00
package api
2022-05-01 22:22:28 +00:00
import "context"
2022-09-03 23:28:25 +00:00
func (c *Client) RemoveAll(ctx context.Context, paths ...string) error {
return c.client.Call(
ctx,
"FS",
"RemoveAll",
paths,
nil,
)
}
2022-05-01 22:22:28 +00:00
func (c *Client) Remove(ctx context.Context, paths ...string) error {
return c.client.Call(
2022-05-01 22:22:28 +00:00
ctx,
"FS",
2022-04-23 00:12:30 +00:00
"Remove",
paths,
nil,
)
2021-11-23 19:12:16 +00:00
}
2022-05-01 22:22:28 +00:00
func (c *Client) Rename(ctx context.Context, old, new string) error {
return c.client.Call(
2022-05-01 22:22:28 +00:00
ctx,
"FS",
"Rename",
2022-04-23 00:12:30 +00:00
[2]string{old, new},
nil,
)
2021-11-23 19:12:16 +00:00
}
2022-09-03 23:28:25 +00:00
func (c *Client) MkdirAll(ctx context.Context, paths ...string) error {
return c.client.Call(
ctx,
"FS",
"MkdirAll",
paths,
nil,
)
}
2022-05-01 22:22:28 +00:00
func (c *Client) Mkdir(ctx context.Context, paths ...string) error {
return c.client.Call(
2022-05-01 22:22:28 +00:00
ctx,
"FS",
2022-04-23 00:12:30 +00:00
"Mkdir",
paths,
nil,
)
2021-11-23 19:12:16 +00:00
}
2022-05-01 22:22:28 +00:00
func (c *Client) ReadDir(ctx context.Context, dir string) (out []FileInfo, err error) {
err = c.client.Call(
2022-05-01 22:22:28 +00:00
ctx,
"FS",
2022-04-23 00:12:30 +00:00
"ReadDir",
dir,
&out,
)
return
2021-11-23 19:12:16 +00:00
}
2022-05-01 22:22:28 +00:00
func (c *Client) Upload(ctx context.Context, dst, src string) (chan FSTransferProgress, error) {
progressCh := make(chan FSTransferProgress, 5)
err := c.client.Call(
2022-05-01 22:22:28 +00:00
ctx,
"FS",
2022-04-23 00:12:30 +00:00
"Upload",
[2]string{dst, src},
progressCh,
2022-04-23 00:12:30 +00:00
)
2021-11-23 19:12:16 +00:00
if err != nil {
2021-12-13 01:08:48 +00:00
return nil, err
2021-11-23 19:12:16 +00:00
}
2021-12-13 01:08:48 +00:00
2022-04-23 00:12:30 +00:00
return progressCh, nil
}
2021-12-13 01:08:48 +00:00
2022-05-01 22:22:28 +00:00
func (c *Client) Download(ctx context.Context, dst, src string) (chan FSTransferProgress, error) {
progressCh := make(chan FSTransferProgress, 5)
err := c.client.Call(
2022-05-01 22:22:28 +00:00
ctx,
"FS",
2022-04-23 00:12:30 +00:00
"Download",
[2]string{dst, src},
progressCh,
2022-04-23 00:12:30 +00:00
)
2021-11-23 19:12:16 +00:00
if err != nil {
2021-12-13 01:08:48 +00:00
return nil, err
2021-11-23 19:12:16 +00:00
}
2021-12-13 01:08:48 +00:00
2022-04-23 00:12:30 +00:00
return progressCh, nil
2021-11-23 19:12:16 +00:00
}