a lot of work, but i'd guess mostly api in the works
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import { db } from '$lib/server/db';
|
||||
import { filesystem } from '$lib/server/db/schema';
|
||||
import { MD5 } from '$lib/termos/util/hash';
|
||||
import { eq } from 'drizzle-orm';
|
||||
|
||||
export async function GET({ request }): Promise<Response> {
|
||||
const row = await db
|
||||
.select({
|
||||
data: filesystem.data,
|
||||
checksum: filesystem.checksum
|
||||
})
|
||||
.from(filesystem)
|
||||
.where(eq(filesystem.id, 1))
|
||||
.limit(1);
|
||||
|
||||
if (!row.length) {
|
||||
return new Response('Filesystem is not initialized on the database', { status: 500 });
|
||||
}
|
||||
|
||||
const { data, checksum } = row[0];
|
||||
const clientETag = request.headers.get('if-none-match');
|
||||
|
||||
if (clientETag === `"${checksum}"`) {
|
||||
return new Response(null, {
|
||||
status: 304,
|
||||
headers: { ETag: `"${checksum}"` }
|
||||
});
|
||||
}
|
||||
|
||||
return new Response(data, {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
ETag: `"${checksum}"`,
|
||||
'Cache-Control': 'no-cache'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export async function POST({ request }) {
|
||||
const newData = await request.text();
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(newData);
|
||||
//TODO: Schema validation
|
||||
} catch {
|
||||
//TODO: Change that to a proper http headers error
|
||||
return new Response(null, {
|
||||
status: 400
|
||||
});
|
||||
}
|
||||
|
||||
const checksum: string = MD5.hash(newData);
|
||||
|
||||
await db.update(filesystem).set({ data: newData, checksum }).where(eq(filesystem.id, 1));
|
||||
|
||||
return new Response(JSON.stringify({ success: true }), { status: 200 });
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { db } from '$lib/server/db';
|
||||
import { users } from '$lib/server/db/schema';
|
||||
import { json } from '@sveltejs/kit';
|
||||
|
||||
export async function GET({ request }): Promise<Response> {
|
||||
const rows = await db
|
||||
.select({
|
||||
uid: users.uid,
|
||||
username: users.username,
|
||||
password: users.password,
|
||||
home: users.home,
|
||||
gid: users.gid,
|
||||
accessible: users.accessible
|
||||
})
|
||||
.from(users);
|
||||
|
||||
if (!rows.length) {
|
||||
return new Response('Filesystem is not initialized on the database', { status: 500 });
|
||||
}
|
||||
|
||||
const result: {}[] = rows.map((u) => ({
|
||||
...u,
|
||||
avatarUrl: `/api/users/${u.uid}/avatar`
|
||||
}));
|
||||
|
||||
return json(result);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { db } from '$lib/server/db';
|
||||
import { users } from '$lib/server/db/schema';
|
||||
import { eq } from 'drizzle-orm';
|
||||
|
||||
export async function GET({ params, request }): Promise<Response> {
|
||||
const row = await db
|
||||
.select({
|
||||
uid: users.uid,
|
||||
username: users.username,
|
||||
password: users.password,
|
||||
home: users.home,
|
||||
gid: users.gid,
|
||||
accessible: users.accessible
|
||||
})
|
||||
.from(users)
|
||||
.where(eq(users.uid, Number(params.uid)))
|
||||
.limit(1);
|
||||
|
||||
if (!row.length) {
|
||||
return new Response(`User not found`, { status: 404 });
|
||||
}
|
||||
|
||||
const user = row[0];
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
...user,
|
||||
avatarUrl: `/api/users/${user.uid}/avatar`
|
||||
}),
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { db } from '$lib/server/db';
|
||||
import { users } from '$lib/server/db/schema';
|
||||
import { eq } from 'drizzle-orm';
|
||||
|
||||
export async function PUT({ params, request }) {
|
||||
const uid = Number(params.uid);
|
||||
const arrayBuffer = await request.arrayBuffer();
|
||||
const buffer = Buffer.from(arrayBuffer);
|
||||
await db.update(users).set({ face: buffer }).where(eq(users.uid, uid));
|
||||
return new Response(null, { status: 204 });
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
<script lang="ts">
|
||||
import '../../app.css';
|
||||
import favicon from '$lib/assets/favicon.svg';
|
||||
import { getContext, setContext, type Snippet } from 'svelte';
|
||||
import { BookA, ChartLine, ChartNoAxesColumn, Construction, FolderArchive, Plus } from '@lucide/svelte';
|
||||
import { BookA, ChartLine, ChartNoAxesColumn, FolderArchive, Plus } from '@lucide/svelte';
|
||||
import { type Snippet } from 'svelte';
|
||||
import '../../app.css';
|
||||
import SidebarButton from '../../modules/panel/SidebarButton.svelte';
|
||||
let { children, data}: { children: Snippet, data: any } = $props();
|
||||
|
||||
let { children, data }: { children: Snippet; data: any } = $props();
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@@ -36,7 +35,7 @@
|
||||
</SidebarButton>
|
||||
</form>
|
||||
</div>
|
||||
<div class="flex w-full grow">
|
||||
<div class=" w-full">
|
||||
{@render children()}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { db } from '$lib/server/db';
|
||||
import { locales } from '$lib/server/db/schema';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async () => {
|
||||
return {
|
||||
locales: await db
|
||||
.select({
|
||||
code: locales.code,
|
||||
name: locales.name,
|
||||
dictionary: locales.dictionary,
|
||||
flag: locales.flag,
|
||||
enabled: locales.enabled
|
||||
})
|
||||
.from(locales)
|
||||
};
|
||||
};
|
||||
@@ -1,19 +1,25 @@
|
||||
<script lang="ts">
|
||||
import LangModule from '../../../modules/panel/LangModule.svelte';
|
||||
import plFlag from '$lib/assets/plFlag.svg';
|
||||
import enFlag from '$lib/assets/enFlag.svg';
|
||||
import deFlag from '$lib/assets/deFlag.svg';
|
||||
import frFlag from '$lib/assets/frFlag.svg';
|
||||
import jaFlag from '$lib/assets/jaFlag.svg';
|
||||
|
||||
let { data }: { data: any } = $props();
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<form name="langs" class="m-10 flex flex-col gap-4">
|
||||
<LangModule checked langName="Polish" icon={plFlag} />
|
||||
<form name="locales" class="m-10 flex flex-col gap-4">
|
||||
{#each data.locales as locale}
|
||||
<LangModule checked={locale.enabled} langName={locale.name} icon={locale.flag} />
|
||||
{/each}
|
||||
<!-- <LangModule checked langName="Polish" icon={plFlag} />
|
||||
<LangModule checked langName="English" icon={enFlag} />
|
||||
<LangModule checked langName="German" icon={deFlag} />
|
||||
<LangModule langName="Japanese" icon={jaFlag} />
|
||||
<LangModule langName="French" icon={frFlag} />
|
||||
<LangModule langName="French" icon={frFlag} /> -->
|
||||
</form>
|
||||
<div></div>
|
||||
<div>
|
||||
<form>
|
||||
<input type="file" />
|
||||
<input type="image" alt="NaN" />
|
||||
<input type="text" />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,10 +1,34 @@
|
||||
import { db } from "$lib/server/db";
|
||||
import { settings } from "$lib/server/db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import type { PageServerLoad } from "./$types";
|
||||
import fsData from '$lib/assets/fs/fs.json';
|
||||
import { db } from '$lib/server/db';
|
||||
import { projects, settings } from '$lib/server/db/schema';
|
||||
import { FileSystem } from '$lib/termos/filesystem/filesystem';
|
||||
import { Sort, SortNodeBy } from '$lib/termos/util/sort';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async () => {
|
||||
FileSystem.Init(fsData as any);
|
||||
|
||||
const fs = FileSystem.instance;
|
||||
|
||||
const node = fs.getNodeByInode(13); //Gordonox home dir
|
||||
let nodes = node.children.map((child) => fs.getNodeByInode(child));
|
||||
nodes = Sort.nodeArraySort(nodes, false, SortNodeBy.NAME);
|
||||
|
||||
return {
|
||||
settings: await db.select({setting: settings.state}).from(settings).where(eq(settings.var, 'maintenance')).limit(1)
|
||||
settings: await db
|
||||
.select({ setting: settings.state })
|
||||
.from(settings)
|
||||
.where(eq(settings.var, 'maintenance'))
|
||||
.limit(1),
|
||||
projects: await db
|
||||
.select({
|
||||
id: projects.id,
|
||||
name: projects.name,
|
||||
data: projects.data,
|
||||
enabled: projects.enabled
|
||||
})
|
||||
.from(projects),
|
||||
nodes: nodes
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,33 +1,75 @@
|
||||
<script lang="ts">
|
||||
import { Construction } from '@lucide/svelte';
|
||||
import { Construction, Eye, EyeOff } from '@lucide/svelte';
|
||||
import NodeModule from '../../../modules/panel/NodeModule.svelte';
|
||||
import ProjectModule from '../../../modules/panel/ProjectModule.svelte';
|
||||
import { setMaintenanceState } from '../settings.remote';
|
||||
|
||||
let { data }: { data: any } = $props();
|
||||
|
||||
let maintenance = $state(Boolean(data.settings[0].setting));
|
||||
console.log(maintenance);
|
||||
let showHidden = $state(false);
|
||||
|
||||
console.log(data.projects[0].name);
|
||||
|
||||
function handleToggle() {
|
||||
console.log(maintenance);
|
||||
maintenance = !maintenance;
|
||||
maintenance = !maintenance;
|
||||
console.log(maintenance);
|
||||
let result = setMaintenanceState(Number(maintenance) as 1 | 0);
|
||||
console.log(result);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleHidden() {
|
||||
showHidden = !showHidden;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class=" m-10">
|
||||
<ProjectModule projectName="ProjectName" checked={false} />
|
||||
</div>
|
||||
<div
|
||||
class=" grid-cols-[1.5fr, 1fr] grid w-full"
|
||||
style="grid-template-areas:
|
||||
'a b'; "
|
||||
>
|
||||
<div class=" m-10">
|
||||
{#each data.projects as project}
|
||||
<ProjectModule projectName={project.name} checked={project.enabled} />
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<div class="m-8 flex w-xl flex-col justify-self-end">
|
||||
<div>
|
||||
<button title="ButtonShowHidden" onclick={toggleHidden}>
|
||||
{#if !showHidden}
|
||||
<EyeOff stroke-width={1} class="text-text-muted-dark" />
|
||||
{:else}
|
||||
<Eye stroke-width={1} />
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
<div class=" flex flex-col gap-1">
|
||||
{#each data.nodes as node}
|
||||
{#if showHidden}
|
||||
<NodeModule nodeName={node.name} nodeType={node.type} isProject={false} />
|
||||
{/if}
|
||||
{#if !node.name.startsWith('.') && !showHidden}
|
||||
<NodeModule nodeName={node.name} nodeType={node.type} isProject={false} />
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class=" mt-4">
|
||||
<Construction strokeWidth={1} />
|
||||
<label
|
||||
for='maintenence'
|
||||
for="maintenence"
|
||||
class="relative m-2 ml-auto block h-5 w-10 cursor-pointer rounded-full bg-bg-lighter-dark shadow-subtle"
|
||||
>
|
||||
<input type="checkbox" checked={maintenance} onclick={async () => await setMaintenanceState(Number(!maintenance))} id='maintenence' class=" peer sr-only" />
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={maintenance}
|
||||
onclick={async () => await setMaintenanceState(Number(!maintenance))}
|
||||
id="maintenence"
|
||||
class=" peer sr-only"
|
||||
/>
|
||||
<span
|
||||
class=" absolute top-0.5 left-0.5 h-4/5 w-2/5 rounded-full bg-bg-dark peer-checked:left-5.5 peer-checked:bg-primary-dark"
|
||||
>
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { query } from "$app/server";
|
||||
import { db } from "$lib/server/db";
|
||||
import { settings } from "$lib/server/db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import z from "zod";
|
||||
import { query } from '$app/server';
|
||||
import { db } from '$lib/server/db';
|
||||
import { settings } from '$lib/server/db/schema';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import z from 'zod';
|
||||
|
||||
export const setMaintenanceState = query(z.number(), async (state) => {
|
||||
await db.update(settings)
|
||||
.set({ state })
|
||||
.where(eq(settings.var, 'maintenance'));
|
||||
await db.update(settings).set({ state }).where(eq(settings.var, 'maintenance'));
|
||||
});
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<script lang="ts">
|
||||
import { FileSystem } from '$lib/termos/filesystem/filesystem';
|
||||
import { MD5 } from '$lib/termos/util/hash';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
@@ -7,7 +6,5 @@
|
||||
console.log(MD5.hash('a'));
|
||||
console.log(MD5.hash('abc'));
|
||||
|
||||
onMount(() => {
|
||||
FileSystem.Init();
|
||||
});
|
||||
onMount(() => {});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user