feat: rename file only when storagePath exists

This commit is contained in:
krau
2025-06-11 09:54:08 +08:00
parent 9d3a3a8dcd
commit e85d3c9441
8 changed files with 59 additions and 19 deletions

View File

@@ -70,3 +70,17 @@ func (m *Minio) Save(ctx context.Context, r io.Reader, storagePath string) error
return nil
}
func (m *Minio) Exists(ctx context.Context, storagePath string) bool {
common.Log.Debugf("Checking if file exists at %s", storagePath)
// TODO: test it.
_, err := m.client.StatObject(ctx, m.config.BucketName, storagePath, minio.StatObjectOptions{})
if err != nil {
if minio.ToErrorResponse(err).Code == "NoSuchKey" {
return false // File does not exist
}
return false
}
return true
}