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

View File

@ -170,11 +170,8 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
} }
oneRuneStr := string(r) oneRuneStr := string(r)
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
} }
@ -184,10 +181,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)
@ -202,10 +197,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)
@ -229,11 +222,8 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
} }
oneRuneStr := string(r) oneRuneStr := string(r)
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
} }
@ -241,9 +231,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"] = buf.content channelRet["output"] = buf.content
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)
@ -253,6 +241,14 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
wsChannel.Refresh() wsChannel.Refresh()
} }
} }
cmd.Wait()
if 124 == cmd.ProcessState.ExitCode() {
channelRet["cmd"] = "run-done"
channelRet["output"] = "<span class='stderr'>run program timeout in 5s</span>\n"
wsChannel.WriteJSON(&channelRet)
wsChannel.Refresh()
}
}(rand.Int()) }(rand.Int())
} }