mirror of
https://github.com/multipleof4/ntfy.git
synced 2026-10-08 21:05:21 +00:00
More consistent logging
This commit is contained in:
@@ -6,12 +6,8 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"heckel.io/ntfy/v2/log"
|
||||
)
|
||||
|
||||
const tagFileBackend = "attachment_file"
|
||||
|
||||
type fileBackend struct {
|
||||
dir string
|
||||
}
|
||||
@@ -86,8 +82,8 @@ func (b *fileBackend) Get(id string) (io.ReadCloser, int64, error) {
|
||||
func (b *fileBackend) Delete(ids ...string) error {
|
||||
for _, id := range ids {
|
||||
file := filepath.Join(b.dir, id)
|
||||
if err := os.Remove(file); err != nil {
|
||||
log.Tag(tagFileBackend).Field("message_id", id).Err(err).Debug("Error deleting attachment")
|
||||
if err := os.Remove(file); err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -5,14 +5,10 @@ import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"heckel.io/ntfy/v2/log"
|
||||
"heckel.io/ntfy/v2/s3"
|
||||
)
|
||||
|
||||
const (
|
||||
tagS3Backend = "attachment_s3"
|
||||
deleteBatchSize = 1000
|
||||
)
|
||||
const deleteBatchSize = 1000
|
||||
|
||||
type s3Backend struct {
|
||||
client *s3.Client
|
||||
@@ -55,11 +51,7 @@ func (b *s3Backend) Delete(ids ...string) error {
|
||||
if end > len(ids) {
|
||||
end = len(ids)
|
||||
}
|
||||
batch := ids[i:end]
|
||||
for _, id := range batch {
|
||||
log.Tag(tagS3Backend).Field("message_id", id).Debug("Deleting attachment from S3")
|
||||
}
|
||||
if err := b.client.DeleteObjects(context.Background(), batch); err != nil {
|
||||
if err := b.client.DeleteObjects(context.Background(), ids[i:end]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,6 +113,9 @@ func (c *Store) Remove(ids ...string) error {
|
||||
}
|
||||
}
|
||||
// Remove from backend
|
||||
for _, id := range ids {
|
||||
log.Tag(tagStore).Field("message_id", id).Debug("Removing attachment")
|
||||
}
|
||||
if err := c.backend.Delete(ids...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user