Fix the superfluous header errors.
Shorten the query parameter for phrases. Move the cache control header in the phrase route down to avoid caching errors improperly. Fixes #53
This commit is contained in:
parent
101b1c51df
commit
f7720575d5
|
@ -185,7 +185,7 @@ function initPhrases(loggedIn, panel = false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchPhrases(plist) {
|
function fetchPhrases(plist) {
|
||||||
fetch("/api/phrases/?query="+plist, {cache: "no-cache"})
|
fetch("/api/phrases/?q="+plist, {cache: "no-cache"})
|
||||||
.then((resp) => resp.json())
|
.then((resp) => resp.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.log("loaded phrase endpoint data");
|
console.log("loaded phrase endpoint data");
|
||||||
|
|
19
routes.go
19
routes.go
|
@ -193,22 +193,18 @@ func routeAPIPhrases(w http.ResponseWriter, r *http.Request, user c.User) c.Rout
|
||||||
// TODO: Don't make this too JSON dependent so that we can swap in newer more efficient formats
|
// TODO: Don't make this too JSON dependent so that we can swap in newer more efficient formats
|
||||||
h := w.Header()
|
h := w.Header()
|
||||||
h.Set("Content-Type", "application/json")
|
h.Set("Content-Type", "application/json")
|
||||||
h.Set("Cache-Control", cacheControlMaxAge) //Cache-Control: max-age=31536000
|
|
||||||
|
|
||||||
err := r.ParseForm()
|
err := r.ParseForm()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.PreErrorJS("Bad Form", w, r)
|
return c.PreErrorJS("Bad Form", w, r)
|
||||||
}
|
}
|
||||||
query := r.FormValue("query")
|
query := r.FormValue("q")
|
||||||
if query == "" {
|
if query == "" {
|
||||||
return c.PreErrorJS("No query provided", w, r)
|
return c.PreErrorJS("No query provided", w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
var negations []string
|
var negations, positives []string
|
||||||
var positives []string
|
for _, queryBit := range strings.Split(query, ",") {
|
||||||
|
|
||||||
queryBits := strings.Split(query, ",")
|
|
||||||
for _, queryBit := range queryBits {
|
|
||||||
queryBit = strings.TrimSpace(queryBit)
|
queryBit = strings.TrimSpace(queryBit)
|
||||||
if queryBit[0] == '!' && len(queryBit) > 1 {
|
if queryBit[0] == '!' && len(queryBit) > 1 {
|
||||||
queryBit = strings.TrimPrefix(queryBit, "!")
|
queryBit = strings.TrimPrefix(queryBit, "!")
|
||||||
|
@ -230,6 +226,7 @@ func routeAPIPhrases(w http.ResponseWriter, r *http.Request, user c.User) c.Rout
|
||||||
if len(positives) == 0 {
|
if len(positives) == 0 {
|
||||||
return c.PreErrorJS("You haven't requested any phrases", w, r)
|
return c.PreErrorJS("You haven't requested any phrases", w, r)
|
||||||
}
|
}
|
||||||
|
h.Set("Cache-Control", cacheControlMaxAge) //Cache-Control: max-age=31536000
|
||||||
|
|
||||||
var etag string
|
var etag string
|
||||||
_, ok := w.(c.GzipResponseWriter)
|
_, ok := w.(c.GzipResponseWriter)
|
||||||
|
@ -240,6 +237,7 @@ func routeAPIPhrases(w http.ResponseWriter, r *http.Request, user c.User) c.Rout
|
||||||
}
|
}
|
||||||
|
|
||||||
var plist map[string]string
|
var plist map[string]string
|
||||||
|
var doneHead = false
|
||||||
var posLoop = func(positive string) c.RouteError {
|
var posLoop = func(positive string) c.RouteError {
|
||||||
// ! Constrain it to a subset of phrases for now
|
// ! Constrain it to a subset of phrases for now
|
||||||
for _, item := range phraseWhitelist {
|
for _, item := range phraseWhitelist {
|
||||||
|
@ -251,13 +249,13 @@ func routeAPIPhrases(w http.ResponseWriter, r *http.Request, user c.User) c.Rout
|
||||||
} else {
|
} else {
|
||||||
ok = true
|
ok = true
|
||||||
w.Header().Set("ETag", etag)
|
w.Header().Set("ETag", etag)
|
||||||
if match := r.Header.Get("If-None-Match"); match != "" {
|
match := r.Header.Get("If-None-Match")
|
||||||
if strings.Contains(match, etag) {
|
if match != "" && !doneHead && strings.Contains(match, etag) {
|
||||||
w.WriteHeader(http.StatusNotModified)
|
w.WriteHeader(http.StatusNotModified)
|
||||||
|
doneHead = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -309,7 +307,6 @@ func routeAPIPhrases(w http.ResponseWriter, r *http.Request, user c.User) c.Rout
|
||||||
return c.InternalError(err, w, r)
|
return c.InternalError(err, w, r)
|
||||||
}
|
}
|
||||||
w.Write(jsonBytes)
|
w.Write(jsonBytes)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,6 @@ func UsersEdit(w http.ResponseWriter, r *http.Request, user c.User, suid string)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return c.InternalError(err, w, r)
|
return c.InternalError(err, w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
if targetUser.IsAdmin && !user.IsAdmin {
|
if targetUser.IsAdmin && !user.IsAdmin {
|
||||||
return c.LocalError("Only administrators can edit the account of an administrator.", w, r, user)
|
return c.LocalError("Only administrators can edit the account of an administrator.", w, r, user)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<div class="formrow real_first_child">
|
<div class="formrow real_first_child">
|
||||||
<div class="formitem formlabel"><a>{{lang "create_topic_board"}}</a></div>
|
<div class="formitem formlabel"><a>{{lang "create_topic_board"}}</a></div>
|
||||||
<div class="formitem"><select form="quick_post_form" id="topic_board_input" name="topic-board">
|
<div class="formitem"><select form="quick_post_form" id="topic_board_input" name="topic-board">
|
||||||
{{range .ItemList}}<option {{if eq .ID $.FID}}selected{{end}} value="{{.ID}}">{{.Name}}</option>{{end}}
|
{{range .ItemList}}<option{{if eq .ID $.FID}} selected{{end}} value="{{.ID}}">{{.Name}}</option>{{end}}
|
||||||
</select></div>
|
</select></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="formrow">
|
<div class="formrow">
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
{{range .Header.PreScriptsAsync}}
|
{{range .Header.PreScriptsAsync}}
|
||||||
<script async type="text/javascript" src="/static/{{.}}"></script>{{end}}
|
<script async type="text/javascript" src="/static/{{.}}"></script>{{end}}
|
||||||
<meta property="x-loggedin" content="{{.CurrentUser.Loggedin}}" />
|
<meta property="x-loggedin" content="{{.CurrentUser.Loggedin}}" />
|
||||||
<script type="text/javascript" src="/static/init.js?i=7"></script>
|
<script type="text/javascript" src="/static/init.js?i=8"></script>
|
||||||
{{range .Header.ScriptsAsync}}
|
{{range .Header.ScriptsAsync}}
|
||||||
<script async type="text/javascript" src="/static/{{.}}"></script>{{end}}
|
<script async type="text/javascript" src="/static/{{.}}"></script>{{end}}
|
||||||
<script type="text/javascript" src="/static/jquery-3.1.1.min.js"></script>
|
<script type="text/javascript" src="/static/jquery-3.1.1.min.js"></script>
|
||||||
|
|
Loading…
Reference in New Issue