Compare commits
5 Commits
c79c776225
...
46d308ce35
| Author | SHA1 | Date | |
|---|---|---|---|
| 46d308ce35 | |||
| 7cd85a3315 | |||
| fd338d2dad | |||
| 6dbe2f6e20 | |||
| 36d23c3d74 |
@@ -104,9 +104,10 @@ export class Xterm {
|
||||
private intervalID: NodeJS.Timeout;
|
||||
private writeFunc = (data: ArrayBuffer) => this.writeData(new Uint8Array(data));
|
||||
private status = false;
|
||||
private titleStatus = false;
|
||||
private checkStatus = false;
|
||||
private connectStatus = false;
|
||||
private hostTitle = "";
|
||||
private postAttachCommand = [];
|
||||
private postAttachCommandStatus = false;
|
||||
private workdir = "";
|
||||
private beforeCommand?: string;
|
||||
constructor(
|
||||
private options: XtermOptions,
|
||||
@@ -352,26 +353,17 @@ export class Xterm {
|
||||
)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (this.workdir === ''){
|
||||
this.workdir = data.workdir;
|
||||
}
|
||||
if (data.status !== '4' && data.status !== '0') {
|
||||
this.sendData(data.command);
|
||||
} else {
|
||||
clearInterval(this.intervalID);
|
||||
if (data.status === '4') {
|
||||
fetch(
|
||||
'http://' + options.get('domain') + ':'+ options.get('port') +'/' +
|
||||
options.get('user') +
|
||||
'/' +
|
||||
options.get('repo') +
|
||||
'/devcontainer/command?' +
|
||||
params
|
||||
)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
this.sendData(data.command);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
const parts = data.command.split('\n');
|
||||
this.sendData(parts[0]+"\n");
|
||||
this.postAttachCommand = parts;
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -423,42 +415,65 @@ export class Xterm {
|
||||
switch (cmd) {
|
||||
case Command.OUTPUT:
|
||||
const options = new URLSearchParams(decodeURIComponent(window.location.search));
|
||||
const params = new URLSearchParams({
|
||||
repo: options.get('repoid') as string,
|
||||
user: options.get('userid') as string,
|
||||
});
|
||||
if (options.get('type') === 'docker') {
|
||||
// 保存host的标题
|
||||
if (this.hostTitle === ""){
|
||||
this.hostTitle = textDecoder.decode(data).replace(/\s/g, '');
|
||||
}
|
||||
// 检测是否退出devcontainer,标题等于host的标题
|
||||
if (this.status && textDecoder.decode(data).replace(/\s/g, '').includes(this.hostTitle)){
|
||||
this.status = false
|
||||
}
|
||||
// this.status = true 连接完成
|
||||
if (
|
||||
this.status === false &&
|
||||
textDecoder.decode(data).replace(/\s/g, '').includes('Successfully connected to the container'.replace(/\s/g, ''))
|
||||
textDecoder.decode(data).replace(/\s/g, '').includes('Successfully connected to the devcontainer'.replace(/\s/g, ''))
|
||||
) {
|
||||
if(this.connectStatus == true){
|
||||
this.status = true;
|
||||
}
|
||||
this.connectStatus = true;
|
||||
}
|
||||
if (this.checkStatus) {
|
||||
if (textDecoder.decode(data).replace(/\s/g, '').includes('You have out the container. Please refresh the terminal to reconnect.'.replace(/\s/g, ''))) {
|
||||
this.checkStatus = false;
|
||||
this.status = false;
|
||||
this.connectStatus = false;
|
||||
}
|
||||
if(textDecoder.decode(data).includes('\x1b')){
|
||||
this.checkStatus = false;
|
||||
}
|
||||
}
|
||||
if (this.titleStatus && textDecoder.decode(data).includes('\x1b')) {
|
||||
this.titleStatus = false;
|
||||
this.checkStatus = true;
|
||||
this.sendData(
|
||||
`echo $WEB_TERMINAL\n`
|
||||
);
|
||||
this.status = true;
|
||||
fetch('http://' + options.get('domain') + ':'+ options.get('port') +'/' +
|
||||
options.get('user') +
|
||||
'/' +
|
||||
options.get('repo') +
|
||||
'/devcontainer/output?' +
|
||||
params
|
||||
).then(response => response.json())
|
||||
.then(data => {
|
||||
this.writeData(data.output);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('[ttyd] Failed to get output:', err);
|
||||
});
|
||||
|
||||
}
|
||||
// 连接完成之前,不输出标题和docker命令
|
||||
if (
|
||||
!(this.status === false && (textDecoder.decode(data).includes('\x1b') || textDecoder.decode(data).replace(/\s/g, '').includes('docker'))) &&
|
||||
this.titleStatus !== true &&
|
||||
this.checkStatus !== true
|
||||
!(this.status === false && (textDecoder.decode(data).includes('\x1b') || textDecoder.decode(data).replace(/\s/g, '').includes('docker')))
|
||||
){
|
||||
this.writeFunc(data);
|
||||
fetch('http://' + options.get('domain') + ':'+ options.get('port') +'/' +
|
||||
options.get('user') +
|
||||
'/' +
|
||||
options.get('repo') +
|
||||
'/devcontainer/output?' +
|
||||
params, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'text/plain'
|
||||
},
|
||||
body: textDecoder.decode(data),
|
||||
}).catch(err => {
|
||||
console.error('[ttyd] Failed to send output:', err);
|
||||
});
|
||||
}
|
||||
if (textDecoder.decode(data).replace(/\s/g, '').includes('exit')) {
|
||||
this.titleStatus = true;
|
||||
if (this.status && textDecoder.decode(data).replace(/\s/g, '').includes(this.workdir) && !this.postAttachCommandStatus){
|
||||
for (let i = 1; i < this.postAttachCommand.length; i++){
|
||||
this.sendData(this.postAttachCommand[i]+"\n");
|
||||
}
|
||||
this.postAttachCommandStatus = true;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "ttyd",
|
||||
"name": "webTerminal",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {}
|
||||
|
||||
28247
src/html.h
generated
28247
src/html.h
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user