Spaces:
Runtime error
Runtime error
File size: 1,491 Bytes
4327358 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
// eslint-disable-next-line @typescript-eslint/no-var-requires
const axios = require('axios');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const yargs = require('yargs/yargs');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { hideBin } = require('yargs/helpers');
// Parse CLI arguments
const argv = yargs(hideBin(process.argv))
.option('sessions', {
alias: 'n',
type: 'number',
description: 'Number of sessions to create',
default: 10,
})
.option('api-key', {
alias: 'k',
type: 'string',
description: 'API key for authentication',
demandOption: true,
})
.help().argv;
const createSessions = async (numSessions, apiKey) => {
const url = 'http://localhost:3000/api/sessions/';
for (let i = 1; i <= numSessions; i++) {
try {
console.log(`Creating session ${i}`);
const response = await axios.post(
url,
{
name: '',
config: {
metadata: {},
webhooks: [],
},
start: true,
},
{
headers: {
Accept: 'application/json',
'X-Api-Key': apiKey,
'Content-Type': 'application/json',
},
},
);
console.log(`Session ${i} created successfully:`, response.data);
} catch (error) {
console.error(`Error creating session ${i}:`, error.message);
}
}
};
// Run the script
createSessions(argv.sessions, argv['api-key']);
|