mirror of
https://github.com/thiloho/archtika.git
synced 2025-11-22 10:51:36 +01:00
Remove NGINX website directories from API and fix some minor issues
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
{websiteUrl}
|
||||
/>
|
||||
|
||||
<Nav {websiteOverview} isDocsTemplate={false} isIndexPage={true} {apiUrl} />
|
||||
<Nav {websiteOverview} isDocsTemplate={false} isIndexPage={true} {isLegalPage} {apiUrl} />
|
||||
|
||||
<header>
|
||||
<div class="container">
|
||||
|
||||
@@ -6,12 +6,14 @@
|
||||
websiteOverview,
|
||||
isDocsTemplate,
|
||||
isIndexPage,
|
||||
apiUrl
|
||||
apiUrl,
|
||||
isLegalPage
|
||||
}: {
|
||||
websiteOverview: WebsiteOverview;
|
||||
isDocsTemplate: boolean;
|
||||
isIndexPage: boolean;
|
||||
apiUrl: string;
|
||||
isLegalPage?: boolean;
|
||||
} = $props();
|
||||
|
||||
const categorizedArticles = Object.fromEntries(
|
||||
@@ -70,7 +72,10 @@
|
||||
</ul>
|
||||
</section>
|
||||
{/if}
|
||||
<svelte:element this={isIndexPage ? "span" : "a"} href="..">
|
||||
<svelte:element
|
||||
this={isIndexPage && !isLegalPage ? "span" : "a"}
|
||||
href={`${isLegalPage ? "./" : "../"}`}
|
||||
>
|
||||
{#if websiteOverview.header.logo_type === "text"}
|
||||
<strong>{websiteOverview.header.logo_text}</strong>
|
||||
{:else}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
{websiteUrl}
|
||||
/>
|
||||
|
||||
<Nav {websiteOverview} isDocsTemplate={true} isIndexPage={true} {apiUrl} />
|
||||
<Nav {websiteOverview} isDocsTemplate={true} isIndexPage={true} {isLegalPage} {apiUrl} />
|
||||
|
||||
<header>
|
||||
<div class="container">
|
||||
|
||||
@@ -38,7 +38,14 @@
|
||||
<form method="POST" use:enhance={enhanceForm()}>
|
||||
<label>
|
||||
Username:
|
||||
<input type="text" name="username" minlength="3" maxlength="16" required />
|
||||
<input
|
||||
type="text"
|
||||
name="username"
|
||||
minlength="3"
|
||||
maxlength="16"
|
||||
pattern="^[a-zA-Z0-9_\-]+$"
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Password:
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import type { Actions, PageServerLoad } from "./$types";
|
||||
import { apiRequest } from "$lib/server/utils";
|
||||
import { API_BASE_PREFIX } from "$lib/server/utils";
|
||||
import { rm } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import type { Website } from "$lib/db-schema";
|
||||
|
||||
export const load: PageServerLoad = async ({ fetch, url, locals }) => {
|
||||
@@ -11,7 +9,7 @@ export const load: PageServerLoad = async ({ fetch, url, locals }) => {
|
||||
|
||||
const params = new URLSearchParams();
|
||||
|
||||
const baseFetchUrl = `${API_BASE_PREFIX}/website?order=last_modified_at.desc,created_at.desc`;
|
||||
const baseFetchUrl = `${API_BASE_PREFIX}/website?select=*,collab(user_id)&collab.user_id=eq.${locals.user.id}&or=(user_id.eq.${locals.user.id},collab.not.is.null)&order=last_modified_at.desc,created_at.desc`;
|
||||
|
||||
if (searchQuery) {
|
||||
params.append("title", `wfts.${searchQuery}`);
|
||||
@@ -77,15 +75,6 @@ export const actions: Actions = {
|
||||
const data = await request.formData();
|
||||
const id = data.get("id");
|
||||
|
||||
const oldDomainPrefix = (
|
||||
await apiRequest(fetch, `${API_BASE_PREFIX}/domain_prefix?website_id=eq.${id}`, "GET", {
|
||||
headers: {
|
||||
Accept: "application/vnd.pgrst.object+json"
|
||||
},
|
||||
returnData: true
|
||||
})
|
||||
).data;
|
||||
|
||||
const deleteWebsite = await apiRequest(
|
||||
fetch,
|
||||
`${API_BASE_PREFIX}/website?id=eq.${id}`,
|
||||
@@ -99,16 +88,6 @@ export const actions: Actions = {
|
||||
return deleteWebsite;
|
||||
}
|
||||
|
||||
await rm(join("/", "var", "www", "archtika-websites", "previews", id as string), {
|
||||
recursive: true,
|
||||
force: true
|
||||
});
|
||||
|
||||
await rm(join("/", "var", "www", "archtika-websites", oldDomainPrefix?.prefix ?? id), {
|
||||
recursive: true,
|
||||
force: true
|
||||
});
|
||||
|
||||
return deleteWebsite;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -21,7 +21,7 @@ export const actions: Actions = {
|
||||
logout: async ({ cookies }) => {
|
||||
cookies.delete("session_token", { path: "/" });
|
||||
|
||||
return { success: true, message: "Successfully logged out" };
|
||||
return { success: true, message: "Successfully logged out, you can refresh the page" };
|
||||
},
|
||||
deleteAccount: async ({ request, fetch, cookies }) => {
|
||||
const data = await request.formData();
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
{#if data.storageSizes.data.length > 0}
|
||||
{#if (data.storageSizes.data ?? []).length > 0}
|
||||
<section id="storage">
|
||||
<h2>
|
||||
<a href="#storage">Storage</a>
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import type { Actions, PageServerLoad } from "./$types";
|
||||
import { API_BASE_PREFIX } from "$lib/server/utils";
|
||||
import { apiRequest } from "$lib/server/utils";
|
||||
import type { Website, User } from "$lib/db-schema";
|
||||
|
||||
export const load: PageServerLoad = async ({ fetch }) => {
|
||||
const allUsers = (
|
||||
const usersWithWebsites: (User & { website: Website[] })[] = (
|
||||
await apiRequest(
|
||||
fetch,
|
||||
`${API_BASE_PREFIX}/all_user_websites?order=user_created_at.desc`,
|
||||
`${API_BASE_PREFIX}/user?select=*,website!user_id(*)&order=created_at`,
|
||||
"GET",
|
||||
{
|
||||
returnData: true
|
||||
@@ -15,7 +16,7 @@ export const load: PageServerLoad = async ({ fetch }) => {
|
||||
).data;
|
||||
|
||||
return {
|
||||
allUsers,
|
||||
usersWithWebsites,
|
||||
API_BASE_PREFIX
|
||||
};
|
||||
};
|
||||
@@ -39,8 +40,6 @@ export const actions: Actions = {
|
||||
updateStorageLimit: async ({ request, fetch }) => {
|
||||
const data = await request.formData();
|
||||
|
||||
console.log(`${API_BASE_PREFIX}/website?id=eq.${data.get("website-id")}`);
|
||||
|
||||
return await apiRequest(
|
||||
fetch,
|
||||
`${API_BASE_PREFIX}/website?id=eq.${data.get("website-id")}`,
|
||||
|
||||
@@ -32,15 +32,15 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each data.allUsers as { user_id, user_created_at, username, max_number_websites, websites }}
|
||||
{#each data.usersWithWebsites as { id, created_at, username, max_number_websites, website }}
|
||||
<tr>
|
||||
<td>
|
||||
<DateTime date={user_created_at} />
|
||||
<DateTime date={created_at} />
|
||||
</td>
|
||||
<td>{user_id}</td>
|
||||
<td>{id}</td>
|
||||
<td>{username}</td>
|
||||
<td>
|
||||
<Modal id="manage-user-{user_id}" text="Manage">
|
||||
<Modal id="manage-user-{id}" text="Manage">
|
||||
<hgroup>
|
||||
<h3>Manage user</h3>
|
||||
<p>User "{username}"</p>
|
||||
@@ -51,7 +51,7 @@
|
||||
action="?/updateMaxWebsiteAmount"
|
||||
use:enhance={enhanceForm({ reset: false })}
|
||||
>
|
||||
<input type="hidden" name="user-id" value={user_id} />
|
||||
<input type="hidden" name="user-id" value={id} />
|
||||
<label>
|
||||
Number of websites allowed:
|
||||
<input
|
||||
@@ -64,9 +64,9 @@
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
|
||||
{#if websites.length > 0}
|
||||
{#if website.length > 0}
|
||||
<h4>Websites</h4>
|
||||
{#each websites as { id, title, max_storage_size }}
|
||||
{#each website as { id, title, max_storage_size }}
|
||||
<details>
|
||||
<summary>{title}</summary>
|
||||
<div>
|
||||
@@ -105,7 +105,7 @@
|
||||
action="?/deleteUser"
|
||||
use:enhance={enhanceForm({ closeModal: true })}
|
||||
>
|
||||
<input type="hidden" name="user-id" value={user_id} />
|
||||
<input type="hidden" name="user-id" value={id} />
|
||||
<button type="submit">Delete user</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -4,37 +4,24 @@ import { apiRequest } from "$lib/server/utils";
|
||||
import type { Settings, Header, Footer } from "$lib/db-schema";
|
||||
|
||||
export const load: PageServerLoad = async ({ params, fetch }) => {
|
||||
const globalSettings: Settings = (
|
||||
await apiRequest(
|
||||
fetch,
|
||||
`${API_BASE_PREFIX}/settings?website_id=eq.${params.websiteId}`,
|
||||
"GET",
|
||||
{
|
||||
headers: {
|
||||
Accept: "application/vnd.pgrst.object+json"
|
||||
},
|
||||
returnData: true
|
||||
}
|
||||
)
|
||||
).data;
|
||||
|
||||
const header: Header = (
|
||||
await apiRequest(fetch, `${API_BASE_PREFIX}/header?website_id=eq.${params.websiteId}`, "GET", {
|
||||
headers: {
|
||||
Accept: "application/vnd.pgrst.object+json"
|
||||
},
|
||||
const [globalSettingsResponse, headerResponse, footerResponse] = await Promise.all([
|
||||
apiRequest(fetch, `${API_BASE_PREFIX}/settings?website_id=eq.${params.websiteId}`, "GET", {
|
||||
headers: { Accept: "application/vnd.pgrst.object+json" },
|
||||
returnData: true
|
||||
}),
|
||||
apiRequest(fetch, `${API_BASE_PREFIX}/header?website_id=eq.${params.websiteId}`, "GET", {
|
||||
headers: { Accept: "application/vnd.pgrst.object+json" },
|
||||
returnData: true
|
||||
}),
|
||||
apiRequest(fetch, `${API_BASE_PREFIX}/footer?website_id=eq.${params.websiteId}`, "GET", {
|
||||
headers: { Accept: "application/vnd.pgrst.object+json" },
|
||||
returnData: true
|
||||
})
|
||||
).data;
|
||||
]);
|
||||
|
||||
const footer: Footer = (
|
||||
await apiRequest(fetch, `${API_BASE_PREFIX}/footer?website_id=eq.${params.websiteId}`, "GET", {
|
||||
headers: {
|
||||
Accept: "application/vnd.pgrst.object+json"
|
||||
},
|
||||
returnData: true
|
||||
})
|
||||
).data;
|
||||
const globalSettings: Settings = globalSettingsResponse.data;
|
||||
const header: Header = headerResponse.data;
|
||||
const footer: Footer = footerResponse.data;
|
||||
|
||||
return {
|
||||
globalSettings,
|
||||
|
||||
@@ -44,14 +44,16 @@
|
||||
<input type="number" name="article-weight" value={data.article.article_weight} min="0" />
|
||||
</label>
|
||||
|
||||
<label>
|
||||
Category:
|
||||
<select name="category">
|
||||
{#each data.categories as { id, category_name }}
|
||||
<option value={id} selected={id === data.article.category}>{category_name}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</label>
|
||||
{#if data.categories.length > 0}
|
||||
<label>
|
||||
Category:
|
||||
<select name="category">
|
||||
{#each data.categories as { id, category_name }}
|
||||
<option value={id} selected={id === data.article.category}>{category_name}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</label>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<label>
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { Actions, PageServerLoad } from "./$types";
|
||||
import { API_BASE_PREFIX, apiRequest } from "$lib/server/utils";
|
||||
import { rm } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import type { LegalInformation } from "$lib/db-schema";
|
||||
|
||||
export const load: PageServerLoad = async ({ parent, fetch, params }) => {
|
||||
@@ -58,11 +56,6 @@ export const actions: Actions = {
|
||||
return deleteLegalInformation;
|
||||
}
|
||||
|
||||
await rm(
|
||||
join("/", "var", "www", "archtika-websites", params.websiteId, "legal-information.html"),
|
||||
{ force: true }
|
||||
);
|
||||
|
||||
return deleteLegalInformation;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@ import BlogIndex from "$lib/templates/blog/BlogIndex.svelte";
|
||||
import DocsArticle from "$lib/templates/docs/DocsArticle.svelte";
|
||||
import DocsIndex from "$lib/templates/docs/DocsIndex.svelte";
|
||||
import { type WebsiteOverview, hexToHSL, slugify } from "$lib/utils";
|
||||
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
||||
import { mkdir, readFile, rename, writeFile, chmod, readdir } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { render } from "svelte/server";
|
||||
import type { Actions, PageServerLoad } from "./$types";
|
||||
@@ -290,5 +290,20 @@ const generateStaticFiles = async (websiteData: WebsiteOverview, isPreview = tru
|
||||
await writeFile(join(uploadDir, "common.css"), commonStyles);
|
||||
await writeFile(join(uploadDir, "scoped.css"), specificStyles);
|
||||
|
||||
await setPermissions(isPreview ? join(uploadDir, "../") : uploadDir);
|
||||
|
||||
return { websitePreviewUrl, websiteProdUrl };
|
||||
};
|
||||
|
||||
const setPermissions = async (dir: string) => {
|
||||
await chmod(dir, 0o777);
|
||||
const entries = await readdir(dir, { withFileTypes: true });
|
||||
for (const entry of entries) {
|
||||
const fullPath = join(dir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
await setPermissions(fullPath);
|
||||
} else {
|
||||
await chmod(fullPath, 0o777);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user