From 72ba5666a6ffd06ccdfd2db8dacc47de7f777a4c Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Wed, 17 Jul 2024 15:26:33 +0000 Subject: [chore] media pipeline improvements (#3110) * don't set emoji / media image paths on failed download, migrate FileType from string to integer * fix incorrect uses of util.PtrOr, fix returned frontend media * fix migration not setting arguments correctly in where clause * fix not providing default with not null column * whoops * ensure a default gets set for media attachment file type * remove the exclusive flag from writing files in disk storage * rename PtrOr -> PtrOrZero, and rename PtrValueOr -> PtrOrValue to match * slight wording changes * use singular / plural word forms (no parentheses), is better for screen readers * update testmodels with unknown media type to have unset file details, update attachment focus handling converting to frontend, update tests * store first instance in ffmpeg wasm pool, fill remaining with closed instances --- internal/typeutils/util.go | 100 +++++++++++++++++++++++++++------------------ 1 file changed, 60 insertions(+), 40 deletions(-) (limited to 'internal/typeutils/util.go') diff --git a/internal/typeutils/util.go b/internal/typeutils/util.go index d674bc150..f28cd2554 100644 --- a/internal/typeutils/util.go +++ b/internal/typeutils/util.go @@ -20,6 +20,7 @@ package typeutils import ( "context" "fmt" + "math" "net/url" "path" "slices" @@ -35,6 +36,26 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/text" ) +// toAPISize converts a set of media dimensions +// to mastodon API compatible size string. +func toAPISize(width, height int) string { + return strconv.Itoa(width) + + "x" + + strconv.Itoa(height) +} + +// toAPIFrameRate converts a media framerate ptr +// to mastodon API compatible framerate string. +func toAPIFrameRate(framerate *float32) string { + if framerate == nil { + return "" + } + // The masto api expects this as a string in + // the format `integer/1`, so 30fps is `30/1`. + round := math.Round(float64(*framerate)) + return strconv.Itoa(int(round)) + "/1" +} + type statusInteractions struct { Favourited bool Muted bool @@ -92,7 +113,7 @@ func misskeyReportInlineURLs(content string) []*url.URL { return urls } -// placeholdUnknownAttachments separates any attachments with type `unknown` +// placeholderAttachments separates any attachments with missing local URL // out of the given slice, and returns a piece of text containing links to // those attachments, as well as the slice of remaining "known" attachments. // If there are no unknown-type attachments in the provided slice, an empty @@ -104,62 +125,61 @@ func misskeyReportInlineURLs(content string) []*url.URL { // Example: // //
ℹ️ Note from your.instance.com: 2 attachments in this status could not be downloaded. Treat the following external links with care:
+//ℹ️ Note from your.instance.com: 2 attachment(s) in this status were not downloaded. Treat the following external link(s) with care:
//ℹ️ Note from `)
+ note.WriteString(config.GetHost())
+ note.WriteString(`: `)
+ note.WriteString(strconv.Itoa(len(nonLocal)))
- if unknownsLen == 1 {
- attachments = "1 attachment"
- links = "link"
+ if len(nonLocal) > 1 {
+ // Use plural word form.
+ note.WriteString(` attachments in this status were not downloaded. ` +
+ `Treat the following external links with care:`)
} else {
- attachments = strconv.Itoa(unknownsLen) + " attachments"
- links = "links"
+ // Use singular word form.
+ note.WriteString(` attachment in this status was not downloaded. ` +
+ `Treat the following external link with care:`)
}
- var note strings.Builder
- note.WriteString(`
`)
- note.WriteString(`
`) - note.WriteString(`ℹ️ Note from ` + config.GetHost() + `: ` + attachments + ` in this status could not be downloaded. Treat the following external ` + links + ` with care:`) - note.WriteString(`
`) - note.WriteString(`