2021-11-23 19:12:16 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mitchellh/mapstructure"
|
|
|
|
"go.arsenm.dev/itd/internal/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (c *Client) Rename(old, new string) error {
|
|
|
|
_, err := c.request(types.Request{
|
|
|
|
Type: types.ReqTypeFS,
|
|
|
|
Data: types.ReqDataFS{
|
|
|
|
Type: types.FSTypeMove,
|
|
|
|
Files: []string{old, new},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-11-23 21:35:18 +00:00
|
|
|
func (c *Client) Remove(paths ...string) error {
|
2021-11-23 19:12:16 +00:00
|
|
|
_, err := c.request(types.Request{
|
|
|
|
Type: types.ReqTypeFS,
|
|
|
|
Data: types.ReqDataFS{
|
|
|
|
Type: types.FSTypeDelete,
|
2021-11-23 21:35:18 +00:00
|
|
|
Files: paths,
|
2021-11-23 19:12:16 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-11-23 21:35:18 +00:00
|
|
|
func (c *Client) Mkdir(paths ...string) error {
|
2021-11-23 19:12:16 +00:00
|
|
|
_, err := c.request(types.Request{
|
|
|
|
Type: types.ReqTypeFS,
|
|
|
|
Data: types.ReqDataFS{
|
|
|
|
Type: types.FSTypeMkdir,
|
2021-11-23 21:35:18 +00:00
|
|
|
Files: paths,
|
2021-11-23 19:12:16 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) ReadDir(path string) ([]types.FileInfo, error) {
|
|
|
|
res, err := c.request(types.Request{
|
|
|
|
Type: types.ReqTypeFS,
|
|
|
|
Data: types.ReqDataFS{
|
|
|
|
Type: types.FSTypeList,
|
|
|
|
Files: []string{path},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var out []types.FileInfo
|
|
|
|
err = mapstructure.Decode(res.Value, &out)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
2021-12-12 06:11:01 +00:00
|
|
|
func (c *Client) ReadFile(localPath, remotePath string) error {
|
|
|
|
_, err := c.request(types.Request{
|
2021-11-23 19:12:16 +00:00
|
|
|
Type: types.ReqTypeFS,
|
|
|
|
Data: types.ReqDataFS{
|
|
|
|
Type: types.FSTypeRead,
|
2021-12-12 06:11:01 +00:00
|
|
|
Files: []string{localPath, remotePath},
|
2021-11-23 19:12:16 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
2021-12-12 06:11:01 +00:00
|
|
|
return err
|
2021-11-23 19:12:16 +00:00
|
|
|
}
|
2021-12-12 06:11:01 +00:00
|
|
|
return nil
|
2021-11-23 19:12:16 +00:00
|
|
|
}
|
|
|
|
|
2021-12-12 06:11:01 +00:00
|
|
|
func (c *Client) WriteFile(localPath, remotePath string) error {
|
2021-11-23 19:12:16 +00:00
|
|
|
_, err := c.request(types.Request{
|
|
|
|
Type: types.ReqTypeFS,
|
|
|
|
Data: types.ReqDataFS{
|
2021-11-23 22:14:45 +00:00
|
|
|
Type: types.FSTypeWrite,
|
2021-12-12 06:11:01 +00:00
|
|
|
Files: []string{remotePath, localPath},
|
2021-11-23 19:12:16 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|