chore: rename account to storage

This commit is contained in:
Noah Hsu
2022-07-10 14:45:39 +08:00
parent efa20cc7bd
commit fc1204c914
31 changed files with 548 additions and 548 deletions

View File

@ -13,17 +13,17 @@ import (
)
func AddURI(ctx context.Context, uri string, dstDirPath string) error {
// check account
account, dstDirActualPath, err := operations.GetAccountAndActualPath(dstDirPath)
// check storage
storage, dstDirActualPath, err := operations.GetStorageAndActualPath(dstDirPath)
if err != nil {
return errors.WithMessage(err, "failed get account")
return errors.WithMessage(err, "failed get storage")
}
// check is it could upload
if account.Config().NoUpload {
if storage.Config().NoUpload {
return errors.WithStack(errs.UploadNotSupported)
}
// check path is valid
obj, err := operations.Get(ctx, account, dstDirActualPath)
obj, err := operations.Get(ctx, storage, dstDirActualPath)
if err != nil {
if !errs.IsObjectNotFound(err) {
return errors.WithMessage(err, "failed get object")
@ -45,7 +45,7 @@ func AddURI(ctx context.Context, uri string, dstDirPath string) error {
}
DownTaskManager.Submit(task.WithCancelCtx(&task.Task[string]{
ID: gid,
Name: fmt.Sprintf("download %s to [%s](%s)", uri, account.GetAccount().VirtualPath, dstDirActualPath),
Name: fmt.Sprintf("download %s to [%s](%s)", uri, storage.GetStorage().VirtualPath, dstDirActualPath),
Func: func(tsk *task.Task[string]) error {
m := &Monitor{
tsk: tsk,

View File

@ -37,7 +37,7 @@ func TestConnect(t *testing.T) {
func TestDown(t *testing.T) {
TestConnect(t)
err := operations.CreateAccount(context.Background(), model.Account{
err := operations.CreateStorage(context.Background(), model.Storage{
ID: 0,
VirtualPath: "/",
Index: 0,
@ -47,7 +47,7 @@ func TestDown(t *testing.T) {
Remark: "",
})
if err != nil {
t.Fatalf("failed to create account: %+v", err)
t.Fatalf("failed to create storage: %+v", err)
}
err = AddURI(context.Background(), "https://nodejs.org/dist/index.json", "/test")
if err != nil {

View File

@ -113,9 +113,9 @@ var TransferTaskManager = task.NewTaskManager[uint64](3, func(k *uint64) {
func (m *Monitor) Complete() error {
// check dstDir again
account, dstDirActualPath, err := operations.GetAccountAndActualPath(m.dstDirPath)
storage, dstDirActualPath, err := operations.GetStorageAndActualPath(m.dstDirPath)
if err != nil {
return errors.WithMessage(err, "failed get account")
return errors.WithMessage(err, "failed get storage")
}
// get files
files, err := client.GetFiles(m.tsk.ID)
@ -135,7 +135,7 @@ func (m *Monitor) Complete() error {
}()
for _, file := range files {
TransferTaskManager.Submit(task.WithCancelCtx[uint64](&task.Task[uint64]{
Name: fmt.Sprintf("transfer %s to [%s](%s)", file.Path, account.GetAccount().VirtualPath, dstDirActualPath),
Name: fmt.Sprintf("transfer %s to [%s](%s)", file.Path, storage.GetStorage().VirtualPath, dstDirActualPath),
Func: func(tsk *task.Task[uint64]) error {
defer wg.Done()
size, _ := strconv.ParseInt(file.Length, 10, 64)
@ -157,7 +157,7 @@ func (m *Monitor) Complete() error {
ReadCloser: f,
Mimetype: mimetype,
}
return operations.Put(tsk.Ctx, account, dstDirActualPath, stream, tsk.SetProgress)
return operations.Put(tsk.Ctx, storage, dstDirActualPath, stream, tsk.SetProgress)
},
}))
}