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