diff options
author | 2023-11-10 19:29:26 +0100 | |
---|---|---|
committer | 2023-11-10 19:29:26 +0100 | |
commit | ba9d6b467a1f03447789844048d913738c843569 (patch) | |
tree | 5a464ee4a33f26e3284179582ab6d3332d9d5388 /internal/uris | |
parent | [chore/bugfix/horror] Allow `expires_in` and poll choices to be parsed from s... (diff) | |
download | gotosocial-ba9d6b467a1f03447789844048d913738c843569.tar.xz |
[feature] Media attachment placeholders (#2331)
* [feature] Use placeholders for unknown media types
* fix read of underreported small files
* switch to reduce nesting
* simplify cleanup
Diffstat (limited to 'internal/uris')
-rw-r--r-- | internal/uris/uri.go | 84 |
1 files changed, 70 insertions, 14 deletions
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)) |