This commit is contained in:
Liang Ding 2019-05-16 13:51:18 +08:00
parent 8058946f14
commit 93a64bb9d7
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
1 changed files with 1 additions and 11 deletions

View File

@ -175,9 +175,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
oneRuneStr = strings.Replace(oneRuneStr, ">", ">", -1)
buf.content += oneRuneStr
now := time.Now().UnixNano() / int64(time.Millisecond)
if 0 == buf.millisecond {
buf.millisecond = now
}
@ -187,10 +185,8 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
if "\n" == oneRuneStr && !flood {
channelRet["cmd"] = "run"
channelRet["output"] = buf.content
buf = outputBuf{} // a new buffer
count = 0 // clear count
err = wsChannel.WriteJSON(&channelRet)
if nil != err {
logger.Warn(err)
@ -205,10 +201,8 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
if now-outputTimeout >= buf.millisecond || len(buf.content) > outputBufMax {
channelRet["cmd"] = "run"
channelRet["output"] = buf.content
buf = outputBuf{} // a new buffer
count = 0 // clear count
err = wsChannel.WriteJSON(&channelRet)
if nil != err {
logger.Warn(err)
@ -236,9 +230,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
oneRuneStr = strings.Replace(oneRuneStr, ">", ">", -1)
buf.content += oneRuneStr
now := time.Now().UnixNano() / int64(time.Millisecond)
if 0 == buf.millisecond {
buf.millisecond = now
}
@ -246,9 +238,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
if now-outputTimeout >= buf.millisecond || len(buf.content) > outputBufMax || oneRuneStr == "\n" {
channelRet["cmd"] = "run"
channelRet["output"] = "<span class='stderr'>" + buf.content + "</span>"
buf = outputBuf{} // a new buffer
err = wsChannel.WriteJSON(&channelRet)
if nil != err {
logger.Warn(err)
@ -262,7 +252,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
cmd.Wait()
if 124 == cmd.ProcessState.ExitCode() {
channelRet["cmd"] = "run-done"
channelRet["output"] = "run program timeout"
channelRet["output"] = "<span class='stderr'>run program timeout in 5s</span>\n"
wsChannel.WriteJSON(&channelRet)
wsChannel.Refresh()
}