fix: selectable destinations
This commit is contained in:
@@ -6,11 +6,12 @@ import { asyncExecShell, decrypt, errorHandler, executeDockerCmd, listSettings,
|
||||
import { checkContainer, dockerInstance, getEngine } from '../../../../lib/docker';
|
||||
|
||||
import type { OnlyId } from '../../../../types';
|
||||
import type { CheckDestination, NewDestination, Proxy, SaveDestinationSettings } from './types';
|
||||
import type { CheckDestination, ListDestinations, NewDestination, Proxy, SaveDestinationSettings } from './types';
|
||||
|
||||
export async function listDestinations(request: FastifyRequest) {
|
||||
export async function listDestinations(request: FastifyRequest<ListDestinations>) {
|
||||
try {
|
||||
const teamId = request.user.teamId;
|
||||
const { onlyVerified = false } = request.query
|
||||
let destinations = []
|
||||
if (teamId === '0') {
|
||||
destinations = await prisma.destinationDocker.findMany({ include: { teams: true } });
|
||||
@@ -20,6 +21,9 @@ export async function listDestinations(request: FastifyRequest) {
|
||||
include: { teams: true }
|
||||
});
|
||||
}
|
||||
if (onlyVerified) {
|
||||
destinations = destinations.filter(destination => destination.engine || (destination.remoteEngine && destination.remoteVerified))
|
||||
}
|
||||
return {
|
||||
destinations
|
||||
}
|
||||
@@ -163,7 +167,7 @@ export async function startProxy(request: FastifyRequest<Proxy>) {
|
||||
await startTraefikProxy(id);
|
||||
return {}
|
||||
} catch ({ status, message }) {
|
||||
console.log({status, message})
|
||||
console.log({ status, message })
|
||||
await stopTraefikProxy(id);
|
||||
return errorHandler({ status, message })
|
||||
}
|
||||
|
@@ -2,13 +2,13 @@ import { FastifyPluginAsync } from 'fastify';
|
||||
import { assignSSHKey, checkDestination, deleteDestination, getDestination, getDestinationStatus, listDestinations, newDestination, restartProxy, saveDestinationSettings, startProxy, stopProxy, verifyRemoteDockerEngine } from './handlers';
|
||||
|
||||
import type { OnlyId } from '../../../../types';
|
||||
import type { CheckDestination, NewDestination, Proxy, SaveDestinationSettings } from './types';
|
||||
import type { CheckDestination, ListDestinations, NewDestination, Proxy, SaveDestinationSettings } from './types';
|
||||
|
||||
const root: FastifyPluginAsync = async (fastify): Promise<void> => {
|
||||
fastify.addHook('onRequest', async (request) => {
|
||||
return await request.jwtVerify()
|
||||
})
|
||||
fastify.get('/', async (request) => await listDestinations(request));
|
||||
fastify.get<ListDestinations>('/', async (request) => await listDestinations(request));
|
||||
fastify.post<CheckDestination>('/check', async (request) => await checkDestination(request));
|
||||
|
||||
fastify.get<OnlyId>('/:id', async (request) => await getDestination(request));
|
||||
|
@@ -1,5 +1,10 @@
|
||||
import { OnlyId } from "../../../../types"
|
||||
|
||||
export interface ListDestinations {
|
||||
Querystring: {
|
||||
onlyVerified: string
|
||||
}
|
||||
}
|
||||
export interface CheckDestination {
|
||||
Body: {
|
||||
network: string
|
||||
|
Reference in New Issue
Block a user