media.go (3798B)
1 // GoToSocial 2 // Copyright (C) GoToSocial Authors admin@gotosocial.org 3 // SPDX-License-Identifier: AGPL-3.0-or-later 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package db 19 20 import ( 21 "context" 22 "time" 23 24 "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" 25 ) 26 27 // Media contains functions related to creating/getting/removing media attachments. 28 type Media interface { 29 // GetAttachmentByID gets a single attachment by its ID. 30 GetAttachmentByID(ctx context.Context, id string) (*gtsmodel.MediaAttachment, Error) 31 32 // GetAttachmentsByIDs fetches a list of media attachments for given IDs. 33 GetAttachmentsByIDs(ctx context.Context, ids []string) ([]*gtsmodel.MediaAttachment, error) 34 35 // PutAttachment inserts the given attachment into the database. 36 PutAttachment(ctx context.Context, media *gtsmodel.MediaAttachment) error 37 38 // UpdateAttachment will update the given attachment in the database. 39 UpdateAttachment(ctx context.Context, media *gtsmodel.MediaAttachment, columns ...string) error 40 41 // DeleteAttachment deletes the attachment with given ID from the database. 42 DeleteAttachment(ctx context.Context, id string) error 43 44 // GetRemoteOlderThan gets limit n remote media attachments (including avatars and headers) older than the given 45 // olderThan time. These will be returned in order of attachment.created_at descending (newest to oldest in other words). 46 // 47 // The selected media attachments will be those with both a URL and a RemoteURL filled in. 48 // In other words, media attachments that originated remotely, and that we currently have cached locally. 49 GetRemoteOlderThan(ctx context.Context, olderThan time.Time, limit int) ([]*gtsmodel.MediaAttachment, Error) 50 51 // CountRemoteOlderThan is like GetRemoteOlderThan, except instead of getting limit n attachments, 52 // it just counts how many remote attachments in the database (including avatars and headers) meet 53 // the olderThan criteria. 54 CountRemoteOlderThan(ctx context.Context, olderThan time.Time) (int, Error) 55 56 // GetAvatarsAndHeaders fetches limit n avatars and headers with an id < maxID. These headers 57 // and avis may be in use or not; the caller should check this if it's important. 58 GetAvatarsAndHeaders(ctx context.Context, maxID string, limit int) ([]*gtsmodel.MediaAttachment, Error) 59 60 // GetLocalUnattachedOlderThan fetches limit n local media attachments (including avatars and headers), older than 61 // the given time, which aren't header or avatars, and aren't attached to a status. In other words, attachments which were 62 // uploaded but never used for whatever reason, or attachments that were attached to a status which was subsequently deleted. 63 // 64 // These will be returned in order of attachment.created_at descending (newest to oldest in other words). 65 GetLocalUnattachedOlderThan(ctx context.Context, olderThan time.Time, limit int) ([]*gtsmodel.MediaAttachment, Error) 66 67 // CountLocalUnattachedOlderThan is like GetLocalUnattachedOlderThan, except instead of getting limit n attachments, 68 // it just counts how many local attachments in the database meet the olderThan criteria. 69 CountLocalUnattachedOlderThan(ctx context.Context, olderThan time.Time) (int, Error) 70 }