Add file management API with local storage backend

- Implement FileHandler with CRUD operations for files/directories
- Add FileService with business logic and SHA-256 hashing
- Create LocalStorage backend for filesystem persistence
- Add database repository with pagination and name uniqueness
  constraints
- Configure max upload size in storage settings
- Include comprehensive tests for all layers
This commit is contained in:
2026-06-24 14:08:57 +08:00
parent eaa31efd64
commit e2af482cc9
17 changed files with 1815 additions and 15 deletions
+16
View File
@@ -8,6 +8,7 @@ import (
"github.com/dhao2001/mygo/internal/config"
"github.com/dhao2001/mygo/internal/repository"
"github.com/dhao2001/mygo/internal/service"
"github.com/dhao2001/mygo/internal/storage"
)
// WebApp contains application-wide runtime dependencies and metadata.
@@ -21,6 +22,8 @@ type WebApp struct {
FileRepo repository.FileRepository
CredentialRepo repository.CredentialRepository
AuthService *service.AuthService
FileService *service.FileService
Storage storage.StorageBackend
}
// Bootstrap creates a fully initialized WebApp from config.
@@ -48,6 +51,13 @@ func Bootstrap(cfg *config.Config) (*WebApp, error) {
cfg.JWT.RefreshTTL,
)
store, err := storage.NewLocalStorage(cfg.Storage.Local.Path)
if err != nil {
return nil, fmt.Errorf("init storage: %w", err)
}
fileService := service.NewFileService(fileRepo, store, cfg.Storage.MaxUploadSize)
return &WebApp{
Config: cfg,
Version: AppVersion,
@@ -57,6 +67,8 @@ func Bootstrap(cfg *config.Config) (*WebApp, error) {
FileRepo: fileRepo,
CredentialRepo: credentialRepo,
AuthService: authService,
FileService: fileService,
Storage: store,
}, nil
}
@@ -67,6 +79,8 @@ func NewWebApp(cfg *config.Config, db *gorm.DB,
fileRepo repository.FileRepository,
credentialRepo repository.CredentialRepository,
authService *service.AuthService,
fileService *service.FileService,
store storage.StorageBackend,
) *WebApp {
return &WebApp{
Config: cfg,
@@ -77,6 +91,8 @@ func NewWebApp(cfg *config.Config, db *gorm.DB,
FileRepo: fileRepo,
CredentialRepo: credentialRepo,
AuthService: authService,
FileService: fileService,
Storage: store,
}
}