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_start = req.body.block_start;
 | 
				
			||||||
	const block_length = req.body.block_length || 9999;
 | 
						const block_length = req.body.block_length || 9999;
 | 
				
			||||||
	const apiKey = crypto.randomBytes(32).toString('hex');
 | 
						const apiKey = crypto.randomBytes(32).toString('hex');
 | 
				
			||||||
 | 
						const contact = req.body.contact || "Unknown";
 | 
				
			||||||
	// Validate all inputs exist
 | 
						// Validate all inputs exist
 | 
				
			||||||
	if (!server || !port || !block_start) {
 | 
						if (!server || !port || !block_start) {
 | 
				
			||||||
		res.status(400).json({ error: 'Bad Request' });
 | 
							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' });
 | 
								res.status(409).json({ error: 'Conflict' });
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			db.run('INSERT INTO routes (server, port, auth, secret, block_start, block_length, apiKey) VALUES (?, ?, ?, ?, ?, ?, ?)',
 | 
								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],
 | 
									[server, port, auth, secret, block_start, block_length, apiKey, contact],
 | 
				
			||||||
				(err) => {
 | 
									(err) => {
 | 
				
			||||||
					if (err) {
 | 
										if (err) {
 | 
				
			||||||
						console.error('Error creating route:', 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 secret = req.body.secret || row.secret;
 | 
				
			||||||
		const block_start = req.body.block_start || row.block_start;
 | 
							const block_start = req.body.block_start || row.block_start;
 | 
				
			||||||
		const block_length = req.body.block_length || row.block_length;
 | 
							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 = ?',
 | 
							const contact = req.body.contact || row.contact;
 | 
				
			||||||
			[server, port, auth, secret, block_start, block_length, req.params.id],
 | 
							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) => {
 | 
								(err) => {
 | 
				
			||||||
				if (err) {
 | 
									if (err) {
 | 
				
			||||||
					console.error('Error updating route:', 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.secret || ''}</td>
 | 
				
			||||||
			<td class="text-light">${route.block_start || ''} - ${route.block_start + route.block_length || ''}</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.apiKey || ''}</td>
 | 
				
			||||||
 | 
								<td class="text-light">${route.contact || ''}</td>
 | 
				
			||||||
			<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-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>
 | 
									<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>
 | 
									<label for="apiKey" class="form-label">API Key (Optional)</label>
 | 
				
			||||||
				<input type="text" class="form-control" id="apiKey" name="apiKey">
 | 
									<input type="text" class="form-control" id="apiKey" name="apiKey">
 | 
				
			||||||
			</div>
 | 
								</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>
 | 
								<button type="submit" class="btn btn-primary">Submit</button>
 | 
				
			||||||
			<a href="/admin" class="btn btn-secondary">Cancel</a>
 | 
								<a href="/admin" class="btn btn-secondary">Cancel</a>
 | 
				
			||||||
		</form>
 | 
							</form>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,6 +33,7 @@
 | 
				
			||||||
							<th>IAX2 Secret</th>
 | 
												<th>IAX2 Secret</th>
 | 
				
			||||||
							<th>Number Block</th>
 | 
												<th>Number Block</th>
 | 
				
			||||||
							<th>API Key</th>
 | 
												<th>API Key</th>
 | 
				
			||||||
 | 
												<th>Contact</th>
 | 
				
			||||||
							<th>Actions</th>
 | 
												<th>Actions</th>
 | 
				
			||||||
						</tr>
 | 
											</tr>
 | 
				
			||||||
					</thead>
 | 
										</thead>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue