From 26ad61057a13c8c00eeec4edbfeb20f36785d7d1 Mon Sep 17 00:00:00 2001 From: Azareal Date: Fri, 31 Jul 2020 09:40:14 +1000 Subject: [PATCH] cover dynamically loaded static resources cover default noavatars --- common/site.go | 21 ++++++++++----------- common/user.go | 2 +- public/global.js | 6 +++--- public/init.js | 22 +++++++++++++--------- public/member.js | 2 +- routes/api.go | 5 +++-- themes/cosora/public/misc.js | 6 +++--- 7 files changed, 34 insertions(+), 30 deletions(-) diff --git a/common/site.go b/common/site.go index 2dc49301..f0b878ca 100644 --- a/common/site.go +++ b/common/site.go @@ -182,17 +182,6 @@ var noavatarCache200 []string var noavatarCache48 []string func ProcessConfig() (err error) { - if !Config.DisableDefaultNoavatar { - noavatarCache200 = make([]string, 5) - noavatarCache48 = make([]string, 5) - for i := 0; i < 5; i++ { - noavatarCache200[i] = "/s/n" + strconv.Itoa(i) + "-" + strconv.Itoa(200) + ".png?i=0" - noavatarCache48[i] = "/s/n" + strconv.Itoa(i) + "-" + strconv.Itoa(48) + ".png?i=0" - } - } - Config.Noavatar = strings.Replace(Config.Noavatar, "{site_url}", Site.URL, -1) - guestAvatar = GuestAvatar{buildNoavatar(0, 200), buildNoavatar(0, 48)} - // Strip these unnecessary bits, if we find them. Site.URL = strings.TrimPrefix(Site.URL, "http://") Site.URL = strings.TrimPrefix(Site.URL, "https://") @@ -257,6 +246,16 @@ func ProcessConfig() (err error) { if Config.StaticResBase != "" { StaticFiles.Prefix = Config.StaticResBase } + if !Config.DisableDefaultNoavatar { + noavatarCache200 = make([]string, 5) + noavatarCache48 = make([]string, 5) + for i := 0; i < 5; i++ { + noavatarCache200[i] = StaticFiles.Prefix + "n" + strconv.Itoa(i) + "-" + strconv.Itoa(200) + ".png?i=0" + noavatarCache48[i] = StaticFiles.Prefix + "n" + strconv.Itoa(i) + "-" + strconv.Itoa(48) + ".png?i=0" + } + } + Config.Noavatar = strings.Replace(Config.Noavatar, "{site_url}", Site.URL, -1) + guestAvatar = GuestAvatar{buildNoavatar(0, 200), buildNoavatar(0, 48)} if Config.PostIPCutoff == 0 { Config.PostIPCutoff = 120 // Default cutoff diff --git a/common/user.go b/common/user.go index c8895675..c57531e5 100644 --- a/common/user.go +++ b/common/user.go @@ -788,7 +788,7 @@ func buildNoavatar(uid, width int) string { } else if width == 48 { return noavatarCache48[uid] } - return "/s/n" + strconv.Itoa(uid) + "-" + strconv.Itoa(width) + ".png?i=0" + return StaticFiles.Prefix + "n" + strconv.Itoa(uid) + "-" + strconv.Itoa(width) + ".png?i=0" } return strings.Replace(strings.Replace(Config.Noavatar, "{id}", strconv.Itoa(uid), 1), "{width}", strconv.Itoa(width), 1) } diff --git a/public/global.js b/public/global.js index 4dac62ed..ecbd9175 100644 --- a/public/global.js +++ b/public/global.js @@ -896,11 +896,11 @@ function mainInit(){ if(xr!=null) { for(let res of xr.split(",")) { let pro; - if(stripQ(getExt(res))=="css") pro = asyncGetSheet("/s/"+res) - else pro = asyncGetScript("/s/"+res) + if(stripQ(getExt(res))=="css") pro = asyncGetSheet(pre+res) + else pro = asyncGetScript(pre+res) pro.then(() => log("Loaded "+res)) .catch(e => { - log("Unable to get '"+res+"'",e); + log("Unable to get "+res,e); console.trace(); }); } diff --git a/public/init.js b/public/init.js index 1316285f..d50423c6 100644 --- a/public/init.js +++ b/public/init.js @@ -5,7 +5,8 @@ if(tmplInits===undefined) var tmplInits={}; var tmplPhrases=[]; // [key] array of phrases indexed by order of use var hooks={}; var ranInitHooks={} -var log = console.log; +var log=console.log; +var pre="/s/"; function runHook(name,...args) { if(!(name in hooks)) { @@ -16,7 +17,7 @@ function runHook(name,...args) { let hook = hooks[name]; let o; - for (const index in hook) o = hook[index](...args); + for(const index in hook) o = hook[index](...args); return o; } function addHook(name,h) { @@ -32,7 +33,10 @@ function runInitHook(name,...args) { } function addInitHook(name,h) { addHook(name,h); - if(name in ranInitHooks) h(); + if(name in ranInitHooks) { + log("Delay running "+name); + h(); + } } // Temporary hack for templates @@ -52,7 +56,6 @@ function asyncGetScript(src) { isAbort ? reject(e) : resolve(); } } - script.onerror = e => { reject(e); }; @@ -66,9 +69,9 @@ function asyncGetScript(src) { } function notifyOnScript(src) { - src = "/s/"+src; + src = pre+src; return new Promise((resolve,reject) => { - let ss = src.replace("/s/",""); + let ss = src.replace(pre,""); try { let ssp = ss.charAt(0).toUpperCase() + ss.slice(1) log("ssp",ssp) @@ -119,8 +122,8 @@ function loadScript(name,h,fail) { let parts = value.split("; current_theme="); if(parts.length==2) fname += "_"+parts.pop().split(";").shift(); - let url = `/s/${fname}.js` - let iurl = `/s/${name}.js` + let url = pre+fname+".js" + let iurl = pre+name+".js" asyncGetScript(url) .then(h).catch(e => { log("Unable to get "+url,e); @@ -209,10 +212,11 @@ function fetchPhrases(plist) { .then(d => { log("me",d); me=d; + pre=d.StaticPrefix; runInitHook("pre_init"); }); } else { - me={User:{ID:0,S:""},Site:{"MaxRequestSize":0}}; + me={User:{ID:0,S:""},Site:{"MaxReqSize":0}}; runInitHook("pre_init"); } })() \ No newline at end of file diff --git a/public/member.js b/public/member.js index 17c4ab3a..9fb737d7 100644 --- a/public/member.js +++ b/public/member.js @@ -23,7 +23,7 @@ var imageExts = ["png","jpg","jpe","jpeg","jif","jfi","jfif","svg","bmp","gif"," log("file "+i,files[i]); totalSize += files[i]["size"]; } - if(totalSize > me.Site.MaxRequestSize) throw("You can't upload this much at once, max: "+me.Site.MaxRequestSize); + if(totalSize > me.Site.MaxReqSize) throw("You can't upload this much at once, max: "+me.Site.MaxReqSize); for(let i=0; i { let loggedIn = document.head.querySelector("[property='x-mem']")!=null; if(loggedIn) { - if(navigator.userAgent.indexOf("Firefox")!=-1) $.trumbowyg.svgPath = "/s/trumbowyg/ui/icons.svg"; + if(navigator.userAgent.indexOf("Firefox")!=-1) $.trumbowyg.svgPath = pre+"trumbowyg/ui/icons.svg"; // Is there we way we can append instead? Maybe, an editor plugin? attachItemCallback = function(attachItem) { let currentContent = $('#input_content').trumbowyg('html'); - $('#input_content').trumbowyg('html', currentContent); + $('#input_content').trumbowyg('html',currentContent); } quoteItemCallback = function() { let currentContent = $('#input_content').trumbowyg('html'); - $('#input_content').trumbowyg('html', currentContent); + $('#input_content').trumbowyg('html',currentContent); } $(".topic_name_row").click(() => {