add audio player

add wav, oga, ogv, ogx file extensions
This commit is contained in:
Azareal 2020-05-05 18:10:19 +10:00
parent 33c203600d
commit 6746c9c91b
4 changed files with 42 additions and 8 deletions

View File

@ -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)

View File

@ -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",

View File

@ -34,6 +34,9 @@ var URLClose = []byte("</a>")
var videoOpen = []byte("<video controls src=\"")
var videoOpen2 = []byte("\"><a class='attach'href=\"")
var videoClose = []byte("\"download>Attachment</a></video>")
var audioOpen = []byte("<audio controls src=\"")
var audioOpen2 = []byte("\"><a class='attach'href=\"")
var audioClose = []byte("\"download>Attachment</a></audio>")
var imageOpen = []byte("<a href=\"")
var imageOpen2 = []byte("\"><img src='")
var imageClose = []byte("'class='postImage'></a>")
@ -46,6 +49,7 @@ var urlReg *regexp.Regexp
const imageSizeHint = len("<a href=\"") + len("\"><img src='") + len("'class='postImage'></a>")
const videoSizeHint = len("<video controls src=\"") + len("\"><a class='attach'href=\"") + len("\"download>Attachment</a></video>") + len("?sid=") + len("&amp;stype=") + 8
const audioSizeHint = len("<audio controls src=\"") + len("\"><a class='attach'href=\"") + len("\"download>Attachment</a></audio>") + len("?sid=") + len("&amp;stype=") + 8
const mentionSizeHint = len("<a href='") + len("'class='mention'") + len(">@") + len("</a>")
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

View File

@ -237,6 +237,11 @@ func TestParser(t *testing.T) {
l.Add("//"+u+"/attachs/sha256hash.webm?sid=1", "<video controls src=\""+fs+"/attachs/sha256hash.webm?sid=1&amp;stype=forums\"><a class='attach'href=\""+fs+"/attachs/sha256hash.webm?sid=1&amp;stype=forums\"download>Attachment</a></video>")
l.Add("//"+u+"/attachs/sha256hash.webm?stype=forums", "<video controls src=\""+fs+"/attachs/sha256hash.webm?sid=1&amp;stype=forums\"><a class='attach'href=\""+fs+"/attachs/sha256hash.webm?sid=1&amp;stype=forums\"download>Attachment</a></video>")
l.Add("//"+u+"/attachs/sha256hash.mp3?sid=1&stype=forums", "<audio controls src=\""+fs+"/attachs/sha256hash.mp3?sid=1&amp;stype=forums\"><a class='attach'href=\""+fs+"/attachs/sha256hash.mp3?sid=1&amp;stype=forums\"download>Attachment</a></audio>")
l.Add("//"+u+"/attachs/sha256hash.mp3", "<audio controls src=\""+fs+"/attachs/sha256hash.mp3?sid=1&amp;stype=forums\"><a class='attach'href=\""+fs+"/attachs/sha256hash.mp3?sid=1&amp;stype=forums\"download>Attachment</a></audio>")
l.Add("//"+u+"/attachs/sha256hash.mp3?sid=1", "<audio controls src=\""+fs+"/attachs/sha256hash.mp3?sid=1&amp;stype=forums\"><a class='attach'href=\""+fs+"/attachs/sha256hash.mp3?sid=1&amp;stype=forums\"download>Attachment</a></audio>")
l.Add("//"+u+"/attachs/sha256hash.mp3?stype=forums", "<audio controls src=\""+fs+"/attachs/sha256hash.mp3?sid=1&amp;stype=forums\"><a class='attach'href=\""+fs+"/attachs/sha256hash.mp3?sid=1&amp;stype=forums\"download>Attachment</a></audio>")
l.Add("//"+u+"/attachs/sha256hash.png?sid=1&stype=forums", "<a href=\""+fs+"/attachs/sha256hash.png?sid=1&amp;stype=forums\"><img src='"+fs+"/attachs/sha256hash.png?sid=1&amp;stype=forums'class='postImage'></a>")
l.Add("//"+u+"/attachs/sha256hash?sid=1&stype=forums", "<red>[Invalid URL]</red>")
l.Add("//"+u+"/attachs/s?sid=1&stype=forums", "<red>[Invalid URL]</red>")