feat: 完成基本功能
( 1. 新建连接 2. 新建桶 3. 上传文件 4. 下载文件 5. 预览图片 )
This commit is contained in:
@ -2,10 +2,12 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/loveuer/nf-disk/internal/api"
|
||||
"github.com/loveuer/nf-disk/internal/db"
|
||||
"github.com/loveuer/nf-disk/internal/manager"
|
||||
"github.com/loveuer/nf-disk/internal/model"
|
||||
"github.com/loveuer/nf-disk/internal/opt"
|
||||
"github.com/loveuer/nf-disk/internal/tool"
|
||||
"github.com/loveuer/nf-disk/ndh"
|
||||
"github.com/loveuer/nf/nft/log"
|
||||
@ -37,7 +39,8 @@ func NewApp(gctx context.Context) *App {
|
||||
func (a *App) Startup(ctx context.Context) {
|
||||
log.Info("app startup!!!")
|
||||
a.ctx = ctx
|
||||
tool.Must(db.Init(ctx, "sqlite::memory", db.OptSqliteByMem(nil)))
|
||||
tool.Must(opt.Init())
|
||||
tool.Must(db.Init(ctx, fmt.Sprintf("sqlite::%s", opt.ConfigFile)))
|
||||
tool.Must(model.Init(db.Default.Session()))
|
||||
tool.Must(manager.Init(ctx))
|
||||
tool.Must(api.Init(ctx))
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"github.com/loveuer/nf-disk/internal/s3"
|
||||
"github.com/loveuer/nf-disk/ndh"
|
||||
"github.com/samber/lo"
|
||||
"time"
|
||||
)
|
||||
|
||||
func ConnectionTest(c *ndh.Ctx) error {
|
||||
@ -210,11 +209,5 @@ func ConnectionBuckets(c *ndh.Ctx) error {
|
||||
return c.Send500(err.Error())
|
||||
}
|
||||
|
||||
// todo: for frontend test
|
||||
buckets = append(buckets, &s3.ListBucketRes{
|
||||
Name: "这是一个非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长的名字",
|
||||
CreatedAt: time.Now().UnixMilli(),
|
||||
})
|
||||
|
||||
return c.Send200(map[string]any{"list": buckets})
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/loveuer/nf-disk/internal/opt"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
func Init(tx *gorm.DB) (err error) {
|
||||
@ -11,24 +9,5 @@ func Init(tx *gorm.DB) (err error) {
|
||||
&Connection{},
|
||||
)
|
||||
|
||||
if opt.Debug {
|
||||
err = tx.Create([]*Connection{
|
||||
{
|
||||
Name: "dev-minio",
|
||||
Endpoint: "http://10.220.10.15:9000",
|
||||
Access: "8ALV3DUZI31YG4BDRJ0Z",
|
||||
Key: "CRqwS1MsiUj27TbRK+3T2n+LpKWd07VvaDKuzU0H",
|
||||
},
|
||||
{
|
||||
Name: "test",
|
||||
Endpoint: "http://10.220.10.14:19000",
|
||||
Access: "5VCR05L4BSGNCTCD8DXP",
|
||||
Key: "FPTMYBEiHhWLJ05C3aGXW8bjFXXNmghc8Za3Fo2u",
|
||||
},
|
||||
}).Clauses(clause.OnConflict{
|
||||
DoNothing: true,
|
||||
}).Error
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
24
internal/opt/init.go
Normal file
24
internal/opt/init.go
Normal file
@ -0,0 +1,24 @@
|
||||
package opt
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func Init() error {
|
||||
var (
|
||||
err error
|
||||
)
|
||||
|
||||
if ConfigDir, err = os.UserConfigDir(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if os.MkdirAll(filepath.Join(ConfigDir, "nf-disk"), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ConfigFile = filepath.Join(ConfigDir, "nf-disk", "config.db")
|
||||
|
||||
return nil
|
||||
}
|
@ -7,5 +7,7 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
Debug bool = false
|
||||
Debug bool = false
|
||||
ConfigDir string
|
||||
ConfigFile string
|
||||
)
|
||||
|
@ -12,10 +12,10 @@ import (
|
||||
)
|
||||
|
||||
type ObjectInfo struct {
|
||||
Bucket string
|
||||
Key string
|
||||
ContentType string
|
||||
Expire int64
|
||||
Bucket string `json:"bucket"`
|
||||
Key string `json:"key"`
|
||||
ContentType string `json:"content_type"`
|
||||
Expire int64 `json:"expire"`
|
||||
}
|
||||
|
||||
func (c *Client) GetObjectInfo(ctx context.Context, bucket string, key string) (*ObjectInfo, error) {
|
||||
@ -62,9 +62,9 @@ func (presigner *Presigner) GetObject(ctx context.Context, bucketName string, ob
|
||||
}
|
||||
|
||||
type ObjectEntry struct {
|
||||
URL string
|
||||
Method string
|
||||
Header http.Header
|
||||
URL string `json:"url"`
|
||||
Method string `json:"method"`
|
||||
Header http.Header `json:"header"`
|
||||
}
|
||||
|
||||
func (c *Client) GetObjectEntry(ctx context.Context, bucket string, key string, lifetimes ...int64) (*ObjectEntry, error) {
|
||||
@ -92,7 +92,7 @@ func (c *Client) GetObjectEntry(ctx context.Context, bucket string, key string,
|
||||
|
||||
type ObjectEntity struct {
|
||||
ObjectInfo
|
||||
Body io.ReadCloser
|
||||
Body io.ReadCloser `json:"body"`
|
||||
}
|
||||
|
||||
func (c *Client) GetObject(ctx context.Context, bucket string, key string) (*ObjectEntity, error) {
|
||||
|
Reference in New Issue
Block a user