diff --git a/apps/api/src/lib/common.ts b/apps/api/src/lib/common.ts index 149ee0820..63c366c8e 100644 --- a/apps/api/src/lib/common.ts +++ b/apps/api/src/lib/common.ts @@ -45,7 +45,7 @@ export function getAPIUrl() { if (process.env.CODESANDBOX_HOST) { return `https://${process.env.CODESANDBOX_HOST.replace(/\$PORT/, '3001')}` } - return isDev ? 'http://host.docker.internal:3001' : 'http://localhost:3000'; + return isDev ? 'http://localhost:3001' : 'http://localhost:3000'; } export function getUIUrl() { diff --git a/apps/api/src/routes/api/v1/applications/handlers.ts b/apps/api/src/routes/api/v1/applications/handlers.ts index 6d13eb0a4..1ba52858b 100644 --- a/apps/api/src/routes/api/v1/applications/handlers.ts +++ b/apps/api/src/routes/api/v1/applications/handlers.ts @@ -452,12 +452,14 @@ export async function stopApplication(request: FastifyRequest, reply: Fa export async function deleteApplication(request: FastifyRequest, reply: FastifyReply) { try { const { id } = request.params + const { force } = request.body + const { teamId } = request.user const application = await prisma.application.findUnique({ where: { id }, include: { destinationDocker: true } }); - if (application?.destinationDockerId && application.destinationDocker?.network) { + if (!force && application?.destinationDockerId && application.destinationDocker?.network) { const { stdout: containers } = await executeDockerCmd({ dockerId: application.destinationDocker.id, command: `docker ps -a --filter network=${application.destinationDocker.network} --filter name=${id} --format '{{json .}}'` diff --git a/apps/api/src/routes/api/v1/applications/types.ts b/apps/api/src/routes/api/v1/applications/types.ts index 6452c0c9d..0248c20c1 100644 --- a/apps/api/src/routes/api/v1/applications/types.ts +++ b/apps/api/src/routes/api/v1/applications/types.ts @@ -29,6 +29,7 @@ export interface SaveApplicationSettings extends OnlyId { } export interface DeleteApplication extends OnlyId { Querystring: { domain: string; }; + Body: { force: boolean } } export interface CheckDomain extends OnlyId { Querystring: { domain: string; }; diff --git a/apps/api/src/routes/api/v1/databases/handlers.ts b/apps/api/src/routes/api/v1/databases/handlers.ts index 8372fb76d..e918c21fc 100644 --- a/apps/api/src/routes/api/v1/databases/handlers.ts +++ b/apps/api/src/routes/api/v1/databases/handlers.ts @@ -7,7 +7,7 @@ import { ComposeFile, createDirectories, decrypt, encrypt, errorHandler, execute import { day } from '../../../../lib/dayjs'; import { GetDatabaseLogs, OnlyId, SaveDatabase, SaveDatabaseDestination, SaveDatabaseSettings, SaveVersion } from '../../../../types'; -import { SaveDatabaseType } from './types'; +import { DeleteDatabase, SaveDatabaseType } from './types'; export async function listDatabases(request: FastifyRequest) { try { @@ -167,6 +167,7 @@ export async function saveDatabaseDestination(request: FastifyRequest) return errorHandler({ status, message }) } } -export async function deleteDatabase(request: FastifyRequest) { +export async function deleteDatabase(request: FastifyRequest) { try { const teamId = request.user.teamId; const { id } = request.params; + const { force } = request.body; const database = await prisma.database.findFirst({ where: { id, teams: { some: { id: teamId === '0' ? undefined : teamId } } }, include: { destinationDocker: true, settings: true } }); - if (database.dbUserPassword) database.dbUserPassword = decrypt(database.dbUserPassword); - if (database.rootUserPassword) database.rootUserPassword = decrypt(database.rootUserPassword); - if (database.destinationDockerId) { - const everStarted = await stopDatabaseContainer(database); - if (everStarted) await stopTcpHttpProxy(id, database.destinationDocker, database.publicPort); + if (!force) { + if (database.dbUserPassword) database.dbUserPassword = decrypt(database.dbUserPassword); + if (database.rootUserPassword) database.rootUserPassword = decrypt(database.rootUserPassword); + if (database.destinationDockerId) { + const everStarted = await stopDatabaseContainer(database); + if (everStarted) await stopTcpHttpProxy(id, database.destinationDocker, database.publicPort); + } } await prisma.databaseSettings.deleteMany({ where: { databaseId: id } }); await prisma.database.delete({ where: { id } }); @@ -436,7 +440,7 @@ export async function saveDatabaseSettings(request: FastifyRequest => { @@ -13,7 +13,7 @@ const root: FastifyPluginAsync = async (fastify): Promise => { fastify.get('/:id', async (request) => await getDatabase(request)); fastify.post('/:id', async (request, reply) => await saveDatabase(request, reply)); - fastify.delete('/:id', async (request) => await deleteDatabase(request)); + fastify.delete('/:id', async (request) => await deleteDatabase(request)); fastify.get('/:id/status', async (request) => await getDatabaseStatus(request)); diff --git a/apps/api/src/routes/api/v1/databases/types.ts b/apps/api/src/routes/api/v1/databases/types.ts index b7e4c8692..a56a45c23 100644 --- a/apps/api/src/routes/api/v1/databases/types.ts +++ b/apps/api/src/routes/api/v1/databases/types.ts @@ -2,4 +2,7 @@ import type { OnlyId } from "../../../../types"; export interface SaveDatabaseType extends OnlyId { Body: { type: string } +} +export interface DeleteDatabase extends OnlyId { + Body: { force: string } } \ No newline at end of file diff --git a/apps/api/src/routes/api/v1/services/types.ts b/apps/api/src/routes/api/v1/services/types.ts index 098e7880f..3de06fa57 100644 --- a/apps/api/src/routes/api/v1/services/types.ts +++ b/apps/api/src/routes/api/v1/services/types.ts @@ -96,5 +96,3 @@ export interface SetGlitchTipSettings extends OnlyId { emailSmtpUseTls: boolean } } - - diff --git a/apps/api/src/types.ts b/apps/api/src/types.ts index 6367fd566..71f3db158 100644 --- a/apps/api/src/types.ts +++ b/apps/api/src/types.ts @@ -36,4 +36,3 @@ export interface SaveDatabaseSettings extends OnlyId { } - diff --git a/apps/ui/src/routes/applications/[id]/__layout.svelte b/apps/ui/src/routes/applications/[id]/__layout.svelte index 3d0e656d0..554a25ca5 100644 --- a/apps/ui/src/routes/applications/[id]/__layout.svelte +++ b/apps/ui/src/routes/applications/[id]/__layout.svelte @@ -65,6 +65,7 @@ import Tooltip from '$lib/components/Tooltip.svelte'; let statusInterval: any; + let forceDelete = false; $disabledButton = !$appSession.isAdmin || (!application.fqdn && !application.settings.isBot) || @@ -97,14 +98,17 @@ } } - async function deleteApplication(name: string) { + async function deleteApplication(name: string, force: boolean) { const sure = confirm($t('application.confirm_to_delete', { name })); if (sure) { $status.application.initialLoading = true; try { - await del(`/applications/${id}`, { id }); + await del(`/applications/${id}`, { id, force }); return await goto(`/applications`); } catch (error) { + if (error.message.startsWith(`Command failed: SSH_AUTH_SOCK=/tmp/ssh-agent.pid`)) { + forceDelete = true; + } return errorNotification(error); } finally { $status.application.initialLoading = false; @@ -117,9 +121,9 @@ $status.application.loading = true; await post(`/applications/${id}/restart`, {}); addToast({ - type: 'success', - message: 'Restart successful.' - }); + type: 'success', + message: 'Restart successful.' + }); } catch (error) { return errorNotification(error); } finally { @@ -537,16 +541,29 @@ >
- + {#if forceDelete} + + {:else} + + {/if} diff --git a/apps/ui/src/routes/applications/[id]/configuration/_GitlabRepositories.svelte b/apps/ui/src/routes/applications/[id]/configuration/_GitlabRepositories.svelte index 02fa103bc..3da8c6415 100644 --- a/apps/ui/src/routes/applications/[id]/configuration/_GitlabRepositories.svelte +++ b/apps/ui/src/routes/applications/[id]/configuration/_GitlabRepositories.svelte @@ -169,10 +169,6 @@ } } } - function selectBranch(event: any) { - selected.branch = event.detail; - isBranchAlreadyUsed(); - } async function loadBranches(page: number = 1) { let perPage = 100; //@ts-ignore @@ -199,21 +195,22 @@ } } - async function isBranchAlreadyUsed() { + async function isBranchAlreadyUsed(event) { + selected.branch = event.detail; try { - const data = await get( - `/applications/${id}/configuration/repository?repository=${selected.project.path_with_namespace}&branch=${selected.branch.name}` - ); - if (data.used) { - const sure = confirm($t('application.configuration.branch_already_in_use')); - if (sure) { - autodeploy = false; - showSave = true; - return true; - } - showSave = false; - return true; - } + // const data = await get( + // `/applications/${id}/configuration/repository?repository=${selected.project.path_with_namespace}&branch=${selected.branch.name}` + // ); + // if (data.used) { + // const sure = confirm($t('application.configuration.branch_already_in_use')); + // if (sure) { + // autodeploy = false; + // showSave = true; + // return true; + // } + // showSave = false; + // return true; + // } showSave = true; } catch (error) { return errorNotification(error); @@ -227,9 +224,7 @@ } } async function setWebhook(url: any, webhookToken: any) { - const host = dev - ? getWebhookUrl('gitlab') - : `${window.location.origin}/webhooks/gitlab/events`; + const host = dev ? getWebhookUrl('gitlab') : `${window.location.origin}/webhooks/gitlab/events`; try { await post( url, @@ -294,17 +289,15 @@ ); await post(updateDeployKeyIdUrl, { deployKeyId: id }); } catch (error) { - return errorNotification(error); - } finally { loading.save = false; + return errorNotification(error); } try { await setWebhook(webhookUrl, webhookToken); } catch (error) { - return errorNotification(error); - } finally { loading.save = false; + return errorNotification(error); } const url = `/applications/${id}/configuration/repository`; @@ -317,11 +310,11 @@ autodeploy, webhookToken }); + loading.save = false; return await goto(from || `/applications/${id}/configuration/buildpack`); } catch (error) { - return errorNotification(error); - } finally { loading.save = false; + return errorNotification(error); } } async function handleSubmit() { @@ -396,7 +389,7 @@ showIndicator={!loading.branches} isWaiting={loading.branches} isDisabled={loading.branches || !selected.project} - on:select={selectBranch} + on:select={isBranchAlreadyUsed} on:clear={() => { showSave = false; selected.branch = null; @@ -425,7 +418,7 @@ configuration here.
+ {#if forceDelete} + {:else} + + {/if} + {'Delete'} {/if} diff --git a/apps/ui/src/routes/services/[id]/_Services/_Ghost.svelte b/apps/ui/src/routes/services/[id]/_Services/_Ghost.svelte index 5ee803d99..745955f1d 100644 --- a/apps/ui/src/routes/services/[id]/_Services/_Ghost.svelte +++ b/apps/ui/src/routes/services/[id]/_Services/_Ghost.svelte @@ -1,14 +1,15 @@
-
Ghost
- +
+ Ghost +
diff --git a/apps/ui/src/routes/services/[id]/_Services/_Hasura.svelte b/apps/ui/src/routes/services/[id]/_Services/_Hasura.svelte index b097ec84f..cb26d5767 100644 --- a/apps/ui/src/routes/services/[id]/_Services/_Hasura.svelte +++ b/apps/ui/src/routes/services/[id]/_Services/_Hasura.svelte @@ -1,6 +1,5 @@ diff --git a/apps/ui/src/routes/services/[id]/_Services/_PlausibleAnalytics.svelte b/apps/ui/src/routes/services/[id]/_Services/_PlausibleAnalytics.svelte index 8532896dc..f704c039f 100644 --- a/apps/ui/src/routes/services/[id]/_Services/_PlausibleAnalytics.svelte +++ b/apps/ui/src/routes/services/[id]/_Services/_PlausibleAnalytics.svelte @@ -1,6 +1,6 @@ @@ -13,7 +12,11 @@
- + -
diff --git a/apps/ui/src/routes/sources/[id]/_Github.svelte b/apps/ui/src/routes/sources/[id]/_Github.svelte index 80f6d9904..2639d87bd 100644 --- a/apps/ui/src/routes/sources/[id]/_Github.svelte +++ b/apps/ui/src/routes/sources/[id]/_Github.svelte @@ -3,12 +3,11 @@ export let settings: any; import { page } from '$app/stores'; import { getAPIUrl, getWebhookUrl, post } from '$lib/api'; - import Explainer from '$lib/components/Explainer.svelte'; import { t } from '$lib/translations'; import { dashify, errorNotification, getDomain } from '$lib/common'; import { addToast, appSession } from '$lib/store'; import { dev } from '$app/env'; -import DocLink from '$lib/components/DocLink.svelte'; + import DocLink from '$lib/components/DocLink.svelte'; const { id } = $page.params; @@ -116,9 +115,11 @@ import DocLink from '$lib/components/DocLink.svelte';
- + Organization
{$t('general')}
- + {#if $appSession.isAdmin} Custom SSH Port -
{/if}