Initialize playwright, fix file upload issue, show publication status and delete website dir on website deletion

This commit is contained in:
thiloho
2024-08-30 15:48:15 +02:00
parent 8915a7cfd9
commit bb73c2350d
15 changed files with 284 additions and 41 deletions

View File

@@ -49,22 +49,27 @@ export const actions: Actions = {
const data = await request.formData();
const faviconFile = data.get("favicon") as File;
const headers: Record<string, string> = {
"Content-Type": "application/octet-stream",
Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json",
"X-Website-Id": params.websiteId
};
if (faviconFile) {
headers["X-Mimetype"] = faviconFile.type;
headers["X-Original-Filename"] = faviconFile.name;
}
const uploadedImageData = await fetch(`${API_BASE_PREFIX}/rpc/upload_file`, {
method: "POST",
headers: {
"Content-Type": "application/octet-stream",
Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json",
"X-Website-Id": params.websiteId,
"X-Mimetype": faviconFile.type,
"X-Original-Filename": faviconFile.name
},
body: await faviconFile.arrayBuffer()
headers,
body: faviconFile ? await faviconFile.arrayBuffer() : null
});
const uploadedImage = await uploadedImageData.json();
if (!uploadedImageData.ok && faviconFile.size > 0) {
if (!uploadedImageData.ok && (faviconFile?.size ?? 0 > 0)) {
return { success: false, message: uploadedImage.message };
}
@@ -95,22 +100,27 @@ export const actions: Actions = {
const data = await request.formData();
const logoImage = data.get("logo-image") as File;
const headers: Record<string, string> = {
"Content-Type": "application/octet-stream",
Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json",
"X-Website-Id": params.websiteId
};
if (logoImage) {
headers["X-Mimetype"] = logoImage.type;
headers["X-Original-Filename"] = logoImage.name;
}
const uploadedImageData = await fetch(`${API_BASE_PREFIX}/rpc/upload_file`, {
method: "POST",
headers: {
"Content-Type": "application/octet-stream",
Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json",
"X-Website-Id": params.websiteId,
"X-Mimetype": logoImage.type,
"X-Original-Filename": logoImage.name
},
body: await logoImage.arrayBuffer()
headers,
body: logoImage ? await logoImage.arrayBuffer() : null
});
const uploadedImage = await uploadedImageData.json();
if (!uploadedImageData.ok && logoImage.size > 0) {
if (!uploadedImageData.ok && (logoImage?.size ?? 0 > 0)) {
return { success: false, message: uploadedImage.message };
}

View File

@@ -123,12 +123,7 @@
<div class="file-field">
<label>
Logo image:
<input
type="file"
name="logo-image"
accept={ALLOWED_MIME_TYPES.join(", ")}
required={data.header.logo_type === "image"}
/>
<input type="file" name="logo-image" accept={ALLOWED_MIME_TYPES.join(", ")} />
</label>
{#if data.header.logo_image}
<Modal id="preview-logo-header-{data.header.website_id}" text="Preview">

View File

@@ -34,22 +34,27 @@ export const actions: Actions = {
const data = await request.formData();
const coverFile = data.get("cover-image") as File;
const headers: Record<string, string> = {
"Content-Type": "application/octet-stream",
Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json",
"X-Website-Id": params.websiteId
};
if (coverFile) {
headers["X-Mimetype"] = coverFile.type;
headers["X-Original-Filename"] = coverFile.name;
}
const uploadedImageData = await fetch(`${API_BASE_PREFIX}/rpc/upload_file`, {
method: "POST",
headers: {
"Content-Type": "application/octet-stream",
Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json",
"X-Website-Id": params.websiteId,
"X-Mimetype": coverFile.type,
"X-Original-Filename": coverFile.name
},
body: await coverFile.arrayBuffer()
headers,
body: coverFile ? await coverFile.arrayBuffer() : null
});
const uploadedImage = await uploadedImageData.json();
if (!uploadedImageData.ok && coverFile.size > 0) {
if (!uploadedImageData.ok && (coverFile?.size ?? 0 > 0)) {
return { success: false, message: uploadedImage.message };
}

View File

@@ -54,6 +54,22 @@ export const actions: Actions = {
const websiteOverview = await websiteOverviewData.json();
generateStaticFiles(websiteOverview, false);
const res = await fetch(`${API_BASE_PREFIX}/website?id=eq.${params.websiteId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${cookies.get("session_token")}`
},
body: JSON.stringify({
is_published: true
})
});
if (!res.ok) {
const response = await res.json();
return { success: false, message: response.message };
}
return { success: true, message: "Successfully published website" };
}
};

View File

@@ -5,6 +5,8 @@
import type { ActionData, PageServerData } from "./$types";
const { data, form }: { data: PageServerData; form: ActionData } = $props();
const prodWebsiteUrl = data.websitePreviewUrl.replace("/previews", "");
</script>
<SuccessOrError success={form?.success} message={form?.message} />
@@ -28,5 +30,18 @@
<form method="POST" action="?/publishWebsite" use:enhance>
<button type="submit">Publish</button>
</form>
{#if data.website.is_published}
<section>
<h3>
<a href="#publication-status">Publication status</a>
</h3>
<p>
Your website is published at:
<br />
<a href={prodWebsiteUrl}>{prodWebsiteUrl}</a>
</p>
</section>
{/if}
</section>
</WebsiteEditor>