Browse Source

manual id from bot

pull/1519/head
Ruslan 9 months ago
parent
commit
ff8c62c244
  1. 13
      src/lib/Server.js
  2. 5
      src/lib/WireGuard.js

13
src/lib/Server.js

@ -245,13 +245,22 @@ module.exports = class Server {
return config;
}))
.post('/api/wireguard/client', defineEventHandler(async (event) => {
const { name } = await readBody(event);
const { name, id } = await readBody(event);
const { expiredDate } = await readBody(event);
const client = await WireGuard.createClient({ name, expiredDate });
let client;
try {
client = await WireGuard.createClient({ name, expiredDate, id });
}
catch (e) {
return e;
}
return {
client_id: client.id,
success: true
};
}))
.delete('/api/wireguard/client/:clientId', defineEventHandler(async (event) => {
const clientId = getRouterParam(event, 'clientId');

5
src/lib/WireGuard.js

@ -235,7 +235,7 @@ Endpoint = ${WG_HOST}:${WG_CONFIG_PORT}`;
});
}
async createClient({ name, expiredDate }) {
async createClient({ name, expiredDate, id }) {
if (!name) {
throw new Error('Missing: Name');
}
@ -265,9 +265,8 @@ Endpoint = ${WG_HOST}:${WG_CONFIG_PORT}`;
throw new Error('Maximum number of clients reached.');
}
// Create Client
const id = crypto.randomUUID();
const client = {
id,
id, //id from tg bot
name,
address,
privateKey,

Loading…
Cancel
Save