Add contact field to backend
This commit is contained in:
parent
4e2f1e6495
commit
0f0fac9354
11
index.js
11
index.js
|
@ -257,6 +257,7 @@ app.post('/api/v1/admin/route', (req, res) => { // Create a new route
|
|||
const block_start = req.body.block_start;
|
||||
const block_length = req.body.block_length || 9999;
|
||||
const apiKey = crypto.randomBytes(32).toString('hex');
|
||||
const contact = req.body.contact || "Unknown";
|
||||
// Validate all inputs exist
|
||||
if (!server || !port || !block_start) {
|
||||
res.status(400).json({ error: 'Bad Request' });
|
||||
|
@ -273,8 +274,8 @@ app.post('/api/v1/admin/route', (req, res) => { // Create a new route
|
|||
res.status(409).json({ error: 'Conflict' });
|
||||
return;
|
||||
} else {
|
||||
db.run('INSERT INTO routes (server, port, auth, secret, block_start, block_length, apiKey) VALUES (?, ?, ?, ?, ?, ?, ?)',
|
||||
[server, port, auth, secret, block_start, block_length, apiKey],
|
||||
db.run('INSERT INTO routes (server, port, auth, secret, block_start, block_length, apiKey, contact) VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
[server, port, auth, secret, block_start, block_length, apiKey, contact],
|
||||
(err) => {
|
||||
if (err) {
|
||||
console.error('Error creating route:', err);
|
||||
|
@ -311,8 +312,10 @@ app.put('/api/v1/admin/route/:id', (req, res) => { // Update a route
|
|||
const secret = req.body.secret || row.secret;
|
||||
const block_start = req.body.block_start || row.block_start;
|
||||
const block_length = req.body.block_length || row.block_length;
|
||||
db.run('UPDATE routes SET server = ?, port = ?, auth = ?, secret = ?, block_start = ?, block_length = ? WHERE id = ?',
|
||||
[server, port, auth, secret, block_start, block_length, req.params.id],
|
||||
const contact = req.body.contact || row.contact;
|
||||
console.log(`Updating ${req.params.id} to ${server}:${port} with ${auth}:${secret} for ${block_start} - ${block_start + block_length}. Contact: ${contact}`);
|
||||
db.run('UPDATE routes SET server = ?, port = ?, auth = ?, secret = ?, block_start = ?, block_length = ?, contact = ? WHERE id = ?',
|
||||
[server, port, auth, secret, block_start, block_length, contact, req.params.id],
|
||||
(err) => {
|
||||
if (err) {
|
||||
console.error('Error updating route:', err);
|
||||
|
|
2
migrations/007_add_contact_col_routes.sql
Normal file
2
migrations/007_add_contact_col_routes.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE routes
|
||||
ADD COLUMN contact TEXT;
|
|
@ -45,6 +45,7 @@ function populateTable(routes) {
|
|||
<td class="text-light">${route.secret || ''}</td>
|
||||
<td class="text-light">${route.block_start || ''} - ${route.block_start + route.block_length || ''}</td>
|
||||
<td class="text-light">${route.apiKey || ''}</td>
|
||||
<td class="text-light">${route.contact || ''}</td>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-outline-primary edit-btn" onclick="window.location.href = '/admin/route/${route.id}'" data-id="${route.id}">Edit</button>
|
||||
<button class="btn btn-sm btn-outline-danger delete-btn" onclick="deleteRoute(${route.id})" data-id="${route.id}">Delete</button>
|
||||
|
|
|
@ -49,6 +49,10 @@
|
|||
<label for="apiKey" class="form-label">API Key (Optional)</label>
|
||||
<input type="text" class="form-control" id="apiKey" name="apiKey">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="contact" class="form-label">Contact</label>
|
||||
<input type="text" class="form-control" id="contact" name="contact" placeholder="Contact method (Discord username, email, etc)" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
<a href="/admin" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
<th>IAX2 Secret</th>
|
||||
<th>Number Block</th>
|
||||
<th>API Key</th>
|
||||
<th>Contact</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
Loading…
Reference in a new issue