cover dynamically loaded static resources
cover default noavatars
This commit is contained in:
parent
43d72e6f3b
commit
26ad61057a
|
@ -182,17 +182,6 @@ var noavatarCache200 []string
|
||||||
var noavatarCache48 []string
|
var noavatarCache48 []string
|
||||||
|
|
||||||
func ProcessConfig() (err error) {
|
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.
|
// Strip these unnecessary bits, if we find them.
|
||||||
Site.URL = strings.TrimPrefix(Site.URL, "http://")
|
Site.URL = strings.TrimPrefix(Site.URL, "http://")
|
||||||
Site.URL = strings.TrimPrefix(Site.URL, "https://")
|
Site.URL = strings.TrimPrefix(Site.URL, "https://")
|
||||||
|
@ -257,6 +246,16 @@ func ProcessConfig() (err error) {
|
||||||
if Config.StaticResBase != "" {
|
if Config.StaticResBase != "" {
|
||||||
StaticFiles.Prefix = 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 {
|
if Config.PostIPCutoff == 0 {
|
||||||
Config.PostIPCutoff = 120 // Default cutoff
|
Config.PostIPCutoff = 120 // Default cutoff
|
||||||
|
|
|
@ -788,7 +788,7 @@ func buildNoavatar(uid, width int) string {
|
||||||
} else if width == 48 {
|
} else if width == 48 {
|
||||||
return noavatarCache48[uid]
|
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)
|
return strings.Replace(strings.Replace(Config.Noavatar, "{id}", strconv.Itoa(uid), 1), "{width}", strconv.Itoa(width), 1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -896,11 +896,11 @@ function mainInit(){
|
||||||
if(xr!=null) {
|
if(xr!=null) {
|
||||||
for(let res of xr.split(",")) {
|
for(let res of xr.split(",")) {
|
||||||
let pro;
|
let pro;
|
||||||
if(stripQ(getExt(res))=="css") pro = asyncGetSheet("/s/"+res)
|
if(stripQ(getExt(res))=="css") pro = asyncGetSheet(pre+res)
|
||||||
else pro = asyncGetScript("/s/"+res)
|
else pro = asyncGetScript(pre+res)
|
||||||
pro.then(() => log("Loaded "+res))
|
pro.then(() => log("Loaded "+res))
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
log("Unable to get '"+res+"'",e);
|
log("Unable to get "+res,e);
|
||||||
console.trace();
|
console.trace();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@ if(tmplInits===undefined) var tmplInits={};
|
||||||
var tmplPhrases=[]; // [key] array of phrases indexed by order of use
|
var tmplPhrases=[]; // [key] array of phrases indexed by order of use
|
||||||
var hooks={};
|
var hooks={};
|
||||||
var ranInitHooks={}
|
var ranInitHooks={}
|
||||||
var log = console.log;
|
var log=console.log;
|
||||||
|
var pre="/s/";
|
||||||
|
|
||||||
function runHook(name,...args) {
|
function runHook(name,...args) {
|
||||||
if(!(name in hooks)) {
|
if(!(name in hooks)) {
|
||||||
|
@ -16,7 +17,7 @@ function runHook(name,...args) {
|
||||||
|
|
||||||
let hook = hooks[name];
|
let hook = hooks[name];
|
||||||
let o;
|
let o;
|
||||||
for (const index in hook) o = hook[index](...args);
|
for(const index in hook) o = hook[index](...args);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
function addHook(name,h) {
|
function addHook(name,h) {
|
||||||
|
@ -32,7 +33,10 @@ function runInitHook(name,...args) {
|
||||||
}
|
}
|
||||||
function addInitHook(name,h) {
|
function addInitHook(name,h) {
|
||||||
addHook(name,h);
|
addHook(name,h);
|
||||||
if(name in ranInitHooks) h();
|
if(name in ranInitHooks) {
|
||||||
|
log("Delay running "+name);
|
||||||
|
h();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Temporary hack for templates
|
// Temporary hack for templates
|
||||||
|
@ -52,7 +56,6 @@ function asyncGetScript(src) {
|
||||||
isAbort ? reject(e) : resolve();
|
isAbort ? reject(e) : resolve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
script.onerror = e => {
|
script.onerror = e => {
|
||||||
reject(e);
|
reject(e);
|
||||||
};
|
};
|
||||||
|
@ -66,9 +69,9 @@ function asyncGetScript(src) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function notifyOnScript(src) {
|
function notifyOnScript(src) {
|
||||||
src = "/s/"+src;
|
src = pre+src;
|
||||||
return new Promise((resolve,reject) => {
|
return new Promise((resolve,reject) => {
|
||||||
let ss = src.replace("/s/","");
|
let ss = src.replace(pre,"");
|
||||||
try {
|
try {
|
||||||
let ssp = ss.charAt(0).toUpperCase() + ss.slice(1)
|
let ssp = ss.charAt(0).toUpperCase() + ss.slice(1)
|
||||||
log("ssp",ssp)
|
log("ssp",ssp)
|
||||||
|
@ -119,8 +122,8 @@ function loadScript(name,h,fail) {
|
||||||
let parts = value.split("; current_theme=");
|
let parts = value.split("; current_theme=");
|
||||||
if(parts.length==2) fname += "_"+parts.pop().split(";").shift();
|
if(parts.length==2) fname += "_"+parts.pop().split(";").shift();
|
||||||
|
|
||||||
let url = `/s/${fname}.js`
|
let url = pre+fname+".js"
|
||||||
let iurl = `/s/${name}.js`
|
let iurl = pre+name+".js"
|
||||||
asyncGetScript(url)
|
asyncGetScript(url)
|
||||||
.then(h).catch(e => {
|
.then(h).catch(e => {
|
||||||
log("Unable to get "+url,e);
|
log("Unable to get "+url,e);
|
||||||
|
@ -209,10 +212,11 @@ function fetchPhrases(plist) {
|
||||||
.then(d => {
|
.then(d => {
|
||||||
log("me",d);
|
log("me",d);
|
||||||
me=d;
|
me=d;
|
||||||
|
pre=d.StaticPrefix;
|
||||||
runInitHook("pre_init");
|
runInitHook("pre_init");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
me={User:{ID:0,S:""},Site:{"MaxRequestSize":0}};
|
me={User:{ID:0,S:""},Site:{"MaxReqSize":0}};
|
||||||
runInitHook("pre_init");
|
runInitHook("pre_init");
|
||||||
}
|
}
|
||||||
})()
|
})()
|
|
@ -23,7 +23,7 @@ var imageExts = ["png","jpg","jpe","jpeg","jif","jfi","jfif","svg","bmp","gif","
|
||||||
log("file "+i,files[i]);
|
log("file "+i,files[i]);
|
||||||
totalSize += files[i]["size"];
|
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<files.length; i++) {
|
for(let i=0; i<files.length; i++) {
|
||||||
let fname = files[i]["name"];
|
let fname = files[i]["name"];
|
||||||
|
|
|
@ -229,7 +229,8 @@ type JsonMe struct {
|
||||||
|
|
||||||
// We don't want to expose too much information about the site, so we'll make this a small subset of c.site
|
// We don't want to expose too much information about the site, so we'll make this a small subset of c.site
|
||||||
type MeSite struct {
|
type MeSite struct {
|
||||||
MaxRequestSize int
|
MaxReqSize int
|
||||||
|
StaticPrefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
// APIMe returns information about the current logged-in user
|
// APIMe returns information about the current logged-in user
|
||||||
|
@ -243,7 +244,7 @@ func APIMe(w http.ResponseWriter, r *http.Request, u *c.User) c.RouteError {
|
||||||
// TODO: Use this header anywhere with a user check?
|
// TODO: Use this header anywhere with a user check?
|
||||||
h.Set("Cache-Control", "private")
|
h.Set("Cache-Control", "private")
|
||||||
|
|
||||||
me := JsonMe{u.Me(), MeSite{c.Site.MaxRequestSize}}
|
me := JsonMe{u.Me(), MeSite{c.Site.MaxRequestSize, c.StaticFiles.Prefix}}
|
||||||
jsonBytes, err := json.Marshal(me)
|
jsonBytes, err := json.Marshal(me)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.InternalErrorJS(err, w, r)
|
return c.InternalErrorJS(err, w, r)
|
||||||
|
|
|
@ -21,16 +21,16 @@
|
||||||
addInitHook("end_init", () => {
|
addInitHook("end_init", () => {
|
||||||
let loggedIn = document.head.querySelector("[property='x-mem']")!=null;
|
let loggedIn = document.head.querySelector("[property='x-mem']")!=null;
|
||||||
if(loggedIn) {
|
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?
|
// Is there we way we can append instead? Maybe, an editor plugin?
|
||||||
attachItemCallback = function(attachItem) {
|
attachItemCallback = function(attachItem) {
|
||||||
let currentContent = $('#input_content').trumbowyg('html');
|
let currentContent = $('#input_content').trumbowyg('html');
|
||||||
$('#input_content').trumbowyg('html', currentContent);
|
$('#input_content').trumbowyg('html',currentContent);
|
||||||
}
|
}
|
||||||
quoteItemCallback = function() {
|
quoteItemCallback = function() {
|
||||||
let currentContent = $('#input_content').trumbowyg('html');
|
let currentContent = $('#input_content').trumbowyg('html');
|
||||||
$('#input_content').trumbowyg('html', currentContent);
|
$('#input_content').trumbowyg('html',currentContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
$(".topic_name_row").click(() => {
|
$(".topic_name_row").click(() => {
|
||||||
|
|
Loading…
Reference in New Issue