mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-05 15:26:36 +08:00
Merge remote-tracking branch 'wavelet/main'
This commit is contained in:
@@ -99,6 +99,7 @@ func (p *Plugin) Apply(ctx *core.Context) error {
|
||||
core.Bind[contracts.RiskControlService](ctx, service.SetRiskControlService)
|
||||
service.SetEventEmitter(ctx.Events().Emit)
|
||||
core.Provide[contracts.PublicConfigProvider](ctx, service.PublicConfigAdapter{})
|
||||
core.Provide[contracts.SystemConfigService](ctx, service.SystemConfigServiceImpl{})
|
||||
|
||||
ctx.OnDispose(func() error {
|
||||
service.ResetServices()
|
||||
|
||||
@@ -26,6 +26,85 @@ func (PublicConfigAdapter) PublicConfig(ctx context.Context) (map[string]string,
|
||||
return PublicSystemConfigs(ctx)
|
||||
}
|
||||
|
||||
// SystemConfigServiceImpl implements contracts.SystemConfigService.
|
||||
type SystemConfigServiceImpl struct{}
|
||||
|
||||
func (SystemConfigServiceImpl) GetByKey(ctx context.Context, key string) (contracts.SystemConfigDTO, error) {
|
||||
cfg, err := repository.GetSystemConfigByKey(ctx, key)
|
||||
if err != nil {
|
||||
return contracts.SystemConfigDTO{}, err
|
||||
}
|
||||
return toSystemConfigDTO(cfg), nil
|
||||
}
|
||||
|
||||
func (SystemConfigServiceImpl) ListByKeys(ctx context.Context, keys []string) (map[string]contracts.SystemConfigDTO, error) {
|
||||
cfgs, err := repository.ListSystemConfigsByKeys(ctx, keys)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res := make(map[string]contracts.SystemConfigDTO, len(cfgs))
|
||||
for k, v := range cfgs {
|
||||
res[k] = toSystemConfigDTO(v)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (SystemConfigServiceImpl) ListVisible(ctx context.Context) ([]contracts.SystemConfigDTO, error) {
|
||||
cfgs, err := repository.ListVisibleSystemConfigs(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res := make([]contracts.SystemConfigDTO, len(cfgs))
|
||||
for i, v := range cfgs {
|
||||
res[i] = toSystemConfigDTO(v)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (SystemConfigServiceImpl) ListByType(ctx context.Context, configType string) ([]contracts.SystemConfigDTO, error) {
|
||||
cfgs, err := repository.ListAdminSystemConfigs(ctx, configType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res := make([]contracts.SystemConfigDTO, len(cfgs))
|
||||
for i, v := range cfgs {
|
||||
res[i] = toSystemConfigDTO(v)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (SystemConfigServiceImpl) GetIntByKey(ctx context.Context, key string) (int, error) {
|
||||
return repository.GetIntByKey(ctx, key)
|
||||
}
|
||||
|
||||
func (SystemConfigServiceImpl) GetBoolByKey(ctx context.Context, key string) (bool, error) {
|
||||
return repository.GetBoolByKey(ctx, key)
|
||||
}
|
||||
|
||||
func (SystemConfigServiceImpl) SaveOrUpdate(ctx context.Context, key, value string) error {
|
||||
return repository.SaveOrUpdateSystemConfig(ctx, key, value)
|
||||
}
|
||||
|
||||
func (SystemConfigServiceImpl) InvalidateCache(ctx context.Context, key string) error {
|
||||
return repository.InvalidateSystemConfigCache(ctx, key)
|
||||
}
|
||||
|
||||
func (SystemConfigServiceImpl) InvalidateAllCaches(ctx context.Context) error {
|
||||
return repository.InvalidateAllSystemConfigCaches(ctx)
|
||||
}
|
||||
|
||||
func toSystemConfigDTO(c model.SystemConfig) contracts.SystemConfigDTO {
|
||||
return contracts.SystemConfigDTO{
|
||||
Key: c.Key,
|
||||
Value: c.Value,
|
||||
Type: c.Type,
|
||||
Visibility: c.Visibility,
|
||||
Description: c.Description,
|
||||
UpdatedAt: c.UpdatedAt,
|
||||
CreatedAt: c.CreatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// PublicSystemConfigs returns the key/value map exposed to unauthenticated clients.
|
||||
func PublicSystemConfigs(ctx context.Context) (map[string]string, error) {
|
||||
configs, err := repository.ListVisibleSystemConfigs(ctx)
|
||||
|
||||
@@ -62,6 +62,7 @@ func (p *Plugin) Apply(ctx *core.Context) error {
|
||||
core.Bind[contracts.StorageService](ctx, shared.SetStorageService)
|
||||
core.Bind[contracts.TaskService](ctx, shared.SetTaskService)
|
||||
core.Bind[contracts.AuthService](ctx, shared.SetAuthService)
|
||||
core.Provide[contracts.UploadService](ctx, &uploadServiceImpl{})
|
||||
|
||||
ctx.OnDispose(func() error {
|
||||
shared.ResetServices()
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
// Copyright 2026 Arctel.net
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package upload
|
||||
|
||||
import (
|
||||
"Wavelet/core/contracts"
|
||||
"Wavelet/plugins/domain/upload/models"
|
||||
"Wavelet/plugins/domain/upload/repository"
|
||||
"Wavelet/plugins/domain/upload/shared"
|
||||
"context"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type uploadServiceImpl struct{}
|
||||
|
||||
func (s *uploadServiceImpl) GetByID(ctx context.Context, id uint64) (*contracts.UploadDTO, error) {
|
||||
u, err := repository.GetActiveUploadByID(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dto := toUploadDTO(&u)
|
||||
return &dto, nil
|
||||
}
|
||||
|
||||
func (s *uploadServiceImpl) OpenStoredUpload(ctx context.Context, id uint64) (*contracts.OpenedUploadDTO, error) {
|
||||
u, err := repository.GetActiveUploadByID(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
storageSvc := shared.GetStorage(ctx)
|
||||
if storageSvc == nil {
|
||||
return nil, errors.New("storage service not available")
|
||||
}
|
||||
obj, err := storageSvc.Get(ctx, u.FilePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &contracts.OpenedUploadDTO{
|
||||
Upload: toUploadDTO(&u),
|
||||
Body: obj.Body,
|
||||
ContentType: obj.ContentType,
|
||||
ContentLength: obj.ContentLength,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *uploadServiceImpl) Remove(ctx context.Context, id uint64) error {
|
||||
_, err := Remove(ctx, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *uploadServiceImpl) RemoveOwned(ctx context.Context, id uint64, userID uint64) error {
|
||||
_, err := RemoveOwned(ctx, userID, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *uploadServiceImpl) FindByHash(ctx context.Context, hash string, size int64) (*contracts.UploadDTO, error) {
|
||||
u, err := FindByHash(ctx, hash, size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dto := toUploadDTO(&u)
|
||||
return &dto, nil
|
||||
}
|
||||
|
||||
func (s *uploadServiceImpl) RebuildStats(ctx context.Context) error {
|
||||
return RebuildUploadStats(ctx)
|
||||
}
|
||||
|
||||
func toUploadDTO(u *models.Upload) contracts.UploadDTO {
|
||||
return contracts.UploadDTO{
|
||||
ID: u.ID,
|
||||
UserID: u.UserID,
|
||||
FileName: u.FileName,
|
||||
FilePath: u.FilePath,
|
||||
MimeType: u.MimeType,
|
||||
Size: u.FileSize,
|
||||
Hash: u.Hash,
|
||||
Status: string(u.Status),
|
||||
Type: u.Type,
|
||||
CreatedAt: u.CreatedAt,
|
||||
UpdatedAt: u.UpdatedAt,
|
||||
}
|
||||
}
|
||||
@@ -555,6 +555,15 @@ func (s *taskServiceImpl) GetExecution(ctx context.Context, id uint64) (*contrac
|
||||
return &dto, nil
|
||||
}
|
||||
|
||||
func (s *taskServiceImpl) GetExecutionByTaskID(ctx context.Context, taskID string) (*contracts.TaskExecutionDTO, error) {
|
||||
exec, err := GetTaskExecutionByTaskID(ctx, taskID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dto := toTaskExecutionDTO(exec)
|
||||
return &dto, nil
|
||||
}
|
||||
|
||||
func toTaskExecutionDTO(exec *TaskExecution) contracts.TaskExecutionDTO {
|
||||
return contracts.TaskExecutionDTO{
|
||||
ID: exec.ID,
|
||||
|
||||
@@ -125,6 +125,19 @@ func (s *inprocTaskService) GetExecution(ctx context.Context, id uint64) (*contr
|
||||
return &dto, nil
|
||||
}
|
||||
|
||||
func (s *inprocTaskService) GetExecutionByTaskID(ctx context.Context, taskID string) (*contracts.TaskExecutionDTO, error) {
|
||||
db := getDB(ctx)
|
||||
if db == nil {
|
||||
return nil, errors.New("driver_inproc_worker: db not initialized")
|
||||
}
|
||||
var exec taskExecution
|
||||
if err := db.Where("task_id = ?", taskID).First(&exec).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dto := toExecutionDTO(&exec)
|
||||
return &dto, nil
|
||||
}
|
||||
|
||||
func toExecutionDTO(exec *taskExecution) contracts.TaskExecutionDTO {
|
||||
return contracts.TaskExecutionDTO{
|
||||
ID: exec.ID,
|
||||
|
||||
Reference in New Issue
Block a user