diff --git a/common/alerts.go b/common/alerts.go
index 6c89fc0a..0d4bfbfa 100644
--- a/common/alerts.go
+++ b/common/alerts.go
@@ -298,7 +298,7 @@ func BuildAlertSb(sb *strings.Builder, a *Alert, u *User /* The current user */)
return nil
}
-//var AlertsGrowHint3 = len(`{"msg":"._","sub":["",""],"path":"","img":"","id":}`) + 3 + 2 + 2 + 2 + 2 + 1
+//const AlertsGrowHint3 = len(`{"msg":"._","sub":["",""],"path":"","img":"","id":}`) + 3 + 2 + 2 + 2 + 2 + 1
func AddActivityAndNotifyAll(a Alert) error {
id, err := Activity.Add(a)
diff --git a/common/common.go b/common/common.go
index a2346a11..90682c4f 100644
--- a/common/common.go
+++ b/common/common.go
@@ -69,9 +69,9 @@ var AllowedFileExts = StringList{
"txt", "xml", "json", "yaml", "toml", "ini", "md", "html", "rtf", "js", "py", "rb", "css", "scss", "less", "eqcss", "pcss", "java", "ts", "cs", "c", "cc", "cpp", "cxx", "C", "c++", "h", "hh", "hpp", "hxx", "h++", "rs", "rlib", "htaccess", "gitignore", /*"go","php",*/ // text
- "mp3", // audio
+ "wav", "mp3", "oga", // audio
- "mp4", "avi", "ogg", "wmv", "webm", // video
+ "mp4", "avi", "ogg", "ogv", "ogx", "wmv", "webm", // video
"otf", "woff2", "woff", "ttf", "eot", // fonts
@@ -83,10 +83,13 @@ var ImageFileExts = StringList{
"png", "jpg", "jpe", "jpeg", "jif", "jfi", "jfif", "svg", "bmp", "gif", "tiff", "tif", "webp", /* "apng", "bpg", */
}
var VideoFileExts = StringList{
- "mp4", "avi", "ogg", "wmv", "webm",
+ "mp4", "avi", "ogg", "ogv", "ogx", "wmv", "webm",
}
var WebVideoFileExts = StringList{
- "mp4", "avi", "ogg", "webm",
+ "mp4", "avi", "ogg", "ogv", "webm",
+}
+var WebAudioFileExts = StringList{
+ "wav", "mp3", "oga",
}
var ArchiveFileExts = StringList{
"bz2", "zip", "zipx", "gz", "7z", "tar", "cab", "rar", "kgb", "pea", "xz", "zz",
diff --git a/common/parser.go b/common/parser.go
index 59ca1526..2d115676 100644
--- a/common/parser.go
+++ b/common/parser.go
@@ -34,6 +34,9 @@ var URLClose = []byte("")
var videoOpen = []byte("")
+var audioOpen = []byte("")
var imageOpen = []byte("")
@@ -46,6 +49,7 @@ var urlReg *regexp.Regexp
const imageSizeHint = len("")
const videoSizeHint = len("") + len("?sid=") + len("&stype=") + 8
+const audioSizeHint = len("") + len("?sid=") + len("&stype=") + 8
const mentionSizeHint = len("@") + len("")
func init() {
@@ -688,6 +692,24 @@ func ParseMessage(msg string, sectionID int, sectionType string, settings *Parse
i += urlLen
lastItem = i
continue
+ case AAudio:
+ sb.Grow(audioSizeHint + (len(media.URL) + len(sectionType)*2))
+ sb.Write(audioOpen)
+ sb.WriteString(media.URL)
+ sb.Write(sidParam)
+ sb.WriteString(strconv.Itoa(sectionID))
+ sb.Write(stypeParam)
+ sb.WriteString(sectionType)
+ sb.Write(audioOpen2)
+ sb.WriteString(media.URL)
+ sb.Write(sidParam)
+ sb.WriteString(strconv.Itoa(sectionID))
+ sb.Write(stypeParam)
+ sb.WriteString(sectionType)
+ sb.Write(audioClose)
+ i += urlLen
+ lastItem = i
+ continue
case EImage:
addImage(media.URL)
continue
@@ -928,6 +950,7 @@ const (
EImage
AImage
AVideo
+ AAudio
AOther
)
@@ -981,11 +1004,14 @@ func parseMediaString(data string, settings *ParseSettings) (media MediaEmbed, o
// TODO: Write a unit test for this
return media, false
}
- if ImageFileExts.Contains(ext) {
+ switch {
+ case ImageFileExts.Contains(ext):
media.Type = AImage
- } else if WebVideoFileExts.Contains(ext) {
+ case WebVideoFileExts.Contains(ext):
media.Type = AVideo
- } else {
+ case WebAudioFileExts.Contains(ext):
+ media.Type = AAudio
+ default:
media.Type = AOther
}
return media, true
diff --git a/parser_test.go b/parser_test.go
index 19a606ad..c85defa0 100644
--- a/parser_test.go
+++ b/parser_test.go
@@ -237,6 +237,11 @@ func TestParser(t *testing.T) {
l.Add("//"+u+"/attachs/sha256hash.webm?sid=1", "")
l.Add("//"+u+"/attachs/sha256hash.webm?stype=forums", "")
+ l.Add("//"+u+"/attachs/sha256hash.mp3?sid=1&stype=forums", "")
+ l.Add("//"+u+"/attachs/sha256hash.mp3", "")
+ l.Add("//"+u+"/attachs/sha256hash.mp3?sid=1", "")
+ l.Add("//"+u+"/attachs/sha256hash.mp3?stype=forums", "")
+
l.Add("//"+u+"/attachs/sha256hash.png?sid=1&stype=forums", "")
l.Add("//"+u+"/attachs/sha256hash?sid=1&stype=forums", "[Invalid URL]")
l.Add("//"+u+"/attachs/s?sid=1&stype=forums", "[Invalid URL]")