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