An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
ui/fix: Insane amount
Andras Bacsai0d0715a3405f
diff --git a/src/lib/database/applications.ts b/src/lib/database/applications.tsindex 1c6e172c2a..ce53fe7096 100644--- a/src/lib/database/applications.ts+++ b/src/lib/database/applications.ts@@ -73,7 +73,11 @@ export async function removeApplication({ id, teamId }) {await prisma.build.deleteMany({ where: { applicationId: id } });await prisma.secret.deleteMany({ where: { applicationId: id } });await prisma.applicationPersistentStorage.deleteMany({ where: { applicationId: id } });- await prisma.application.deleteMany({ where: { id, teams: { some: { id: teamId } } } });+ if (teamId === '0') {+ await prisma.application.deleteMany({ where: { id } });+ } else {+ await prisma.application.deleteMany({ where: { id, teams: { some: { id: teamId } } } });+ }}export async function getApplicationWebhook({ projectId, branch }) {diff --git a/src/lib/database/gitSources.ts b/src/lib/database/gitSources.tsindex 0ed6f29b1e..b8279c268e 100644--- a/src/lib/database/gitSources.ts+++ b/src/lib/database/gitSources.ts@@ -13,15 +13,11 @@ export async function listSources(teamId) {});}-export async function newSource({ name, teamId, type, htmlUrl, apiUrl, organization }) {+export async function newSource({ teamId, name }) {return await prisma.gitSource.create({data: {- teams: { connect: { id: teamId } },name,- type,- htmlUrl,- apiUrl,- organization+ teams: { connect: { id: teamId } }}});}@@ -55,8 +51,29 @@ export async function getSource({ id, teamId }) {if (body?.gitlabApp?.appSecret) body.gitlabApp.appSecret = decrypt(body.gitlabApp.appSecret);return body;}-export async function addSource({ id, appId, teamId, oauthId, groupName, appSecret }) {+export async function addGitHubSource({ id, teamId, type, name, htmlUrl, apiUrl }) {+ await prisma.gitSource.update({ where: { id }, data: { type, name, htmlUrl, apiUrl } });+ return await prisma.githubApp.create({+ data: {+ teams: { connect: { id: teamId } },+ gitSource: { connect: { id } }+ }+ });+}+export async function addGitLabSource({+ id,+ teamId,+ type,+ name,+ htmlUrl,+ apiUrl,+ oauthId,+ appId,+ appSecret,+ groupName+}) {const encrptedAppSecret = encrypt(appSecret);+ await prisma.gitSource.update({ where: { id }, data: { type, apiUrl, htmlUrl, name } });return await prisma.gitlabApp.create({data: {teams: { connect: { id: teamId } },@@ -75,9 +92,9 @@ export async function configureGitsource({ id, gitSourceId }) {data: { gitSource: { connect: { id: gitSourceId } } }});}-export async function updateGitsource({ id, name }) {+export async function updateGitsource({ id, name, htmlUrl, apiUrl }) {return await prisma.gitSource.update({where: { id },- data: { name }+ data: { name, htmlUrl, apiUrl }});}diff --git a/src/routes/applications/[id]/delete.json.ts b/src/routes/applications/[id]/delete.json.tsindex b451728df4..03e48a8470 100644--- a/src/routes/applications/[id]/delete.json.ts+++ b/src/routes/applications/[id]/delete.json.ts@@ -14,6 +14,7 @@ export const del: RequestHandler = async (event) => {status: 200};} catch (error) {+ console.log(error);return ErrorHandler(error);}};diff --git a/src/routes/applications/_Application.svelte b/src/routes/applications/_Application.sveltedeleted file mode 100644index 8f183eb137..0000000000--- a/src/routes/applications/_Application.svelte+++ /dev/null@@ -1,70 +0,0 @@-<script lang="ts">- export let application;- import Rust from '$lib/components/svg/applications/Rust.svelte';- import Nodejs from '$lib/components/svg/applications/Nodejs.svelte';- import React from '$lib/components/svg/applications/React.svelte';- import Svelte from '$lib/components/svg/applications/Svelte.svelte';- import Vuejs from '$lib/components/svg/applications/Vuejs.svelte';- import PHP from '$lib/components/svg/applications/PHP.svelte';- import Python from '$lib/components/svg/applications/Python.svelte';- import Static from '$lib/components/svg/applications/Static.svelte';- import Nestjs from '$lib/components/svg/applications/Nestjs.svelte';- import Nuxtjs from '$lib/components/svg/applications/Nuxtjs.svelte';- import Nextjs from '$lib/components/svg/applications/Nextjs.svelte';- import Gatsby from '$lib/components/svg/applications/Gatsby.svelte';- import Docker from '$lib/components/svg/applications/Docker.svelte';- import Astro from '$lib/components/svg/applications/Astro.svelte';- import Eleventy from '$lib/components/svg/applications/Eleventy.svelte';- import { session } from '$app/stores';-- const buildPack = application?.buildPack?.toLowerCase();-</script>--<a href="/applications/{application.id}" class="w-96 p-2 no-underline">- <div class="box-selection group relative hover:bg-green-600">- {#if buildPack === 'rust'}- <Rust />- {:else if buildPack === 'node'}- <Nodejs />- {:else if buildPack === 'react'}- <React />- {:else if buildPack === 'svelte'}- <Svelte />- {:else if buildPack === 'vuejs'}- <Vuejs />- {:else if buildPack === 'php'}- <PHP />- {:else if buildPack === 'python'}- <Python />- {:else if buildPack === 'static'}- <Static />- {:else if buildPack === 'nestjs'}- <Nestjs />- {:else if buildPack === 'nuxtjs'}- <Nuxtjs />- {:else if buildPack === 'nextjs'}- <Nextjs />- {:else if buildPack === 'gatsby'}- <Gatsby />- {:else if buildPack === 'docker'}- <Docker />- {:else if buildPack === 'astro'}- <Astro />- {:else if buildPack === 'eleventy'}- <Eleventy />- {/if}-- <div class="truncate text-center text-xl font-bold">{application.name}</div>- {#if $session.teamId === '0'}- <div class="truncate text-center">Team {application.teams[0].name}</div>- {/if}- {#if application.fqdn}- <div class="truncate text-center">{application.fqdn}</div>- {/if}- {#if !application.gitSourceId || !application.destinationDockerId}- <div class="truncate text-center font-bold text-red-500 group-hover:text-white">- Configuration missing- </div>- {/if}- </div>-</a>diff --git a/src/routes/applications/index.svelte b/src/routes/applications/index.svelteindex 547382498c..0c69c47fea 100644--- a/src/routes/applications/index.svelte+++ b/src/routes/applications/index.svelte@@ -1,9 +1,26 @@<script lang="ts">export let applications: Array<Application>;import { session } from '$app/stores';- import Application from './_Application.svelte';import { post } from '$lib/api';import { goto } from '$app/navigation';++ import Rust from '$lib/components/svg/applications/Rust.svelte';+ import Nodejs from '$lib/components/svg/applications/Nodejs.svelte';+ import React from '$lib/components/svg/applications/React.svelte';+ import Svelte from '$lib/components/svg/applications/Svelte.svelte';+ import Vuejs from '$lib/components/svg/applications/Vuejs.svelte';+ import PHP from '$lib/components/svg/applications/PHP.svelte';+ import Python from '$lib/components/svg/applications/Python.svelte';+ import Static from '$lib/components/svg/applications/Static.svelte';+ import Nestjs from '$lib/components/svg/applications/Nestjs.svelte';+ import Nuxtjs from '$lib/components/svg/applications/Nuxtjs.svelte';+ import Nextjs from '$lib/components/svg/applications/Nextjs.svelte';+ import Gatsby from '$lib/components/svg/applications/Gatsby.svelte';+ import Docker from '$lib/components/svg/applications/Docker.svelte';+ import Astro from '$lib/components/svg/applications/Astro.svelte';+ import Eleventy from '$lib/components/svg/applications/Eleventy.svelte';+ import { getDomain } from '$lib/components/common';+async function newApplication() {const { id } = await post('/applications/new', {});return await goto(`/applications/${id}`, { replaceState: true });@@ -49,14 +66,108 @@<div class="flex flex-col"><div class="flex flex-col md:flex-row flex-wrap px-2 justify-center">{#each ownApplications as application}- <Application {application} />+ <a href="/applications/{application.id}" class="w-96 p-2 no-underline">+ <div class="box-selection group relative hover:bg-green-600">+ {#if application.buildPack.toLowerCase() === 'rust'}+ <Rust />+ {:else if application.buildPack.toLowerCase() === 'node'}+ <Nodejs />+ {:else if application.buildPack.toLowerCase() === 'react'}+ <React />+ {:else if application.buildPack.toLowerCase() === 'svelte'}+ <Svelte />+ {:else if application.buildPack.toLowerCase() === 'vuejs'}+ <Vuejs />+ {:else if application.buildPack.toLowerCase() === 'php'}+ <PHP />+ {:else if application.buildPack.toLowerCase() === 'python'}+ <Python />+ {:else if application.buildPack.toLowerCase() === 'static'}+ <Static />+ {:else if application.buildPack.toLowerCase() === 'nestjs'}+ <Nestjs />+ {:else if application.buildPack.toLowerCase() === 'nuxtjs'}+ <Nuxtjs />+ {:else if application.buildPack.toLowerCase() === 'nextjs'}+ <Nextjs />+ {:else if application.buildPack.toLowerCase() === 'gatsby'}+ <Gatsby />+ {:else if application.buildPack.toLowerCase() === 'docker'}+ <Docker />+ {:else if application.buildPack.toLowerCase() === 'astro'}+ <Astro />+ {:else if application.buildPack.toLowerCase() === 'eleventy'}+ <Eleventy />+ {/if}++ <div class="truncate text-center text-xl font-bold">{application.name}</div>+ {#if $session.teamId === '0' && otherApplications.length > 0}+ <div class="truncate text-center">Team {application.teams[0].name}</div>+ {/if}+ {#if application.fqdn}+ <div class="truncate text-center">{getDomain(application.fqdn)}</div>+ {/if}+ {#if !application.gitSourceId || !application.destinationDockerId || !application.fqdn}+ <div class="truncate text-center font-bold text-red-500 group-hover:text-white">+ Configuration missing+ </div>+ {/if}+ </div>+ </a>{/each}</div>{#if otherApplications.length > 0 && $session.teamId === '0'}<div class="text-xl font-bold pb-5 pt-10 px-6">Other Applications</div><div class="flex flex-col md:flex-row flex-wrap px-2 justify-center">{#each otherApplications as application}- <Application {application} />+ <a href="/applications/{application.id}" class="w-96 p-2 no-underline">+ <div class="box-selection group relative hover:bg-green-600">+ {#if application.buildPack.toLowerCase() === 'rust'}+ <Rust />+ {:else if application.buildPack.toLowerCase() === 'node'}+ <Nodejs />+ {:else if application.buildPack.toLowerCase() === 'react'}+ <React />+ {:else if application.buildPack.toLowerCase() === 'svelte'}+ <Svelte />+ {:else if application.buildPack.toLowerCase() === 'vuejs'}+ <Vuejs />+ {:else if application.buildPack.toLowerCase() === 'php'}+ <PHP />+ {:else if application.buildPack.toLowerCase() === 'python'}+ <Python />+ {:else if application.buildPack.toLowerCase() === 'static'}+ <Static />+ {:else if application.buildPack.toLowerCase() === 'nestjs'}+ <Nestjs />+ {:else if application.buildPack.toLowerCase() === 'nuxtjs'}+ <Nuxtjs />+ {:else if application.buildPack.toLowerCase() === 'nextjs'}+ <Nextjs />+ {:else if application.buildPack.toLowerCase() === 'gatsby'}+ <Gatsby />+ {:else if application.buildPack.toLowerCase() === 'docker'}+ <Docker />+ {:else if application.buildPack.toLowerCase() === 'astro'}+ <Astro />+ {:else if application.buildPack.toLowerCase() === 'eleventy'}+ <Eleventy />+ {/if}++ <div class="truncate text-center text-xl font-bold">{application.name}</div>+ {#if $session.teamId === '0'}+ <div class="truncate text-center">Team {application.teams[0].name}</div>+ {/if}+ {#if application.fqdn}+ <div class="truncate text-center">{getDomain(application.fqdn)}</div>+ {/if}+ {#if !application.gitSourceId || !application.destinationDockerId || !application.fqdn}+ <div class="truncate text-center font-bold text-red-500 group-hover:text-white">+ Configuration missing+ </div>+ {/if}+ </div>+ </a>{/each}</div>{/if}diff --git a/src/routes/databases/index.svelte b/src/routes/databases/index.svelteindex 7185e7f284..c160bc009c 100644--- a/src/routes/databases/index.svelte+++ b/src/routes/databases/index.svelte@@ -72,7 +72,7 @@<div class="font-bold text-xl text-center truncate">{database.name}</div>- {#if $session.teamId === '0'}+ {#if $session.teamId === '0' && otherDatabases.length > 0}<div class="text-center truncate">{database.teams[0].name}</div>{/if}{#if !database.type}diff --git a/src/routes/destinations/index.svelte b/src/routes/destinations/index.svelteindex 04077f57c0..84d1fc0bba 100644--- a/src/routes/destinations/index.svelte+++ b/src/routes/destinations/index.svelte@@ -68,7 +68,7 @@<a href="/destinations/{destination.id}" class="no-underline p-2 w-96"><div class="box-selection hover:bg-sky-600"><div class="font-bold text-xl text-center truncate">{destination.name}</div>- {#if $session.teamId === '0'}+ {#if $session.teamId === '0' && otherDestinations.length > 0}<div class="text-center truncate">{destination.teams[0].name}</div>{/if}<div class="text-center truncate">{destination.network}</div>diff --git a/src/routes/iam/index.svelte b/src/routes/iam/index.svelteindex f2554813ef..8c33d5a386 100644--- a/src/routes/iam/index.svelte+++ b/src/routes/iam/index.svelte@@ -55,7 +55,7 @@}try {await post(`/iam/password.json`, { id });- toast.push('Password reset successfully.');+ toast.push('Password reset successfully. Please relogin to reset it.');} catch ({ error }) {return errorNotification(error);}@@ -80,10 +80,7 @@<div class="mr-4 text-2xl tracking-tight">Identity and Access Management</div></div>-<!-- <div class="flex items-center px-6">- <div>{account.email}</div>-</div> -->-<div class="mx-auto max-w-4xl px-6">+<div class="mx-auto max-w-4xl px-6 py-4">{#if $session.teamId === '0' && accounts.length > 0}<div class="title font-bold">Accounts</div>{:else}diff --git a/src/routes/index.svelte b/src/routes/index.svelteindex 1a5f61b4bb..84cf7188f3 100644--- a/src/routes/index.svelte+++ b/src/routes/index.svelte@@ -92,7 +92,7 @@</a><a- href="/teams"+ href="/iam"sveltekit:prefetchclass="flex cursor-pointer flex-col rounded p-6 text-center text-cyan-500 no-underline transition duration-150 hover:bg-cyan-500 hover:text-white">diff --git a/src/routes/new/source/_Github.svelte b/src/routes/new/source/_Github.sveltedeleted file mode 100644index e8f2d33c42..0000000000--- a/src/routes/new/source/_Github.svelte+++ /dev/null@@ -1,96 +0,0 @@-<script lang="ts">- export let gitSource;- import { goto } from '$app/navigation';- import { post } from '$lib/api';-- import Explainer from '$lib/components/Explainer.svelte';-- import { errorNotification } from '$lib/form';- import { onMount } from 'svelte';-- let nameEl;- let organizationEl;-- onMount(() => {- nameEl.focus();- });- async function handleSubmit() {- try {- const { id } = await post(`/new/source.json`, { ...gitSource });- return await goto(`/sources/${id}/`);- } catch ({ error }) {- return errorNotification(error);- }- }-</script>--<div class="mx-auto max-w-4xl px-6">- <div class="flex justify-center pb-8">- <form on:submit|preventDefault={handleSubmit} class="grid grid-flow-row gap-2 py-4">- <div class="flex h-8 items-center space-x-2">- <div class="text-xl font-bold text-white">Configuration</div>- <button type="submit" class="bg-orange-600 hover:bg-orange-500">Save</button>- </div>- <div class="grid grid-cols-2 items-center px-10">- <label for="type" class="text-base font-bold text-stone-100">Type</label>-- <select name="type" id="type" class="w-96" bind:value={gitSource.type}>- <option value="github">GitHub</option>- <option value="gitlab">GitLab</option>- <option value="bitbucket">BitBucket</option>- </select>- </div>- <div class="grid grid-cols-2 items-center px-10">- <label for="name" class="text-base font-bold text-stone-100">Name</label>- <input- name="name"- id="name"- placeholder="GitHub.com"- required- bind:this={nameEl}- bind:value={gitSource.name}- />- </div>-- <div class="grid grid-cols-2 items-center px-10">- <label for="htmlUrl" class="text-base font-bold text-stone-100">HTML URL</label>- <input- type="url"- name="htmlUrl"- id="htmlUrl"- placeholder="eg: https://github.com"- required- bind:value={gitSource.htmlUrl}- />- </div>- <div class="grid grid-cols-2 items-center px-10">- <label for="apiUrl" class="text-base font-bold text-stone-100">API URL</label>- <input- name="apiUrl"- type="url"- id="apiUrl"- placeholder="eg: https://api.github.com"- required- bind:value={gitSource.apiUrl}- />- </div>- <div class="grid grid-cols-2 px-10">- <div class="flex flex-col">- <label for="organization" class="pt-2 text-base font-bold text-stone-100"- >Organization</label- >- <Explainer- text="Fill it if you would like to use an organization's as your Git Source. Otherwise your user will be used."- />- </div>- <input- name="organization"- id="organization"- placeholder="eg: coollabsio"- bind:value={gitSource.organization}- bind:this={organizationEl}- />- </div>- </form>- </div>-</div>diff --git a/src/routes/new/source/_Gitlab.svelte b/src/routes/new/source/_Gitlab.sveltedeleted file mode 100644index 219bc56b0a..0000000000--- a/src/routes/new/source/_Gitlab.svelte+++ /dev/null@@ -1,73 +0,0 @@-<script lang="ts">- export let gitSource;- import { goto } from '$app/navigation';- import { post } from '$lib/api';-- import { errorNotification } from '$lib/form';- import { onMount } from 'svelte';-- let nameEl;-- onMount(() => {- nameEl.focus();- });- async function handleSubmit() {- try {- const { id } = await post(`/new/source.json`, { ...gitSource });- return await goto(`/sources/${id}/`);- } catch ({ error }) {- return errorNotification(error);- }- }-</script>--<div class="flex justify-center pb-8">- <form on:submit|preventDefault={handleSubmit} class="grid grid-flow-row gap-2 py-4">- <div class="flex h-8 items-center space-x-2">- <div class="text-xl font-bold text-white">Configuration</div>- <button type="submit" class="bg-orange-600 hover:bg-orange-500">Save</button>- </div>- <div class="grid grid-cols-2 items-center px-10">- <label for="type" class="text-base font-bold text-stone-100">Type</label>- <select name="type" id="type" class="w-96" bind:value={gitSource.type}>- <option value="github">GitHub</option>- <option value="gitlab">GitLab</option>- <option value="bitbucket">BitBucket</option>- </select>- </div>- <div class="grid grid-cols-2 items-center px-10">- <label for="name" class="text-base font-bold text-stone-100">Name</label>- <input- name="name"- id="name"- placeholder="GitHub.com"- required- bind:this={nameEl}- bind:value={gitSource.name}- />- </div>-- <div class="grid grid-cols-2 items-center px-10">- <label for="htmlUrl" class="text-base font-bold text-stone-100">HTML URL</label>- <input- type="url"- name="htmlUrl"- id="htmlUrl"- placeholder="eg: https://github.com"- required- bind:value={gitSource.htmlUrl}- />- </div>- <div class="grid grid-cols-2 items-center px-10">- <label for="apiUrl" class="text-base font-bold text-stone-100">API URL</label>- <input- name="apiUrl"- type="url"- id="apiUrl"- placeholder="eg: https://api.github.com"- required- bind:value={gitSource.apiUrl}- />- </div>- </form>-</div>diff --git a/src/routes/new/source/index.svelte b/src/routes/new/source/index.sveltedeleted file mode 100644index 73384561a5..0000000000--- a/src/routes/new/source/index.svelte+++ /dev/null@@ -1,66 +0,0 @@-<script lang="ts">- import Github from './_Github.svelte';- import Gitlab from './_Gitlab.svelte';- let gitSource = {- name: undefined,- type: 'github',- htmlUrl: undefined,- apiUrl: undefined,- organization: undefined- };- function setPredefined(type) {- switch (type) {- case 'github':- gitSource = {- name: 'GitHub.com',- type,- htmlUrl: 'https://github.com',- apiUrl: 'https://api.github.com',- organization: undefined- };- break;- case 'gitlab':- gitSource = {- name: 'GitLab.com',- type,- htmlUrl: 'https://gitlab.com',- apiUrl: 'https://gitlab.com/api',- organization: undefined- };- break;- case 'bitbucket':- gitSource = {- name: 'BitBucket.com',- type,- htmlUrl: 'https://bitbucket.com',- apiUrl: 'https://bitbucket.com',- organization: undefined- };- break;- default:- break;- }- }-</script>--<div class="flex space-x-1 p-6 font-bold">- <div class="mr-4 text-2xl tracking-tight">Add New Git Source</div>-</div>--<div class="flex-col space-y-2 pb-10 text-center">- <div class="text-xl font-bold text-white">Official providers</div>- <div class="flex justify-center space-x-2">- <button class="w-32" on:click={() => setPredefined('github')}>GitHub.com</button>- <button class="w-32" on:click={() => setPredefined('gitlab')}>GitLab.com</button>- <button class="w-32" on:click={() => setPredefined('bitbucket')}>Bitbucket.com</button>- </div>-</div>-<div class="px-6">- {#if gitSource.type === 'github'}- <Github {gitSource} />- {:else if gitSource.type === 'gitlab'}- <Gitlab {gitSource} />- {:else if gitSource.type === 'bitbucket'}- <div class="text-center font-bold text-4xl py-10">Not implemented yet</div>- {/if}-</div>diff --git a/src/routes/services/index.svelte b/src/routes/services/index.svelteindex 06e74873be..389ee80364 100644--- a/src/routes/services/index.svelte+++ b/src/routes/services/index.svelte@@ -13,6 +13,7 @@import Ghost from '$lib/components/svg/services/Ghost.svelte';import MeiliSearch from '$lib/components/svg/services/MeiliSearch.svelte';import { session } from '$app/stores';+ import { getDomain } from '$lib/components/common';export let services;async function newService() {@@ -87,9 +88,12 @@<div class="font-bold text-xl text-center truncate">{service.name}</div>- {#if $session.teamId === '0'}+ {#if $session.teamId === '0' && otherServices.length > 0}<div class="text-center truncate">{service.teams[0].name}</div>{/if}+ {#if service.fqdn}+ <div class="truncate text-center">{getDomain(service.fqdn)}</div>+ {/if}{#if !service.type || !service.fqdn}<div class="font-bold text-center truncate text-red-500 group-hover:text-white">Configuration missing@@ -134,6 +138,9 @@{#if $session.teamId === '0'}<div class="text-center truncate">{service.teams[0].name}</div>{/if}+ {#if service.fqdn}+ <div class="truncate text-center">{getDomain(service.fqdn)}</div>+ {/if}{#if !service.type || !service.fqdn}<div class="font-bold text-center truncate text-red-500 group-hover:text-white">Configuration missingdiff --git a/src/routes/sources/[id]/_Github.svelte b/src/routes/sources/[id]/_Github.svelteindex 1029713539..b2866d195e 100644--- a/src/routes/sources/[id]/_Github.svelte+++ b/src/routes/sources/[id]/_Github.svelte@@ -3,13 +3,19 @@import { page, session } from '$app/stores';import { post } from '$lib/api';import { errorNotification } from '$lib/form';+ import { toast } from '@zerodevx/svelte-toast';const { id } = $page.params;let loading = false;async function handleSubmit() {loading = true;try {- return await post(`/sources/${id}.json`, { name: source.name });+ await post(`/sources/${id}.json`, {+ name: source.name,+ htmlUrl: source.htmlUrl,+ apiUrl: source.apiUrl+ });+ toast.push('Settings saved.');} catch ({ error }) {return errorNotification(error);} finally {@@ -38,7 +44,18 @@}, 100);}- function newGithubApp() {+ async function newGithubApp() {+ loading = true;+ try {+ await post(`/sources/${id}/github.json`, {+ type: 'github',+ name: source.name,+ htmlUrl: source.htmlUrl,+ apiUrl: source.apiUrl+ });+ } catch ({ error }) {+ return errorNotification(error);+ }const left = screen.width / 2 - 1020 / 2;const top = screen.height / 2 - 618 / 2;const newWindow = open(@@ -59,31 +76,72 @@}</script>-{#if !source.githubAppId}- <button on:click={newGithubApp}>Create new GitHub App</button>-{:else if source.githubApp?.installationId}- <form on:submit|preventDefault={handleSubmit} class="py-4">- <div class="flex space-x-1 pb-5 font-bold">- <div class="title">General</div>- {#if $session.isAdmin}- <button- type="submit"- class:bg-orange-600={!loading}- class:hover:bg-orange-500={!loading}- disabled={loading}>{loading ? 'Saving...' : 'Save'}</button- >- <button on:click|preventDefault={() => installRepositories(source)}- >Change GitHub App Settings</button- >+<div class="mx-auto max-w-4xl">+ {#if !source.githubAppId}+ <form on:submit|preventDefault={newGithubApp} class="py-4">+ <div class="flex space-x-1 pb-5 font-bold">+ <div class="title">General</div>+ </div>+ <div class="grid grid-flow-row gap-2 px-10">+ <div class="grid grid-flow-row gap-2">+ <div class="mt-2 grid grid-cols-2 items-center">+ <label for="name" class="text-base font-bold text-stone-100">Name</label>+ <input name="name" id="name" required bind:value={source.name} />+ </div>+ </div>+ <div class="grid grid-cols-2 items-center">+ <label for="htmlUrl" class="text-base font-bold text-stone-100">HTML URL</label>+ <input name="htmlUrl" id="htmlUrl" required bind:value={source.htmlUrl} />+ </div>+ <div class="grid grid-cols-2 items-center">+ <label for="apiUrl" class="text-base font-bold text-stone-100">API URL</label>+ <input name="apiUrl" id="apiUrl" required bind:value={source.apiUrl} />+ </div>+ </div>+ {#if source.apiUrl && source.htmlUrl && source.name}+ <div class="text-center">+ <button class=" mt-8 bg-orange-600" type="submit">Create new GitHub App</button>+ </div>{/if}- </div>- <div class="grid grid-flow-row gap-2 px-10">- <div class="grid grid-cols-2 items-center mt-2">- <label for="name" class="text-base font-bold text-stone-100">Name</label>- <input name="name" id="name" required bind:value={source.name} />+ </form>+ {:else if source.githubAppId}+ <form on:submit|preventDefault={handleSubmit} class="py-4">+ <div class="flex space-x-1 pb-5 font-bold">+ <div class="title">General</div>+ {#if $session.isAdmin}+ <button+ type="submit"+ class:bg-orange-600={!loading}+ class:hover:bg-orange-500={!loading}+ disabled={loading}>{loading ? 'Saving...' : 'Save'}</button+ >+ <button on:click|preventDefault={() => installRepositories(source)}+ >Change GitHub App Settings</button+ >+ {/if}+ </div>+ <div class="grid grid-flow-row gap-2 px-10">+ <div class="grid grid-flow-row gap-2">+ <div class="mt-2 grid grid-cols-2 items-center">+ <label for="name" class="text-base font-bold text-stone-100">Name</label>+ <input name="name" id="name" required bind:value={source.name} />+ </div>+ </div>+ <div class="grid grid-cols-2 items-center">+ <label for="htmlUrl" class="text-base font-bold text-stone-100">HTML URL</label>+ <input name="htmlUrl" id="htmlUrl" required bind:value={source.htmlUrl} />+ </div>+ <div class="grid grid-cols-2 items-center">+ <label for="apiUrl" class="text-base font-bold text-stone-100">API URL</label>+ <input name="apiUrl" id="apiUrl" required bind:value={source.apiUrl} />+ </div></div>+ </form>+ {:else}+ <div class="text-center">+ <button class=" bg-orange-600 mt-8" on:click={() => installRepositories(source)}+ >Install Repositories</button+ ></div>- </form>-{:else}- <button on:click={() => installRepositories(source)}>Install Repositories</button>-{/if}+ {/if}+</div>diff --git a/src/routes/sources/[id]/_Gitlab.svelte b/src/routes/sources/[id]/_Gitlab.svelteindex 7823aebe96..bf3b487339 100644--- a/src/routes/sources/[id]/_Gitlab.svelte+++ b/src/routes/sources/[id]/_Gitlab.svelte@@ -1,35 +1,73 @@<script lang="ts">export let source;+ export let settings;import Explainer from '$lib/components/Explainer.svelte';- import { enhance, errorNotification } from '$lib/form';+ import { errorNotification } from '$lib/form';import { page, session } from '$app/stores';import { onMount } from 'svelte';import { post } from '$lib/api';import { browser } from '$app/env';+ import CopyPasswordField from '$lib/components/CopyPasswordField.svelte';+ import { toast } from '@zerodevx/svelte-toast';+const { id } = $page.params;+ let url = browser ? (settings.fqdn ? settings.fqdn : window.location.origin) : '';let loading = false;+let oauthIdEl;- let payload = {- oauthId: undefined,- groupName: undefined,- appId: undefined,- appSecret: undefined,- applicationType: 'user'- };+ let applicationType;+ if (!source.gitlabAppId) {+ source.gitlabApp = {+ oauthId: null,+ groupName: null,+ appId: null,+ appSecret: null+ };+ }onMount(() => {oauthIdEl && oauthIdEl.focus();});- async function handleSubmitSave() {++ async function handleSubmit() {+ if (loading) return;loading = true;- try {- return await post(`/sources/${id}.json`, { name: source.name });- } catch ({ error }) {- return errorNotification(error);- } finally {- loading = false;+ if (!source.gitlabAppId) {+ // New GitLab App+ try {+ await post(`/sources/${id}/gitlab.json`, {+ type: 'gitlab',+ name: source.name,+ htmlUrl: source.htmlUrl,+ apiUrl: source.apiUrl,+ oauthId: source.gitlabApp.oauthId,+ appId: source.gitlabApp.appId,+ appSecret: source.gitlabApp.appSecret,+ groupName: source.gitlabApp.groupName+ });+ return window.location.reload();+ } catch ({ error }) {+ return errorNotification(error);+ } finally {+ loading = false;+ }+ } else {+ // Update GitLab App+ try {+ await post(`/sources/${id}.json`, {+ name: source.name,+ htmlUrl: source.htmlUrl,+ apiUrl: source.apiUrl+ });+ } catch ({ error }) {+ return errorNotification(error);+ } finally {+ toast.push('Settings saved.');+ loading = false;+ }}}+async function changeSettings() {const {htmlUrl,@@ -53,23 +91,27 @@}, 100);}async function checkOauthId() {- if (payload.oauthId) {+ if (source.gitlabApp?.oauthId) {try {- await post(`/sources/${id}/check.json`, { oauthId: payload.oauthId });+ await post(`/sources/${id}/check.json`, {+ oauthId: source.gitlabApp?.oauthId+ });} catch ({ error }) {- payload.oauthId = null;+ source.gitlabApp.oauthId = null;oauthIdEl.focus();return errorNotification(error);}}}function newApp() {- switch (payload.applicationType) {+ switch (applicationType) {case 'user':window.open(`${source.htmlUrl}/-/profile/applications`);break;case 'group':- window.open(`${source.htmlUrl}/groups/${payload.groupName}/-/settings/applications`);+ window.open(+ `${source.htmlUrl}/groups/${source.gitlabApp.groupName}/-/settings/applications`+ );break;case 'instance':break;@@ -77,130 +119,136 @@break;}}- async function handleSubmit() {- loading = true;- try {- await post(`/sources/${id}/gitlab.json`, { ...payload });- return window.location.reload();- } catch ({ error }) {- return errorNotification(error);- } finally {- loading = false;- }- }</script>-{#if !source.gitlabApp?.appId}- <div>- <form class="grid grid-flow-row gap-2 py-4" on:submit|preventDefault={newApp}>- <div class="grid grid-cols-2 items-center">- <label for="type">GitLab Application Type</label>- <select name="type" id="type" class="w-96" bind:value={payload.applicationType}>- <option value="user">User owned application</option>- <option value="group">Group owned application</option>- {#if source.htmlUrl !== 'https://gitlab.com'}- <option value="instance">Instance-wide application (self-hosted)</option>- {/if}- </select>- </div>- {#if payload.applicationType === 'group'}- <div class="grid grid-cols-2 items-center">- <label for="groupName">Group Name</label>- <input name="groupName" id="groupName" required bind:value={payload.groupName} />- </div>- {/if}-- <div class="w-full pt-10 text-center">- <button class="w-96 bg-orange-600 hover:bg-orange-500" type="submit"- >Register new OAuth application on GitLab</button- >- </div>-- <Explainer- customClass="w-full"- text="<span class='font-bold text-base text-white'>Scopes required:</span>- <br>- <span class='text-orange-500 font-bold'>api</span> (Access the authenticated user's API)- <br>- <span class='text-orange-500 font-bold'>read_repository</span> (Allows read-only access to the repository)- <br>- <span class='text-orange-500 font-bold'>email</span> (Allows read-only access to the user's primary email address using OpenID Connect)- <br>- <br>For extra security, you can set Expire access tokens!- <br><br>Webhook URL: <span class='text-orange-500 font-bold'>{browser- ? window.location.origin- : ''}/webhooks/gitlab</span>- <br>But if you will set a custom domain name for Coolify, use that instead."- />- </form>- <form on:submit|preventDefault={handleSubmit} class="grid grid-flow-row gap-2 py-4 pt-10">- <div class="flex h-8 items-center space-x-2">- <div class="text-xl font-bold text-white">Configuration</div>+<div class="mx-auto max-w-4xl">+ <form on:submit|preventDefault={handleSubmit} class="py-4">+ <div class="flex space-x-1 pb-5 font-bold">+ <div class="title">General</div>+ {#if $session.isAdmin}<buttontype="submit"class:bg-orange-600={!loading}class:hover:bg-orange-500={!loading}disabled={loading}>{loading ? 'Saving...' : 'Save'}</button>- </div>+ {#if source.gitlabAppId}+ <button on:click|preventDefault={changeSettings}>Change GitLab App Settings</button>+ {/if}+ {/if}+ </div>+ <div class="grid grid-flow-row gap-2 px-10">+ {#if !source.gitlabAppId}+ <div class="grid grid-cols-2 items-center">+ <label for="type" class="text-base font-bold text-stone-100"+ >GitLab Application Type</label+ >+ <select name="type" id="type" class="w-96" bind:value={applicationType}>+ <option value="user">User owned application</option>+ <option value="group">Group owned application</option>+ {#if source.htmlUrl !== 'https://gitlab.com'}+ <option value="instance">Instance-wide application (self-hosted)</option>+ {/if}+ </select>+ </div>+ {#if applicationType === 'group'}+ <div class="grid grid-cols-2 items-center">+ <label for="groupName" class="text-base font-bold text-stone-100">Group Name</label>+ <input+ name="groupName"+ id="groupName"+ required+ bind:value={source.gitlabApp.groupName}+ />+ </div>+ {/if}+ {/if}++ <div class="grid grid-flow-row gap-2">+ <div class="mt-2 grid grid-cols-2 items-center">+ <label for="name" class="text-base font-bold text-stone-100">Name</label>+ <input name="name" id="name" required bind:value={source.name} />+ </div>+ </div>+ {#if source.gitlabApp.groupName}+ <div class="grid grid-cols-2 items-center">+ <label for="groupName" class="text-base font-bold text-stone-100">Group Name</label>+ <input+ name="groupName"+ id="groupName"+ disabled={source.gitlabAppId}+ readonly={source.gitlabAppId}+ required+ bind:value={source.gitlabApp.groupName}+ />+ </div>+ {/if}+ <div class="grid grid-cols-2 items-center">+ <label for="htmlUrl" class="text-base font-bold text-stone-100">HTML URL</label>+ <input name="htmlUrl" id="htmlUrl" required bind:value={source.htmlUrl} />+ </div>+ <div class="grid grid-cols-2 items-center">+ <label for="apiUrl" class="text-base font-bold text-stone-100">API URL</label>+ <input name="apiUrl" id="apiUrl" required bind:value={source.apiUrl} />+ </div><div class="grid grid-cols-2 items-start"><div class="flex-col">- <label for="oauthId" class="pt-2">OAuth ID</label>- <Explainer- text="The OAuth ID is the unique identifier of the GitLab application. <br>You can find it <span class='font-bold text-orange-600' >in the URL</span> of your GitLab OAuth Application."- />+ <label for="oauthId" class="pt-2 text-base font-bold text-stone-100">OAuth ID</label>+ {#if !source.gitlabAppId}+ <Explainer+ text="The OAuth ID is the unique identifier of the GitLab application. <br>You can find it <span class='font-bold text-orange-600' >in the URL</span> of your GitLab OAuth Application."+ />+ {/if}</div><input+ disabled={source.gitlabAppId}+ readonly={source.gitlabAppId}on:change={checkOauthId}bind:this={oauthIdEl}name="oauthId"id="oauthId"type="number"required- bind:value={payload.oauthId}+ bind:value={source.gitlabApp.oauthId}/></div>- {#if payload.applicationType === 'group'}- <div class="grid grid-cols-2 items-center">- <label for="groupName">Group Name</label>- <input name="groupName" id="groupName" required bind:value={payload.groupName} />- </div>- {/if}+<div class="grid grid-cols-2 items-center">- <label for="appId">Application ID</label>- <input name="appId" id="appId" required bind:value={payload.appId} />+ <label for="appId" class="text-base font-bold text-stone-100">Application ID</label>+ <input+ name="appId"+ id="appId"+ disabled={source.gitlabAppId}+ readonly={source.gitlabAppId}+ required+ bind:value={source.gitlabApp.appId}+ /></div><div class="grid grid-cols-2 items-center">- <label for="appSecret">Secret</label>- <input+ <label for="appSecret" class="text-base font-bold text-stone-100">Secret</label>+ <CopyPasswordField+ disabled={source.gitlabAppId}+ readonly={source.gitlabAppId}+ isPasswordField={true}name="appSecret"id="appSecret"- type="password"required- bind:value={payload.appSecret}+ bind:value={source.gitlabApp.appSecret}/></div>- </form>- </div>-{:else}- <div class="mx-auto max-w-4xl px-6">- <form on:submit|preventDefault={handleSubmitSave} class="py-4">- <div class="flex space-x-1 pb-5 font-bold">- <div class="title">General</div>- {#if $session.isAdmin}- <button- type="submit"- class:bg-orange-600={!loading}- class:hover:bg-orange-500={!loading}- disabled={loading}>{loading ? 'Saving...' : 'Save'}</button- >- <button on:click|preventDefault={changeSettings}>Change GitLab App Settings</button>- {/if}- </div>- <div class="grid grid-flow-row gap-2 px-10">- <div class="mt-2 grid grid-cols-2 items-center">- <label for="name" class="text-base font-bold text-stone-100">Name</label>- <input name="name" id="name" required bind:value={source.name} />- </div>- </div>- </form>- </div>-{/if}+ </div>+ </form>+ {#if !source.gitlabAppId}+ <Explainer+ customClass="w-full"+ text="<span class='font-bold text-base text-white'>Scopes required:</span>+<br>- <span class='text-orange-500 font-bold'>api</span> (Access the authenticated user's API)+<br>- <span class='text-orange-500 font-bold'>read_repository</span> (Allows read-only access to the repository)+<br>- <span class='text-orange-500 font-bold'>email</span> (Allows read-only access to the user's primary email address using OpenID Connect)+<br>+<br>For extra security, you can set <span class='text-orange-500 font-bold'>Expire Access Tokens</span>+<br><br>Webhook URL: <span class='text-orange-500 font-bold'>{url}/webhooks/gitlab</span>"+ />+ {/if}+</div>diff --git a/src/routes/sources/[id]/github.json.ts b/src/routes/sources/[id]/github.json.tsnew file mode 100644index 0000000000..e0f1d3b61d--- /dev/null+++ b/src/routes/sources/[id]/github.json.ts@@ -0,0 +1,18 @@+import { getUserDetails } from '$lib/common';+import * as db from '$lib/database';+import { ErrorHandler } from '$lib/database';+import type { RequestHandler } from '@sveltejs/kit';++export const post: RequestHandler = async (event) => {+ const { teamId, status, body } = await getUserDetails(event);+ if (status === 401) return { status, body };+ const { id } = event.params;++ try {+ let { type, name, htmlUrl, apiUrl } = await event.request.json();+ await db.addGitHubSource({ id, teamId, type, name, htmlUrl, apiUrl });+ return { status: 201 };+ } catch (error) {+ return ErrorHandler(error);+ }+};diff --git a/src/routes/sources/[id]/gitlab.json.ts b/src/routes/sources/[id]/gitlab.json.tsindex 8420669e60..b1ed314bf0 100644--- a/src/routes/sources/[id]/gitlab.json.ts+++ b/src/routes/sources/[id]/gitlab.json.ts@@ -9,11 +9,23 @@ export const post: RequestHandler = async (event) => {const { id } = event.params;try {- let { oauthId, groupName, appId, appSecret } = await event.request.json();+ let { type, name, htmlUrl, apiUrl, oauthId, appId, appSecret, groupName } =+ await event.request.json();oauthId = Number(oauthId);- await db.addSource({ id, teamId, oauthId, groupName, appId, appSecret });+ await db.addGitLabSource({+ id,+ teamId,+ type,+ name,+ htmlUrl,+ apiUrl,+ oauthId,+ appId,+ appSecret,+ groupName+ });return { status: 201 };} catch (error) {return ErrorHandler(error);diff --git a/src/routes/sources/[id]/index.json.ts b/src/routes/sources/[id]/index.json.tsindex 58fb7008b0..cd19e6785f 100644--- a/src/routes/sources/[id]/index.json.ts+++ b/src/routes/sources/[id]/index.json.ts@@ -43,10 +43,10 @@ export const post: RequestHandler = async (event) => {const { id } = event.params;- const { name } = await event.request.json();+ const { name, htmlUrl, apiUrl } = await event.request.json();try {- await db.updateGitsource({ id, name });+ await db.updateGitsource({ id, name, htmlUrl, apiUrl });return { status: 201 };} catch (error) {return ErrorHandler(error);diff --git a/src/routes/sources/[id]/index.svelte b/src/routes/sources/[id]/index.svelteindex 83f1714122..015c98a1ff 100644--- a/src/routes/sources/[id]/index.svelte+++ b/src/routes/sources/[id]/index.svelte@@ -29,9 +29,41 @@<script lang="ts">export let source: Prisma.GitSource;+ export let settings;import type Prisma from '@prisma/client';import Github from './_Github.svelte';import Gitlab from './_Gitlab.svelte';++ function setPredefined(type) {+ switch (type) {+ case 'github':+ source.name = 'Github.com';+ source.type = 'github';+ source.htmlUrl = 'https://github.com';+ source.apiUrl = 'https://api.github.com';+ source.organization = undefined;++ break;+ case 'gitlab':+ source.name = 'Gitlab.com';+ source.type = 'gitlab';+ source.htmlUrl = 'https://gitlab.com';+ source.apiUrl = 'https://gitlab.com/api';+ source.organization = undefined;++ break;+ case 'bitbucket':+ source.name = 'Bitbucket.com';+ source.type = 'bitbucket';+ source.htmlUrl = 'https://bitbucket.com';+ source.apiUrl = 'https://api.bitbucket.org';+ source.organization = undefined;++ break;+ default:+ break;+ }+ }</script><div class="flex space-x-1 p-6 px-6 text-2xl font-bold">@@ -40,10 +72,21 @@<span class="pr-2">{source.name}</span></div>-<div class="flex justify-center px-6 pb-8">- {#if source.type === 'github'}- <Github bind:source />- {:else if source.type === 'gitlab'}- <Gitlab bind:source />+<div class="flex flex-col justify-center">+ {#if !source.gitlabAppId && !source.githubAppId}+ <div class="flex-col space-y-2 pb-10 text-center">+ <div class="text-xl font-bold text-white">Select a provider</div>+ <div class="flex justify-center space-x-2">+ <button class="w-32" on:click={() => setPredefined('github')}>GitHub.com</button>+ <button class="w-32" on:click={() => setPredefined('gitlab')}>GitLab.com</button>+ </div>+ </div>{/if}+ <div>+ {#if source.type === 'github'}+ <Github bind:source />+ {:else if source.type === 'gitlab'}+ <Gitlab bind:source {settings} />+ {/if}+ </div></div>diff --git a/src/routes/sources/[id]/newGithubApp.svelte b/src/routes/sources/[id]/newGithubApp.svelteindex c8cb4f6f38..b6a74c3bab 100644--- a/src/routes/sources/[id]/newGithubApp.svelte+++ b/src/routes/sources/[id]/newGithubApp.svelte@@ -36,6 +36,7 @@export let settings;onMount(() => {const { organization, id, htmlUrl } = source;+ console.log(source);const { fqdn } = settings;const host = dev? 'http://localhost:3000'diff --git a/src/routes/sources/index.svelte b/src/routes/sources/index.svelteindex c763e0b58f..e07c219733 100644--- a/src/routes/sources/index.svelte+++ b/src/routes/sources/index.svelte@@ -22,6 +22,9 @@<script lang="ts">export let sources;import { session } from '$app/stores';+ import { post } from '$lib/api';+ import { goto } from '$app/navigation';+ import { getDomain } from '$lib/components/common';const ownSources = sources.filter((source) => {if (source.teams[0].id === $session.teamId) {return source;@@ -32,12 +35,16 @@return source;}});+ async function newSource() {+ const { id } = await post('/sources/new', {});+ return await goto(`/sources/${id}`, { replaceState: true });+ }</script><div class="flex space-x-1 p-6 font-bold"><div class="mr-4 text-2xl tracking-tight">Git Sources</div>{#if $session.isAdmin}- <a href="/new/source" sveltekit:prefetch class="add-icon bg-orange-600 hover:bg-orange-500">+ <button on:click={newSource} class="add-icon bg-orange-600 hover:bg-orange-500"><svgclass="w-6"xmlns="http://www.w3.org/2000/svg"@@ -51,7 +58,7 @@d="M12 6v6m0 0v6m0-6h6m-6 0H6"/></svg>- </a>+ </button>{/if}</div><div class="flex justify-center">@@ -71,7 +78,7 @@class:border-l-4={source.gitlabApp && !source.gitlabAppId}><div class="font-bold text-xl text-center truncate">{source.name}</div>- {#if $session.teamId === '0'}+ {#if $session.teamId === '0' && otherSources.length > 0}<div class="text-center truncate">{source.teams[0].name}</div>{/if}{#if (source.type === 'gitlab' && !source.gitlabAppId) || (source.type === 'github' && !source.githubAppId && !source.githubApp?.installationId)}@@ -79,7 +86,7 @@Configuration missing</div>{:else}- <div class="truncate text-center">{source.htmlUrl}</div>+ <div class="truncate text-center">{getDomain(source.htmlUrl)}</div>{/if}</div></a>diff --git a/src/routes/new/source/index.json.ts b/src/routes/sources/new.tssimilarity index 64%rename from src/routes/new/source/index.json.tsrename to src/routes/sources/new.tsindex 803b597e96..25943f8bc7 100644--- a/src/routes/new/source/index.json.ts+++ b/src/routes/sources/new.ts@@ -1,4 +1,4 @@-import { getUserDetails } from '$lib/common';+import { getUserDetails, uniqueName } from '$lib/common';import * as db from '$lib/database';import { ErrorHandler } from '$lib/database';import type { RequestHandler } from '@sveltejs/kit';@@ -7,9 +7,9 @@ export const post: RequestHandler = async (event) => {const { teamId, status, body } = await getUserDetails(event);if (status === 401) return { status, body };- const { name, type, htmlUrl, apiUrl, organization } = await event.request.json();+ const name = uniqueName();try {- const { id } = await db.newSource({ name, teamId, type, htmlUrl, apiUrl, organization });+ const { id } = await db.newSource({ teamId, name });return { status: 201, body: { id } };} catch (e) {return ErrorHandler(e);