mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-05 09:33:07 +00:00
refactor: update token generation method and improve maxSessions validation
- Changed the token generation method to use slice instead of substr for better readability. - Enhanced maxSessions validation in the settings update handler to check for undefined values and ensure the input is a number before processing.
This commit is contained in:
@@ -54,7 +54,7 @@ export function getTokenData(
|
|||||||
export function generateToken(): string {
|
export function generateToken(): string {
|
||||||
return `term-${Date.now()}-${Math.random()
|
return `term-${Date.now()}-${Math.random()
|
||||||
.toString(36)
|
.toString(36)
|
||||||
.substr(2, 15)}${Math.random().toString(36).substr(2, 15)}`;
|
.slice(2, 17)}${Math.random().toString(36).slice(2, 17)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25,7 +25,15 @@ export function createSettingsUpdateHandler() {
|
|||||||
const terminalService = getTerminalService();
|
const terminalService = getTerminalService();
|
||||||
const { maxSessions } = req.body;
|
const { maxSessions } = req.body;
|
||||||
|
|
||||||
if (typeof maxSessions === "number") {
|
// Validate maxSessions if provided
|
||||||
|
if (maxSessions !== undefined) {
|
||||||
|
if (typeof maxSessions !== "number") {
|
||||||
|
res.status(400).json({
|
||||||
|
success: false,
|
||||||
|
error: "maxSessions must be a number",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!Number.isInteger(maxSessions)) {
|
if (!Number.isInteger(maxSessions)) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
success: false,
|
success: false,
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ export class TerminalService extends EventEmitter {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const id = `term-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
const id = `term-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
||||||
|
|
||||||
const { shell: detectedShell, args: shellArgs } = this.detectShell();
|
const { shell: detectedShell, args: shellArgs } = this.detectShell();
|
||||||
const shell = options.shell || detectedShell;
|
const shell = options.shell || detectedShell;
|
||||||
|
|||||||
@@ -579,7 +579,7 @@ export function TerminalView() {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
type: "split",
|
type: "split",
|
||||||
id: persisted.id || `split-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
id: persisted.id || `split-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`,
|
||||||
direction: persisted.direction,
|
direction: persisted.direction,
|
||||||
panels: childPanels,
|
panels: childPanels,
|
||||||
size: persisted.size,
|
size: persisted.size,
|
||||||
|
|||||||
Reference in New Issue
Block a user