mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-05-11 17:39:41 +08:00
chore: translate some import log to cn
This commit is contained in:
@@ -25,7 +25,7 @@ var Storages = make(map[string]Storage)
|
||||
// GetStorageByName returns storage by name from cache or creates new one
|
||||
func GetStorageByName(name string) (Storage, error) {
|
||||
if name == "" {
|
||||
return nil, fmt.Errorf("storage name is required")
|
||||
return nil, ErrStorageNameEmpty
|
||||
}
|
||||
|
||||
storage, ok := Storages[name]
|
||||
@@ -34,7 +34,7 @@ func GetStorageByName(name string) (Storage, error) {
|
||||
}
|
||||
cfg := config.Cfg.GetStorageByName(name)
|
||||
if cfg == nil {
|
||||
return nil, fmt.Errorf("storage %s not found", name)
|
||||
return nil, fmt.Errorf("未找到存储 %s", name)
|
||||
}
|
||||
|
||||
storage, err := NewStorage(cfg)
|
||||
@@ -48,11 +48,11 @@ func GetStorageByName(name string) (Storage, error) {
|
||||
// 检查 user 是否可用指定的 storage, 若不可用则返回未找到错误
|
||||
func GetStorageByUserIDAndName(chatID int64, name string) (Storage, error) {
|
||||
if name == "" {
|
||||
return nil, fmt.Errorf("storage name is required")
|
||||
return nil, ErrStorageNameEmpty
|
||||
}
|
||||
|
||||
if !config.Cfg.HasStorage(chatID, name) {
|
||||
return nil, fmt.Errorf("storage %s not found for user %d", name, chatID)
|
||||
return nil, fmt.Errorf("没有找到用户 %d 的存储 %s", chatID, name)
|
||||
}
|
||||
|
||||
return GetStorageByName(name)
|
||||
@@ -81,24 +81,24 @@ var storageConstructors = map[string]StorageConstructor{
|
||||
func NewStorage(cfg config.StorageConfig) (Storage, error) {
|
||||
constructor, ok := storageConstructors[string(cfg.GetType())]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unsupported storage type: %s", cfg.GetType())
|
||||
return nil, fmt.Errorf("不支持的存储类型: %s", cfg.GetType())
|
||||
}
|
||||
|
||||
storage := constructor()
|
||||
if err := storage.Init(cfg); err != nil {
|
||||
return nil, fmt.Errorf("failed to init %s storage: %w", cfg.GetName(), err)
|
||||
return nil, fmt.Errorf("初始化 %s 存储失败: %w", cfg.GetName(), err)
|
||||
}
|
||||
|
||||
return storage, nil
|
||||
}
|
||||
|
||||
func LoadStorages() {
|
||||
logger.L.Info("Loading storages")
|
||||
logger.L.Info("加载存储...")
|
||||
for _, storage := range config.Cfg.Storages {
|
||||
_, err := GetStorageByName(storage.GetName())
|
||||
if err != nil {
|
||||
logger.L.Errorf("Failed to load storage %s: %v", storage.GetName(), err)
|
||||
logger.L.Errorf("加载存储 %s 失败: %v", storage.GetName(), err)
|
||||
}
|
||||
}
|
||||
logger.L.Infof("Successfully loaded %d storages", len(Storages))
|
||||
logger.L.Infof("成功加载 %d 个存储", len(Storages))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user