Static images now work again after they were accidentally broken when I added Gzip Compression.
Fixed a topic desync and eliminates a number of possible race conditions in the caches. Optimised global.js by swapping out some of the unnecessary jQuery with native javascript code. Updated jQuery to version 3.1.11 Fixed the CSS on the areyousure and error templates.
This commit is contained in:
parent
61358b5449
commit
1d85224dbc
4
files.go
4
files.go
|
@ -18,6 +18,7 @@ type SFile struct
|
|||
GzipData []byte
|
||||
Pos int64
|
||||
Length int64
|
||||
GzipLength int64
|
||||
Mimetype string
|
||||
Info os.FileInfo
|
||||
FormattedModTime string
|
||||
|
@ -77,8 +78,9 @@ func add_static_file(path string, prefix string) error {
|
|||
log.Print("Adding the '" + path + "' static file")
|
||||
path = strings.TrimPrefix(path, prefix)
|
||||
log.Print("Added the '" + path + "' static file")
|
||||
gzip_data := compress_bytes_gzip(data)
|
||||
|
||||
static_files["/static" + path] = SFile{data,compress_bytes_gzip(data),0,int64(len(data)),mime.TypeByExtension(filepath.Ext(prefix + path)),f,f.ModTime().UTC().Format(http.TimeFormat)}
|
||||
static_files["/static" + path] = SFile{data,gzip_data,0,int64(len(data)),int64(len(gzip_data)),mime.TypeByExtension(filepath.Ext(prefix + path)),f,f.ModTime().UTC().Format(http.TimeFormat)}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
4
main.go
4
main.go
|
@ -138,7 +138,9 @@ func init_static_files() {
|
|||
|
||||
path = strings.TrimPrefix(path,"public/")
|
||||
log.Print("Added the '" + path + "' static file.")
|
||||
static_files["/static/" + path] = SFile{data,compress_bytes_gzip(data),0,int64(len(data)),mime.TypeByExtension(filepath.Ext("/public/" + path)),f,f.ModTime().UTC().Format(http.TimeFormat)}
|
||||
gzip_data := compress_bytes_gzip(data)
|
||||
|
||||
static_files["/static/" + path] = SFile{data,gzip_data,0,int64(len(data)),int64(len(gzip_data)),mime.TypeByExtension(filepath.Ext("/public/" + path)),f,f.ModTime().UTC().Format(http.TimeFormat)}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -59,7 +59,7 @@ func route_edit_topic(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
err = topics.Load(tid)
|
||||
if err != nil {
|
||||
LocalError("This topic no longer exists!",w,r,user)
|
||||
LocalErrorJSQ("This topic no longer exists!",w,r,user,is_js)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -153,8 +153,12 @@ func route_stick_topic(w http.ResponseWriter, r *http.Request) {
|
|||
InternalError(err,w,r)
|
||||
return
|
||||
}
|
||||
|
||||
topic.Sticky = true
|
||||
//topic.Sticky = true
|
||||
err = topics.Load(tid)
|
||||
if err != nil {
|
||||
LocalError("This topic doesn't exist!",w,r,user)
|
||||
return
|
||||
}
|
||||
http.Redirect(w,r,"/topic/" + strconv.Itoa(tid),http.StatusSeeOther)
|
||||
}
|
||||
|
||||
|
@ -188,8 +192,12 @@ func route_unstick_topic(w http.ResponseWriter, r *http.Request) {
|
|||
InternalError(err,w,r)
|
||||
return
|
||||
}
|
||||
|
||||
topic.Sticky = false
|
||||
//topic.Sticky = false
|
||||
err = topics.Load(tid)
|
||||
if err != nil {
|
||||
LocalError("This topic doesn't exist!",w,r,user)
|
||||
return
|
||||
}
|
||||
http.Redirect(w,r,"/topic/" + strconv.Itoa(tid),http.StatusSeeOther)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,13 +4,13 @@ function post_link(event)
|
|||
{
|
||||
event.preventDefault();
|
||||
var form_action = $(event.target).closest('a').attr("href");
|
||||
console.log("Form Action: " + form_action);
|
||||
//console.log("Form Action: " + form_action);
|
||||
$.ajax({ url: form_action, type: "POST", dataType: "json", data: { js: "1" } });
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
$(".open_edit").click(function(event){
|
||||
console.log("Clicked on edit");
|
||||
//console.log("Clicked on edit");
|
||||
event.preventDefault();
|
||||
$(".hide_on_edit").hide();
|
||||
$(".show_on_edit").show();
|
||||
|
@ -29,9 +29,9 @@ $(document).ready(function(){
|
|||
var topic_status_input = $('.topic_status_input').val();
|
||||
var topic_content_input = $('.topic_content_input').val();
|
||||
var form_action = $(this).closest('form').attr("action");
|
||||
console.log("New Topic Name: " + topic_name_input);
|
||||
console.log("New Topic Status: " + topic_status_input);
|
||||
console.log("Form Action: " + form_action);
|
||||
//console.log("New Topic Name: " + topic_name_input);
|
||||
//console.log("New Topic Status: " + topic_status_input);
|
||||
//console.log("Form Action: " + form_action);
|
||||
$.ajax({
|
||||
url: form_action,
|
||||
data: {
|
||||
|
@ -45,7 +45,6 @@ $(document).ready(function(){
|
|||
});
|
||||
});
|
||||
|
||||
$(".post_link").click(post_link);
|
||||
$(".delete_item").click(function(event)
|
||||
{
|
||||
post_link(event);
|
||||
|
@ -69,7 +68,7 @@ $(document).ready(function(){
|
|||
block.html(newContent);
|
||||
|
||||
var form_action = $(this).closest('a').attr("href");
|
||||
console.log("Form Action: " + form_action);
|
||||
//console.log("Form Action: " + form_action);
|
||||
$.ajax({ url: form_action, type: "POST", dataType: "json", data: { is_js: "1", edit_item: newContent }
|
||||
});
|
||||
});
|
||||
|
@ -91,7 +90,7 @@ $(document).ready(function(){
|
|||
block.html(newContent);
|
||||
|
||||
var form_action = $(this).closest('a').attr("href");
|
||||
console.log("Form Action: " + form_action);
|
||||
//console.log("Form Action: " + form_action);
|
||||
$.ajax({
|
||||
url: form_action + "?session=" + session,
|
||||
type: "POST",
|
||||
|
@ -108,10 +107,10 @@ $(document).ready(function(){
|
|||
block_parent.find('.hide_on_edit').hide();
|
||||
block_parent.find('.editable_block').show();
|
||||
block_parent.find('.editable_block').each(function(){
|
||||
var field_name = $(this).data("field");
|
||||
var field_type = $(this).data("type");
|
||||
var field_name = this.getAttribute("data-field");
|
||||
var field_type = this.getAttribute("data-type");
|
||||
if(field_type=="list") {
|
||||
var field_value = $(this).data("value");
|
||||
var field_value = this.getAttribute("data-value");
|
||||
if(field_name in form_vars) var it = form_vars[field_name];
|
||||
else var it = ['No','Yes'];
|
||||
var itLen = it.length;
|
||||
|
@ -121,9 +120,9 @@ $(document).ready(function(){
|
|||
else sel = "";
|
||||
out += "<option "+sel+"value='"+i+"'>"+it[i]+"</option>";
|
||||
}
|
||||
$(this).html("<select data-field='"+field_name+"' name='"+field_name+"'>" + out + "</select>");
|
||||
this.innerHTML = "<select data-field='"+field_name+"' name='"+field_name+"'>" + out + "</select>";
|
||||
}
|
||||
else $(this).html("<input name='"+field_name+"' value='" + $(this).text() + "' type='text'/>");
|
||||
else this.innerHTML = "<input name='"+field_name+"' value='" + this.textContent + "' type='text'/>";
|
||||
});
|
||||
block_parent.find('.show_on_edit').eq(0).show();
|
||||
|
||||
|
@ -133,38 +132,38 @@ $(document).ready(function(){
|
|||
var out_data = {is_js: "1"}
|
||||
var block_parent = $(this).closest('.editable_parent');
|
||||
var block = block_parent.find('.editable_block').each(function(){
|
||||
var field_name = $(this).data("field");
|
||||
var field_type = $(this).data("type");
|
||||
var field_name = this.getAttribute("data-field");
|
||||
var field_type = this.getAttribute("data-type");
|
||||
if(field_type == "list") var newContent = $(this).find('select :selected').text();
|
||||
else var newContent = $(this).find('input').eq(0).val();
|
||||
|
||||
$(this).html(newContent);
|
||||
this.innerHTML = newContent;
|
||||
out_data[field_name] = newContent
|
||||
});
|
||||
|
||||
var form_action = $(this).closest('a').attr("href");
|
||||
console.log("Form Action: " + form_action);
|
||||
console.log(out_data);
|
||||
//console.log("Form Action: " + form_action);
|
||||
//console.log(out_data);
|
||||
$.ajax({ url: form_action + "?session=" + session, type:"POST", dataType:"json", data: out_data });
|
||||
block_parent.find('.hide_on_edit').show();
|
||||
block_parent.find('.show_on_edit').hide();
|
||||
});
|
||||
});
|
||||
|
||||
$(this).find(".ip_item").each(function(){
|
||||
var ip = $(this).text();
|
||||
console.log("IP: " + ip);
|
||||
$(".ip_item").each(function(){
|
||||
var ip = this.textContent;
|
||||
//console.log("IP: " + ip);
|
||||
if(ip.length > 10){
|
||||
$(this).html("Show IP");
|
||||
$(this).click(function(event){
|
||||
this.innerHTML = "Show IP";
|
||||
this.onclick = function(event){
|
||||
event.preventDefault();
|
||||
$(this).text(ip);
|
||||
});
|
||||
this.textContent = ip;
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
$(this).keyup(function(event){
|
||||
if(event.which == 37) $("#prevFloat a")[0].click();
|
||||
if(event.which == 39) $("#nextFloat a")[0].click();
|
||||
});
|
||||
this.onkeyup = function(event){
|
||||
if(event.which == 37) this.querySelectorAll("#prevFloat a")[0].click();
|
||||
if(event.which == 39) this.querySelectorAll("#nextFloat a")[0].click();
|
||||
};
|
||||
});
|
File diff suppressed because one or more lines are too long
|
@ -41,13 +41,14 @@ func route_static(w http.ResponseWriter, r *http.Request){
|
|||
h := w.Header()
|
||||
h.Set("Last-Modified", file.FormattedModTime)
|
||||
h.Set("Content-Type", file.Mimetype)
|
||||
h.Set("Content-Length", strconv.FormatInt(file.Length, 10)) // Avoid doing a type conversion every time?
|
||||
//http.ServeContent(w,r,r.URL.Path,file.Info.ModTime(),file)
|
||||
//w.Write(file.Data)
|
||||
if strings.Contains(r.Header.Get("Accept-Encoding"),"gzip") {
|
||||
h.Set("Content-Encoding","gzip")
|
||||
h.Set("Content-Length", strconv.FormatInt(file.GzipLength, 10))
|
||||
io.Copy(w, bytes.NewReader(file.GzipData)) // Use w.Write instead?
|
||||
} else {
|
||||
h.Set("Content-Length", strconv.FormatInt(file.Length, 10)) // Avoid doing a type conversion every time?
|
||||
io.Copy(w, bytes.NewReader(file.Data))
|
||||
}
|
||||
//io.CopyN(w, bytes.NewReader(file.Data), static_files[r.URL.Path].Length)
|
||||
|
|
|
@ -6,9 +6,8 @@ var header_0 []byte = []byte(`<!doctype html>
|
|||
<title>`)
|
||||
var header_1 []byte = []byte(`</title>
|
||||
<link href="/static/main.css" rel="stylesheet" type="text/css">
|
||||
<script type="text/javascript" src="/static/jquery-1.12.3.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
var session = "`)
|
||||
<script type="text/javascript" src="/static/jquery-3.1.1.min.js"></script>
|
||||
<script type="text/javascript">var session = "`)
|
||||
var header_2 []byte = []byte(`";
|
||||
</script>
|
||||
<script type="text/javascript" src="/static/global.js"></script>
|
||||
|
@ -47,7 +46,8 @@ var menu_7 []byte = []byte(`
|
|||
<div style="clear: both;"></div>
|
||||
</div>`)
|
||||
var header_3 []byte = []byte(`
|
||||
<div id="back"><div id="main">`)
|
||||
<div id="back"><div id="main">
|
||||
`)
|
||||
var header_4 []byte = []byte(`<div class="alert">`)
|
||||
var header_5 []byte = []byte(`</div>`)
|
||||
var topic_0 []byte = []byte(`<div id="prevFloat" class="prev_button"><a class="prev_link" href="/topic/`)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{template "header.html" . }}
|
||||
<div class="rowblock">
|
||||
<div class="rowitem"><a>Are you sure?</a></div>
|
||||
<div class="rowitem rowhead"><a>Are you sure?</a></div>
|
||||
</div>
|
||||
<div class="rowblock">
|
||||
<div class="rowitem passive">{{.Something.Message}}<br /><br />
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{template "header.html" . }}
|
||||
<div class="rowblock">
|
||||
<div class="rowitem"><a>An error has occured</a></div>
|
||||
<div class="rowitem rowhead"><a>An error has occured</a></div>
|
||||
</div>
|
||||
<div class="rowblock">
|
||||
<div class="rowitem passive">{{.Something}}</div>
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
<head>
|
||||
<title>{{.Title}}</title>
|
||||
<link href="/static/main.css" rel="stylesheet" type="text/css">
|
||||
<script type="text/javascript" src="/static/jquery-1.12.3.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
var session = "{{.CurrentUser.Session}}";
|
||||
<script type="text/javascript" src="/static/jquery-3.1.1.min.js"></script>
|
||||
<script type="text/javascript">var session = "{{.CurrentUser.Session}}";
|
||||
</script>
|
||||
<script type="text/javascript" src="/static/global.js"></script>
|
||||
<meta name="viewport" content="width=device-width,initial-scale = 1.0, maximum-scale=1.0,user-scalable=no" />
|
||||
|
@ -13,4 +12,5 @@
|
|||
<body>
|
||||
<div class="container">
|
||||
{{template "menu.html" .}}
|
||||
<div id="back"><div id="main">{{range .NoticeList}}<div class="alert">{{.}}</div>{{end}}
|
||||
<div id="back"><div id="main">
|
||||
{{range .NoticeList}}<div class="alert">{{.}}</div>{{end}}
|
|
@ -104,8 +104,9 @@ func add_theme_static_files(themeName string) {
|
|||
|
||||
path = strings.TrimPrefix(path,"themes/" + themeName + "/public")
|
||||
log.Print("Added the '" + path + "' static file for default theme " + themeName + ".")
|
||||
gzip_data := compress_bytes_gzip(data)
|
||||
|
||||
static_files["/static" + path] = SFile{data,compress_bytes_gzip(data),0,int64(len(data)),mime.TypeByExtension(filepath.Ext("/themes/" + themeName + "/public" + path)),f,f.ModTime().UTC().Format(http.TimeFormat)}
|
||||
static_files["/static" + path] = SFile{data,gzip_data,0,int64(len(data)),int64(len(gzip_data)),mime.TypeByExtension(filepath.Ext("/themes/" + themeName + "/public" + path)),f,f.ModTime().UTC().Format(http.TimeFormat)}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -174,7 +174,6 @@ hr { color: silver; border: 1px solid silver; }
|
|||
.rowhead span { display: block; padding-top: 5px; }
|
||||
.colhead a { color: white; display: block; padding-top: 5px; }
|
||||
.colhead span { display: block; padding-top: 5px; }
|
||||
.open_edit { display: none !important; }
|
||||
.show_on_edit { display: none; }
|
||||
.rowhead .topic_status_e { display: none !important; }
|
||||
.topic_button { float: right; position: relative; top: -22px; margin-right: 2px; border-style: solid !important; }
|
||||
|
|
|
@ -171,7 +171,6 @@ hr { color: silver; border: 1px solid silver; }
|
|||
.rowhead span { display: block; padding-top: 5px; }
|
||||
.colhead a { color: white; display: block; padding-top: 5px; }
|
||||
.colhead span { display: block; padding-top: 5px; }
|
||||
.open_edit { display: none !important; }
|
||||
.show_on_edit { display: none; }
|
||||
.rowhead .topic_status_e { display: none !important; }
|
||||
.topic_button { float: right; position: relative; top: -22px; margin-right: 2px; border-style: solid !important; }
|
||||
|
|
6
topic.go
6
topic.go
|
@ -144,13 +144,15 @@ func (sts *StaticTopicStore) Load(id int) error {
|
|||
err := get_topic_stmt.QueryRow(id).Scan(&topic.Title, &topic.Content, &topic.CreatedBy, &topic.CreatedAt, &topic.Is_Closed, &topic.Sticky, &topic.ParentID, &topic.IpAddress, &topic.PostCount, &topic.LikeCount)
|
||||
if err == nil {
|
||||
sts.Set(topic)
|
||||
} else {
|
||||
sts.Remove(id)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (sts *StaticTopicStore) Set(item *Topic) error {
|
||||
sts.mu.Lock()
|
||||
item, ok := sts.items[item.ID]
|
||||
_, ok := sts.items[item.ID]
|
||||
if ok {
|
||||
sts.items[item.ID] = item
|
||||
} else if sts.length >= sts.capacity {
|
||||
|
@ -158,9 +160,9 @@ func (sts *StaticTopicStore) Set(item *Topic) error {
|
|||
return ErrStoreCapacityOverflow
|
||||
} else {
|
||||
sts.items[item.ID] = item
|
||||
sts.length++
|
||||
}
|
||||
sts.mu.Unlock()
|
||||
sts.length++
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
5
user.go
5
user.go
|
@ -118,6 +118,7 @@ func (sts *StaticUserStore) Load(id int) error {
|
|||
user := &User{ID:id,Loggedin:true}
|
||||
err := get_full_user_stmt.QueryRow(id).Scan(&user.Name, &user.Group, &user.Is_Super_Admin, &user.Session, &user.Email, &user.Avatar, &user.Message, &user.URLPrefix, &user.URLName, &user.Level, &user.Score, &user.Last_IP)
|
||||
if err != nil {
|
||||
sts.Remove(id)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -136,7 +137,7 @@ func (sts *StaticUserStore) Load(id int) error {
|
|||
|
||||
func (sts *StaticUserStore) Set(item *User) error {
|
||||
sts.mu.Lock()
|
||||
item, ok := sts.items[item.ID]
|
||||
_, ok := sts.items[item.ID]
|
||||
if ok {
|
||||
sts.items[item.ID] = item
|
||||
} else if sts.length >= sts.capacity {
|
||||
|
@ -144,9 +145,9 @@ func (sts *StaticUserStore) Set(item *User) error {
|
|||
return ErrStoreCapacityOverflow
|
||||
} else {
|
||||
sts.items[item.ID] = item
|
||||
sts.length++
|
||||
}
|
||||
sts.mu.Unlock()
|
||||
sts.length++
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue