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:
parent
bbe127f7b0
commit
d0c4ec776e
10 changed files with 32 additions and 20 deletions
|
|
@ -396,8 +396,9 @@ func (c *DiscordChannel) handleMessage(s *discordgo.Session, m *discordgo.Messag
|
|||
storeMedia := func(localPath, filename string) string {
|
||||
if store := c.GetMediaStore(); store != nil {
|
||||
ref, err := store.Store(localPath, media.MediaMeta{
|
||||
Filename: filename,
|
||||
Source: "discord",
|
||||
Filename: filename,
|
||||
Source: "discord",
|
||||
CleanupPolicy: media.CleanupPolicyDeleteOnCleanup,
|
||||
}, scope)
|
||||
if err == nil {
|
||||
return ref
|
||||
|
|
|
|||
|
|
@ -725,8 +725,9 @@ func (c *FeishuChannel) downloadResource(
|
|||
out.Close()
|
||||
|
||||
ref, err := store.Store(localPath, media.MediaMeta{
|
||||
Filename: filename,
|
||||
Source: "feishu",
|
||||
Filename: filename,
|
||||
Source: "feishu",
|
||||
CleanupPolicy: media.CleanupPolicyDeleteOnCleanup,
|
||||
}, scope)
|
||||
if err != nil {
|
||||
logger.ErrorCF("feishu", "Failed to store downloaded resource", map[string]any{
|
||||
|
|
|
|||
|
|
@ -301,8 +301,9 @@ func (c *LINEChannel) processEvent(event lineEvent) {
|
|||
storeMedia := func(localPath, filename string) string {
|
||||
if store := c.GetMediaStore(); store != nil {
|
||||
ref, err := store.Store(localPath, media.MediaMeta{
|
||||
Filename: filename,
|
||||
Source: "line",
|
||||
Filename: filename,
|
||||
Source: "line",
|
||||
CleanupPolicy: media.CleanupPolicyDeleteOnCleanup,
|
||||
}, scope)
|
||||
if err == nil {
|
||||
return ref
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -749,8 +749,9 @@ func (c *OneBotChannel) parseMessageSegments(
|
|||
storeFile := func(localPath, filename string) string {
|
||||
if store != nil {
|
||||
ref, err := store.Store(localPath, media.MediaMeta{
|
||||
Filename: filename,
|
||||
Source: "onebot",
|
||||
Filename: filename,
|
||||
Source: "onebot",
|
||||
CleanupPolicy: media.CleanupPolicyDeleteOnCleanup,
|
||||
}, scope)
|
||||
if err == nil {
|
||||
return ref
|
||||
|
|
|
|||
|
|
@ -670,9 +670,10 @@ func (c *QQChannel) extractInboundAttachments(
|
|||
storeMedia := func(localPath string, attachment *dto.MessageAttachment) string {
|
||||
if store := c.GetMediaStore(); store != nil {
|
||||
ref, err := store.Store(localPath, media.MediaMeta{
|
||||
Filename: qqAttachmentFilename(attachment),
|
||||
ContentType: attachment.ContentType,
|
||||
Source: "qq",
|
||||
Filename: qqAttachmentFilename(attachment),
|
||||
ContentType: attachment.ContentType,
|
||||
Source: "qq",
|
||||
CleanupPolicy: media.CleanupPolicyDeleteOnCleanup,
|
||||
}, scope)
|
||||
if err == nil {
|
||||
return ref
|
||||
|
|
|
|||
|
|
@ -327,8 +327,9 @@ func (c *SlackChannel) handleMessageEvent(ev *slackevents.MessageEvent) {
|
|||
storeMedia := func(localPath, filename string) string {
|
||||
if store := c.GetMediaStore(); store != nil {
|
||||
ref, err := store.Store(localPath, media.MediaMeta{
|
||||
Filename: filename,
|
||||
Source: "slack",
|
||||
Filename: filename,
|
||||
Source: "slack",
|
||||
CleanupPolicy: media.CleanupPolicyDeleteOnCleanup,
|
||||
}, scope)
|
||||
if err == nil {
|
||||
return ref
|
||||
|
|
|
|||
|
|
@ -561,8 +561,9 @@ func (c *TelegramChannel) handleMessage(ctx context.Context, message *telego.Mes
|
|||
storeMedia := func(localPath, filename string) string {
|
||||
if store := c.GetMediaStore(); store != nil {
|
||||
ref, err := store.Store(localPath, media.MediaMeta{
|
||||
Filename: filename,
|
||||
Source: "telegram",
|
||||
Filename: filename,
|
||||
Source: "telegram",
|
||||
CleanupPolicy: media.CleanupPolicyDeleteOnCleanup,
|
||||
}, scope)
|
||||
if err == nil {
|
||||
return ref
|
||||
|
|
|
|||
|
|
@ -1218,8 +1218,9 @@ func (c *WeComAIBotWSChannel) storeWSMedia(
|
|||
|
||||
scope := channels.BuildMediaScope("wecom_aibot", chatID, msgID)
|
||||
ref, err := store.Store(tmpPath, media.MediaMeta{
|
||||
Filename: msgID + ext,
|
||||
Source: "wecom_aibot",
|
||||
Filename: msgID + ext,
|
||||
Source: "wecom_aibot",
|
||||
CleanupPolicy: media.CleanupPolicyDeleteOnCleanup,
|
||||
}, scope)
|
||||
if err != nil {
|
||||
os.Remove(tmpPath)
|
||||
|
|
|
|||
|
|
@ -291,9 +291,10 @@ func (c *WeixinChannel) storeInboundBytes(
|
|||
return "", err
|
||||
}
|
||||
ref, err := store.Store(tmpPath, media.MediaMeta{
|
||||
Filename: filename,
|
||||
ContentType: contentType,
|
||||
Source: "weixin",
|
||||
Filename: filename,
|
||||
ContentType: contentType,
|
||||
Source: "weixin",
|
||||
CleanupPolicy: media.CleanupPolicyDeleteOnCleanup,
|
||||
}, basechannels.BuildMediaScope("weixin", chatID, messageID))
|
||||
if err != nil {
|
||||
os.Remove(tmpPath)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue