forked from mtusi2026/mtusi2026lab4
feat(cleanup): remove stale queued attachments after grace period
This commit is contained in:
@@ -30,6 +30,7 @@ type attachmentQueries interface {
|
||||
CreateAttachment(ctx context.Context, arg db.CreateAttachmentParams) (db.Attachment, error)
|
||||
GetAttachmentByID(ctx context.Context, id uuid.UUID) (db.Attachment, error)
|
||||
IsChatMember(ctx context.Context, arg db.IsChatMemberParams) (bool, error)
|
||||
MarkAttachmentReady(ctx context.Context, id uuid.UUID) (db.Attachment, error)
|
||||
}
|
||||
|
||||
type AttachmentService struct {
|
||||
@@ -104,11 +105,8 @@ func (s *AttachmentService) Upload(
|
||||
if _, err := tmp.Seek(0, io.SeekStart); err != nil {
|
||||
return model.Attachment{}, err
|
||||
}
|
||||
if err := s.s3.Put(ctx, key, tmp, size, string(detectedType)); err != nil {
|
||||
return model.Attachment{}, err
|
||||
}
|
||||
|
||||
row, err := s.q.CreateAttachment(ctx, db.CreateAttachmentParams{
|
||||
_, err = s.q.CreateAttachment(ctx, db.CreateAttachmentParams{
|
||||
ID: id,
|
||||
ChatID: chatID,
|
||||
OwnerID: userID,
|
||||
@@ -117,9 +115,20 @@ func (s *AttachmentService) Upload(
|
||||
ContentType: db.AttachmentContentType(detectedType),
|
||||
SizeBytes: int(size),
|
||||
Sha256: hash,
|
||||
Status: db.AttachmentStatusReady,
|
||||
ErrorCode: "",
|
||||
})
|
||||
if postgres.IsNotFound(err) {
|
||||
return model.Attachment{}, ErrAttachmentNotFound
|
||||
}
|
||||
if err != nil {
|
||||
return model.Attachment{}, err
|
||||
}
|
||||
|
||||
if err := s.s3.Put(ctx, key, tmp, size, string(detectedType)); err != nil {
|
||||
return model.Attachment{}, err
|
||||
}
|
||||
|
||||
row, err := s.q.MarkAttachmentReady(ctx, id)
|
||||
if err != nil {
|
||||
return model.Attachment{}, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user