mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
updates.
This commit is contained in:
1 parent
14e782e351
commit
9b860cd0a5
9 files changed
+296
-304
No files matched your search
@@ -1,3 +1,21 @@
|
||||
export function getNestedRootDirectory(repository: string): string | null {
|
||||
const match = repository.match(/\/tree\/[^/]+\/(.+)$/);
|
||||
return match ? match[1] : null;
|
||||
}
|
||||
|
||||
export function getRepositoryInfo(repository: string): { owner: string; name: string } | null {
|
||||
const match = repository
|
||||
.trim()
|
||||
.match(/(?:^|\/\/|@)github\.com[/:]([^/]+)\/([^/]+?)(?:\.git)?(?:$|[/?#])/i);
|
||||
|
||||
if (!match) return null;
|
||||
|
||||
const owner = decodeURIComponent(match[1]);
|
||||
const name = decodeURIComponent(match[2].replace(/\.git$/i, ''));
|
||||
|
||||
return { owner, name };
|
||||
}
|
||||
|
||||
export async function getLatestTag(owner: string, name: string): Promise<string | null> {
|
||||
try {
|
||||
const tagsResponse = await fetch(`https://api.github.com/repos/${owner}/${name}/tags`);
|
||||
|
||||
+2
-7
@@ -41,13 +41,13 @@
|
||||
let id = $state(ID.unique());
|
||||
let name = $state(data.repository.name);
|
||||
|
||||
let rootDir = $state('./');
|
||||
let execute = $state(true);
|
||||
let entrypoint = $state('');
|
||||
let specification = $state('');
|
||||
let runtime = $state<Runtime>();
|
||||
let installCommand = $state('');
|
||||
let selectedScopes = $state<string[]>([]);
|
||||
let rootDir = $state(data.repository?.rootDirectory);
|
||||
let variables = $state<Array<{ key: string; value: string; secret: boolean }>>([]);
|
||||
|
||||
let latestTag = $state(null);
|
||||
@@ -71,23 +71,18 @@
|
||||
);
|
||||
|
||||
onMount(() => {
|
||||
// Get URL params
|
||||
const runtimeParam = data.runtime || page.url.searchParams.get('runtime') || 'node-18.0';
|
||||
runtime = runtimeParam as Runtime;
|
||||
|
||||
// Build configuration - use from URL params or defaults
|
||||
entrypoint = page.url.searchParams.get('entrypoint') || '';
|
||||
|
||||
// Using 'install' param for consistency with sites
|
||||
installCommand = page.url.searchParams.get('install') || '';
|
||||
rootDir = page.url.searchParams.get('rootDir') || './';
|
||||
rootDir = page.url.searchParams.get('rootDir') || data.repository?.rootDirectory || './';
|
||||
|
||||
// Set default specification
|
||||
if (specificationOptions.length > 0) {
|
||||
specification = specificationOptions[0].value;
|
||||
}
|
||||
|
||||
// Initialize environment variables from query params
|
||||
if (data.envKeys.length > 0) {
|
||||
variables = data.envKeys.map((key) => ({ key, value: '', secret: false }));
|
||||
}
|
||||
|
||||
+6
-7
@@ -2,6 +2,7 @@ import { sdk } from '$lib/stores/sdk';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import { base } from '$app/paths';
|
||||
import type { PageLoad } from './$types';
|
||||
import { getNestedRootDirectory, getRepositoryInfo } from '$lib/helpers/github';
|
||||
|
||||
export const load: PageLoad = async ({ url, params, parent }) => {
|
||||
const { installations: vcsInstallations, runtimesList, specificationsList } = await parent();
|
||||
@@ -12,14 +13,11 @@ export const load: PageLoad = async ({ url, params, parent }) => {
|
||||
redirect(302, `${base}/project-${params.region}-${params.project}/functions`);
|
||||
}
|
||||
|
||||
const repositoryMatch = repository.match(/github\.com[/:]([^/]+)\/([^/?]+)/);
|
||||
if (!repositoryMatch) {
|
||||
const info = getRepositoryInfo(repository!);
|
||||
if (!info) {
|
||||
redirect(302, `${base}/project-${params.region}-${params.project}/functions`);
|
||||
}
|
||||
|
||||
const [, owner, repoName] = repositoryMatch;
|
||||
const repositoryName = repoName.replace(/\.git$/, '');
|
||||
|
||||
const envParam = url.searchParams.get('env');
|
||||
const envKeys = envParam ? envParam.split(',').map((key: string) => key.trim()) : [];
|
||||
|
||||
@@ -43,9 +41,10 @@ export const load: PageLoad = async ({ url, params, parent }) => {
|
||||
installations,
|
||||
specificationsList,
|
||||
repository: {
|
||||
owner,
|
||||
url: repository,
|
||||
name: repositoryName
|
||||
name: info.owner,
|
||||
owner: info.owner,
|
||||
rootDirectory: getNestedRootDirectory(repository)
|
||||
}
|
||||
};
|
||||
};
|
||||
+96
-121
@@ -18,7 +18,6 @@
|
||||
Selector
|
||||
} from '@appwrite.io/pink-svelte';
|
||||
import { IconGithub, IconExternalLink, IconPencil } from '@appwrite.io/pink-icons-svelte';
|
||||
import { writable } from 'svelte/store';
|
||||
import { onMount } from 'svelte';
|
||||
import Domain from '../domain.svelte';
|
||||
import { Adapter, BuildRuntime, Framework, ID } from '@appwrite.io/console';
|
||||
@@ -27,28 +26,72 @@
|
||||
import { regionalConsoleVariables } from '$routes/(console)/project-[region]-[project]/store';
|
||||
import { iconPath } from '$lib/stores/app';
|
||||
import type { PageData } from './$types';
|
||||
import { writable } from 'svelte/store';
|
||||
import { getLatestTag } from '$lib/helpers/github';
|
||||
|
||||
export let data: PageData;
|
||||
let {
|
||||
data
|
||||
}: {
|
||||
data: PageData;
|
||||
} = $props();
|
||||
|
||||
let showExitModal = false;
|
||||
let showCustomId = false;
|
||||
let formComponent: Form;
|
||||
let isSubmitting = writable(false);
|
||||
let showCustomId = $state(false);
|
||||
let showExitModal = $state(false);
|
||||
let formComponent = $state<Form>();
|
||||
let isSubmitting = $state(writable(false));
|
||||
|
||||
// State variables
|
||||
let name = data.repository?.name || '';
|
||||
let id = ID.unique();
|
||||
let domain = '';
|
||||
let domainIsValid = false;
|
||||
let framework: Framework = Framework.Nextjs;
|
||||
let rootDir = '';
|
||||
let variables: Array<{ key: string; value: string; secret: boolean }> = [];
|
||||
let installCommand = '';
|
||||
let buildCommand = '';
|
||||
let outputDirectory = '';
|
||||
let id = $state(ID.unique());
|
||||
let name = $state(data.repository?.name || '');
|
||||
|
||||
let domain = $state('');
|
||||
let rootDir = $state(data.repository?.rootDirectory || '');
|
||||
let buildCommand = $state('');
|
||||
let installCommand = $state('');
|
||||
let outputDirectory = $state('');
|
||||
let domainIsValid = $state(false);
|
||||
let framework = $state<Framework>(Framework.Nextjs);
|
||||
let variables = $state<Array<{ key: string; value: string; secret: boolean }>>([]);
|
||||
|
||||
// Track if we have custom commands from URL
|
||||
let hasCustomCommands = false;
|
||||
let hasCustomCommands = $state(false);
|
||||
|
||||
// Framework options - dynamically generate from enum
|
||||
const frameworkOptions = $derived(
|
||||
Object.values(Framework).map((fw) => ({
|
||||
key: fw,
|
||||
name:
|
||||
fw === Framework.Nextjs
|
||||
? 'Next.js'
|
||||
: fw === Framework.Sveltekit
|
||||
? 'SvelteKit'
|
||||
: fw.charAt(0).toUpperCase() + fw.slice(1),
|
||||
buildRuntime: fw === Framework.Other ? BuildRuntime.Static1 : BuildRuntime.Node210
|
||||
}))
|
||||
);
|
||||
|
||||
const selectedFramework = $derived(
|
||||
frameworkOptions.find((f) => f.key === framework) || frameworkOptions[0]
|
||||
);
|
||||
|
||||
const frameworkSelectOptions = $derived(
|
||||
frameworkOptions.map((fw) => ({
|
||||
value: fw.key,
|
||||
label: fw.name,
|
||||
leadingHtml: `<img src='${$iconPath(getFrameworkIcon(fw.key), 'color')}' style='inline-size: var(--icon-size-m)' />`
|
||||
}))
|
||||
);
|
||||
|
||||
$effect(() => {
|
||||
if (framework && data.frameworks && !hasCustomCommands) {
|
||||
const fw = data.frameworks.frameworks.find((f) => f.key === framework);
|
||||
if (fw && fw.adapters && fw.adapters.length > 0) {
|
||||
const adapter = fw.adapters[0];
|
||||
installCommand = adapter.installCommand || '';
|
||||
buildCommand = adapter.buildCommand || '';
|
||||
outputDirectory = adapter.outputDirectory || '';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
onMount(() => {
|
||||
const preset = page.url.searchParams.get('preset') || 'nextjs';
|
||||
@@ -83,64 +126,6 @@
|
||||
}
|
||||
});
|
||||
|
||||
// Framework options - dynamically generate from enum
|
||||
const frameworkOptions = Object.values(Framework).map((fw) => ({
|
||||
key: fw,
|
||||
name:
|
||||
fw === Framework.Nextjs
|
||||
? 'Next.js'
|
||||
: fw === Framework.Sveltekit
|
||||
? 'SvelteKit'
|
||||
: fw.charAt(0).toUpperCase() + fw.slice(1),
|
||||
buildRuntime: fw === Framework.Other ? BuildRuntime.Static1 : BuildRuntime.Node210
|
||||
}));
|
||||
|
||||
$: selectedFramework = frameworkOptions.find((f) => f.key === framework) || frameworkOptions[0];
|
||||
|
||||
// Update build commands when framework changes (only if not provided via URL)
|
||||
$: if (framework && data.frameworks && !hasCustomCommands) {
|
||||
const fw = data.frameworks.frameworks.find((f) => f.key === framework);
|
||||
if (fw && fw.adapters && fw.adapters.length > 0) {
|
||||
const adapter = fw.adapters[0];
|
||||
installCommand = adapter.installCommand || '';
|
||||
buildCommand = adapter.buildCommand || '';
|
||||
outputDirectory = adapter.outputDirectory || '';
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchLatestGitHubTag(): Promise<string | null> {
|
||||
try {
|
||||
const tagsResponse = await fetch(
|
||||
`https://api.github.com/repos/${data.repository.owner}/${data.repository.name}/tags`
|
||||
);
|
||||
|
||||
if (!tagsResponse.ok) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: 'Failed to fetch tags from GitHub.'
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
const tags = await tagsResponse.json();
|
||||
if (tags.length === 0) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: 'No tags found in repository. Please create a tag before deploying.'
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
return tags[0].name;
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: 'Failed to fetch tags from GitHub: ' + error.message
|
||||
});
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function create() {
|
||||
if (!domainIsValid) {
|
||||
addNotification({
|
||||
@@ -150,61 +135,53 @@
|
||||
return;
|
||||
}
|
||||
|
||||
$isSubmitting = true;
|
||||
|
||||
try {
|
||||
// Create site with build configuration
|
||||
let site = await sdk.forProject(page.params.region, page.params.project).sites.create(
|
||||
id || ID.unique(),
|
||||
let site = await sdk.forProject(page.params.region, page.params.project).sites.create({
|
||||
siteId: id || ID.unique(),
|
||||
name,
|
||||
framework,
|
||||
selectedFramework.buildRuntime,
|
||||
undefined, // enabled
|
||||
undefined, // logging
|
||||
undefined, // timeout
|
||||
installCommand || undefined,
|
||||
buildCommand || undefined,
|
||||
outputDirectory || undefined,
|
||||
framework === Framework.Other ? Adapter.Static : undefined, // adapter
|
||||
undefined, // installationId
|
||||
undefined, // fallbackFile
|
||||
undefined, // providerRepositoryId
|
||||
undefined, // branch
|
||||
false, // silentMode
|
||||
undefined // rootDir
|
||||
);
|
||||
buildRuntime: selectedFramework.buildRuntime,
|
||||
installCommand: installCommand || undefined,
|
||||
buildCommand: buildCommand || undefined,
|
||||
outputDirectory: outputDirectory || undefined,
|
||||
adapter: framework === Framework.Other ? Adapter.Static : undefined,
|
||||
providerSilentMode: false
|
||||
});
|
||||
|
||||
// Add domain
|
||||
await sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.proxy.createSiteRule(
|
||||
`${domain}.${$regionalConsoleVariables._APP_DOMAIN_SITES}`,
|
||||
site.$id
|
||||
);
|
||||
await sdk.forProject(page.params.region, page.params.project).proxy.createSiteRule({
|
||||
domain: `${domain}.${$regionalConsoleVariables._APP_DOMAIN_SITES}`,
|
||||
siteId: site.$id
|
||||
});
|
||||
|
||||
// Add variables
|
||||
const promises = variables.map((variable) =>
|
||||
sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.sites.createVariable(site.$id, variable.key, variable.value, variable.secret)
|
||||
sdk.forProject(page.params.region, page.params.project).sites.createVariable({
|
||||
siteId: site.$id,
|
||||
key: variable.key,
|
||||
value: variable.value,
|
||||
secret: variable.secret
|
||||
})
|
||||
);
|
||||
await Promise.all(promises);
|
||||
|
||||
// Fetch latest tag from GitHub
|
||||
const latestTag = await fetchLatestGitHubTag();
|
||||
if (!latestTag) {
|
||||
return; // Error already handled in helper function
|
||||
}
|
||||
const latestTag = await getLatestTag(data.repository.owner, data.repository.name);
|
||||
|
||||
// Create deployment from GitHub repository using the latest tag
|
||||
const deployment = await sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.sites.createTemplateDeployment(
|
||||
site.$id,
|
||||
data.repository.name,
|
||||
data.repository.owner,
|
||||
rootDir || '.',
|
||||
latestTag,
|
||||
true
|
||||
);
|
||||
.sites.createTemplateDeployment({
|
||||
siteId: site.$id,
|
||||
repository: data.repository.name,
|
||||
owner: data.repository.owner,
|
||||
rootDirectory: rootDir || '.',
|
||||
version: latestTag ?? '1.0.0',
|
||||
activate: true
|
||||
});
|
||||
|
||||
trackEvent(Submit.SiteCreate, {
|
||||
source: 'deploy-button',
|
||||
@@ -221,6 +198,8 @@
|
||||
message: e.message
|
||||
});
|
||||
trackError(e, Submit.SiteCreate);
|
||||
} finally {
|
||||
$isSubmitting = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -234,7 +213,7 @@
|
||||
bind:showExitModal
|
||||
href={`${base}/project-${page.params.region}-${page.params.project}/sites/`}
|
||||
confirmExit>
|
||||
<Form bind:this={formComponent} onSubmit={create} bind:isSubmitting>
|
||||
<Form bind:this={formComponent} onSubmit={create} {isSubmitting}>
|
||||
<Layout.Stack gap="xl">
|
||||
<Card padding="s" radius="s">
|
||||
<Layout.Stack gap="m">
|
||||
@@ -267,7 +246,7 @@
|
||||
<CustomId bind:id bind:show={showCustomId} name="Site" />
|
||||
{:else}
|
||||
<div>
|
||||
<Tag size="s" on:click={() => (showCustomId = !showCustomId)}>
|
||||
<Tag size="s" onclick={() => (showCustomId = !showCustomId)}>
|
||||
<Icon icon={IconPencil} size="s" />
|
||||
Site ID
|
||||
</Tag>
|
||||
@@ -279,11 +258,7 @@
|
||||
label="Framework"
|
||||
placeholder="Select framework"
|
||||
bind:value={framework}
|
||||
options={frameworkOptions.map((fw) => ({
|
||||
value: fw.key,
|
||||
label: fw.name,
|
||||
leadingHtml: `<img src='${$iconPath(getFrameworkIcon(fw.key), 'color')}' style='inline-size: var(--icon-size-m)' />`
|
||||
}))} />
|
||||
options={frameworkSelectOptions} />
|
||||
</Layout.Stack>
|
||||
</Fieldset>
|
||||
|
||||
|
||||
@@ -2,49 +2,40 @@ import { sdk } from '$lib/stores/sdk';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import { base } from '$app/paths';
|
||||
import type { PageLoad } from './$types';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
import { getNestedRootDirectory, getRepositoryInfo } from '$lib/helpers/github';
|
||||
|
||||
export const load: PageLoad = async ({ url, params }) => {
|
||||
// Get repository URL from query params
|
||||
const repoUrl = url.searchParams.get('repo');
|
||||
if (!repoUrl) {
|
||||
const repository = url.searchParams.get('repo') || url.searchParams.get('repository');
|
||||
|
||||
if (!repository) {
|
||||
redirect(302, `${base}/project-${params.region}-${params.project}/sites`);
|
||||
}
|
||||
|
||||
// Parse repository information
|
||||
const repoMatch = repoUrl.match(/github\.com[/:]([^/]+)\/([^/?s]+)/);
|
||||
if (!repoMatch) {
|
||||
const info = getRepositoryInfo(repository!);
|
||||
if (!info) {
|
||||
redirect(302, `${base}/project-${params.region}-${params.project}/sites`);
|
||||
}
|
||||
|
||||
const [, owner, repoName] = repoMatch;
|
||||
// Clean repository name (remove .git extension if present)
|
||||
const cleanRepoName = repoName.replace(/\.git$/, '');
|
||||
|
||||
// Get environment variables from query params
|
||||
const envParam = url.searchParams.get('env');
|
||||
const envKeys = envParam ? envParam.split(',').map((key: string) => key.trim()) : [];
|
||||
|
||||
// Try to fetch installations
|
||||
let installations: Models.InstallationList | null = null;
|
||||
try {
|
||||
installations = await sdk.forProject(params.region, params.project).vcs.listInstallations();
|
||||
} catch (error) {
|
||||
// If error, user might not have GitHub connected
|
||||
installations = null;
|
||||
}
|
||||
|
||||
// Fetch frameworks list
|
||||
const frameworks = await sdk.forProject(params.region, params.project).sites.listFrameworks();
|
||||
const [frameworks, installations] = await Promise.all([
|
||||
sdk.forProject(params.region, params.project).sites.listFrameworks(),
|
||||
sdk
|
||||
.forProject(params.region, params.project)
|
||||
.vcs.listInstallations()
|
||||
.catch(() => null)
|
||||
]);
|
||||
|
||||
return {
|
||||
repository: {
|
||||
url: repoUrl,
|
||||
owner,
|
||||
name: cleanRepoName
|
||||
},
|
||||
envKeys,
|
||||
frameworks,
|
||||
installations,
|
||||
frameworks
|
||||
repository: {
|
||||
url: repository,
|
||||
name: info.name,
|
||||
owner: info.owner,
|
||||
rootDirectory: getNestedRootDirectory(repository!)
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -10,7 +10,7 @@
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { isCloud } from '$lib/system';
|
||||
import { ID, Query, type Models, Region } from '@appwrite.io/console';
|
||||
import { IconGithub, IconPencil, IconPlusSm } from '@appwrite.io/pink-icons-svelte';
|
||||
import { IconGithub, IconPencil, IconPlus } from '@appwrite.io/pink-icons-svelte';
|
||||
import { Card, Divider, Icon, Input, Layout, Tag, Typography } from '@appwrite.io/pink-svelte';
|
||||
import { filterRegions } from '$lib/helpers/regions';
|
||||
import { loadAvailableRegions } from '$routes/(console)/regions';
|
||||
@@ -27,23 +27,33 @@
|
||||
let showCustomId = $state(false);
|
||||
let region = $state<AllowedRegions>();
|
||||
let id = $state<string>('');
|
||||
|
||||
let loadingProjects = $state(false);
|
||||
|
||||
async function fetchProjects() {
|
||||
projects = await sdk.forConsole.projects.list([
|
||||
Query.equal('teamId', selectedOrg),
|
||||
Query.orderDesc('')
|
||||
]);
|
||||
selectedProject = projects?.total ? projects.projects[0].$id : 'create-new';
|
||||
loadingProjects = true;
|
||||
|
||||
projects = await sdk.forConsole.projects.list({
|
||||
queries: [Query.equal('teamId', selectedOrg), Query.orderDesc('')]
|
||||
});
|
||||
|
||||
selectedProject = projects?.total ? projects.projects[0].$id : null;
|
||||
loadingProjects = false;
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
if (selectedProject === 'create-new') {
|
||||
if (selectedProject === null) {
|
||||
try {
|
||||
const p = await sdk.forConsole.projects.create(
|
||||
id ?? ID.unique(),
|
||||
projectName,
|
||||
selectedOrg,
|
||||
isCloud ? (region as Region) : undefined
|
||||
);
|
||||
loadingProjects = true;
|
||||
const project = await sdk.forConsole.projects.create({
|
||||
projectId: id ?? ID.unique(),
|
||||
name: projectName,
|
||||
teamId: selectedOrg,
|
||||
region: isCloud ? (region as Region) : undefined
|
||||
});
|
||||
|
||||
selectedProject = project.$id;
|
||||
|
||||
trackEvent(Submit.ProjectCreate, {
|
||||
customId: !!id,
|
||||
selectedOrg,
|
||||
@@ -51,9 +61,7 @@
|
||||
source: 'deploy-button-functions'
|
||||
});
|
||||
|
||||
selectedProject = p.$id;
|
||||
|
||||
const deployUrl = buildDeployUrl(p);
|
||||
const deployUrl = buildDeployUrl(project);
|
||||
await goto(deployUrl);
|
||||
} catch (e) {
|
||||
trackError(e, Submit.ProjectCreate);
|
||||
@@ -61,6 +69,8 @@
|
||||
type: 'error',
|
||||
message: e.message
|
||||
});
|
||||
} finally {
|
||||
loadingProjects = false;
|
||||
}
|
||||
} else {
|
||||
const project = projects.projects.find((p) => p.$id === selectedProject);
|
||||
@@ -70,15 +80,14 @@
|
||||
}
|
||||
|
||||
function buildDeployUrl(project: Models.Project) {
|
||||
// Use the selected region or default to 'default' if not available
|
||||
const projectRegion = isCloud ? region : 'default';
|
||||
let url: URL;
|
||||
const projectRegion = isCloud ? region : 'default';
|
||||
|
||||
// For repository deployments, navigate to the deploy page
|
||||
url = new URL(
|
||||
`${base}/project-${projectRegion}-${project.$id}/functions/create-function/deploy`,
|
||||
window.location.origin
|
||||
);
|
||||
|
||||
url.searchParams.set('repo', data.deploymentData.repository.url);
|
||||
|
||||
// Pass runtime if specified from original URL
|
||||
@@ -96,7 +105,11 @@
|
||||
if (entrypoint) url.searchParams.set('entrypoint', entrypoint);
|
||||
if (install) url.searchParams.set('install', install);
|
||||
if (build) url.searchParams.set('build', build);
|
||||
if (rootDir) url.searchParams.set('rootDir', rootDir);
|
||||
if (rootDir)
|
||||
url.searchParams.set(
|
||||
'rootDir',
|
||||
rootDir || data.deploymentData.repository.rootDirectory
|
||||
);
|
||||
|
||||
if (data.envKeys.length > 0) {
|
||||
url.searchParams.set('env', data.envKeys.join(','));
|
||||
@@ -111,14 +124,12 @@
|
||||
}
|
||||
});
|
||||
|
||||
// Load regions when organization is selected
|
||||
$effect(() => {
|
||||
if (isCloud && selectedOrg) {
|
||||
loadAvailableRegions(selectedOrg);
|
||||
}
|
||||
});
|
||||
|
||||
// Set default region when regions are loaded
|
||||
$effect(() => {
|
||||
if (isCloud && $regionsStore.regions?.length > 0 && !region) {
|
||||
region = $regionsStore.regions.find((r) => r.default)?.$id as AllowedRegions;
|
||||
@@ -194,25 +205,28 @@
|
||||
}))}
|
||||
bind:value={selectedOrg} />
|
||||
|
||||
{#if projects?.total}
|
||||
<InputSelect
|
||||
id="project"
|
||||
label="Project"
|
||||
required
|
||||
options={[
|
||||
...projects.projects.map((p) => ({
|
||||
label: p.name,
|
||||
value: p.$id
|
||||
})),
|
||||
{
|
||||
label: 'Create project',
|
||||
leadingIcon: IconPlusSm,
|
||||
value: 'create-new'
|
||||
}
|
||||
]}
|
||||
bind:value={selectedProject} />
|
||||
{/if}
|
||||
{#if selectedProject === 'create-new'}
|
||||
<InputSelect
|
||||
id="project"
|
||||
label="Project"
|
||||
required
|
||||
placeholder={loadingProjects
|
||||
? 'Loading projects...'
|
||||
: undefined}
|
||||
disabled={loadingProjects}
|
||||
options={[
|
||||
...(projects?.projects?.map((p) => ({
|
||||
label: p.name,
|
||||
value: p.$id
|
||||
})) ?? []),
|
||||
{
|
||||
label: 'Create project',
|
||||
leadingIcon: IconPlus,
|
||||
value: null
|
||||
}
|
||||
]}
|
||||
bind:value={selectedProject} />
|
||||
|
||||
{#if selectedProject === null}
|
||||
<Layout.Stack direction="column" gap="s">
|
||||
<Input.Text
|
||||
label="Name"
|
||||
|
||||
@@ -7,66 +7,61 @@ import { ID, type Models } from '@appwrite.io/console';
|
||||
import type { OrganizationList } from '$lib/stores/organization';
|
||||
import { redirectTo } from '$routes/store';
|
||||
import type { PageLoad } from './$types';
|
||||
import { getRepositoryInfo } from '$lib/helpers/github';
|
||||
|
||||
export const load: PageLoad = async ({ parent, url }) => {
|
||||
const { account } = await parent();
|
||||
|
||||
// Store the full URL for redirect after auth
|
||||
const fullUrl = url.pathname + url.search;
|
||||
|
||||
// Check if user is authenticated
|
||||
if (!account) {
|
||||
redirectTo.set(fullUrl);
|
||||
redirect(302, base + '/login?redirect=' + encodeURIComponent(fullUrl));
|
||||
}
|
||||
|
||||
// Check deployment type - repo only for functions
|
||||
const repoUrl = url.searchParams.get('repo');
|
||||
const runtime = url.searchParams.get('runtime');
|
||||
const repository = url.searchParams.get('repo') || url.searchParams.get('repository');
|
||||
|
||||
// Must have repo
|
||||
if (!repoUrl) {
|
||||
if (!repository) {
|
||||
redirect(302, base + '/');
|
||||
}
|
||||
|
||||
// Get common parameters
|
||||
const name = url.searchParams.get('name');
|
||||
const envParam = url.searchParams.get('env');
|
||||
const envKeys = envParam ? envParam.split(',').map((key: string) => key.trim()) : [];
|
||||
const name = url.searchParams.get('name');
|
||||
|
||||
const deploymentData: {
|
||||
type: 'repo';
|
||||
repository: { url: string; owner: string; name: string };
|
||||
repository: {
|
||||
url: string;
|
||||
owner?: string;
|
||||
name?: string;
|
||||
rootDirectory?: string;
|
||||
};
|
||||
runtime?: string;
|
||||
name?: string;
|
||||
} = {
|
||||
type: 'repo',
|
||||
repository: {
|
||||
url: repoUrl!,
|
||||
owner: '',
|
||||
name: ''
|
||||
url: repository!,
|
||||
rootDirectory: null
|
||||
},
|
||||
runtime: runtime || 'node-18.0',
|
||||
name: name || ''
|
||||
name: name || '',
|
||||
runtime: runtime || 'node-18.0'
|
||||
};
|
||||
|
||||
// Get available runtimes
|
||||
const runtimesList = await sdk.forConsole.functions.listRuntimes();
|
||||
|
||||
// Repository deployment only
|
||||
const repoMatch = repoUrl!.match(/github\.com[/:]([^/]+)\/([^/?s]+)/);
|
||||
if (!repoMatch) {
|
||||
const info = getRepositoryInfo(repository!);
|
||||
if (!info) {
|
||||
redirect(302, base + '/');
|
||||
}
|
||||
|
||||
const [, owner, repoName] = repoMatch;
|
||||
// Clean repository name (remove .git extension if present)
|
||||
const cleanRepoName = repoName.replace(/\.git$/, '');
|
||||
|
||||
// Update deployment data with parsed repository info
|
||||
deploymentData.repository.owner = owner;
|
||||
deploymentData.repository.name = cleanRepoName;
|
||||
deploymentData.name = name || cleanRepoName;
|
||||
deploymentData.name = name || info.name;
|
||||
deploymentData.repository.name = info.name;
|
||||
deploymentData.repository.owner = info.owner;
|
||||
|
||||
// Get organizations
|
||||
let organizations: Models.TeamList<Record<string, unknown>> | OrganizationList | undefined;
|
||||
@@ -76,7 +71,6 @@ export const load: PageLoad = async ({ parent, url }) => {
|
||||
organizations = await sdk.forConsole.teams.list();
|
||||
}
|
||||
|
||||
// Create default organization if none exists - matches console's onboarding behavior
|
||||
if (!organizations?.total) {
|
||||
try {
|
||||
if (isCloud) {
|
||||
@@ -88,18 +82,18 @@ export const load: PageLoad = async ({ parent, url }) => {
|
||||
null
|
||||
);
|
||||
} else {
|
||||
await sdk.forConsole.teams.create(ID.unique(), 'Personal Projects');
|
||||
await sdk.forConsole.teams.create({
|
||||
teamId: ID.unique(),
|
||||
name: 'Personal Projects'
|
||||
});
|
||||
}
|
||||
|
||||
// Refetch organizations after creation
|
||||
if (isCloud) {
|
||||
organizations = await sdk.forConsole.billing.listOrganization();
|
||||
} else {
|
||||
organizations = await sdk.forConsole.teams.list();
|
||||
}
|
||||
} catch (e) {
|
||||
// If organization creation fails, still redirect to deploy page
|
||||
// The page will handle showing an error
|
||||
console.error('Failed to create default organization:', e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
import { getFrameworkIcon } from '$lib/stores/sites.js';
|
||||
import { isCloud } from '$lib/system';
|
||||
import { ID, Query, type Models, Region } from '@appwrite.io/console';
|
||||
import { IconGithub, IconPencil, IconPlusSm } from '@appwrite.io/pink-icons-svelte';
|
||||
import { IconGithub, IconPencil, IconPlus } from '@appwrite.io/pink-icons-svelte';
|
||||
import {
|
||||
Card,
|
||||
Divider,
|
||||
@@ -41,23 +41,31 @@
|
||||
let imageLoaded = $state(false);
|
||||
let imageError = $state(false);
|
||||
|
||||
let loadingProjects = $state(false);
|
||||
|
||||
async function fetchProjects() {
|
||||
projects = await sdk.forConsole.projects.list([
|
||||
Query.equal('teamId', selectedOrg),
|
||||
Query.orderDesc('')
|
||||
]);
|
||||
selectedProject = projects?.total ? projects.projects[0].$id : 'create-new';
|
||||
loadingProjects = true;
|
||||
projects = await sdk.forConsole.projects.list({
|
||||
queries: [Query.equal('teamId', selectedOrg), Query.orderDesc('')]
|
||||
});
|
||||
|
||||
selectedProject = projects?.total ? projects.projects[0].$id : null;
|
||||
loadingProjects = false;
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
if (selectedProject === 'create-new') {
|
||||
if (selectedProject === null) {
|
||||
try {
|
||||
const p = await sdk.forConsole.projects.create(
|
||||
id ?? ID.unique(),
|
||||
projectName,
|
||||
selectedOrg,
|
||||
isCloud ? (region as Region) : undefined
|
||||
);
|
||||
loadingProjects = true;
|
||||
const project = await sdk.forConsole.projects.create({
|
||||
projectId: id ?? ID.unique(),
|
||||
name: projectName,
|
||||
teamId: selectedOrg,
|
||||
region: isCloud ? (region as Region) : undefined
|
||||
});
|
||||
|
||||
selectedProject = project.$id;
|
||||
|
||||
trackEvent(Submit.ProjectCreate, {
|
||||
customId: !!id,
|
||||
selectedOrg,
|
||||
@@ -65,9 +73,7 @@
|
||||
source: 'deploy-button'
|
||||
});
|
||||
|
||||
selectedProject = p.$id;
|
||||
|
||||
const deployUrl = buildDeployUrl(p);
|
||||
const deployUrl = buildDeployUrl(project);
|
||||
await goto(deployUrl);
|
||||
} catch (e) {
|
||||
trackError(e, Submit.ProjectCreate);
|
||||
@@ -75,6 +81,8 @@
|
||||
type: 'error',
|
||||
message: e.message
|
||||
});
|
||||
} finally {
|
||||
loadingProjects = false;
|
||||
}
|
||||
} else {
|
||||
const project = projects.projects.find((p) => p.$id === selectedProject);
|
||||
@@ -98,7 +106,8 @@
|
||||
`${base}/project-${projectRegion}-${project.$id}/sites/create-site/deploy`,
|
||||
window.location.origin
|
||||
);
|
||||
url.searchParams.set('repo', data.deploymentData.repository.url);
|
||||
|
||||
url.searchParams.set('repository', data.deploymentData.repository.url);
|
||||
|
||||
// Pass through all the original URL params for repo deployments
|
||||
const currentUrl = new URL(window.location.href);
|
||||
@@ -126,32 +135,32 @@
|
||||
}
|
||||
});
|
||||
|
||||
// Load regions when organization is selected
|
||||
$effect(() => {
|
||||
if (isCloud && selectedOrg) {
|
||||
loadAvailableRegions(selectedOrg);
|
||||
}
|
||||
});
|
||||
|
||||
// Set default region when regions are loaded
|
||||
$effect(() => {
|
||||
if (isCloud && $regionsStore.regions?.length > 0 && !region) {
|
||||
region = $regionsStore.regions.find((r) => r.default)?.$id as AllowedRegions;
|
||||
}
|
||||
});
|
||||
|
||||
// Load screenshot if available for repositories
|
||||
$effect(() => {
|
||||
if (data.deploymentData.type === 'repo' && data.deploymentData.screenshot) {
|
||||
imageLoaded = false;
|
||||
imageError = false;
|
||||
|
||||
const img = document.createElement('img');
|
||||
img.onload = () => {
|
||||
imageLoaded = true;
|
||||
};
|
||||
|
||||
img.onerror = () => {
|
||||
imageError = true;
|
||||
};
|
||||
|
||||
img.src = data.deploymentData.screenshot;
|
||||
}
|
||||
});
|
||||
@@ -317,25 +326,28 @@
|
||||
}))}
|
||||
bind:value={selectedOrg} />
|
||||
|
||||
{#if projects?.total}
|
||||
<InputSelect
|
||||
id="project"
|
||||
label="Project"
|
||||
required
|
||||
options={[
|
||||
...projects.projects.map((p) => ({
|
||||
label: p.name,
|
||||
value: p.$id
|
||||
})),
|
||||
{
|
||||
label: 'Create project',
|
||||
leadingIcon: IconPlusSm,
|
||||
value: 'create-new'
|
||||
}
|
||||
]}
|
||||
bind:value={selectedProject} />
|
||||
{/if}
|
||||
{#if selectedProject === 'create-new'}
|
||||
<InputSelect
|
||||
id="project"
|
||||
label="Project"
|
||||
required
|
||||
placeholder={loadingProjects
|
||||
? 'Loading projects...'
|
||||
: undefined}
|
||||
disabled={loadingProjects}
|
||||
options={[
|
||||
...(projects?.projects?.map((p) => ({
|
||||
label: p.name,
|
||||
value: p.$id
|
||||
})) ?? []),
|
||||
{
|
||||
label: 'Create project',
|
||||
leadingIcon: IconPlus,
|
||||
value: null
|
||||
}
|
||||
]}
|
||||
bind:value={selectedProject} />
|
||||
|
||||
{#if selectedProject === null}
|
||||
<Layout.Stack direction="column" gap="s">
|
||||
<Input.Text
|
||||
label="Name"
|
||||
|
||||
@@ -7,37 +7,35 @@ import { ID, type Models } from '@appwrite.io/console';
|
||||
import type { OrganizationList } from '$lib/stores/organization';
|
||||
import { redirectTo } from '$routes/store';
|
||||
import type { PageLoad } from './$types';
|
||||
import { getRepositoryInfo } from '$lib/helpers/github';
|
||||
|
||||
export const load: PageLoad = async ({ parent, url }) => {
|
||||
const { account } = await parent();
|
||||
|
||||
// Store the full URL for redirect after auth
|
||||
const fullUrl = url.pathname + url.search;
|
||||
|
||||
// Check if user is authenticated
|
||||
if (!account) {
|
||||
redirectTo.set(fullUrl);
|
||||
redirect(302, base + '/login?redirect=' + encodeURIComponent(fullUrl));
|
||||
}
|
||||
|
||||
// Check deployment type - either template or repo
|
||||
const templateKey = url.searchParams.get('template');
|
||||
const repoUrl = url.searchParams.get('repo');
|
||||
const repository = url.searchParams.get('repo') || url.searchParams.get('repository');
|
||||
|
||||
// Must have either template or repo, but not both
|
||||
if (!templateKey && !repoUrl) {
|
||||
if (!templateKey && !repository) {
|
||||
redirect(302, base + '/');
|
||||
}
|
||||
if (templateKey && repoUrl) {
|
||||
|
||||
if (templateKey && repository) {
|
||||
error(400, 'Cannot specify both template and repo parameters');
|
||||
}
|
||||
|
||||
// Get common parameters
|
||||
const envParam = url.searchParams.get('env');
|
||||
const envKeys = envParam ? envParam.split(',').map((key: string) => key.trim()) : [];
|
||||
const screenshot = url.searchParams.get('screenshot');
|
||||
const name = url.searchParams.get('name');
|
||||
const envParam = url.searchParams.get('env');
|
||||
const tagline = url.searchParams.get('tagline');
|
||||
const screenshot = url.searchParams.get('screenshot');
|
||||
const envKeys = envParam ? envParam.split(',').map((key: string) => key.trim()) : [];
|
||||
|
||||
let deploymentData: {
|
||||
type: 'template' | 'repo';
|
||||
@@ -49,52 +47,48 @@ export const load: PageLoad = async ({ parent, url }) => {
|
||||
};
|
||||
|
||||
if (templateKey) {
|
||||
// Template deployment
|
||||
try {
|
||||
const template = await sdk.forConsole.sites.getTemplate(templateKey);
|
||||
const template = await sdk.forConsole.sites.getTemplate({ templateId: templateKey });
|
||||
deploymentData = {
|
||||
type: 'template',
|
||||
template,
|
||||
screenshot: screenshot || template.screenshotLight,
|
||||
name: name || template.name,
|
||||
tagline: tagline || template.tagline
|
||||
tagline: tagline || template.tagline,
|
||||
// TODO: maybe get the browser's theme
|
||||
// and select appropriate theme here.
|
||||
screenshot: screenshot || template.screenshotLight
|
||||
};
|
||||
} catch (e) {
|
||||
error(404, `Template "${templateKey}" not found`);
|
||||
}
|
||||
} else {
|
||||
// Repository deployment
|
||||
const repoMatch = repoUrl!.match(/github\.com[/:]([^/]+)\/([^/?s]+)/);
|
||||
if (!repoMatch) {
|
||||
const info = getRepositoryInfo(repository!);
|
||||
if (!info) {
|
||||
console.log(info);
|
||||
redirect(302, base + '/');
|
||||
}
|
||||
|
||||
const [, owner, repoName] = repoMatch;
|
||||
// Clean repository name (remove .git extension if present)
|
||||
const cleanRepoName = repoName.replace(/\.git$/, '');
|
||||
|
||||
deploymentData = {
|
||||
type: 'repo',
|
||||
repository: {
|
||||
url: repoUrl!,
|
||||
owner,
|
||||
name: cleanRepoName
|
||||
url: repository,
|
||||
name: info.name,
|
||||
owner: info.owner
|
||||
},
|
||||
screenshot,
|
||||
name: name || cleanRepoName,
|
||||
name: name || info.name,
|
||||
tagline
|
||||
};
|
||||
}
|
||||
|
||||
// Get organizations
|
||||
let organizations: Models.TeamList<Record<string, unknown>> | OrganizationList | undefined;
|
||||
|
||||
if (isCloud) {
|
||||
organizations = await sdk.forConsole.billing.listOrganization();
|
||||
} else {
|
||||
organizations = await sdk.forConsole.teams.list();
|
||||
}
|
||||
|
||||
// Create default organization if none exists - matches console's onboarding behavior
|
||||
if (!organizations?.total) {
|
||||
try {
|
||||
if (isCloud) {
|
||||
@@ -102,11 +96,13 @@ export const load: PageLoad = async ({ parent, url }) => {
|
||||
ID.unique(),
|
||||
'Personal Projects',
|
||||
BillingPlan.FREE,
|
||||
null,
|
||||
null
|
||||
);
|
||||
} else {
|
||||
await sdk.forConsole.teams.create(ID.unique(), 'Personal Projects');
|
||||
await sdk.forConsole.teams.create({
|
||||
teamId: ID.unique(),
|
||||
name: 'Personal Projects'
|
||||
});
|
||||
}
|
||||
|
||||
// Refetch organizations after creation
|
||||
@@ -116,8 +112,6 @@ export const load: PageLoad = async ({ parent, url }) => {
|
||||
organizations = await sdk.forConsole.teams.list();
|
||||
}
|
||||
} catch (e) {
|
||||
// If organization creation fails, still redirect to deploy page
|
||||
// The page will handle showing an error
|
||||
console.error('Failed to create default organization:', e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user