2017-11-10 03:33:11 +00:00
package common
2017-11-11 23:34:27 +00:00
import (
"database/sql"
2017-11-13 05:22:37 +00:00
"log"
2017-11-12 03:29:05 +00:00
"../query_gen/lib"
2017-11-11 23:34:27 +00:00
)
2017-11-10 03:33:11 +00:00
2017-11-11 04:06:16 +00:00
// nolint I don't want to write comments for each of these o.o
const Hour int = 60 * 60
const Day int = Hour * 24
const Week int = Day * 7
const Month int = Day * 30
const Year int = Day * 365
const Kilobyte int = 1024
const Megabyte int = Kilobyte * 1024
const Gigabyte int = Megabyte * 1024
const Terabyte int = Gigabyte * 1024
const Petabyte int = Terabyte * 1024
const SaltLength int = 32
const SessionLength int = 80
var TmplPtrMap = make ( map [ string ] interface { } )
2017-11-10 03:33:11 +00:00
// ErrNoRows is an alias of sql.ErrNoRows, just in case we end up with non-database/sql datastores
var ErrNoRows = sql . ErrNoRows
2017-11-11 04:06:16 +00:00
// ? - Make this more customisable?
var ExternalSites = map [ string ] string {
"YT" : "https://www.youtube.com/" ,
}
type StringList [ ] string
// ? - Should we allow users to upload .php or .go files? It could cause security issues. We could store them with a mangled extension to render them inert
// TODO: Let admins manage this from the Control Panel
var AllowedFileExts = StringList {
"png" , "jpg" , "jpeg" , "svg" , "bmp" , "gif" , "tif" , "webp" , "apng" , // images
"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" , // text
"mp3" , "mp4" , "avi" , "wmv" , "webm" , // video
"otf" , "woff2" , "woff" , "ttf" , "eot" , // fonts
}
var ImageFileExts = StringList {
"png" , "jpg" , "jpeg" , "svg" , "bmp" , "gif" , "tif" , "webp" , "apng" ,
}
var ArchiveFileExts = StringList {
"bz2" , "zip" , "gz" , "7z" , "tar" , "cab" ,
}
var ExecutableFileExts = StringList {
"exe" , "jar" , "phar" , "shar" , "iso" ,
}
// TODO: Write a test for this
func ( slice StringList ) Contains ( needle string ) bool {
for _ , item := range slice {
if item == needle {
return true
}
}
return false
}
2017-11-12 03:29:05 +00:00
type dbInits [ ] func ( acc * qgen . Accumulator ) error
2017-11-11 04:06:16 +00:00
2017-11-11 23:34:27 +00:00
var DbInits dbInits
2017-11-11 04:06:16 +00:00
2017-11-11 23:34:27 +00:00
func ( inits dbInits ) Run ( ) error {
2017-11-11 04:06:16 +00:00
for _ , init := range inits {
2017-11-12 03:29:05 +00:00
acc := qgen . Builder . Accumulator ( )
err := init ( acc )
2017-11-11 04:06:16 +00:00
if err != nil {
return err
}
}
return nil
}
2017-11-12 03:29:05 +00:00
func ( inits dbInits ) Add ( init ... func ( acc * qgen . Accumulator ) error ) {
2017-11-11 23:34:27 +00:00
DbInits = dbInits ( append ( DbInits , init ... ) )
2017-11-11 04:06:16 +00:00
}
2017-11-13 05:22:37 +00:00
func debugDetail ( args ... interface { } ) {
if Dev . SuperDebug {
log . Print ( args ... )
}
}
func debugDetailf ( str string , args ... interface { } ) {
if Dev . SuperDebug {
log . Printf ( str , args ... )
}
}
func debugLog ( args ... interface { } ) {
if Dev . DebugMode {
log . Print ( args ... )
}
}
func debugLogf ( str string , args ... interface { } ) {
if Dev . DebugMode {
log . Printf ( str , args ... )
}
}
2017-12-19 03:53:13 +00:00
// TODO: Make a neater API for this
var routeMapEnum map [ string ] int
var reverseRouteMapEnum map [ int ] string
func SetRouteMapEnum ( rme map [ string ] int ) {
routeMapEnum = rme
}
func SetReverseRouteMapEnum ( rrme map [ int ] string ) {
reverseRouteMapEnum = rrme
}