Made it possible to create links with commands for console page.
This commit is contained in:
@@ -102,14 +102,21 @@
|
|||||||
import {useStorage} from "@vueuse/core";
|
import {useStorage} from "@vueuse/core";
|
||||||
import {notification} from "~/utils/index.js";
|
import {notification} from "~/utils/index.js";
|
||||||
|
|
||||||
const fromTask = useRoute().query.task || '';
|
const route = useRoute()
|
||||||
|
|
||||||
|
const fromTask = route.query.task || '';
|
||||||
|
let fromCommand = route.query.cmd || '';
|
||||||
|
if (fromCommand) {
|
||||||
|
// -- decode base64
|
||||||
|
fromCommand = atob(fromCommand);
|
||||||
|
}
|
||||||
|
|
||||||
useHead({title: `Console`})
|
useHead({title: `Console`})
|
||||||
|
|
||||||
let sse;
|
let sse;
|
||||||
|
|
||||||
const response = ref([]);
|
const response = ref([]);
|
||||||
const command = ref('');
|
const command = ref(fromCommand);
|
||||||
const isLoading = ref(false);
|
const isLoading = ref(false);
|
||||||
const outputConsole = ref();
|
const outputConsole = ref();
|
||||||
const hasPrefix = computed(() => command.value.startsWith('console') || command.value.startsWith('docker'));
|
const hasPrefix = computed(() => command.value.startsWith('console') || command.value.startsWith('docker'));
|
||||||
@@ -162,11 +169,15 @@ const finished = () => {
|
|||||||
onUpdated(() => outputConsole.value.scrollTop = outputConsole.value.scrollHeight);
|
onUpdated(() => outputConsole.value.scrollTop = outputConsole.value.scrollHeight);
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
if (!fromTask) {
|
if (!fromTask && '' === command.value) {
|
||||||
await RunCommand();
|
await RunCommand();
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!fromTask) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const response = await request(`/tasks/${fromTask}`);
|
const response = await request(`/tasks/${fromTask}`);
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
command.value = `${json.command} ${json.args || ''}`;
|
command.value = `${json.command} ${json.args || ''}`;
|
||||||
|
|||||||
@@ -292,6 +292,13 @@ const copyText = (str) => {
|
|||||||
notification('success', 'Success', 'Text copied to clipboard.')
|
notification('success', 'Success', 'Text copied to clipboard.')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const makeConsoleCommand = (cmd) => {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
// -- base64 encode the command to prevent XSS
|
||||||
|
params.append('cmd', btoa(cmd));
|
||||||
|
return `/console?${params.toString()}`
|
||||||
|
}
|
||||||
|
|
||||||
const stringToRegex = (str) => new RegExp(str.match(/\/(.+)\/.*/)[1], str.match(/\/.+\/(.*)/)[1]);
|
const stringToRegex = (str) => new RegExp(str.match(/\/(.+)\/.*/)[1], str.match(/\/.+\/(.*)/)[1]);
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -304,5 +311,6 @@ export {
|
|||||||
makeGUIDLink,
|
makeGUIDLink,
|
||||||
formatDuration,
|
formatDuration,
|
||||||
copyText,
|
copyText,
|
||||||
stringToRegex
|
stringToRegex,
|
||||||
|
makeConsoleCommand
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user