fix(channels): declare managed media cleanup policy

Explicitly mark downloaded and managed channel media as delete-on-cleanup so media ownership is visible at each registration site.

Refs #1886
This commit is contained in:
Hoshina 2026-03-22 17:50:34 +08:00
parent bbe127f7b0
commit d0c4ec776e
10 changed files with 32 additions and 20 deletions

View file

@ -398,6 +398,7 @@ func (c *DiscordChannel) handleMessage(s *discordgo.Session, m *discordgo.Messag
ref, err := store.Store(localPath, media.MediaMeta{
Filename: filename,
Source: "discord",
CleanupPolicy: media.CleanupPolicyDeleteOnCleanup,
}, scope)
if err == nil {
return ref

View file

@ -727,6 +727,7 @@ func (c *FeishuChannel) downloadResource(
ref, err := store.Store(localPath, media.MediaMeta{
Filename: filename,
Source: "feishu",
CleanupPolicy: media.CleanupPolicyDeleteOnCleanup,
}, scope)
if err != nil {
logger.ErrorCF("feishu", "Failed to store downloaded resource", map[string]any{

View file

@ -303,6 +303,7 @@ func (c *LINEChannel) processEvent(event lineEvent) {
ref, err := store.Store(localPath, media.MediaMeta{
Filename: filename,
Source: "line",
CleanupPolicy: media.CleanupPolicyDeleteOnCleanup,
}, scope)
if err == nil {
return ref

View file

@ -692,6 +692,9 @@ func (c *MatrixChannel) extractInboundMedia(
func (c *MatrixChannel) storeMedia(localPath string, meta media.MediaMeta, scope string) string {
if store := c.GetMediaStore(); store != nil {
if meta.CleanupPolicy == "" {
meta.CleanupPolicy = media.CleanupPolicyDeleteOnCleanup
}
ref, err := store.Store(localPath, meta, scope)
if err == nil {
return ref

View file

@ -751,6 +751,7 @@ func (c *OneBotChannel) parseMessageSegments(
ref, err := store.Store(localPath, media.MediaMeta{
Filename: filename,
Source: "onebot",
CleanupPolicy: media.CleanupPolicyDeleteOnCleanup,
}, scope)
if err == nil {
return ref

View file

@ -673,6 +673,7 @@ func (c *QQChannel) extractInboundAttachments(
Filename: qqAttachmentFilename(attachment),
ContentType: attachment.ContentType,
Source: "qq",
CleanupPolicy: media.CleanupPolicyDeleteOnCleanup,
}, scope)
if err == nil {
return ref

View file

@ -329,6 +329,7 @@ func (c *SlackChannel) handleMessageEvent(ev *slackevents.MessageEvent) {
ref, err := store.Store(localPath, media.MediaMeta{
Filename: filename,
Source: "slack",
CleanupPolicy: media.CleanupPolicyDeleteOnCleanup,
}, scope)
if err == nil {
return ref

View file

@ -563,6 +563,7 @@ func (c *TelegramChannel) handleMessage(ctx context.Context, message *telego.Mes
ref, err := store.Store(localPath, media.MediaMeta{
Filename: filename,
Source: "telegram",
CleanupPolicy: media.CleanupPolicyDeleteOnCleanup,
}, scope)
if err == nil {
return ref

View file

@ -1220,6 +1220,7 @@ func (c *WeComAIBotWSChannel) storeWSMedia(
ref, err := store.Store(tmpPath, media.MediaMeta{
Filename: msgID + ext,
Source: "wecom_aibot",
CleanupPolicy: media.CleanupPolicyDeleteOnCleanup,
}, scope)
if err != nil {
os.Remove(tmpPath)

View file

@ -294,6 +294,7 @@ func (c *WeixinChannel) storeInboundBytes(
Filename: filename,
ContentType: contentType,
Source: "weixin",
CleanupPolicy: media.CleanupPolicyDeleteOnCleanup,
}, basechannels.BuildMediaScope("weixin", chatID, messageID))
if err != nil {
os.Remove(tmpPath)