mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-06-02 14:10:48 +08:00
feat: rename file only when storagePath exists
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user