🎨 Fix #361
This commit is contained in:
parent
4a28d10a9d
commit
2e0f150cdb
|
@ -49,7 +49,6 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
locale := user.Locale
|
locale := user.Locale
|
||||||
|
|
||||||
var args map[string]interface{}
|
var args map[string]interface{}
|
||||||
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
result.Succ = false
|
result.Succ = false
|
||||||
|
@ -58,9 +57,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sid := args["sid"].(string)
|
sid := args["sid"].(string)
|
||||||
|
|
||||||
filePath := args["file"].(string)
|
filePath := args["file"].(string)
|
||||||
|
|
||||||
if util.Go.IsAPI(filePath) || !session.CanAccess(uid, filePath) {
|
if util.Go.IsAPI(filePath) || !session.CanAccess(uid, filePath) {
|
||||||
http.Error(w, "Forbidden", http.StatusForbidden)
|
http.Error(w, "Forbidden", http.StatusForbidden)
|
||||||
|
|
||||||
|
@ -68,9 +65,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
curDir := filepath.Dir(filePath)
|
curDir := filepath.Dir(filePath)
|
||||||
|
|
||||||
fout, err := os.Create(filePath)
|
fout, err := os.Create(filePath)
|
||||||
|
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
result.Succ = false
|
result.Succ = false
|
||||||
|
@ -79,7 +74,6 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
code := args["code"].(string)
|
code := args["code"].(string)
|
||||||
|
|
||||||
fout.WriteString(code)
|
fout.WriteString(code)
|
||||||
|
|
||||||
if err := fout.Close(); nil != err {
|
if err := fout.Close(); nil != err {
|
||||||
|
@ -94,13 +88,15 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
suffix = ".exe"
|
suffix = ".exe"
|
||||||
}
|
}
|
||||||
|
|
||||||
goBuildArgs := []string{}
|
var goBuildArgs []string
|
||||||
goBuildArgs = append(goBuildArgs, "build", "-i")
|
goBuildArgs = append(goBuildArgs, "build")
|
||||||
goBuildArgs = append(goBuildArgs, user.BuildArgs(runtime.GOOS)...)
|
goBuildArgs = append(goBuildArgs, user.BuildArgs(runtime.GOOS)...)
|
||||||
|
if !util.Str.Contains("-i", goBuildArgs) {
|
||||||
|
goBuildArgs = append(goBuildArgs, "-i")
|
||||||
|
}
|
||||||
|
|
||||||
cmd := exec.Command("go", goBuildArgs...)
|
cmd := exec.Command("go", goBuildArgs...)
|
||||||
cmd.Dir = curDir
|
cmd.Dir = curDir
|
||||||
|
|
||||||
setCmdEnv(cmd, uid)
|
setCmdEnv(cmd, uid)
|
||||||
|
|
||||||
executable := filepath.Base(curDir) + suffix
|
executable := filepath.Base(curDir) + suffix
|
||||||
|
|
Loading…
Reference in New Issue