🎨 加入只读模式配置

This commit is contained in:
Liang Ding 2022-08-09 09:43:46 +08:00
parent 029982f00e
commit 877e96df4d
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
7 changed files with 33 additions and 1 deletions

View File

@ -65,6 +65,7 @@ type conf struct {
Locale string // default locale
Autocomplete bool // default autocomplete
SiteStatCode template.HTML // site statistic code
ReadOnly bool // read-only mode
}
// Logger.

View File

@ -6,5 +6,6 @@
"HTTPSessionMaxAge": 86400,
"StaticResourceVersion": "${time}",
"Locale": "zh_CN",
"SiteStatCode": ""
"SiteStatCode": "",
"ReadOnly": false
}

View File

@ -242,6 +242,12 @@ func SaveFileHandler(w http.ResponseWriter, r *http.Request) {
result := gulu.Ret.NewResult()
defer gulu.Ret.RetResult(w, r, result)
if conf.Wide.ReadOnly {
result.Code = -1
result.Msg = "readonly mode"
return
}
var args map[string]interface{}
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {

View File

@ -38,6 +38,12 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
result := gulu.Ret.NewResult()
defer gulu.Ret.RetResult(w, r, result)
if conf.Wide.ReadOnly {
result.Code = -1
result.Msg = "readonly mode"
return
}
httpSession, _ := session.HTTPSession.Get(r, session.CookieName)
if httpSession.IsNew {
http.Error(w, "Forbidden", http.StatusForbidden)

View File

@ -37,6 +37,12 @@ func CrossCompilationHandler(w http.ResponseWriter, r *http.Request) {
result := gulu.Ret.NewResult()
defer gulu.Ret.RetResult(w, r, result)
if conf.Wide.ReadOnly {
result.Code = -1
result.Msg = "readonly mode"
return
}
httpSession, _ := session.HTTPSession.Get(r, session.CookieName)
if httpSession.IsNew {
http.Error(w, "Forbidden", http.StatusForbidden)

View File

@ -37,6 +37,12 @@ func GoInstallHandler(w http.ResponseWriter, r *http.Request) {
result := gulu.Ret.NewResult()
defer gulu.Ret.RetResult(w, r, result)
if conf.Wide.ReadOnly {
result.Code = -1
result.Msg = "readonly mode"
return
}
httpSession, _ := session.HTTPSession.Get(r, session.CookieName)
if httpSession.IsNew {
http.Error(w, "Forbidden", http.StatusForbidden)

View File

@ -48,6 +48,12 @@ func RunHandler(w http.ResponseWriter, r *http.Request, channel map[string]*util
result := gulu.Ret.NewResult()
defer gulu.Ret.RetResult(w, r, result)
if conf.Wide.ReadOnly {
result.Code = -1
result.Msg = "readonly mode"
return
}
var args map[string]interface{}
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {