Skip to content

Commit

Permalink
perf: fix web sz failed
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeEirc committed Oct 15, 2024
1 parent 896ddbf commit f5ae807
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
4 changes: 1 addition & 3 deletions pkg/proxy/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,8 @@ func (p *Parser) splitCmdStream(b []byte) []byte {
p.userOutputChan <- charEnter
return nil
}
if !p.zmodemParser.IsStartSession() {
p.srvOutputChan <- b
if !p.zmodemParser.IsStartSession() && p.zmodemParser.AbnormalFinish {
p.srvOutputChan <- []byte{0x4f, 0x4f}
return nil
}
return b
} else {
Expand Down
4 changes: 2 additions & 2 deletions pkg/zmodem/frame_type.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package zmodem

//FRAME TYPES
// FRAME TYPES
const (
ZRQINIT = 0x00 /* request receive init (s->r) */
ZRINIT = 0x01 /* receive init (r->s) */
Expand Down Expand Up @@ -90,7 +90,7 @@ const (
CAN = 0x18
)

//ZDLE SEQUENCES
// ZDLE SEQUENCES
const (
ZCRCE = 0x68 /* CRC next, frame ends, header packet follows */
ZCRCG = 0x69 /* CRC next, frame continues nonstop */
Expand Down
5 changes: 3 additions & 2 deletions pkg/zmodem/zmodem.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type ZmodemParser struct {
hasDataTransfer bool

FireStatusEvent func(event StatusEvent)

AbnormalFinish bool
}

// rz sz 解析的入口
Expand All @@ -47,6 +49,7 @@ func (z *ZmodemParser) Parse(p []byte) {
zSession := z.currentSession
zSession.consume(p)
if zSession.IsEnd() {
z.AbnormalFinish = zSession.AbnormalFinish
z.currentSession = nil
if z.FileEventCallback != nil && z.currentZFileInfo != nil {
info := z.currentZFileInfo
Expand Down Expand Up @@ -84,7 +87,6 @@ func (z *ZmodemParser) Parse(p []byte) {
z.currentSession = &ZSession{
Type: TypeDownload,
endCallback: func() {
z.setStatus(ZParserStatusNone)
if z.FireStatusEvent != nil {
z.FireStatusEvent(EndEvent)
}
Expand All @@ -101,7 +103,6 @@ func (z *ZmodemParser) Parse(p []byte) {
z.currentSession = &ZSession{
Type: TypeUpload,
endCallback: func() {
z.setStatus(ZParserStatusNone)
if z.FireStatusEvent != nil {
z.FireStatusEvent(EndEvent)
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/zmodem/zsession.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ type ZSession struct {
ZFileHeaderCallback func(zInfo *ZFileInfo)

zOnHeader func(hd *ZmodemHeader)

AbnormalFinish bool
}

// zsession 入口
Expand All @@ -199,6 +201,7 @@ func (s *ZSession) consume(p []byte) {
return
}
logger.Infof("Zmodem session %s abnormally finish", s.Type)
s.AbnormalFinish = true
return
}
if s.checkAbort(p) {
Expand Down Expand Up @@ -347,7 +350,7 @@ func (s *ZSession) onHeader(hd *ZmodemHeader) {
s.transferStatus = TransferStatusFinished
s.zFileInfo = nil
case ZFIN:
s.haveEnd = true
//s.haveEnd = true
if s.endCallback != nil {
s.endCallback()
}
Expand Down
9 changes: 8 additions & 1 deletion ui/src/hooks/useTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,14 @@ export const useTerminal = async (el: HTMLElement, option: ICallbackOptions): Pr

if (typeof event.data === 'object') {
if (enableZmodem.value) {
sentry.consume(event.data);
try {
sentry.consume(event.data);
} catch (e) {
sentry.get_confirmed_session()?.abort()
message.error('File transfer error, file transfer interrupted');
console.log(e);
}

} else {
writeBufferToTerminal(enableZmodem.value, zmodemStatus.value, terminal!, event.data);
}
Expand Down

0 comments on commit f5ae807

Please sign in to comment.