mirror of
https://github.com/thiloho/archtika.git
synced 2025-11-22 10:51:36 +01:00
Use environment variables for ports in web app
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
import type { Actions, PageServerLoad } from "./$types";
|
||||
|
||||
export const load: PageServerLoad = async ({ parent, params, cookies, fetch }) => {
|
||||
const articleData = await fetch(`http://localhost:3000/article?id=eq.${params.articleId}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${cookies.get("session_token")}`,
|
||||
Accept: "application/vnd.pgrst.object+json"
|
||||
const articleData = await fetch(
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/article?id=eq.${params.articleId}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${cookies.get("session_token")}`,
|
||||
Accept: "application/vnd.pgrst.object+json"
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
const article = await articleData.json();
|
||||
const { website } = await parent();
|
||||
@@ -21,40 +24,46 @@ export const actions: Actions = {
|
||||
const data = await request.formData();
|
||||
const coverFile = data.get("cover-image") as File;
|
||||
|
||||
const uploadedImageData = await fetch(`http://localhost:3000/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()
|
||||
});
|
||||
const uploadedImageData = await fetch(
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/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()
|
||||
}
|
||||
);
|
||||
|
||||
const uploadedImage = await uploadedImageData.json();
|
||||
|
||||
if (!uploadedImageData.ok) {
|
||||
if (!uploadedImageData.ok && coverFile.size > 0) {
|
||||
return { success: false, message: uploadedImage.message };
|
||||
}
|
||||
|
||||
const res = await fetch(`http://localhost:3000/article?id=eq.${params.articleId}`, {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${cookies.get("session_token")}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
title: data.get("title"),
|
||||
meta_description: data.get("description"),
|
||||
meta_author: data.get("author"),
|
||||
cover_image: uploadedImage.file_id,
|
||||
publication_date: data.get("publication-date"),
|
||||
main_content: data.get("main-content")
|
||||
})
|
||||
});
|
||||
const res = await fetch(
|
||||
`http://localhost:${process.env.ARCHTIKA_API_PORT}/article?id=eq.${params.articleId}`,
|
||||
{
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${cookies.get("session_token")}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
title: data.get("title"),
|
||||
meta_description: data.get("description"),
|
||||
meta_author: data.get("author"),
|
||||
cover_image: uploadedImage.file_id,
|
||||
publication_date: data.get("publication-date"),
|
||||
main_content: data.get("main-content")
|
||||
})
|
||||
}
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
const response = await res.json();
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
{#if data.article.cover_image}
|
||||
<Modal id="preview-cover-article-{data.article.id}" text="Preview">
|
||||
<img
|
||||
src={`http://localhost:3000/rpc/retrieve_file?id=${data.article.cover_image}`}
|
||||
src={`http://localhost:${process.env.ARCHTIKA_API_PORT}/rpc/retrieve_file?id=${data.article.cover_image}`}
|
||||
alt=""
|
||||
/>
|
||||
</Modal>
|
||||
|
||||
Reference in New Issue
Block a user