2023-09-13 08:51:05 +00:00
|
|
|
package pkg
|
|
|
|
|
|
|
|
import (
|
2023-09-15 10:55:29 +00:00
|
|
|
"fmt"
|
2023-10-21 09:26:13 +00:00
|
|
|
"github.com/ente-io/cli/internal/api"
|
|
|
|
"github.com/ente-io/cli/pkg/secrets"
|
2023-09-13 08:51:05 +00:00
|
|
|
bolt "go.etcd.io/bbolt"
|
2023-10-16 16:27:31 +00:00
|
|
|
"os"
|
2023-10-21 06:52:45 +00:00
|
|
|
"path/filepath"
|
2023-09-13 08:51:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ClICtrl struct {
|
2023-10-16 16:27:31 +00:00
|
|
|
Client *api.Client
|
|
|
|
DB *bolt.DB
|
|
|
|
KeyHolder *secrets.KeyHolder
|
|
|
|
tempFolder string
|
2023-09-13 08:51:05 +00:00
|
|
|
}
|
2023-09-15 10:55:29 +00:00
|
|
|
|
|
|
|
func (c *ClICtrl) Init() error {
|
2023-10-25 11:52:22 +00:00
|
|
|
tempPath := filepath.Join(os.TempDir(), "ente-download")
|
2023-10-21 06:52:45 +00:00
|
|
|
// create temp folder if not exists
|
|
|
|
if _, err := os.Stat(tempPath); os.IsNotExist(err) {
|
|
|
|
err = os.Mkdir(tempPath, 0755)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-10-16 16:27:31 +00:00
|
|
|
}
|
2023-10-21 06:52:45 +00:00
|
|
|
c.tempFolder = tempPath
|
2023-09-15 10:55:29 +00:00
|
|
|
return c.DB.Update(func(tx *bolt.Tx) error {
|
|
|
|
_, err := tx.CreateBucketIfNotExists([]byte(AccBucket))
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("create bucket: %s", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|