add flif, heif, heic, bpg and opus to allowed file extensions

add flac web audio extension
eliminate aloocs with inqbuild and inqbuildstr
This commit is contained in:
Azareal 2021-02-19 13:28:20 +10:00
parent b66aeac966
commit 8decc0c1a8
3 changed files with 52 additions and 21 deletions

View File

@ -11,6 +11,7 @@ import (
"io" "io"
"log" "log"
"os" "os"
"strconv"
//"sync" //"sync"
"sync/atomic" "sync/atomic"
"time" "time"
@ -68,11 +69,11 @@ type StringList []string
// TODO: Let admins manage this from the Control Panel // TODO: Let admins manage this from the Control Panel
// apng is commented out for now, as we have no way of re-encoding it into a smaller file // apng is commented out for now, as we have no way of re-encoding it into a smaller file
var AllowedFileExts = StringList{ var AllowedFileExts = StringList{
"png", "jpg", "jpe", "jpeg", "jif", "jfi", "jfif", "svg", "bmp", "gif", "tiff", "tif", "webp", "apng", "avif", /*"bpg", "heif", */ // images (encodable) + apng (browser support) + bpg + avif "png", "jpg", "jpe", "jpeg", "jif", "jfi", "jfif", "svg", "bmp", "gif", "tiff", "tif", "webp", "apng", "avif", "flif", "heif", "heic", "bpg", // images (encodable) + apng (browser support) + bpg + avif + flif + heif / heic
"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 "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
"wav", "mp3", "oga", "m4a", "flac", "ac3", "aac", // audio "wav", "mp3", "oga", "m4a", "flac", "ac3", "aac", "opus", // audio
"mp4", "avi", "ogg", "ogv", "ogx", "wmv", "webm", "flv", "f4v", "xvid", "mov", "movie", "qt", // video "mp4", "avi", "ogg", "ogv", "ogx", "wmv", "webm", "flv", "f4v", "xvid", "mov", "movie", "qt", // video
@ -95,7 +96,7 @@ var WebVideoFileExts = StringList{
"mp4", "avi", "ogg", "ogv", "webm", "mp4", "avi", "ogg", "ogv", "webm",
} }
var WebAudioFileExts = StringList{ var WebAudioFileExts = StringList{
"wav", "mp3", "oga", "m4a", "wav", "mp3", "oga", "m4a", "flac",
} }
var ArchiveFileExts = StringList{ var ArchiveFileExts = StringList{
"bz2", "zip", "zipx", "gz", "7z", "tar", "cab", "rar", "kgb", "pea", "xz", "zz", "tgz", "xpi", "bz2", "zip", "zipx", "gz", "7z", "tar", "cab", "rar", "kgb", "pea", "xz", "zz", "tgz", "xpi",
@ -221,3 +222,49 @@ func eachall(stmt *sql.Stmt, f func(r *sql.Rows) error) error {
} }
return rows.Err() return rows.Err()
} }
var qcache = []string{0: "?", 1: "?,?", 2: "?,?,?", 3: "?,?,?,?", 4: "?,?,?,?,?", 5: "?,?,?,?,?,?"}
func inqbuild(ids []int) ([]interface{}, string) {
if len(ids) < 5 {
idList := make([]interface{}, len(ids))
for i, id := range ids {
idList[i] = strconv.Itoa(id)
}
return idList, qcache[len(ids)-1]
}
var q string
idList := make([]interface{}, len(ids))
for i, id := range ids {
idList[i] = strconv.Itoa(id)
if i == 0 {
q = "?"
} else {
q += ",?"
}
}
return idList, q
}
func inqbuildstr(strs []string) ([]interface{}, string) {
if len(strs) < 5 {
idList := make([]interface{}, len(strs))
for i, id := range strs {
idList[i] = id
}
return idList, qcache[len(strs)-1]
}
var q string
idList := make([]interface{}, len(strs))
for i, id := range strs {
idList[i] = id
if i == 0 {
q = "?"
} else {
q += ",?"
}
}
return idList, q
}

View File

@ -116,15 +116,7 @@ func (s *DefaultPollStore) BulkGetMap(ids []int) (list map[int]*Poll, err error)
return list, nil return list, nil
} }
// TODO: Add a function for the qlist stuff idList, q := inqbuild(ids)
var q string
idList := make([]interface{}, len(ids))
for i, id := range ids {
idList[i] = strconv.Itoa(id)
q += "?,"
}
q = q[0 : len(q)-1]
rows, err := qgen.NewAcc().Select("polls").Columns("pollID,parentID,parentTable,type,options,votes").Where("pollID IN(" + q + ")").Query(idList...) rows, err := qgen.NewAcc().Select("polls").Columns("pollID,parentID,parentTable,type,options,votes").Where("pollID IN(" + q + ")").Query(idList...)
if err != nil { if err != nil {
return list, err return list, err

View File

@ -151,15 +151,7 @@ func (s *DefaultTopicStore) BulkGetMap(ids []int) (list map[int]*Topic, err erro
return list, nil return list, nil
} }
// TODO: Add a function for the qlist stuff idList, q := inqbuild(ids)
var q string
idList := make([]interface{}, len(ids))
for i, id := range ids {
idList[i] = strconv.Itoa(id)
q += "?,"
}
q = q[0 : len(q)-1]
rows, err := qgen.NewAcc().Select("topics").Columns("tid,title,content,createdBy,createdAt,lastReplyBy,lastReplyAt,lastReplyID,is_closed,sticky,parentID,ip,views,postCount,likeCount,attachCount,poll,data").Where("tid IN(" + q + ")").Query(idList...) rows, err := qgen.NewAcc().Select("topics").Columns("tid,title,content,createdBy,createdAt,lastReplyBy,lastReplyAt,lastReplyID,is_closed,sticky,parentID,ip,views,postCount,likeCount,attachCount,poll,data").Where("tid IN(" + q + ")").Query(idList...)
if err != nil { if err != nil {
return list, err return list, err