From ba9d6b467a1f03447789844048d913738c843569 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Fri, 10 Nov 2023 19:29:26 +0100 Subject: [feature] Media attachment placeholders (#2331) * [feature] Use placeholders for unknown media types * fix read of underreported small files * switch to reduce nesting * simplify cleanup --- internal/uris/uri.go | 84 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 14 deletions(-) (limited to 'internal/uris/uri.go') diff --git a/internal/uris/uri.go b/internal/uris/uri.go index 1e631bcbc..ca98b6416 100644 --- a/internal/uris/uri.go +++ b/internal/uris/uri.go @@ -165,23 +165,79 @@ func GenerateURIsForAccount(username string) *UserURIs { } } -// GenerateURIForAttachment generates a URI for an attachment/emoji/header etc. -// Will produced something like https://example.org/fileserver/01FPST95B8FC3HG3AGCDKPQNQ2/attachment/original/01FPST9QK4V5XWS3F9Z4F2G1X7.gif -func GenerateURIForAttachment(accountID string, mediaType string, mediaSize string, mediaID string, extension string) string { - protocol := config.GetProtocol() - host := config.GetHost() - return fmt.Sprintf("%s://%s/%s/%s/%s/%s/%s.%s", protocol, host, FileserverPath, accountID, mediaType, mediaSize, mediaID, extension) -} +// URIForAttachment generates a URI for +// an attachment/emoji/header etc. +// +// Will produce something like: +// +// "https://example.org/fileserver/01FPST95B8FC3HG3AGCDKPQNQ2/attachment/original/01FPST9QK4V5XWS3F9Z4F2G1X7.gif" +func URIForAttachment( + accountID string, + mediaType string, + mediaSize string, + mediaID string, + extension string, +) string { + const format = "%s://%s/%s/%s/%s/%s/%s.%s" + + return fmt.Sprintf( + format, + config.GetProtocol(), + config.GetHost(), + FileserverPath, + accountID, + mediaType, + mediaSize, + mediaID, + extension, + ) +} + +// StoragePathForAttachment generates a storage +// path for an attachment/emoji/header etc. +// +// Will produce something like: +// +// "01FPST95B8FC3HG3AGCDKPQNQ2/attachment/original/01FPST9QK4V5XWS3F9Z4F2G1X7.gif" +func StoragePathForAttachment( + accountID string, + mediaType string, + mediaSize string, + mediaID string, + extension string, +) string { + const format = "%s/%s/%s/%s.%s" + + return fmt.Sprintf( + format, + accountID, + mediaType, + mediaSize, + mediaID, + extension, + ) +} + +// URIForEmoji generates an +// ActivityPub URI for an emoji. +// +// Will produce something like: +// +// "https://example.org/emoji/01FPST9QK4V5XWS3F9Z4F2G1X7" +func URIForEmoji(emojiID string) string { + const format = "%s://%s/%s/%s" -// GenerateURIForEmoji generates an activitypub uri for a new emoji. -func GenerateURIForEmoji(emojiID string) string { - protocol := config.GetProtocol() - host := config.GetHost() - return fmt.Sprintf("%s://%s/%s/%s", protocol, host, EmojiPath, emojiID) + return fmt.Sprintf( + format, + config.GetProtocol(), + config.GetHost(), + EmojiPath, + emojiID, + ) } -// GenerateURIForTag generates an activitypub uri for a tag. -func GenerateURIForTag(name string) string { +// URIForTag generates an activitypub uri for a tag. +func URIForTag(name string) string { protocol := config.GetProtocol() host := config.GetHost() return fmt.Sprintf("%s://%s/%s/%s", protocol, host, TagsPath, strings.ToLower(name)) -- cgit v1.2.3