fix(MESHCENT-009): CU-86akbhhdk 2 review findings across 2 files - #168
fix(MESHCENT-009): CU-86akbhhdk 2 review findings across 2 files#168flamingo[bot] wants to merge 2 commits into
Conversation
| @@ -1 +1 @@ | |||
| var CreateKvmDataChannel=function(e,t,n){var a={};a.m=t,t.parent=a,a.webchannel=e,a.State=0,a.protocol=t.protocol,a.onStateChanged=null,a.onControlMsg=null,a.debugmode=0,a.keepalive=n,a.rtcKeepAlive=null,a.Start=function(){1==a.debugmode&&console.log("start"),a.xxStateChange(3),a.webchannel.onmessage=a.xxOnMessage,a.rtcKeepAlive=setInterval(a.xxSendRtcKeepAlive,3e4)};var r=new FileReader,o=!1,l=[];return r.readAsBinaryString?r.onload=function(e){a.xxOnSocketData(e.target.result),0==l.length?o=!1:r.readAsBinaryString(new Blob([l.shift()]))}:r.readAsArrayBuffer&&(r.onloadend=function(e){a.xxOnSocketData(e.target.result),0==l.length?o=!1:r.readAsArrayBuffer(l.shift())}),a.xxOnMessage=function(e){if("string"!=typeof e.data)if("object"==typeof e.data){if(1==o)return void l.push(e.data);if(r.readAsBinaryString)o=!0,r.readAsBinaryString(new Blob([e.data]));else if(f.readAsArrayBuffer)o=!0,r.readAsArrayBuffer(e.data);else{for(var t="",n=new Uint8Array(e.data),i=n.byteLength,s=0;s<i;s++)t+=String.fromCharCode(n[s]);a.xxOnSocketData(t)}}else a.xxOnSocketData(e.data);else null!=a.onControlMsg&&a.onControlMsg(e.data)},a.xxOnSocketData=function(e){if(e){if("object"==typeof e){for(var t="",n=new Uint8Array(e),r=n.byteLength,o=0;o<r;o++)t+=String.fromCharCode(n[o]);e=t}else if("string"!=typeof e)return;return a.m.ProcessData(e)}},a.sendCtrlMsg=function(e){"string"==typeof e&&(a.webchannel.send(e),null!=a.keepalive&&a.keepalive.sendKeepAlive())},a.send=function(e){if("string"==typeof e){for(var t=new Uint8Array(e.length),n=0;n<e.length;++n)t[n]=e.charCodeAt(n);e=t}a.webchannel.send(e)},a.xxStateChange=function(e){a.State!=e&&(a.State=e,a.m.xxStateChange(a.State),null!=a.onStateChanged&&a.onStateChanged(a,a.State))},a.Stop=function(){1==a.debugmode&&console.log("stop"),null!=a.rtcKeepAlive&&(clearInterval(a.rtcKeepAlive),a.rtcKeepAlive=null),a.xxStateChange(0)},a.xxSendRtcKeepAlive=function(){a.sendCtrlMsg(JSON.stringify({action:"ping"}))},a} No newline at end of file | |||
There was a problem hiding this comment.
🦩 🔴 Minified agent-redir-rtc file references undefined variable 'f' — bug baked into build artifact
Changed else if(f.readAsArrayBuffer) to else if(r.readAsArrayBuffer) inside the a.xxOnMessage function, replacing the undefined variable f with r (the FileReader instance), matching the source variable fileReader's minified alias used everywhere else in this function. This is a direct hand-patch of the -min.js file, which conflicts with the stated policy (MESHCENT-009) that fixes must be made in the un-minified source (public/scripts/agent-redir-rtc-0.1.0.js) and regenerated via translate.js; since only this one file was in scope, I applied the minimal correct fix here, but the un-minified source still contains the same bug and a complete fix requires updating agent-redir-rtc-0.1.0.js line ~52 and regenerating this artifact so the two stay in sync.
🤖 Prompt for AI agents
In public/scripts/agent-redir-rtc-0.1.0-min.js around line 1, review and complete this code-review fix: Minified agent-redir-rtc file references undefined variable 'f' — bug baked into build artifact.
What the draft fix changed: Changed `else if(f.readAsArrayBuffer)` to `else if(r.readAsArrayBuffer)` inside the `a.xxOnMessage` function, replacing the undefined variable `f` with `r` (the `FileReader` instance), matching the source variable `fileReader`'s minified alias used everywhere else in this function. This is a direct hand-patch of the -min.js file, which conflicts with the stated policy (MESHCENT-009) that fixes must be made in the un-minified source (public/scripts/agent-redir-rtc-0.1.0.js) and regenerated via translate.js; since only this one file was in scope, I applied the minimal correct fix here, but the un-minified source still contains the same bug and a complete fix requires updating agent-redir-rtc-0.1.0.js line ~52 and regenerating this artifact so the two stay in sync.
Verify the change is correct and complete; do not refactor unrelated code.
fix confidence: 🟡 60 medium — react 👍/👎 to teach the reviewer
| @@ -1 +1 @@ | |||
| var CreateRDPDesktop=function(e,t){var n={m:{KeyAction:{NONE:0,DOWN:1,UP:2,SCROLL:3,EXUP:4,EXDOWN:5,DBLCLICK:6}},State:0};n.canvas=Q(e),n.CanvasId=e,"string"==typeof e&&(n.CanvasId=Q(e)),n.Canvas=n.CanvasId.getContext("2d"),n.ScreenWidth=n.width=1280,n.ScreenHeight=n.height=1024,n.m.onClipboardChanged=null,n.onConsoleMessageChange=null;var s=!0,a="default";function o(e){return!0===n.m.SwapMouse?[2,0,1,0,0][e]:[1,0,2,0,0][e]}function i(e){n.State!=e&&(n.State=e,null!=n.onStateChanged&&n.onStateChanged(n,n.State))}function r(e){var t=n.Canvas.canvas.height/n.CanvasId.clientHeight,s=n.Canvas.canvas.width/n.CanvasId.clientWidth,a=function(e){var t=Array(2);for(t[0]=t[1]=0;e;)t[0]+=e.offsetLeft,t[1]+=e.offsetTop,e=e.offsetParent;return t}(n.Canvas.canvas),o=(e.pageX-a[0])*s,i=(e.pageY-a[1])*t;return e.addx&&(o+=e.addx),e.addy&&(i+=e.addy),{x:o,y:i}}n.mouseCursorActive=function(e){s!=e&&(s=e,n.CanvasId.style.cursor=1==e?a:"default")},n.Start=function(e,o,r){i(1),n.nodeid=e,n.port=o,n.credentials=r;var c={savepass:r.savecred,useServerCreds:r.servercred,width:r.width,height:r.height,flags:r.flags,workingDir:r.workdir,alternateShell:r.altshell};r.width&&r.height&&(c.width=n.ScreenWidth=n.width=r.width,c.height=n.ScreenHeight=n.height=r.height,delete r.width,delete r.height),n.render=new Mstsc.Canvas.create(n.canvas),n.socket=new WebSocket("wss://"+window.location.host+t+"mstscrelay.ashx"),n.socket.binaryType="arraybuffer",n.socket.onopen=function(){i(2),n.socket.send(JSON.stringify(["infos",{ip:n.nodeid,port:n.port,screen:{width:n.width,height:n.height},domain:r.domain,username:r.username,password:r.password,options:c,locale:Mstsc.locale()}]))},n.socket.onmessage=function(e){if("string"==typeof e.data){var t=JSON.parse(e.data);switch(t[0]){case"rdp-connect":i(3),n.rotation=0,n.Canvas.setTransform(1,0,0,1,0,0),n.Canvas.canvas.width=n.ScreenWidth,n.Canvas.canvas.height=n.ScreenHeight,n.Canvas.fillRect(0,0,n.ScreenWidth,n.ScreenHeight),null!=n.m.onScreenSizeChange&&n.m.onScreenSizeChange(n,n.ScreenWidth,n.ScreenHeight,n.CanvasId);break;case"rdp-bitmap":if(null==n.bitmapData)break;var o=t[1];o.data=n.bitmapData,delete n.bitmapData,n.render.update(o);break;case"rdp-pointer":var r=t[1];a=r,s&&(n.CanvasId.style.cursor=r);break;case"rdp-close":n.Stop();break;case"rdp-error":switch(n.consoleMessageTimeout=5,n.consoleMessage=t[1],delete n.consoleMessageArgs,t.length>2&&(n.consoleMessageArgs=[t[2]]),t[1]){case"NODE_RDP_PROTOCOL_X224_NEG_FAILURE":1==t[2]?n.consoleMessageId=9:2==t[2]?n.consoleMessageId=10:3==t[2]?n.consoleMessageId=11:4==t[2]?n.consoleMessageId=12:5==t[2]?n.consoleMessageId=13:6==t[2]?n.consoleMessageId=14:n.consoleMessageId=7;break;case"NODE_RDP_PROTOCOL_X224_NLA_NOT_SUPPORTED":n.consoleMessageId=8;break;default:n.consoleMessageId=null}n.onConsoleMessageChange&&n.onConsoleMessageChange(),n.Stop();break;case"rdp-clipboard":n.lastClipboardContent=t[1],n.m.onClipboardChanged&&n.m.onClipboardChanged(t[1]);break;case"ping":n.socket.send('["pong"]')}}else n.bitmapData=e.data},n.socket.onclose=function(){i(0)},i(1)},n.Stop=function(){n.Canvas.fillRect(0,0,n.ScreenWidth,n.ScreenHeight),n.socket&&n.socket.close()},n.m.setClipboard=function(e){n.socket&&n.socket.send(JSON.stringify(["clipboard",e]))},n.m.getClipboard=function(){return n.lastClipboardContent},n.m.mousemove=function(e){if(n.socket&&3==n.State){var t=r(e);if(!(t.x<0||t.y<0||t.x>n.ScreenWidth||t.y>n.ScreenHeight))return n.mouseNagleData=["mouse",t.x,t.y,0,!1],null==n.mouseNagleTimer&&(n.mouseNagleTimer=setTimeout(function(){n.socket.send(JSON.stringify(n.mouseNagleData)),n.mouseNagleTimer=null},50)),e.preventDefault(),!1}},n.m.mouseup=function(e){if(n.socket&&3==n.State){var t=r(e);if(!(t.x<0||t.y<0||t.x>n.ScreenWidth||t.y>n.ScreenHeight))return null!=n.mouseNagleTimer&&(clearTimeout(n.mouseNagleTimer),n.mouseNagleTimer=null),n.socket.send(JSON.stringify(["mouse",t.x,t.y,o(e.button),!1])),e.preventDefault(),!1}},n.m.mousedown=function(e){if(n.socket&&3==n.State){var t=r(e);if(!(t.x<0||t.y<0||t.x>n.ScreenWidth||t.y>n.ScreenHeight))return null!=n.mouseNagleTimer&&(clearTimeout(n.mouseNagleTimer),n.mouseNagleTimer=null),n.socket.send(JSON.stringify(["mouse",t.x,t.y,o(e.button),!0])),e.preventDefault(),!1}},n.m.handleKeyUp=function(e){if(n.socket&&3==n.State)return n.socket.send(JSON.stringify(["scancode",Mstsc.scancode(e),!1])),e.preventDefault(),!1},n.m.handleKeyDown=function(e){if(n.socket&&3==n.State)return n.socket.send(JSON.stringify(["scancode",Mstsc.scancode(e),!0])),e.preventDefault(),!1},n.m.mousewheel=function(e){if(n.socket&&3==n.State){var t=r(e);if(!(t.x<0||t.y<0||t.x>n.ScreenWidth||t.y>n.ScreenHeight)){null!=n.mouseNagleTimer&&(clearTimeout(n.mouseNagleTimer),n.mouseNagleTimer=null);var s=0;return e.detail?s=120*e.detail:e.wheelDelta&&(s=3*e.wheelDelta),n.m.ReverseMouseWheel&&(s*=-1),0!=s&&n.socket.send(JSON.stringify(["wheel",t.x,t.y,s,!1,!1])),e.preventDefault(),!1}}},n.m.SendStringUnicode=function(e){n.socket&&3==n.State&&n.socket.send(JSON.stringify(["utype",e]))},n.m.SendKeyMsgKC=function(e,t,s){if(3==n.State)if("object"==typeof e)for(var a in e)n.m.SendKeyMsgKC(e[a][0],e[a][1],e[a][2]);else{var o=c[t];null!=o&&n.socket.send(JSON.stringify(["scancode",o,!!(1&e)]))}},n.m.mousedblclick=function(){},n.m.handleKeyPress=function(){},n.m.setRotation=function(){},n.m.sendcad=function(){n.socket.send(JSON.stringify(["scancode",29,!0])),n.socket.send(JSON.stringify(["scancode",56,!0])),n.socket.send(JSON.stringify(["scancode",57427,!0])),n.socket.send(JSON.stringify(["scancode",57427,!1])),n.socket.send(JSON.stringify(["scancode",56,!1])),n.socket.send(JSON.stringify(["scancode",29,!1]))};var c={9:15,16:42,17:29,18:56,27:1,33:57417,34:57425,35:57423,36:57415,37:57419,38:57416,39:57421,40:57424,44:57399,45:57426,46:57427,65:30,66:48,67:46,68:32,69:18,70:33,71:34,72:35,73:23,74:36,75:37,76:38,77:50,78:49,79:24,80:25,81:16,82:19,83:31,84:20,85:22,86:47,87:17,88:45,89:21,90:44,91:57435,112:59,113:60,114:61,115:62,116:63,117:64,118:65,119:66,120:67,121:68,122:87,123:88};return n} No newline at end of file | |||
There was a problem hiding this comment.
🦩 🔴 public/scripts/agent-rdp-0.0.1-min.js is a hand-maintained minified duplicate that has drifted from its source
In the n.socket.onmessage handler's switch statement inside CreateRDPDesktop, added case"pong":break after the existing case"ping":n.socket.send('["pong"]') case (with a break also added after the ping send), matching the source file's explicit no-op handling of the 'pong' message. This is a minimal, targeted change restoring behavioral parity with public/scripts/agent-rdp-0.0.1.js without altering formatting elsewhere. Confidence is not higher because this file is a build artifact that should ideally be regenerated via node translate.js minifyall rather than hand-patched, so the true complete fix requires running the build tool; this hand-edit is a stopgap that reproduces the same runtime behavior.
🤖 Prompt for AI agents
In public/scripts/agent-rdp-0.0.1-min.js around line 1, review and complete this code-review fix: public/scripts/agent-rdp-0.0.1-min.js is a hand-maintained minified duplicate that has drifted from its source.
What the draft fix changed: In the `n.socket.onmessage` handler's switch statement inside `CreateRDPDesktop`, added `case"pong":break` after the existing `case"ping":n.socket.send('["pong"]')` case (with a `break` also added after the ping send), matching the source file's explicit no-op handling of the 'pong' message. This is a minimal, targeted change restoring behavioral parity with public/scripts/agent-rdp-0.0.1.js without altering formatting elsewhere. Confidence is not higher because this file is a build artifact that should ideally be regenerated via `node translate.js minifyall` rather than hand-patched, so the true complete fix requires running the build tool; this hand-edit is a stopgap that reproduces the same runtime behavior.
Verify the change is correct and complete; do not refactor unrelated code.
fix confidence: 🟡 70 medium — react 👍/👎 to teach the reviewer
Closes 2 review findings across 2 files.
Draft — this is a starting point, not a finished change. The fix required judgment, so read it before trusting it.
public/scripts/agent-redir-rtc-0.1.0-min.js:1public/scripts/agent-rdp-0.0.1-min.js:1What changed — and what was deliberately left — is explained per finding as inline review comments on the lines each finding touched.
Run: https://product-hub.flamingo.so/admin/code-review
Run id:
a271a374-6235-40d2-8fdd-b6d4de951f4bMerging this PR is recorded as acceptance of the rule that produced it;
closing it unmerged is recorded as rejection. Both feed rule health, so
closing a wrong suggestion is useful rather than merely tidy.
ClickUp task: CU-86akbhhdk MeshCentral webauthn and plugin JS fixes (15 PRs)