Update index.js

This commit is contained in:
fanategorius
2026-07-06 12:51:15 +03:00
committed by GitHub
parent 26076df94b
commit b98df89971
+87 -45
View File
@@ -1,50 +1,92 @@
(function (OC, window, $, undefined) { (function(OC, window, $, undefined) {
'use strict'; 'use strict';
$(function() {
function scrollToBottom(){ $(document).ready(function() {
var html = $('html'); var sqlMode = false;
html.scrollTop(html.prop('scrollHeight'));
} var term = $('body').terminal(function(command, term) {
var baseUrl = OC.generateUrl('/apps/occweb'); if (command === '') {
$.get(baseUrl + '/cmd', function(response){ return;
$('#app-content').terminal(function(command, term) {
switch (command) {
case "c":
this.clear();
break;
case "exit":
this.reset();
break;
default:
var occCommand = {
command: command
};
term.pause();
$.ajax({
url: baseUrl + '/cmd',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(occCommand)
}).done(function (response) {
term.echo('\n' + response).resume();
}).fail(function (response, code) {
term.echo('\n' + response).resume();
});
} }
}, {
greetings: function (callback) { // Команды переключения режимов
callback('[[;green;]' + new Date().toString().slice(0, 24) + "]\n\nPress [[;#ff5e99;]Enter] for more information on [[;#009ae3;]occ] commands.\n") if (command === ':sql') {
}, sqlMode = true;
name: 'occ', term.set_prompt('sql $ ');
term.echo('SQL mode enabled. Type :occ to return to OCC mode.');
return;
}
if (command === ':occ') {
sqlMode = false;
term.set_prompt('occ $ ');
term.echo('OCC mode enabled.');
return;
}
if (command === ':help') {
term.echo('Available commands:');
term.echo(' :sql - Switch to SQL mode');
term.echo(' :occ - Switch to OCC mode');
term.echo(' :help - Show this help');
term.echo('');
term.echo('In OCC mode: execute Nextcloud occ commands');
term.echo('In SQL mode: execute SQL queries directly');
return;
}
term.pause();
if (sqlMode) {
// SQL режим
$.post(OC.generateUrl('/apps/occweb/db/query'), {
sql: command
}, function(response) {
if (response.success) {
response.results.forEach(function(result) {
if (result.type === 'select') {
term.echo('Query: ' + result.query);
term.echo('Rows: ' + result.count);
if (result.data.length > 0) {
term.echo(JSON.stringify(result.data, null, 2));
} else {
term.echo('(no results)');
}
} else if (result.type === 'write') {
term.echo('Query: ' + result.query);
term.echo('Affected rows: ' + result.affected_rows);
} else if (result.type === 'set') {
term.echo('Skipped: ' + result.query);
}
term.echo('');
});
} else {
term.echo('ERROR: ' + response.error);
}
term.resume();
}).fail(function(xhr, status, error) {
term.echo('ERROR: Request failed - ' + error);
term.resume();
});
} else {
// OCC режим
$.post(OC.generateUrl('/apps/occweb/cmd'), {
command: command
}, function(response) {
term.echo('\n' + response).resume();
}).fail(function(xhr, status, error) {
term.echo('ERROR: Request failed - ' + error);
term.resume();
});
}
}, {
prompt: 'occ $ ', prompt: 'occ $ ',
completion: response, name: 'occweb',
onResize: function(){ greetings: 'Nextcloud OCC Web Terminal\nType :help for available commands\n',
scrollToBottom() onBlur: function() {
return false;
} }
});
}); });
$('html').keypress(function(){ });
scrollToBottom()
})
});
})(OC, window, jQuery); })(OC, window, jQuery);