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 intervalID: NodeJS.Timeout;
|
||||||
private writeFunc = (data: ArrayBuffer) => this.writeData(new Uint8Array(data));
|
private writeFunc = (data: ArrayBuffer) => this.writeData(new Uint8Array(data));
|
||||||
private status = false;
|
private status = false;
|
||||||
private titleStatus = false;
|
private hostTitle = "";
|
||||||
private checkStatus = false;
|
private postAttachCommand = [];
|
||||||
private connectStatus = false;
|
private postAttachCommandStatus = false;
|
||||||
|
private workdir = "";
|
||||||
private beforeCommand?: string;
|
private beforeCommand?: string;
|
||||||
constructor(
|
constructor(
|
||||||
private options: XtermOptions,
|
private options: XtermOptions,
|
||||||
@@ -352,26 +353,17 @@ export class Xterm {
|
|||||||
)
|
)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
if (this.workdir === ''){
|
||||||
|
this.workdir = data.workdir;
|
||||||
|
}
|
||||||
if (data.status !== '4' && data.status !== '0') {
|
if (data.status !== '4' && data.status !== '0') {
|
||||||
this.sendData(data.command);
|
this.sendData(data.command);
|
||||||
} else {
|
} else {
|
||||||
clearInterval(this.intervalID);
|
clearInterval(this.intervalID);
|
||||||
if (data.status === '4') {
|
if (data.status === '4') {
|
||||||
fetch(
|
const parts = data.command.split('\n');
|
||||||
'http://' + options.get('domain') + ':'+ options.get('port') +'/' +
|
this.sendData(parts[0]+"\n");
|
||||||
options.get('user') +
|
this.postAttachCommand = parts;
|
||||||
'/' +
|
|
||||||
options.get('repo') +
|
|
||||||
'/devcontainer/command?' +
|
|
||||||
params
|
|
||||||
)
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
this.sendData(data.command);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('Error:', error);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -423,42 +415,65 @@ export class Xterm {
|
|||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case Command.OUTPUT:
|
case Command.OUTPUT:
|
||||||
const options = new URLSearchParams(decodeURIComponent(window.location.search));
|
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') {
|
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 (
|
if (
|
||||||
this.status === false &&
|
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.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);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
this.connectStatus = true;
|
// 连接完成之前,不输出标题和docker命令
|
||||||
}
|
|
||||||
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`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (
|
if (
|
||||||
!(this.status === false && (textDecoder.decode(data).includes('\x1b') || textDecoder.decode(data).replace(/\s/g, '').includes('docker'))) &&
|
!(this.status === false && (textDecoder.decode(data).includes('\x1b') || textDecoder.decode(data).replace(/\s/g, '').includes('docker')))
|
||||||
this.titleStatus !== true &&
|
|
||||||
this.checkStatus !== true
|
|
||||||
){
|
){
|
||||||
this.writeFunc(data);
|
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')) {
|
if (this.status && textDecoder.decode(data).replace(/\s/g, '').includes(this.workdir) && !this.postAttachCommandStatus){
|
||||||
this.titleStatus = true;
|
for (let i = 1; i < this.postAttachCommand.length; i++){
|
||||||
|
this.sendData(this.postAttachCommand[i]+"\n");
|
||||||
|
}
|
||||||
|
this.postAttachCommandStatus = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "ttyd",
|
"name": "webTerminal",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {}
|
"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