HUUUGE dump of code, toast system in a svelte module, new reworked tailwing color palette, WIP cms, WIP API and probably much more that i forgot about.
@@ -1,6 +1,18 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
<script>
|
||||||
|
// Immediately apply saved or system theme – no flash
|
||||||
|
(function () {
|
||||||
|
const saved = localStorage.getItem('theme');
|
||||||
|
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||||
|
const theme =
|
||||||
|
saved === 'dark' || saved === 'light' ? saved : prefersDark ? 'dark' : 'light';
|
||||||
|
document.documentElement.setAttribute('data-theme', theme);
|
||||||
|
// Optional: prevent transition on load
|
||||||
|
document.documentElement.style.setProperty('--initial-load', 'true');
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
%sveltekit.head%
|
%sveltekit.head%
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 668 B After Width: | Height: | Size: 668 B |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 695 B After Width: | Height: | Size: 695 B |
|
Before Width: | Height: | Size: 620 B After Width: | Height: | Size: 620 B |
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 506 B After Width: | Height: | Size: 506 B |
@@ -72,7 +72,8 @@ export const filesystem = mysqlTable(
|
|||||||
export const fileContents = mysqlTable('file_contents', {
|
export const fileContents = mysqlTable('file_contents', {
|
||||||
guid: varchar('guid', { length: 36 }).primaryKey(),
|
guid: varchar('guid', { length: 36 }).primaryKey(),
|
||||||
data: longblob('data').notNull(),
|
data: longblob('data').notNull(),
|
||||||
mimeType: varchar('mime_type', { length: 127 }).default('text/plain')
|
mimeType: varchar('mime_type', { length: 127 }).default('text/plain'),
|
||||||
|
checksum: varchar('checksum', { length: 32 }).notNull()
|
||||||
});
|
});
|
||||||
|
|
||||||
export const allowList = mysqlTable('allow_list', {
|
export const allowList = mysqlTable('allow_list', {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { WebG } from '$lib/shimagic/renderer/web_g_engine';
|
|
||||||
import type { KeyBind } from '../terminal/keybindRegistry';
|
import type { KeyBind } from '../terminal/keybindRegistry';
|
||||||
import type { Bash, Result } from './bash';
|
import type { Bash, Result } from './bash';
|
||||||
import { cd } from './commands/cd';
|
import { cd } from './commands/cd';
|
||||||
@@ -32,8 +31,6 @@ export const COMMANDS = {
|
|||||||
testProcess
|
testProcess
|
||||||
} as const satisfies Record<string, ICommand>;
|
} as const satisfies Record<string, ICommand>;
|
||||||
|
|
||||||
|
|
||||||
WebG.
|
|
||||||
/* //export const commands {
|
/* //export const commands {
|
||||||
return: {
|
return: {
|
||||||
method: this.cmd_return,
|
method: this.cmd_return,
|
||||||
|
|||||||
@@ -1,217 +0,0 @@
|
|||||||
import type { User } from './etc/userData';
|
|
||||||
import type { Permission, TimeStamps } from './metadata';
|
|
||||||
|
|
||||||
export enum Type {
|
|
||||||
Directory = 16384,
|
|
||||||
File = 32768,
|
|
||||||
SymbolicLink = 40960
|
|
||||||
}
|
|
||||||
|
|
||||||
export type NodePermission = {
|
|
||||||
user: Permission;
|
|
||||||
group: Permission;
|
|
||||||
other: Permission;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type FsInitArgs = {
|
|
||||||
fs: Map<number, TreeNode>;
|
|
||||||
user: User;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type TreeNode = {
|
|
||||||
inode: number;
|
|
||||||
parent: number;
|
|
||||||
name: string;
|
|
||||||
type: Type;
|
|
||||||
size: number; //Size in Bytes
|
|
||||||
children: number[];
|
|
||||||
content: string; // GUID of the cache file that contains the file contents.
|
|
||||||
link: number; // Links
|
|
||||||
permission: NodePerms;
|
|
||||||
owner: number;
|
|
||||||
group: number;
|
|
||||||
timestamps: TimeStamps;
|
|
||||||
interactible: boolean;
|
|
||||||
func: any;
|
|
||||||
};
|
|
||||||
|
|
||||||
export class VirtualFS {
|
|
||||||
private FsTable: Map<number, TreeNode>;
|
|
||||||
private rootINode: number;
|
|
||||||
private user: User;
|
|
||||||
|
|
||||||
home: number;
|
|
||||||
cwd: number;
|
|
||||||
pwd: number;
|
|
||||||
|
|
||||||
constructor(args: FsInitArgs) {
|
|
||||||
this.FsTable = args.fs;
|
|
||||||
this.user = args.user;
|
|
||||||
this.rootINode = 1;
|
|
||||||
|
|
||||||
this.home = this._pathStringToINode(args.user.home);
|
|
||||||
this.cwd = args.user.cwd ? args.user.cwd! : this.home;
|
|
||||||
this.pwd = args.user.pwd ? args.user.pwd! : this.cwd;
|
|
||||||
|
|
||||||
console.log(this.home);
|
|
||||||
console.log(this.cwd);
|
|
||||||
console.log(this.pwd);
|
|
||||||
}
|
|
||||||
|
|
||||||
private _iNodeToPathString(inode: number): string {
|
|
||||||
const currentNode = this.FsTable.get(inode);
|
|
||||||
|
|
||||||
if (!currentNode)
|
|
||||||
throw new Error('could not find the node in the fs table - inodetopathstring');
|
|
||||||
|
|
||||||
if (!currentNode.parent || currentNode.inode === this.rootINode) {
|
|
||||||
return '/';
|
|
||||||
}
|
|
||||||
|
|
||||||
const parentPath: string = this._iNodeToPathString(currentNode.parent);
|
|
||||||
return parentPath === '/' ? `/${currentNode.name}` : `${parentPath}/${currentNode.name}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: Make all backend methods NOT throw errors. Just return null, and let more closely connected with bash functions call throwError() so user can see the error.
|
|
||||||
// this will save a lot of ass pain later.
|
|
||||||
|
|
||||||
private _pathStringToINode(path: string): number {
|
|
||||||
const normalizedPath = path.replace(/^\/+|\/+$/g, '');
|
|
||||||
const pathComponents = normalizedPath.split('/').filter((component) => component.length > 0);
|
|
||||||
|
|
||||||
console.log(path, 'pathstringtoinode');
|
|
||||||
|
|
||||||
if (pathComponents.length === 0) return this.rootINode;
|
|
||||||
|
|
||||||
let currentNode = this.FsTable.get(this.rootINode);
|
|
||||||
if (!currentNode) throw new Error('iNode does not exist,');
|
|
||||||
|
|
||||||
for (const component of pathComponents) {
|
|
||||||
const childINode = this._findChildNodeByName(currentNode, component);
|
|
||||||
if (childINode === null) throw new Error('this child iNode does not exist,');
|
|
||||||
|
|
||||||
const nextNode = this.FsTable.get(childINode);
|
|
||||||
if (!nextNode) throw new Error('iNode child does not exist,');
|
|
||||||
|
|
||||||
currentNode = nextNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(path, currentNode.inode);
|
|
||||||
return currentNode.inode;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _findChildNodeByName(node: TreeNode, name: string): number {
|
|
||||||
console.log(name, node);
|
|
||||||
for (const childINode of node.children) {
|
|
||||||
const child = this.FsTable.get(childINode);
|
|
||||||
if (child && child.name === name) {
|
|
||||||
return childINode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new Error('could not find the specified child node');
|
|
||||||
}
|
|
||||||
|
|
||||||
private _isAbsolutePath = (path: string): boolean => {
|
|
||||||
return typeof path === 'string' && path.startsWith('/');
|
|
||||||
};
|
|
||||||
|
|
||||||
public getPathByInode(inode: number): string {
|
|
||||||
return this._iNodeToPathString(inode);
|
|
||||||
}
|
|
||||||
|
|
||||||
public formatPath(path: string): string {
|
|
||||||
console.log(path, 'formatPath');
|
|
||||||
const prefix = this._iNodeToPathString(this.home);
|
|
||||||
|
|
||||||
if (path.startsWith(prefix)) {
|
|
||||||
return path.replace(prefix, '~');
|
|
||||||
} else return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public resolvePath(path: string): TreeNode {
|
|
||||||
if (path === '/') return this.getNodeByINode(this.rootINode);
|
|
||||||
let parsedPath: string = path;
|
|
||||||
|
|
||||||
if (!this._isAbsolutePath(path)) {
|
|
||||||
const trail: string = this._iNodeToPathString(this.cwd);
|
|
||||||
parsedPath = `${trail}/${path}`;
|
|
||||||
console.log(parsedPath);
|
|
||||||
}
|
|
||||||
if (path.startsWith('~')) {
|
|
||||||
const trail: string = this._iNodeToPathString(this.home);
|
|
||||||
parsedPath = `${trail}/${path.replace('~', '')}`;
|
|
||||||
console.log(parsedPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
const INode: number = this._pathStringToINode(parsedPath);
|
|
||||||
const Node: TreeNode = this.getNodeByINode(INode);
|
|
||||||
|
|
||||||
return Node;
|
|
||||||
}
|
|
||||||
|
|
||||||
public getNodeByINode(inode: number): TreeNode {
|
|
||||||
const node: TreeNode | undefined = this.FsTable.get(inode);
|
|
||||||
if (!node) throw new Error(`Could not get the node, no such inode exists - ${inode}`);
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
|
|
||||||
public recursiveTraversalPre(
|
|
||||||
node: TreeNode,
|
|
||||||
callback: (param: TreeNode) => void,
|
|
||||||
childIndex?: number[],
|
|
||||||
depthIndex?: number
|
|
||||||
): void {
|
|
||||||
if (!depthIndex) depthIndex = 0;
|
|
||||||
if (!childIndex) childIndex = [0];
|
|
||||||
|
|
||||||
if (node.type != Type.File && node.children[childIndex[depthIndex]]) {
|
|
||||||
node = this.getNodeByINode(node.children[childIndex[depthIndex]]);
|
|
||||||
depthIndex++;
|
|
||||||
if (!childIndex[depthIndex]) childIndex[depthIndex] = 0;
|
|
||||||
|
|
||||||
callback(node);
|
|
||||||
} else {
|
|
||||||
node = this.getNodeByINode(node.parent);
|
|
||||||
childIndex[depthIndex] = 0;
|
|
||||||
depthIndex--;
|
|
||||||
childIndex[depthIndex]++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (depthIndex < 0) return;
|
|
||||||
|
|
||||||
this.recursiveTraversalPre(node, callback, childIndex, depthIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
private _createNode(name: string, type: Type, path: number, user: number): void {
|
|
||||||
let children: null | number[];
|
|
||||||
|
|
||||||
const node: TreeNode = {
|
|
||||||
inode: this.FsTable.size + 1,
|
|
||||||
name: name,
|
|
||||||
type: type,
|
|
||||||
size: 4096, //TODO: Calculate the size from the content
|
|
||||||
children: [],
|
|
||||||
content: '',
|
|
||||||
link: -1,
|
|
||||||
permission: {
|
|
||||||
user: {
|
|
||||||
r: true,
|
|
||||||
w: true,
|
|
||||||
x: false
|
|
||||||
},
|
|
||||||
group: {
|
|
||||||
r: true,
|
|
||||||
w: false,
|
|
||||||
x: false
|
|
||||||
},
|
|
||||||
other: {
|
|
||||||
r: true,
|
|
||||||
w: false,
|
|
||||||
x: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
owner: user,
|
|
||||||
group:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { addToast } from '$lib/stores/toasts';
|
||||||
|
import { derived, writable } from 'svelte/store';
|
||||||
|
import type { GroupData } from '../../routes/admin/util';
|
||||||
|
|
||||||
|
export const groups = writable<GroupData[]>([]);
|
||||||
|
export const groupMap = derived(groups, ($groups) => {
|
||||||
|
const map = new Map<number, string>();
|
||||||
|
for (const group of $groups) {
|
||||||
|
map.set(group.gid, group.groupname);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function fetchGroups() {
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/groups');
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json();
|
||||||
|
const groupsData: GroupData[] = data.map((g: any) => ({
|
||||||
|
gid: g.gid,
|
||||||
|
groupname: g.name,
|
||||||
|
members: g.members || []
|
||||||
|
}));
|
||||||
|
groups.set(groupsData);
|
||||||
|
} else {
|
||||||
|
throw new Error('Failed to fetch groups');
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
addToast('error', 'Groups', 'Failed to load groups: ' + error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,348 @@
|
|||||||
|
import { FileSystem } from '$lib/termos/filesystem/filesystem';
|
||||||
|
import type { GroupData, GroupFormData, UserData, UserFormData } from '../../routes/admin/util';
|
||||||
|
import { addToast } from './toasts';
|
||||||
|
|
||||||
|
let users: UserData[] = $state([]);
|
||||||
|
let groups: GroupData[] = $state([]);
|
||||||
|
let config: Record<string, string> = $state({});
|
||||||
|
|
||||||
|
let userSearch = $state('');
|
||||||
|
let groupSearch = $state('');
|
||||||
|
let checkedUsers: Set<number> = $state(new Set());
|
||||||
|
let checkedGroups: Set<number> = $state(new Set());
|
||||||
|
let focusedUid: number | null = $state(null);
|
||||||
|
let focusedGid: number | null = $state(null);
|
||||||
|
let panelMode: 'user' | 'group' | null = $state(null);
|
||||||
|
let editingId: number | null = $state(null);
|
||||||
|
|
||||||
|
let userFormCache: Map<number, UserFormData> = $state(new Map());
|
||||||
|
let groupFormCache: Map<number, GroupFormData> = $state(new Map());
|
||||||
|
|
||||||
|
// ---------- Getters ----------
|
||||||
|
export function getUsers() {
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
export function getGroups() {
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
|
export function getConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
export function getUserSearch() {
|
||||||
|
return userSearch;
|
||||||
|
}
|
||||||
|
export function getGroupSearch() {
|
||||||
|
return groupSearch;
|
||||||
|
}
|
||||||
|
export function getCheckedUsers() {
|
||||||
|
return checkedUsers;
|
||||||
|
}
|
||||||
|
export function getCheckedGroups() {
|
||||||
|
return checkedGroups;
|
||||||
|
}
|
||||||
|
export function getFocusedUid() {
|
||||||
|
return focusedUid;
|
||||||
|
}
|
||||||
|
export function getFocusedGid() {
|
||||||
|
return focusedGid;
|
||||||
|
}
|
||||||
|
export function getPanelMode() {
|
||||||
|
return panelMode;
|
||||||
|
}
|
||||||
|
export function getEditingId() {
|
||||||
|
return editingId;
|
||||||
|
}
|
||||||
|
export function getUserFormCache() {
|
||||||
|
return userFormCache;
|
||||||
|
}
|
||||||
|
export function getGroupFormCache() {
|
||||||
|
return groupFormCache;
|
||||||
|
}
|
||||||
|
export function getFilteredUsers() {
|
||||||
|
return filteredUsers;
|
||||||
|
}
|
||||||
|
export function getFilteredGroups() {
|
||||||
|
return filteredGroups;
|
||||||
|
}
|
||||||
|
export function getActiveUserForm() {
|
||||||
|
return activeUserForm;
|
||||||
|
}
|
||||||
|
export function getActiveGroupForm() {
|
||||||
|
return activeGroupForm;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* prettier-ignore */
|
||||||
|
const filteredUsers = $derived(
|
||||||
|
users.filter(
|
||||||
|
(u) => !userSearch || u.username.toLowerCase().includes(userSearch.toLowerCase())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
const filteredGroups = $derived(
|
||||||
|
groups.filter(
|
||||||
|
(g) => !groupSearch || g.groupname.toLowerCase().includes(groupSearch.toLowerCase())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
const activeUserForm = $derived(
|
||||||
|
panelMode === 'user' && editingId !== null
|
||||||
|
? (userFormCache.get(editingId) ?? newUserForm(editingId))
|
||||||
|
: null
|
||||||
|
);
|
||||||
|
|
||||||
|
const activeGroupForm = $derived(
|
||||||
|
panelMode === 'group' && editingId !== null
|
||||||
|
? (groupFormCache.get(editingId) ?? newGroupForm(editingId))
|
||||||
|
: null
|
||||||
|
);
|
||||||
|
|
||||||
|
function newUserForm(uid: number): UserFormData {
|
||||||
|
const u = users.find((u) => u.uid === uid);
|
||||||
|
if (!u) throw new Error('Failed to create new form data - user not found');
|
||||||
|
|
||||||
|
return {
|
||||||
|
uid,
|
||||||
|
username: u.username,
|
||||||
|
password: '',
|
||||||
|
confirmPassword: '',
|
||||||
|
homeDir: u.homeDir,
|
||||||
|
gid: u.gid,
|
||||||
|
accessible: u.accessible,
|
||||||
|
avatarFile: undefined,
|
||||||
|
avatarUrl: u.avatarUrl,
|
||||||
|
supplementaryGroups: []
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function newGroupForm(gid: number): GroupFormData {
|
||||||
|
const g = groups.find((g) => g.gid === gid);
|
||||||
|
if (!g) throw new Error('Failed to create new form data - group not found');
|
||||||
|
|
||||||
|
return {
|
||||||
|
gid: g.gid,
|
||||||
|
groupname: g.groupname,
|
||||||
|
members: g.members
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchAllData() {
|
||||||
|
try {
|
||||||
|
const groupsRes = await fetch(`/api/v1/groups`);
|
||||||
|
if (!groupsRes.ok) throw new Error('Failed to fetch groups');
|
||||||
|
|
||||||
|
const groupsData: any[] = await groupsRes.json();
|
||||||
|
|
||||||
|
groups = groupsData.map((g: any) => ({
|
||||||
|
gid: g.gid,
|
||||||
|
groupname: g.name,
|
||||||
|
members: g.members || []
|
||||||
|
}));
|
||||||
|
|
||||||
|
const usersRes = await fetch('/api/v1/users');
|
||||||
|
if (!usersRes.ok) throw new Error('Failed to fetch users');
|
||||||
|
|
||||||
|
const usersRaw: any[] = await usersRes.json();
|
||||||
|
|
||||||
|
users = usersRaw.map((u: any) => ({
|
||||||
|
uid: u.uid,
|
||||||
|
username: u.username,
|
||||||
|
homeDir: u.home,
|
||||||
|
homePath: FileSystem.instance.getPathByINode(u.home),
|
||||||
|
gid: u.gid,
|
||||||
|
group: groups.find((g) => g.gid === u.gid)?.groupname || 'unknown',
|
||||||
|
accessible: u.accessible,
|
||||||
|
avatarUrl: u.avatarUrl,
|
||||||
|
supplementaryGroups: [] // computed below
|
||||||
|
}));
|
||||||
|
|
||||||
|
for (const user of users) {
|
||||||
|
const supp = groups.filter((g) => g.members.includes(user.uid)).map((g) => g.groupname);
|
||||||
|
user.supplementaryGroups = supp;
|
||||||
|
}
|
||||||
|
|
||||||
|
const configRes = await fetch(`/api/v1/config`);
|
||||||
|
if (configRes.ok) {
|
||||||
|
config = await configRes.json();
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
throw new Error(err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeUserCheck(uid: number) {
|
||||||
|
if (checkedUsers.has(uid)) checkedUsers.delete(uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeGroupCheck(gid: number) {
|
||||||
|
if (checkedUsers.has(gid)) checkedUsers.delete(gid);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function addUserCheck(uid: number) {
|
||||||
|
if (!checkedUsers.has(uid)) checkedUsers.delete(uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function addGroupCheck(gid: number) {
|
||||||
|
if (!checkedUsers.has(gid)) checkedGroups.delete(gid);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toggleUserCheck(uid: number) {
|
||||||
|
if (checkedUsers.has(uid)) checkedUsers.delete(uid);
|
||||||
|
else checkedUsers.add(uid);
|
||||||
|
}
|
||||||
|
export function toggleGroupCheck(gid: number) {
|
||||||
|
if (checkedGroups.has(gid)) checkedGroups.delete(gid);
|
||||||
|
else checkedGroups.add(gid);
|
||||||
|
}
|
||||||
|
export function clearUserChecks() {
|
||||||
|
checkedUsers.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearGroupChecks() {
|
||||||
|
checkedGroups.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function openEdit(id: number, type: 'user' | 'group') {
|
||||||
|
panelMode = type;
|
||||||
|
editingId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function closePanel() {
|
||||||
|
panelMode = null;
|
||||||
|
editingId = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function updateUserFormCache(uid: number, form: UserFormData) {
|
||||||
|
userFormCache.set(uid, form);
|
||||||
|
}
|
||||||
|
export function updateGroupFormCache(gid: number, form: GroupFormData) {
|
||||||
|
groupFormCache.set(gid, form);
|
||||||
|
}
|
||||||
|
export function clearUserCache(uid: number) {
|
||||||
|
userFormCache.delete(uid);
|
||||||
|
}
|
||||||
|
export function clearGroupCache(gid: number) {
|
||||||
|
groupFormCache.delete(gid);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function saveUser(form: UserFormData) {
|
||||||
|
const formData = new FormData();
|
||||||
|
|
||||||
|
formData.append('uid', form.uid!.toString());
|
||||||
|
formData.append('username', form.username);
|
||||||
|
formData.append('password', form.password);
|
||||||
|
formData.append('home', form.homeDir.toString());
|
||||||
|
formData.append('gid', form.gid.toString());
|
||||||
|
formData.append('accessible', form.accessible ? '1' : '0');
|
||||||
|
|
||||||
|
if (form.avatarFile) formData.append('avatar', form.avatarFile);
|
||||||
|
|
||||||
|
const res = await fetch(`/api/v1/users`, { method: 'POST', body: formData });
|
||||||
|
if (!res.ok) {
|
||||||
|
const err = await res.text();
|
||||||
|
throw new Error(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
let uid: number;
|
||||||
|
if (form.uid !== undefined) {
|
||||||
|
uid = form.uid;
|
||||||
|
} else {
|
||||||
|
const created = await res.json();
|
||||||
|
uid = created.uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
const oldSuppGids = groups
|
||||||
|
.filter((g) => g.members.includes(uid) && g.gid !== form.gid)
|
||||||
|
.map((g) => g.gid);
|
||||||
|
|
||||||
|
const newSuppGids = form.supplementaryGroups ?? [];
|
||||||
|
|
||||||
|
const added = newSuppGids.filter((gid) => !oldSuppGids.includes(gid));
|
||||||
|
const removed = oldSuppGids.filter((gid) => !newSuppGids.includes(gid));
|
||||||
|
|
||||||
|
async function updateGroupMembers(gid: number, members: number[]) {
|
||||||
|
await fetch(`/api/v1/groups`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ gid, members })
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const gid of added) {
|
||||||
|
const group = groups.find((g) => g.gid === gid);
|
||||||
|
if (group) {
|
||||||
|
const newMemebers = [...group.members, uid];
|
||||||
|
await updateGroupMembers(gid, newMemebers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const gid of removed) {
|
||||||
|
const group = groups.find((g) => g.gid === gid);
|
||||||
|
if (group) {
|
||||||
|
const newMemebers = group.members.filter((m) => m !== uid);
|
||||||
|
await updateGroupMembers(gid, newMemebers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (form.uid !== undefined) clearUserCache(form.uid!);
|
||||||
|
await fetchAllData();
|
||||||
|
addToast('success', 'User', 'Saved successfully');
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteUser(uid: number) {
|
||||||
|
const res = await fetch(`/api/v1/users/${uid}`, { method: 'DELETE' });
|
||||||
|
if (!res.ok) {
|
||||||
|
addToast('error', 'Failed', `To delete user - ${users.find((u) => u.uid === uid)?.username}`);
|
||||||
|
throw new Error('Failed to delete user');
|
||||||
|
}
|
||||||
|
|
||||||
|
clearUserCache(uid);
|
||||||
|
await fetchAllData();
|
||||||
|
addToast('success', 'User', 'Deleted');
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function saveGroup(form: GroupFormData) {
|
||||||
|
const body = JSON.stringify({
|
||||||
|
gid: form.gid,
|
||||||
|
name: form.groupname,
|
||||||
|
members: form.members // array of uids
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await fetch(`/api/v1/groups`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res.ok) throw new Error('Failed to save group');
|
||||||
|
|
||||||
|
clearGroupCache(form.gid!);
|
||||||
|
await fetchAllData();
|
||||||
|
addToast('success', 'Group', 'Saved');
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteGroup(gid: number) {
|
||||||
|
const res = await fetch(`/api/v1/groups/${gid}`, { method: 'DELETE' });
|
||||||
|
if (!res.ok) throw new Error('Failed to delete group');
|
||||||
|
|
||||||
|
clearGroupCache(gid);
|
||||||
|
await fetchAllData();
|
||||||
|
addToast('success', 'Group', 'Deleted');
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function setConfig(key: string, value: string) {
|
||||||
|
const oldValue = config[key];
|
||||||
|
config[key] = value;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/v1/config`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ [key]: value })
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res.ok) throw new Error('Config update failed');
|
||||||
|
} catch (err: any) {
|
||||||
|
config[key] = oldValue;
|
||||||
|
addToast('error', 'Config', err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,8 +33,6 @@ export type PageCallbacks = {
|
|||||||
getFontSize: () => number;
|
getFontSize: () => number;
|
||||||
};
|
};
|
||||||
|
|
||||||
TermOS.Shell;
|
|
||||||
|
|
||||||
export class Terminal {
|
export class Terminal {
|
||||||
private _bash: Bash;
|
private _bash: Bash;
|
||||||
private _callbacks: Partial<PageCallbacks> = {};
|
private _callbacks: Partial<PageCallbacks> = {};
|
||||||
|
|||||||
@@ -1,17 +1,30 @@
|
|||||||
import { writable } from 'svelte/store';
|
import { writable } from 'svelte/store';
|
||||||
|
|
||||||
function getInitalTheme(): string {
|
function getInitialTheme(): string {
|
||||||
if (typeof window === 'undefined') return 'dark';
|
// On client, read from the data-theme attribute set by the blocking script
|
||||||
|
if (typeof document !== 'undefined') {
|
||||||
const savedTheme: string | null = localStorage.getItem('theme');
|
const theme = document.documentElement.getAttribute('data-theme');
|
||||||
if (savedTheme === 'dark' || savedTheme === 'light') return savedTheme;
|
if (theme === 'dark' || theme === 'light') return theme;
|
||||||
|
}
|
||||||
const sysPrefTheme = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
// Fallback (SSR or if script failed)
|
||||||
return sysPrefTheme ? 'dark' : 'light';
|
if (typeof window !== 'undefined') {
|
||||||
|
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
||||||
|
}
|
||||||
|
return 'dark';
|
||||||
}
|
}
|
||||||
|
|
||||||
export const theme = writable(getInitalTheme());
|
export const theme = writable(getInitialTheme());
|
||||||
|
|
||||||
theme.subscribe((value) => {
|
theme.subscribe((value) => {
|
||||||
if (typeof window !== 'undefined') localStorage.setItem('theme', value);
|
if (typeof document !== 'undefined') {
|
||||||
|
document.documentElement.setAttribute('data-theme', value);
|
||||||
|
localStorage.setItem('theme', value);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Optional: listen to system preference changes
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
|
||||||
|
theme.set(e.matches ? 'dark' : 'light');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import { Tween } from 'svelte/motion';
|
||||||
|
import { writable } from 'svelte/store';
|
||||||
|
import type { ToastMessage } from '../../routes/admin/util';
|
||||||
|
|
||||||
|
let toastId = 0;
|
||||||
|
export const toasts = writable<ToastMessage[]>([]);
|
||||||
|
|
||||||
|
export function addToast(
|
||||||
|
type: ToastMessage['type'],
|
||||||
|
title: string,
|
||||||
|
message: string,
|
||||||
|
duration?: number,
|
||||||
|
initial?: number,
|
||||||
|
target?: number,
|
||||||
|
hideProgress?: boolean,
|
||||||
|
hideDismiss?: boolean,
|
||||||
|
onClose?: (tm: ToastMessage) => void,
|
||||||
|
onClick?: (tm: ToastMessage) => void
|
||||||
|
) {
|
||||||
|
const id = ++toastId;
|
||||||
|
duration = duration ?? 3000;
|
||||||
|
initial = initial ?? 100;
|
||||||
|
target = target ?? 0;
|
||||||
|
hideProgress = hideProgress ?? false;
|
||||||
|
hideDismiss = hideDismiss ?? false;
|
||||||
|
|
||||||
|
let isPermament: boolean = duration === 0 || duration === Infinity;
|
||||||
|
|
||||||
|
if (hideDismiss) isPermament = false;
|
||||||
|
if (isPermament) hideProgress = true;
|
||||||
|
|
||||||
|
let tween: Tween<number> | undefined;
|
||||||
|
|
||||||
|
if (!isPermament) {
|
||||||
|
tween = new Tween(initial, { duration: duration });
|
||||||
|
tween.set(target).then(() => {
|
||||||
|
removeToast(id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
toasts.update((t) => [
|
||||||
|
...t,
|
||||||
|
{
|
||||||
|
id,
|
||||||
|
type,
|
||||||
|
title,
|
||||||
|
message,
|
||||||
|
duration,
|
||||||
|
tween,
|
||||||
|
initial,
|
||||||
|
target,
|
||||||
|
hideProgress,
|
||||||
|
hideDismiss,
|
||||||
|
onClose,
|
||||||
|
onClick
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeToast(id: number) {
|
||||||
|
let closedToast: ToastMessage | undefined;
|
||||||
|
toasts.update((ts) => {
|
||||||
|
closedToast = ts.find((t) => t.id === id);
|
||||||
|
return ts.filter((t) => t.id !== id);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (closedToast?.onClose) closedToast.onClose(closedToast);
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
// src/lib/stores/users.ts
|
||||||
|
import { addToast } from '$lib/stores/toasts';
|
||||||
|
import { FileSystem } from '$lib/termos/filesystem/filesystem';
|
||||||
|
import { derived, writable } from 'svelte/store';
|
||||||
|
import type { UserData } from '../../routes/admin/util';
|
||||||
|
import { groupMap } from './groups';
|
||||||
|
|
||||||
|
interface RawUser {
|
||||||
|
uid: number;
|
||||||
|
username: string;
|
||||||
|
homeDir: number;
|
||||||
|
gid: number;
|
||||||
|
avatarUrl: string;
|
||||||
|
accessible: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const rawUsers = writable<RawUser[]>([]);
|
||||||
|
export const usersLoading = writable(false);
|
||||||
|
|
||||||
|
export const userDataMap = derived(
|
||||||
|
[rawUsers, groupMap],
|
||||||
|
([$rawUsers, $groupsMap]): Map<number, UserData> | null => {
|
||||||
|
try {
|
||||||
|
FileSystem.instance;
|
||||||
|
} catch {
|
||||||
|
return null; // FileSystem not initialized
|
||||||
|
}
|
||||||
|
|
||||||
|
const map = new Map<number, UserData>();
|
||||||
|
for (const u of $rawUsers) {
|
||||||
|
const resolvedPath = FileSystem.instance.getPathByINode(u.homeDir);
|
||||||
|
const group = $groupsMap.get(u.gid);
|
||||||
|
const groupName = group?.groupname || 'unknown';
|
||||||
|
map.set(u.uid, {
|
||||||
|
uid: u.uid,
|
||||||
|
username: u.username,
|
||||||
|
homeDir: u.homeDir,
|
||||||
|
homePath: resolvedPath,
|
||||||
|
gid: u.gid,
|
||||||
|
group: groupName,
|
||||||
|
accessible: u.accessible,
|
||||||
|
avatarUrl: u.avatarUrl
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const userList = derived(userDataMap, ($map) => {
|
||||||
|
if (!$map) return [];
|
||||||
|
return Array.from($map.values());
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function fetchUsers() {
|
||||||
|
usersLoading.set(true);
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/users');
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json();
|
||||||
|
rawUsers.set(data as RawUser[]);
|
||||||
|
} else {
|
||||||
|
throw new Error('Failed to fetch users');
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
addToast('error', 'Users', 'Failed to load users: ' + err.message);
|
||||||
|
} finally {
|
||||||
|
usersLoading.set(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,125 +1,233 @@
|
|||||||
import type { User } from '../shell/shell';
|
import type { User } from '../shell/shell';
|
||||||
|
|
||||||
export class FileSystem {
|
export class FileSystem {
|
||||||
static #instance: FileSystem;
|
static #instance: FileSystem | null = null;
|
||||||
private _fs: Map<number, TreeNode>;
|
|
||||||
private _root: number;
|
|
||||||
|
|
||||||
private constructor(fs: Map<number, TreeNode>) {
|
private _fs: Map<number, TreeNode> = new Map();
|
||||||
this._fs = fs;
|
private _canon_fs: Map<number, TreeNode> = new Map();
|
||||||
|
private _protectedNodes: Set<number> = new Set();
|
||||||
|
|
||||||
|
private _root: number = 1;
|
||||||
|
|
||||||
|
private constructor() {}
|
||||||
|
|
||||||
|
//TODO: Add a public setNode method that uses the private methods to manage the map;
|
||||||
|
|
||||||
|
public static async init(): Promise<void> {
|
||||||
|
if (FileSystem.#instance) return;
|
||||||
|
|
||||||
|
const instance = new FileSystem();
|
||||||
|
await instance.initialize();
|
||||||
|
|
||||||
|
FileSystem.#instance = instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async initialize(): Promise<void> {
|
||||||
|
const cacheETag = localStorage.getItem(STORAGE_KEYS.etag);
|
||||||
|
const cacheData = localStorage.getItem(STORAGE_KEYS.data);
|
||||||
|
|
||||||
|
const headers: HeadersInit = {};
|
||||||
|
if (cacheETag) {
|
||||||
|
headers['If-None-Match'] = cacheETag;
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(`/api/v1/fs`, { headers });
|
||||||
|
|
||||||
|
let jsonText: string;
|
||||||
|
if (response.status === 304 && cacheData) {
|
||||||
|
jsonText = cacheData;
|
||||||
|
} else if (response.ok) {
|
||||||
|
jsonText = await response.text();
|
||||||
|
const newETag = response.headers.get('ETag');
|
||||||
|
localStorage.setItem(STORAGE_KEYS.data, jsonText);
|
||||||
|
|
||||||
|
if (newETag) {
|
||||||
|
localStorage.setItem(STORAGE_KEYS.etag, newETag);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error(`Failed to load filesystem: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsed = JSON.parse(jsonText);
|
||||||
|
this._canon_fs = FileSystem._jsonToNodeTable(parsed);
|
||||||
|
|
||||||
|
this._fs = FileSystem._cloneFs(this._canon_fs);
|
||||||
this._root = this._fs.values().next().value!.inode;
|
this._root = this._fs.values().next().value!.inode;
|
||||||
|
|
||||||
if (!this._root) throw new Error('First entry in the filesystem map empty!');
|
if (!this._root) throw new Error('First entry in the filesystem map empty!');
|
||||||
|
|
||||||
|
await this.loadProtectedNodesConfig();
|
||||||
|
this.applyLocalEdits();
|
||||||
|
this.applyLocalDeletions();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Init(fsJson: JSON) {
|
private async loadProtectedNodesConfig(): Promise<void> {
|
||||||
//const fsChecksum = MD5.hash(JSON.stringify(fsJson));
|
|
||||||
|
|
||||||
/*
|
|
||||||
const cache: string | null = localStorage.getItem('fs-json');
|
|
||||||
if (cache) {
|
|
||||||
const fsCacheChecksum = MD5.hash(cache);
|
|
||||||
|
|
||||||
console.log(fsChecksum);
|
|
||||||
console.log(fsCacheChecksum);
|
|
||||||
|
|
||||||
if (fsChecksum !== fsCacheChecksum) {
|
|
||||||
//calculate version control difference to preserve user made changes (do a merge)
|
|
||||||
}
|
|
||||||
fsJson = JSON.parse(cache);
|
|
||||||
}
|
|
||||||
|
|
||||||
localStorage.setItem('fs-json', JSON.stringify(fsJson));
|
|
||||||
*/
|
|
||||||
|
|
||||||
const fs: Map<number, TreeNode> = this._jsonToNodeTable(fsJson);
|
|
||||||
|
|
||||||
// This produces a different checksum!
|
|
||||||
// Find a way to produce the same hash from Map and a fetched json file or cached stringified json
|
|
||||||
|
|
||||||
FileSystem.#instance = new FileSystem(fs);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* private async _fetchFsSignature(path: string): Promise<any> {
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(path);
|
const response = await fetch(`/api/v1/config`);
|
||||||
if (!response.ok) {
|
if (!response.ok) return;
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
|
||||||
|
const config = await response.json();
|
||||||
|
if (config.protected_inodes) {
|
||||||
|
const list: number[] = JSON.parse(config.protected_inodes);
|
||||||
|
this._protectedNodes = new Set(list);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
throw new Error(`The protected nodes config failed to load`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.text();
|
private applyLocalEdits(): void {
|
||||||
return data.slice(0, 36); //32 characters of uuid + 4 dashes
|
const cache = localStorage.getItem(STORAGE_KEYS.edits);
|
||||||
} catch (error) {
|
if (!cache) return;
|
||||||
console.error('Failed to fetch the file system signature', error);
|
|
||||||
|
const edits: Record<number, TreeNode> = JSON.parse(cache);
|
||||||
|
|
||||||
|
for (const [inodeStr, node] of Object.entries(edits)) {
|
||||||
|
const inode = Number(inodeStr);
|
||||||
|
if (this._protectedNodes.has(inode)) continue;
|
||||||
|
|
||||||
|
this._fs.set(inode, node);
|
||||||
|
|
||||||
|
if (!node.parent && !this._fs.has(node.parent)) continue;
|
||||||
|
|
||||||
|
const parent = this._fs.get(node.parent)!;
|
||||||
|
|
||||||
|
if (parent.children.includes(inode)) {
|
||||||
|
parent.children.push(inode);
|
||||||
}
|
}
|
||||||
} */
|
|
||||||
|
|
||||||
/* private static async fetchFsJson(): Promise<JSON> {
|
|
||||||
const checksum: string | null = localStorage.getItem('fs-checksum');
|
|
||||||
|
|
||||||
if (checksum !== sig || signature === null || localStorage.getItem('fs') === null) {
|
|
||||||
const fs: JSON = await this._fetchFileSystem('/src/lib/assets/fs/fs.json');
|
|
||||||
localStorage.setItem('signature', sig);
|
|
||||||
localStorage.setItem('fs', JSON.stringify(fs));
|
|
||||||
|
|
||||||
console.info('FS fetched from file, new sinature:', sig);
|
|
||||||
|
|
||||||
return fs;
|
|
||||||
} else {
|
|
||||||
const fs: string | null = localStorage.getItem('fs');
|
|
||||||
if (fs === null) throw new Error('FS in LocalStorage is null!');
|
|
||||||
|
|
||||||
console.info('FS fetched from localStorage with signature:', sig);
|
|
||||||
|
|
||||||
return JSON.parse(fs);
|
|
||||||
}
|
}
|
||||||
} */
|
}
|
||||||
|
|
||||||
|
private applyLocalDeletions(): void {
|
||||||
|
const cache = localStorage.getItem(STORAGE_KEYS.deletions);
|
||||||
|
if (!cache) return;
|
||||||
|
|
||||||
|
const deletions: number[] = JSON.parse(cache);
|
||||||
|
|
||||||
|
while (deletions.length > 0) {
|
||||||
|
const inode = deletions.pop()!;
|
||||||
|
if (this._protectedNodes.has(inode)) continue;
|
||||||
|
|
||||||
|
const node = this._fs.get(inode);
|
||||||
|
if (!node) continue;
|
||||||
|
|
||||||
|
if (node.type === Type.Directory) {
|
||||||
|
deletions.push(...node.children);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.parent && this._fs.has(node.parent)) {
|
||||||
|
const parent = this._fs.get(node.parent)!;
|
||||||
|
parent.children = parent.children.filter((child) => child !== inode);
|
||||||
|
}
|
||||||
|
|
||||||
|
this._fs.delete(inode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static _cloneFs(source: Map<number, TreeNode>): Map<number, TreeNode> {
|
||||||
|
const copy = new Map<number, TreeNode>();
|
||||||
|
|
||||||
|
for (const [inode, node] of source) {
|
||||||
|
copy.set(inode, { ...node, children: [...node.children] });
|
||||||
|
}
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static _NodeTableToJson(table: Map<number, TreeNode>): string {
|
||||||
|
const obj: Record<string, any> = {};
|
||||||
|
const sortedInodes = [...table.keys()].sort((a, b) => a - b);
|
||||||
|
|
||||||
|
for (const inode of sortedInodes) {
|
||||||
|
const node = table.get(inode)!;
|
||||||
|
|
||||||
|
obj[inode.toString()] = {
|
||||||
|
Inode: node.inode,
|
||||||
|
Name: node.name,
|
||||||
|
Type: node.type,
|
||||||
|
Size: node.size,
|
||||||
|
Children: [...node.children].sort((a, b) => a - b),
|
||||||
|
Content: node.content,
|
||||||
|
Target: node.link,
|
||||||
|
Persmision: [
|
||||||
|
{
|
||||||
|
Read: node.permission.user.r,
|
||||||
|
Write: node.permission.user.w,
|
||||||
|
Exec: node.permission.user.x
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Read: node.permission.group.r,
|
||||||
|
Write: node.permission.group.w,
|
||||||
|
Exec: node.permission.group.x
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Read: node.permission.other.r,
|
||||||
|
Write: node.permission.other.w,
|
||||||
|
Exec: node.permission.other.x
|
||||||
|
}
|
||||||
|
],
|
||||||
|
Owner: node.owner,
|
||||||
|
Group: node.group,
|
||||||
|
TimeStamps: {
|
||||||
|
MTime: node.timestamps.modified.toISOString(),
|
||||||
|
CTime: node.timestamps.changed.toISOString(),
|
||||||
|
ATime: node.timestamps.accessed.toISOString()
|
||||||
|
},
|
||||||
|
Interactible: node.interactible,
|
||||||
|
Func: node.func,
|
||||||
|
Parent: node.parent
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return JSON.stringify(obj);
|
||||||
|
}
|
||||||
|
|
||||||
private static _jsonToNodeTable(data: JSON): Map<number, TreeNode> {
|
private static _jsonToNodeTable(data: JSON): Map<number, TreeNode> {
|
||||||
const FsTable: Map<number, TreeNode> = new Map<number, TreeNode>();
|
const FsTable: Map<number, TreeNode> = new Map<number, TreeNode>();
|
||||||
const entryList = Object.entries(data);
|
const entryList = Object.entries(data);
|
||||||
|
|
||||||
for (let i = 0; i < entryList.length; i++) {
|
for (const [key, obj] of Object.entries(data)) {
|
||||||
const object: any = entryList[i][1];
|
const inode = Number(key);
|
||||||
|
|
||||||
const node: TreeNode = {
|
const node: TreeNode = {
|
||||||
inode: object.Inode,
|
inode: inode,
|
||||||
name: object.Name,
|
name: obj.Name,
|
||||||
type: object.Type,
|
type: obj.Type,
|
||||||
size: object.Size,
|
size: obj.Size,
|
||||||
interactible: object.Interactible,
|
interactible: obj.Interactible,
|
||||||
func: object.Func,
|
func: obj.Func,
|
||||||
children: object.Children,
|
children: Array.isArray(obj.Children) ? obj.Children : [],
|
||||||
content: object.Content,
|
content: obj.Content,
|
||||||
link: object.Target,
|
link: obj.Target,
|
||||||
permission: {
|
permission: {
|
||||||
user: {
|
user: {
|
||||||
r: object.Permission[0]?.Read,
|
r: obj.Permission[0]?.Read ?? false,
|
||||||
w: object.Permission[0]?.Write,
|
w: obj.Permission[0]?.Write ?? false,
|
||||||
x: object.Permission[0]?.Exec
|
x: obj.Permission[0]?.Exec ?? false
|
||||||
},
|
},
|
||||||
group: {
|
group: {
|
||||||
r: object.Permission[1]?.Read,
|
r: obj.Permission[1]?.Read ?? false,
|
||||||
w: object.Permission[1]?.Write,
|
w: obj.Permission[1]?.Write ?? false,
|
||||||
x: object.Permission[1]?.Exec
|
x: obj.Permission[1]?.Exec ?? false
|
||||||
},
|
},
|
||||||
other: {
|
other: {
|
||||||
r: object.Permission[2]?.Read,
|
r: obj.Permission[2]?.Read ?? false,
|
||||||
w: object.Permission[2]?.Write,
|
w: obj.Permission[2]?.Write ?? false,
|
||||||
x: object.Permission[2]?.Exec
|
x: obj.Permission[2]?.Exec ?? false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
owner: object.Owner,
|
owner: obj.Owner,
|
||||||
group: object.Group,
|
group: obj.Group,
|
||||||
timestamps: {
|
timestamps: {
|
||||||
modified: new Date(object.TimeStamps.MTime),
|
modified: new Date(obj.TimeStamps.MTime),
|
||||||
changed: new Date(object.TimeStamps.CTime),
|
changed: new Date(obj.TimeStamps.CTime),
|
||||||
accessed: new Date(object.TimeStamps.ATime)
|
accessed: new Date(obj.TimeStamps.ATime)
|
||||||
},
|
},
|
||||||
parent: object.Parent
|
parent: obj.Parent
|
||||||
};
|
};
|
||||||
|
|
||||||
FsTable.set(object.Inode, node);
|
FsTable.set(inode, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
return FsTable;
|
return FsTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,10 +274,31 @@ export class FileSystem {
|
|||||||
this._fs.set(this._fs.size + 1, node);
|
this._fs.set(this._fs.size + 1, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _deleteNode(inode: number): void {
|
private applySingleDeletion(inode: number): void {
|
||||||
|
const node = this._fs.get(inode);
|
||||||
|
if (!node) return;
|
||||||
|
if (node.parent && this._fs.has(node.parent)) {
|
||||||
|
const parent = this._fs.get(node.parent)!;
|
||||||
|
parent.children = parent.children.filter((child) => child !== inode);
|
||||||
|
}
|
||||||
this._fs.delete(inode);
|
this._fs.delete(inode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private removeLocalEdit(inode: number): void {
|
||||||
|
const edits = JSON.parse(localStorage.getItem(STORAGE_KEYS.edits) || '{}');
|
||||||
|
delete edits[inode];
|
||||||
|
localStorage.setItem(STORAGE_KEYS.edits, JSON.stringify(edits));
|
||||||
|
}
|
||||||
|
|
||||||
|
private removeLocalDeletion(inode: number): void {
|
||||||
|
const deletions: number[] = JSON.parse(localStorage.getItem(STORAGE_KEYS.deletions) || '[]');
|
||||||
|
const idx = deletions.indexOf(inode);
|
||||||
|
if (idx !== -1) {
|
||||||
|
deletions.splice(idx, 1);
|
||||||
|
localStorage.setItem(STORAGE_KEYS.deletions, JSON.stringify(deletions));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private _iNodeToPathString(inode: number): string {
|
private _iNodeToPathString(inode: number): string {
|
||||||
const currentNode = this._fs.get(inode);
|
const currentNode = this._fs.get(inode);
|
||||||
|
|
||||||
@@ -228,6 +357,8 @@ export class FileSystem {
|
|||||||
return typeof path === 'string' && path.startsWith('/');
|
return typeof path === 'string' && path.startsWith('/');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public saveEdit(edit: TreeNode): void {}
|
||||||
|
|
||||||
public getPathByINode(inode: number): string {
|
public getPathByINode(inode: number): string {
|
||||||
return this._iNodeToPathString(inode);
|
return this._iNodeToPathString(inode);
|
||||||
}
|
}
|
||||||
@@ -240,10 +371,10 @@ export class FileSystem {
|
|||||||
public getNodeByInode(inode: number): TreeNode {
|
public getNodeByInode(inode: number): TreeNode {
|
||||||
const node: TreeNode | undefined = this._fs.get(inode);
|
const node: TreeNode | undefined = this._fs.get(inode);
|
||||||
if (!node) throw new Error(`No node exists under inode - ${inode}`);
|
if (!node) throw new Error(`No node exists under inode - ${inode}`);
|
||||||
return node;
|
return structuredClone(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
public resolvePath(path: string, user: User): TreeNode {
|
public getNodeByPathString(path: string, user: User): TreeNode {
|
||||||
if (path === '/') return this._fs.get(this._root)!;
|
if (path === '/') return this._fs.get(this._root)!;
|
||||||
|
|
||||||
let parsedPath: string = path;
|
let parsedPath: string = path;
|
||||||
@@ -264,8 +395,8 @@ export class FileSystem {
|
|||||||
});
|
});
|
||||||
parsedPath = `${trail}/${path.replace('~', '')}`;
|
parsedPath = `${trail}/${path.replace('~', '')}`;
|
||||||
}
|
}
|
||||||
|
const node = this._pathStringToNode(parsedPath);
|
||||||
return this._pathStringToNode(parsedPath);
|
return structuredClone(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
public recursiveTraversalPre(
|
public recursiveTraversalPre(
|
||||||
@@ -351,3 +482,10 @@ export type TimeStamps = {
|
|||||||
changed: Date;
|
changed: Date;
|
||||||
accessed: Date;
|
accessed: Date;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const STORAGE_KEYS = {
|
||||||
|
data: 'fs_data', // JSON string of canonical filesystem
|
||||||
|
etag: 'fs_etag', // MD5 checksum from server
|
||||||
|
edits: 'fs_edits', // Record<number, TreeNode> of user modifications
|
||||||
|
deletions: 'fs_deletions' // number[] of inodes deleted by user
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { UserData } from '../../../routes/admin/util';
|
||||||
import { FileSystem, type TreeNode } from '../filesystem/filesystem';
|
import { FileSystem, type TreeNode } from '../filesystem/filesystem';
|
||||||
|
|
||||||
export enum SortNodeBy {
|
export enum SortNodeBy {
|
||||||
@@ -11,7 +12,35 @@ export enum SortNodeBy {
|
|||||||
CTIME = 'changed'
|
CTIME = 'changed'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum SortUserBy {
|
||||||
|
UID = 'uid',
|
||||||
|
USERNAME = 'username',
|
||||||
|
HOME = 'homePath', // sort by home dir name
|
||||||
|
GROUP = 'group', // group name
|
||||||
|
ACCESSIBLE = 'accessible'
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum SortGroupBy {
|
||||||
|
UID = 'uid',
|
||||||
|
NAME = 'groupname',
|
||||||
|
MEMBERS = 'members' // members ammount
|
||||||
|
}
|
||||||
|
|
||||||
export class Sort {
|
export class Sort {
|
||||||
|
public static userArraySort(
|
||||||
|
array: UserData[],
|
||||||
|
reverse: boolean = false,
|
||||||
|
sortBy: SortUserBy = SortUserBy.USERNAME
|
||||||
|
): UserData[] {
|
||||||
|
if (array.length === 0) {
|
||||||
|
console.warn('Tried to sort an empty UserData array!');
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
Sort.userDataQSort(array, reverse, sortBy, 0, array.length - 1);
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
public static nodeArraySort(
|
public static nodeArraySort(
|
||||||
nodes: TreeNode[] | number[],
|
nodes: TreeNode[] | number[],
|
||||||
reverse: boolean = false,
|
reverse: boolean = false,
|
||||||
@@ -38,6 +67,20 @@ export class Sort {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static userDataQSort(
|
||||||
|
array: UserData[],
|
||||||
|
reverse: boolean,
|
||||||
|
sortBy: SortUserBy,
|
||||||
|
start: number,
|
||||||
|
end: number
|
||||||
|
) {
|
||||||
|
if (end <= start) return;
|
||||||
|
|
||||||
|
let pivot: number = this.userPartition(array, reverse, sortBy, start, end);
|
||||||
|
this.userDataQSort(array, reverse, sortBy, start, pivot - 1);
|
||||||
|
this.userDataQSort(array, reverse, sortBy, pivot + 1, end);
|
||||||
|
}
|
||||||
|
|
||||||
private static nodeQSort(
|
private static nodeQSort(
|
||||||
array: TreeNode[],
|
array: TreeNode[],
|
||||||
reverse: boolean,
|
reverse: boolean,
|
||||||
@@ -78,6 +121,32 @@ export class Sort {
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static userPartition(
|
||||||
|
part: UserData[],
|
||||||
|
reverse: boolean,
|
||||||
|
sortBy: SortUserBy,
|
||||||
|
start: number,
|
||||||
|
end: number
|
||||||
|
): number {
|
||||||
|
let pivot: UserData = part[end];
|
||||||
|
let i: number = start - 1;
|
||||||
|
|
||||||
|
for (let j = start; j <= end; j++) {
|
||||||
|
if (this.userCompareElements(part[j], pivot, sortBy, reverse) < 0) {
|
||||||
|
i++;
|
||||||
|
let temp = part[i];
|
||||||
|
part[i] = part[j];
|
||||||
|
part[j] = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
let temp = part[i];
|
||||||
|
part[i] = part[end];
|
||||||
|
part[end] = temp;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
private static nodeCompareElements(
|
private static nodeCompareElements(
|
||||||
a: TreeNode,
|
a: TreeNode,
|
||||||
b: TreeNode,
|
b: TreeNode,
|
||||||
@@ -139,6 +208,75 @@ export class Sort {
|
|||||||
throw new Error(`Sorting basis outside of the declared scope. - `);
|
throw new Error(`Sorting basis outside of the declared scope. - `);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static userCompareElements(
|
||||||
|
a: UserData,
|
||||||
|
b: UserData,
|
||||||
|
sortBy: SortUserBy,
|
||||||
|
reverse: boolean
|
||||||
|
): number {
|
||||||
|
switch (sortBy) {
|
||||||
|
case SortUserBy.USERNAME: {
|
||||||
|
const nameA: string = a.username;
|
||||||
|
const nameB: string = b.username;
|
||||||
|
const minLength = Math.min(nameA.length, nameB.length);
|
||||||
|
|
||||||
|
for (let i = 0; i < minLength; i++) {
|
||||||
|
const charCodeA = Posix.GetCharWeight(nameA[i]);
|
||||||
|
const charCodeB = Posix.GetCharWeight(nameB[i]);
|
||||||
|
|
||||||
|
if (charCodeA !== charCodeB) {
|
||||||
|
return reverse ? charCodeB - charCodeA : charCodeA - charCodeB;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return reverse ? nameB.length - nameA.length : nameA.length - nameB.length;
|
||||||
|
}
|
||||||
|
case SortUserBy.UID: {
|
||||||
|
console.log(sortBy, 'sortby');
|
||||||
|
const uidA: number = a.uid;
|
||||||
|
const uidB: number = b.uid;
|
||||||
|
|
||||||
|
return reverse ? uidB - uidA : uidA - uidB;
|
||||||
|
}
|
||||||
|
case SortUserBy.HOME: {
|
||||||
|
const nameA: string = a.homePath.replaceAll('/', '');
|
||||||
|
const nameB: string = b.homePath.replaceAll('/', '');
|
||||||
|
const minLength = Math.min(nameA.length, nameB.length);
|
||||||
|
|
||||||
|
for (let i = 0; i < minLength; i++) {
|
||||||
|
const charCodeA = Posix.GetCharWeight(nameA[i]);
|
||||||
|
const charCodeB = Posix.GetCharWeight(nameB[i]);
|
||||||
|
|
||||||
|
if (charCodeA !== charCodeB) {
|
||||||
|
return reverse ? charCodeB - charCodeA : charCodeA - charCodeB;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return reverse ? nameB.length - nameA.length : nameA.length - nameB.length;
|
||||||
|
}
|
||||||
|
case SortUserBy.GROUP: {
|
||||||
|
const nameA: string = a.group;
|
||||||
|
const nameB: string = b.group;
|
||||||
|
const minLength = Math.min(nameA.length, nameB.length);
|
||||||
|
|
||||||
|
for (let i = 0; i < minLength; i++) {
|
||||||
|
const charCodeA = Posix.GetCharWeight(nameA[i]);
|
||||||
|
const charCodeB = Posix.GetCharWeight(nameB[i]);
|
||||||
|
|
||||||
|
if (charCodeA !== charCodeB) {
|
||||||
|
return reverse ? charCodeB - charCodeA : charCodeA - charCodeB;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return reverse ? nameB.length - nameA.length : nameA.length - nameB.length;
|
||||||
|
}
|
||||||
|
case SortUserBy.ACCESSIBLE: {
|
||||||
|
return reverse
|
||||||
|
? (b.accessible ? 1 : 0) - (a.accessible ? 1 : 0)
|
||||||
|
: (a.accessible ? 1 : 0) - (b.accessible ? 1 : 0);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw new Error(`Sorting basis outside of the declared scope. - `);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Posix {
|
class Posix {
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
let { children, class: className = '', ...restProps } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button
|
||||||
|
{...restProps}
|
||||||
|
class=" cursor-pointer rounded-md p-2 transition-all duration-200 hover:brightness-110 active:translate-y-0.5 active:brightness-90 disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:brightness-100 {className}"
|
||||||
|
>
|
||||||
|
{@render children()}
|
||||||
|
</button>
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
let x: number = $state(0);
|
||||||
|
let y: number = $state(0);
|
||||||
|
let showContestMenu: boolean = $state(false);
|
||||||
|
let rootElement: HTMLElement | undefined;
|
||||||
|
let parentElement: HTMLElement | null = null;
|
||||||
|
|
||||||
|
let {
|
||||||
|
items = [],
|
||||||
|
onClose = () => {}
|
||||||
|
}: {
|
||||||
|
items: { label: string; action: () => void }[];
|
||||||
|
onClose: () => void;
|
||||||
|
} = $props();
|
||||||
|
|
||||||
|
function handleAction(item: { action: () => void }) {
|
||||||
|
item.action();
|
||||||
|
closeContextMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeContextMenu() {
|
||||||
|
showContestMenu = false;
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleGlobalInteraction(e: MouseEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
showContestMenu = !showContestMenu;
|
||||||
|
x = e.x;
|
||||||
|
y = e.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleKeyDown(e: KeyboardEvent) {
|
||||||
|
if (e.key === 'Escape') {
|
||||||
|
closeContextMenu();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function initEventListener(node: HTMLElement) {
|
||||||
|
const parent = node.parentElement;
|
||||||
|
if (!parent) return;
|
||||||
|
|
||||||
|
parent.addEventListener('contextmenu', handleGlobalInteraction, true);
|
||||||
|
document.addEventListener('keydown', handleKeyDown);
|
||||||
|
|
||||||
|
return {
|
||||||
|
destroy() {
|
||||||
|
parent.removeEventListener('contextmenu', handleGlobalInteraction, true);
|
||||||
|
document.removeEventListener('keydown', handleKeyDown);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div use:initEventListener>
|
||||||
|
{#if showContestMenu}
|
||||||
|
<div
|
||||||
|
id="context-menu"
|
||||||
|
class="fixed z-100 min-w-[150px] bg-bg-lighter-dark"
|
||||||
|
style="left: {x}px; top: {y}px;"
|
||||||
|
>
|
||||||
|
{#each items as item}
|
||||||
|
<button title={item.label} onclick={() => handleAction(item)}
|
||||||
|
><p class="w-full text-text-dark">{item.label}</p></button
|
||||||
|
>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { enhance } from "$app/forms";
|
import { enhance } from '$app/forms';
|
||||||
import { PASSWD } from "$lib/stores/bash/etc/userData";
|
import { PASSWD } from '$lib/stores/bash/etc/userData';
|
||||||
import { ArrowRight, ChevronLeft, ChevronRight, CircleAlert, Lock } from "@lucide/svelte";
|
import { ArrowRight, ChevronLeft, ChevronRight, Lock } from '@lucide/svelte';
|
||||||
import type { effect } from "zod/v3";
|
|
||||||
|
|
||||||
|
|
||||||
let formElem: HTMLElement;
|
let formElem: HTMLElement;
|
||||||
let {init, form}: { init: (formData: FormData) => void, form: any} = $props();
|
let { init, form }: { init: (formData: FormData) => void; form: any } = $props();
|
||||||
|
|
||||||
const USERS = PASSWD.filter((user) => user.accesible == true);
|
const USERS = PASSWD.filter((user) => user.accesible == true);
|
||||||
const basePath: string = '/src/lib/assets/login/';
|
const basePath: string = '/src/lib/assets/login/';
|
||||||
@@ -15,61 +13,104 @@
|
|||||||
let username: string = $state('gornodox');
|
let username: string = $state('gornodox');
|
||||||
|
|
||||||
function changeUser(direction: 0 | 1) {
|
function changeUser(direction: 0 | 1) {
|
||||||
if(direction === 0) userIndex--;
|
if (direction === 0) userIndex--;
|
||||||
else userIndex++;
|
else userIndex++;
|
||||||
|
|
||||||
if(userIndex >= USERS.length) userIndex = 0;
|
if (userIndex >= USERS.length) userIndex = 0;
|
||||||
if(userIndex < 0) userIndex = USERS.length - 1;
|
if (userIndex < 0) userIndex = USERS.length - 1;
|
||||||
|
|
||||||
const user = USERS[userIndex];
|
const user = USERS[userIndex];
|
||||||
username = user.username;
|
username = user.username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: Prefetch the images of the users when hovering on top of user switch buttons
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div id="wrapper" class=" flex flex-col items-center" class:outro={form?.success}>
|
<div id="wrapper" class=" flex flex-col items-center" class:outro={form?.success}>
|
||||||
<img class="rounded-full mb-4 border-primary-dark border-2" src={`${basePath}${username}.png`} onerror={(event) => {(event.currentTarget as HTMLImageElement).src = `${basePath}default.png`; return false;}} alt="user avatar" width="80" height="80" />
|
<img
|
||||||
<div id="name" class=" relative flex flex-row items-center text-text-muted-dark justify-center gap-4 w-1/2">
|
class="mb-4 rounded-full border-2 border-border shadow-subtle"
|
||||||
<button onclick={() => changeUser(0)}
|
src={`${basePath}${username}.png`}
|
||||||
class=" active:-translate-x-0.5 hover:text-primary-hover-dark"><ChevronLeft size={16} strokeWidth={2} /></button>
|
onerror={(event) => {
|
||||||
|
(event.currentTarget as HTMLImageElement).src = `${basePath}default.png`;
|
||||||
|
return false;
|
||||||
|
}}
|
||||||
|
alt="user avatar"
|
||||||
|
width="80"
|
||||||
|
height="80"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
id="name"
|
||||||
|
class=" text-text-muted-dark relative flex w-1/2 flex-row items-center justify-center gap-4"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
id="btn-left"
|
||||||
|
onclick={() => changeUser(0)}
|
||||||
|
class=" hover:text-primary-hover-dark active:-translate-x-0.5"
|
||||||
|
><ChevronLeft size={16} strokeWidth={2} /></button
|
||||||
|
>
|
||||||
<strong class=" mx-auto">{username}</strong>
|
<strong class=" mx-auto">{username}</strong>
|
||||||
<button onclick={() => changeUser(1)}
|
<button
|
||||||
class=" active:translate-x-0.5 hover:text-primary-hover-dark"><ChevronRight size={16} strokeWidth={2} /></button>
|
id="btn-right"
|
||||||
|
onclick={() => changeUser(1)}
|
||||||
|
class=" hover:text-primary-hover-dark active:translate-x-0.5"
|
||||||
|
><ChevronRight size={16} strokeWidth={2} /></button
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
<form bind:this={formElem} onanimationend={() => {formElem.classList.remove('invalid')}} use:enhance={({ formData }) =>
|
<form
|
||||||
{
|
bind:this={formElem}
|
||||||
|
onanimationend={() => {
|
||||||
|
formElem.classList.remove('invalid');
|
||||||
|
}}
|
||||||
|
use:enhance={({ formData }) => {
|
||||||
init(formData);
|
init(formData);
|
||||||
}
|
}}
|
||||||
} method="POST" action="?/login" class:invalid={form?.error} name="login-form" autocomplete="off" class="mt-6 flex flex-row gap-1">
|
method="POST"
|
||||||
<input name="username" value={username} class=" hidden ">
|
action="?/login"
|
||||||
<div class=" bg-bg-lighter-dark flex flex-row ml-4 items-center rounded outline-none border border-transparent text-sm p-1.5 w-2xs text-text-dark focus-within:bg-bg-light-dark focus-within:border-primary-dark {form?.error ? 'focus-within:border-warning-dark text-warning-dark' : ''}">
|
class:invalid={form?.error}
|
||||||
|
name="login-form"
|
||||||
|
autocomplete="off"
|
||||||
|
class="mt-6 flex flex-row gap-1"
|
||||||
|
>
|
||||||
|
<input name="username" value={username} class=" hidden" />
|
||||||
|
<div
|
||||||
|
class="ml-4 flex w-2xs flex-row
|
||||||
|
items-center overflow-clip rounded-md border border-border bg-surface-1 pl-2 text-sm text-muted transition-colors duration-200 outline-none has-focus:border-focus-ring"
|
||||||
|
>
|
||||||
<Lock size={16} strokeWidth={2} />
|
<Lock size={16} strokeWidth={2} />
|
||||||
<input autofocus name="password" type="password" autocomplete="off" placeholder="Password..." class=" placeholder-text-dark {form?.error ? 'placeholder-warning-dark' : ''} grow ml-2 appearance-none outline-none">
|
<input
|
||||||
|
name="password"
|
||||||
|
type="password"
|
||||||
|
placeholder="Password..."
|
||||||
|
class=" ml-2 grow appearance-none px-3 py-2 outline-none"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class=" bg-bg-lighter-dark rounded p-1.5 hover:text-primary-hover-dark active:text-primary-dark active:bg-bg-light-dark">
|
<button
|
||||||
|
type="submit"
|
||||||
|
class=" bg-bg-lighter-dark hover:text-primary-hover-dark active:text-primary-dark active:bg-bg-light-dark rounded p-1.5"
|
||||||
|
>
|
||||||
<ArrowRight size={20} strokeWidth={2} />
|
<ArrowRight size={20} strokeWidth={2} />
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.invalid {
|
.invalid {
|
||||||
animation: var(--animate-error-shake);
|
animation: var(--animate-error-shake);
|
||||||
}
|
}
|
||||||
|
|
||||||
#error {
|
#error {
|
||||||
animation: fadeIn 0.2s forwards cubic-bezier(.4,.7,0,.99);
|
animation: fadeIn 0.2s forwards cubic-bezier(0.4, 0.7, 0, 0.99);
|
||||||
}
|
}
|
||||||
|
|
||||||
.switchL {
|
.switchL {
|
||||||
animation: fadeSlideLeft .75s forwards cubic-bezier(.4,.7,0,.99);
|
animation: fadeSlideLeft 0.75s forwards cubic-bezier(0.4, 0.7, 0, 0.99);
|
||||||
}
|
}
|
||||||
|
|
||||||
.switchR {
|
.switchR {
|
||||||
animation: fadeSlideRight .75s forwards cubic-bezier(.4,.7,0,.99);
|
animation: fadeSlideRight 0.75s forwards cubic-bezier(0.4, 0.7, 0, 0.99);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@keyframes fadeSlideLeft {
|
||||||
@keyframes fadeSlideLeft {
|
|
||||||
25% {
|
25% {
|
||||||
transform: translateX(-1rem);
|
transform: translateX(-1rem);
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
@@ -82,9 +123,9 @@
|
|||||||
transform: none;
|
transform: none;
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes fadeSlideRight {
|
@keyframes fadeSlideRight {
|
||||||
25% {
|
25% {
|
||||||
transform: translateX(1rem);
|
transform: translateX(1rem);
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
@@ -97,19 +138,19 @@
|
|||||||
transform: none;
|
transform: none;
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes fadeIn {
|
@keyframes fadeIn {
|
||||||
to {
|
to {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.outro {
|
.outro {
|
||||||
transition: opacity 0.5s cubic-bezier(.4,.7,0,.99) 1s;
|
transition: opacity 0.5s cubic-bezier(0.4, 0.7, 0, 0.99) 1s;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
form {
|
form {
|
||||||
transition: opacity 0.2s cubic-bezier(.4,.7,0,.99);
|
transition: opacity 0.2s cubic-bezier(0.4, 0.7, 0, 0.99);
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
img {
|
img {
|
||||||
@@ -119,11 +160,24 @@
|
|||||||
#name {
|
#name {
|
||||||
transform: translateY(30px);
|
transform: translateY(30px);
|
||||||
transition: transform 0.5s ease-out;
|
transition: transform 0.5s ease-out;
|
||||||
}
|
#btn-left {
|
||||||
#error {
|
transform: translateX(100px);
|
||||||
transition: opacity 0.2s cubic-bezier(.4,.7,0,.99);
|
transition:
|
||||||
|
transform 0.2s ease-in,
|
||||||
|
opacity 0.2s cubic-bezier(0.4, 0.7, 0, 0.99);
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
}
|
#btn-right {
|
||||||
|
transform: translateX(-100px);
|
||||||
|
transition:
|
||||||
|
transform 0.2s ease-in,
|
||||||
|
opacity 0.2s cubic-bezier(0.4, 0.7, 0, 0.99);
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#error {
|
||||||
|
transition: opacity 0.2s cubic-bezier(0.4, 0.7, 0, 0.99);
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Languages, Settings2, SunMoon } from '@lucide/svelte';
|
|
||||||
import { theme } from '$lib/stores/theme';
|
|
||||||
import { locale } from '$lib/stores/lang';
|
|
||||||
import plFlag from '$lib/assets/plFlag.svg';
|
|
||||||
import enFlag from '$lib/assets/enFlag.svg';
|
|
||||||
import deFlag from '$lib/assets/deFlag.svg';
|
import deFlag from '$lib/assets/deFlag.svg';
|
||||||
|
import enFlag from '$lib/assets/enFlag.svg';
|
||||||
import frFlag from '$lib/assets/frFlag.svg';
|
import frFlag from '$lib/assets/frFlag.svg';
|
||||||
import jaFlag from '$lib/assets/jaFlag.svg';
|
import jaFlag from '$lib/assets/jaFlag.svg';
|
||||||
|
import plFlag from '$lib/assets/plFlag.svg';
|
||||||
|
import { theme } from '$lib/stores/theme';
|
||||||
|
import { Languages, Settings2, SunMoon } from '@lucide/svelte';
|
||||||
|
|
||||||
function toggleSettings() {
|
function toggleSettings() {
|
||||||
const settingsMenu = window.document.getElementById('settings-menu');
|
const settingsMenu = window.document.getElementById('settings-menu');
|
||||||
@@ -20,66 +19,77 @@
|
|||||||
langsMenu?.classList.toggle('hide');
|
langsMenu?.classList.toggle('hide');
|
||||||
}
|
}
|
||||||
|
|
||||||
function setLang(id: string) {
|
function setLang(id: string) {}
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div id="options" class=" absolute top-0 left-0 isolate z-70 mx-4 rounded-b-xl bg-surface-1">
|
||||||
id="options"
|
|
||||||
class=" z-100 absolute top-0 left-0 isolate mx-4 rounded-b-xl bg-bg-dark light:bg-bg-light"
|
|
||||||
>
|
|
||||||
<section class="hide grid" id="settings-menu">
|
<section class="hide grid" id="settings-menu">
|
||||||
<div class="flex flex-col items-center justify-center gap-4 overflow-hidden">
|
<div class="flex flex-col items-center justify-center gap-4 overflow-hidden">
|
||||||
<div class=" mt-4 flex items-center justify-center rounded-lg">
|
<div class=" mt-4 flex items-center justify-center rounded-lg">
|
||||||
<button
|
<button
|
||||||
class=" rounded-lg bg-bg-lighter-dark p-1.5 text-text-dark shadow-button duration-75 hover:text-primary-hover-dark active:translate-y-0.5 light:bg-bg-lighter-light light:text-text-muted-light light:hover:text-primary-hover-light"
|
class="rounded-lg bg-surface-3 p-1.5 text-text-primary shadow-button hover:text-primary active:button-click"
|
||||||
id="theme-btn"
|
id="theme-btn"
|
||||||
onclick={() => {
|
onclick={() => {
|
||||||
$theme = $theme === 'dark' ? 'light' : 'dark';
|
$theme = $theme === 'dark' ? 'light' : 'dark';
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<SunMoon strokeWidth={1} size={32} />
|
<SunMoon strokeWidth={1} size={32} class="mb-0.5" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col content-center items-center">
|
<div class="flex flex-col content-center items-center">
|
||||||
<button
|
<button
|
||||||
class="z-3 mb-4 rounded-lg bg-bg-lighter-dark p-1.5 text-text-dark duration-75 hover:text-primary-hover-dark active:translate-y-0.5 light:bg-bg-lighter-light light:text-text-muted-light light:hover:text-primary-hover-light"
|
class="z-3 mb-4 rounded-lg bg-surface-3 p-1.5 text-text-primary shadow-button hover:text-primary active:button-click"
|
||||||
id="langs-btn"
|
id="langs-btn"
|
||||||
onclick={toggleLangs}
|
onclick={toggleLangs}
|
||||||
>
|
>
|
||||||
<Languages strokeWidth={1} size={32} />
|
<Languages strokeWidth={1} size={32} class="mb-0.5" />
|
||||||
</button>
|
</button>
|
||||||
<form id="langs-menu" class="hide grid">
|
<form id="langs-menu" class="hide grid">
|
||||||
<div class="z-2 mb-4 flex flex-col items-center gap-2 overflow-hidden">
|
<div class="z-2 mb-4 flex flex-col items-center gap-2 overflow-hidden">
|
||||||
<label
|
<label
|
||||||
class="border-primary-dark duration-100 hover:ml-1 hover:pl-1 has-checked:border-l-3 has-checked:hover:m-0 has-checked:hover:p-0 light:border-primary-light"
|
class=" border-primary duration-50 hover:ml-1 hover:pl-1 has-checked:border-l-3 has-checked:hover:m-0 has-checked:hover:p-0"
|
||||||
>
|
>
|
||||||
<input name="langs" type="radio" class="lang hidden" id="pl-PL" autocomplete="off" onclick={() => {console.log($locale)}}/>
|
<input
|
||||||
|
name="langs"
|
||||||
|
type="radio"
|
||||||
|
class="lang hidden"
|
||||||
|
id="pl-PL"
|
||||||
|
autocomplete="off"
|
||||||
|
onclick={(e) => {
|
||||||
|
console.log((e.target as HTMLElement).id);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<img class="flags mx-2" src={plFlag} alt="PL" height="26" width="26" />
|
<img class="flags mx-2" src={plFlag} alt="PL" height="26" width="26" />
|
||||||
</label>
|
</label>
|
||||||
<label
|
<label
|
||||||
class="border-primary-dark duration-100 hover:ml-1 hover:pl-1 has-checked:border-l-3 has-checked:hover:m-0 has-checked:hover:p-0 light:border-primary-light"
|
class="border-primary duration-50 hover:ml-1 hover:pl-1 has-checked:border-l-3 has-checked:hover:m-0 has-checked:hover:p-0"
|
||||||
>
|
>
|
||||||
<input name="langs" type="radio" class="lang hidden" id="en-US" autocomplete="off" onclick={(id) => {
|
<input
|
||||||
console.log(id);
|
name="langs"
|
||||||
}}/>
|
type="radio"
|
||||||
|
class="lang hidden"
|
||||||
|
id="en-US"
|
||||||
|
autocomplete="off"
|
||||||
|
onclick={(e) => {
|
||||||
|
console.log((e.target as HTMLElement).id);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<img class="flags mx-2" src={enFlag} alt="EN" height="26" width="26" />
|
<img class="flags mx-2" src={enFlag} alt="EN" height="26" width="26" />
|
||||||
</label>
|
</label>
|
||||||
<label
|
<label
|
||||||
class="border-primary-dark duration-100 hover:ml-1 hover:pl-1 has-checked:border-l-3 has-checked:hover:m-0 has-checked:hover:p-0 light:border-primary-light"
|
class="border-primary duration-50 hover:ml-1 hover:pl-1 has-checked:border-l-3 has-checked:hover:m-0 has-checked:hover:p-0"
|
||||||
>
|
>
|
||||||
<input name="langs" type="radio" class="lang hidden" id="fr-FR" autocomplete="off" />
|
<input name="langs" type="radio" class="lang hidden" id="fr-FR" autocomplete="off" />
|
||||||
<img class="flags mx-2" src={deFlag} alt="DE" height="26" width="26" />
|
<img class="flags mx-2" src={deFlag} alt="DE" height="26" width="26" />
|
||||||
</label>
|
</label>
|
||||||
<label
|
<label
|
||||||
class="border-primary-dark hover:ml-1 hover:pl-1 has-checked:border-l-3 has-checked:hover:m-0 has-checked:hover:p-0 light:border-primary-light"
|
class="border-primary duration-50 hover:ml-1 hover:pl-1 has-checked:border-l-3 has-checked:hover:m-0 has-checked:hover:p-0"
|
||||||
>
|
>
|
||||||
<input name="langs" type="radio" class="lang hidden" id="en" autocomplete="off" />
|
<input name="langs" type="radio" class="lang hidden" id="en" autocomplete="off" />
|
||||||
<img class="flags mx-2" src={jaFlag} alt="JA" height="26" width="26" />
|
<img class="flags mx-2" src={jaFlag} alt="JA" height="26" width="26" />
|
||||||
</label>
|
</label>
|
||||||
<label
|
<label
|
||||||
class="border-primary-dark transition-none duration-100 hover:ml-1 hover:pl-1 has-checked:border-l-3 has-checked:hover:m-0 has-checked:hover:p-0 light:border-primary-light"
|
class="border-primary duration-50 hover:ml-1 hover:pl-1 has-checked:border-l-3 has-checked:hover:m-0 has-checked:hover:p-0"
|
||||||
>
|
>
|
||||||
<input name="langs" type="radio" class="lang hidden" id="en" autocomplete="off" />
|
<input name="langs" type="radio" class="lang hidden" id="en" autocomplete="off" />
|
||||||
<img class="flags mx-2" src={frFlag} alt="FR" height="26" width="26" />
|
<img class="flags mx-2" src={frFlag} alt="FR" height="26" width="26" />
|
||||||
@@ -90,7 +100,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<button
|
<button
|
||||||
class="rounded-b-xl border-t bg-bg-light-dark p-2 text-text-dark shadow-button hover:text-primary-dark light:bg-bg-lighter-light light:text-text-muted-light light:hover:text-primary-light"
|
class="rounded-b-xl border-t bg-surface-3 p-2 text-text-primary shadow-button duration-50 hover:text-primary active:brightness-90"
|
||||||
id="settings-btn"
|
id="settings-btn"
|
||||||
onclick={toggleSettings}
|
onclick={toggleSettings}
|
||||||
>
|
>
|
||||||
@@ -100,16 +110,18 @@
|
|||||||
|
|
||||||
<style>
|
<style>
|
||||||
#langs-menu {
|
#langs-menu {
|
||||||
transition: 0.2s ease-in;
|
transition: grid-template-rows 0.2s ease-in;
|
||||||
grid-template-rows: 1fr;
|
grid-template-rows: 1fr;
|
||||||
|
|
||||||
&.hide {
|
&.hide {
|
||||||
grid-template-rows: 0fr;
|
grid-template-rows: 0fr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#settings-menu {
|
#settings-menu {
|
||||||
transition: 0.2s ease-in;
|
transition: grid-template-rows 0.2s ease-in;
|
||||||
grid-template-rows: 1fr;
|
grid-template-rows: 1fr;
|
||||||
|
|
||||||
&.hide {
|
&.hide {
|
||||||
grid-template-rows: 0fr;
|
grid-template-rows: 0fr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
export let rows = 5;
|
||||||
|
export let cols = 4;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<table class="min-w-full divide-y divide-gray-700">
|
||||||
|
<tbody>
|
||||||
|
{#each Array(rows) as _}
|
||||||
|
<tr class="animate-pulse">
|
||||||
|
{#each Array(cols) as _}
|
||||||
|
<td class="px-4 py-2">
|
||||||
|
<div class="h-4 w-3/4 rounded bg-gray-600"></div>
|
||||||
|
</td>
|
||||||
|
{/each}
|
||||||
|
</tr>
|
||||||
|
{/each}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
@@ -1,23 +1,19 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { ExitCode } from '$lib/stores/bash/metadata';
|
|
||||||
import { initTerminal } from '$lib/stores/terminal/init.svelte';
|
|
||||||
import { clear, print } from '$lib/stores/terminal/stdio/io';
|
|
||||||
import { Terminal, type PrintData } from '$lib/stores/terminal/terminal';
|
|
||||||
import Input from './terminal/Input.svelte';
|
import Input from './terminal/Input.svelte';
|
||||||
|
|
||||||
const clearTerminal = (): void => clear();
|
//const clearTerminal = (): void => clear();
|
||||||
|
|
||||||
const printOutput = (e: HTMLElement, d: PrintData): void => print(e, d);
|
//const printOutput = (e: HTMLElement, d: PrintData): void => print(e, d);
|
||||||
|
|
||||||
export async function init(username: string, password: string) {
|
export async function init(username: string, password: string) {
|
||||||
try {
|
try {
|
||||||
terminal = await initTerminal({ username, password }, callbackInit, 'en_US');
|
//await initTerminal({ username, password }, callbackInit, 'en_US');
|
||||||
updateTerminal();
|
updateTerminal(); //Rename this
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('terminal init failed', error);
|
console.error('Failed to intialize the terminal', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
runTerminal();
|
document.getElementById('terminal-window')?.classList.remove('hidden');
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateTerminal() {
|
function updateTerminal() {
|
||||||
@@ -50,7 +46,7 @@
|
|||||||
return ctx.measureText('M').width;
|
return ctx.measureText('M').width;
|
||||||
}
|
}
|
||||||
|
|
||||||
function inputHandler(event: KeyboardEvent) {
|
/* function inputHandler(event: KeyboardEvent) {
|
||||||
const terminalKeyInhibitor = terminal.getKeybindInhibitor();
|
const terminalKeyInhibitor = terminal.getKeybindInhibitor();
|
||||||
terminalKeyInhibitor.processKeystroke(event);
|
terminalKeyInhibitor.processKeystroke(event);
|
||||||
|
|
||||||
@@ -86,13 +82,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
elem.scrollTop = elem.scrollHeight;
|
elem.scrollTop = elem.scrollHeight;
|
||||||
}
|
} */
|
||||||
|
|
||||||
function runTerminal() {
|
/* //Callback initializer
|
||||||
document.getElementById('terminal-window')?.classList.remove('hidden');
|
|
||||||
}
|
|
||||||
|
|
||||||
//Callback initializer
|
|
||||||
const callbackInit = {
|
const callbackInit = {
|
||||||
print: (data: any) => {
|
print: (data: any) => {
|
||||||
const e = document.getElementById('outputWrapper');
|
const e = document.getElementById('outputWrapper');
|
||||||
@@ -102,39 +94,35 @@
|
|||||||
clear: clearTerminal,
|
clear: clearTerminal,
|
||||||
getWidth: getWidth,
|
getWidth: getWidth,
|
||||||
getFontSize: getFontSize
|
getFontSize: getFontSize
|
||||||
};
|
}; */
|
||||||
|
|
||||||
//Empty terminal variable where the terminal class instance will be stored
|
|
||||||
let terminal: Terminal;
|
|
||||||
let username: string = $state('');
|
let username: string = $state('');
|
||||||
let cwd: string = $state('');
|
let cwd: string = $state('');
|
||||||
|
const hostname = 'terminal'; //TODO: Change this to pull from config on db
|
||||||
//let isProcessActive = $state(false);
|
//let isProcessActive = $state(false);
|
||||||
|
|
||||||
let inputValue = $state<string>('');
|
let inputValue = $state<string>('');
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<label for="input" onkeydowncapture={(event) => inputHandler(event)} class="w-11/12">
|
<label for="input" class="w-11/12">
|
||||||
<div
|
<div
|
||||||
id="terminal"
|
id="terminal"
|
||||||
class=" terminal-window shadow-() h-full w-full rounded-md shadow-bg transition-discrete"
|
class=" terminal-window flex size-full flex-col rounded-md shadow-subtle transition-discrete"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="terminal-bar flex h-9 w-full flex-row items-center rounded-t-md bg-bg-dark text-center font-terminal text-sm font-bold text-primary-dark light:bg-bg-dark-light light:text-primary-light"
|
class="terminal-bar flex h-9 w-full flex-row items-center rounded-t-md bg-surface-2 text-center font-terminal text-sm font-bold text-primary"
|
||||||
>
|
>
|
||||||
<div class="dots-wrapper mx-2.5 flex h-full flex-row items-center justify-center gap-2.5">
|
<div class="dots-wrapper mx-2.5 flex h-full flex-row items-center justify-center gap-2.5">
|
||||||
<button class="size-2.5 cursor-pointer rounded-full p-0" title=""></button>
|
<button class="size-2.5 cursor-pointer rounded-full p-0" title=""></button>
|
||||||
<button class="size-2.5 cursor-pointer rounded-full p-0" title=""></button>
|
<button class="size-2.5 cursor-pointer rounded-full p-0" title=""></button>
|
||||||
<button class="size-2.5 cursor-pointer rounded-full p-0" title=""></button>
|
<button class="size-2.5 cursor-pointer rounded-full p-0" title=""></button>
|
||||||
</div>
|
</div>
|
||||||
<div class=" mr-2 flex grow">
|
<div class=" mr-2 flex grow text-sm">
|
||||||
<h5>{username}</h5>
|
<p>{username}@{hostname} {cwd}</p>
|
||||||
<!-- prettier-ignore -->
|
|
||||||
<h5 class=" mr-2">@terminal: </h5>
|
|
||||||
<h5>{cwd}</h5>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="inner-content scroll-hidden h-7/8 origin-top overflow-y-auto rounded-b-md bg-bg-light-dark p-4 text-text-dark shadow-subtle light:bg-bg-lighter-light light:text-text-light"
|
class="inner-content scroll-hidden grow origin-top overflow-y-auto rounded-b-md bg-surface-1 p-4 text-sm text-text-primary"
|
||||||
id="cout"
|
id="cout"
|
||||||
>
|
>
|
||||||
<div id="outputWrapper"></div>
|
<div id="outputWrapper"></div>
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { removeToast, toasts } from '$lib/stores/toasts';
|
||||||
|
import { CircleCheckBig, CircleX, Info, TriangleAlert, X } from '@lucide/svelte';
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
import { fly } from 'svelte/transition';
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
toasts.set([]);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="fixed top-4 right-4 z-50 flex h-full flex-col gap-2 overflow-visible">
|
||||||
|
{#each $toasts as toast (toast.id)}
|
||||||
|
<div
|
||||||
|
transition:fly={{ x: 20, y: 0, duration: 300 }}
|
||||||
|
id={`toast-${toast.id.toString()}`}
|
||||||
|
class="w-md overflow-hidden rounded-md bg-bg-lighter-dark"
|
||||||
|
onclick={() => toast.onClick?.(toast)}
|
||||||
|
role="button"
|
||||||
|
tabindex={toast.onClick ? 0 : undefined}
|
||||||
|
onkeydown={toast.onClick
|
||||||
|
? (e) => {
|
||||||
|
if (e.key === 'Enter' || e.key === ' ') {
|
||||||
|
e.preventDefault();
|
||||||
|
toast.onClick?.(toast);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
: undefined}
|
||||||
|
>
|
||||||
|
<div class="flex items-center justify-start">
|
||||||
|
<div class="mx-4 my-8">
|
||||||
|
{#if toast.type === 'info'}
|
||||||
|
<Info class=" text-info-dark"></Info>
|
||||||
|
{:else if toast.type === 'error'}
|
||||||
|
<CircleX class="text-danger-dark"></CircleX>
|
||||||
|
{:else if toast.type === 'warn'}
|
||||||
|
<TriangleAlert class="text-warning-dark"></TriangleAlert>
|
||||||
|
{:else}
|
||||||
|
<CircleCheckBig class="text-success-dark"></CircleCheckBig>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<div class="my-2 mr-auto mb-auto ml-2 flex flex-col items-start justify-start select-none">
|
||||||
|
<h5 class=" text- text-md font-bold text-text-dark">{toast.title}</h5>
|
||||||
|
<p class=" text-md mb-2 overflow-x-hidden overflow-y-scroll text-text-muted-dark">
|
||||||
|
{toast.message}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class=" m-2 self-start">
|
||||||
|
<button
|
||||||
|
class:hidden={toast.hideDismiss}
|
||||||
|
onclick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
removeToast(toast.id);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<X
|
||||||
|
stroke-width={3}
|
||||||
|
size={18}
|
||||||
|
class=" transition-all duration-200 hover:text-text-muted-dark active:scale-90"
|
||||||
|
></X>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{#if !toast.hideProgress && toast.tween}
|
||||||
|
<div
|
||||||
|
style:padding-right={`${toast.tween.current}%`}
|
||||||
|
class=" h-[2px] w-0 bg-primary-hover-dark"
|
||||||
|
></div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
let { id, state, onclick }: { id: string; state: boolean; onclick: (e: MouseEvent) => void } =
|
||||||
|
$props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<label class="inline-flex cursor-pointer items-center gap-3 select-none for={id}">
|
||||||
|
<input
|
||||||
|
class="peer sr-only"
|
||||||
|
{id}
|
||||||
|
role="switch"
|
||||||
|
type="checkbox"
|
||||||
|
checked={state}
|
||||||
|
onclick={(e) => {
|
||||||
|
onclick(e);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
class="relative block h-6 w-11 rounded-full bg-border transition-colors peer-checked:bg-primary after:absolute after:top-0.5 after:left-0.5 after:h-5 after:w-5 after:rounded-full after:bg-white after:shadow after:transition-transform after:content-[''] peer-checked:after:translate-x-5"
|
||||||
|
></span>
|
||||||
|
</label>
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { Snippet } from 'svelte';
|
||||||
|
|
||||||
|
let { icon, callback, id }: { icon: Snippet; callback: () => void; id: string } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class=" m-2 flex w-auto flex-col items-center gap-2 rounded-md bg-bg-light-dark p-2">
|
||||||
|
{@render icon()}
|
||||||
|
<label
|
||||||
|
for={id}
|
||||||
|
class="relative block h-5 w-10 cursor-pointer rounded-full bg-bg-lighter-dark shadow-subtle"
|
||||||
|
>
|
||||||
|
<input type="button" onclick={callback} {id} 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"
|
||||||
|
>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
let { placeholder, value }: { placeholder: string; value: string } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- svelte-ignore a11y_autofocus -->
|
||||||
|
<div
|
||||||
|
class="
|
||||||
|
flex flex-row items-center justify-between
|
||||||
|
overflow-clip rounded-md border border-border
|
||||||
|
bg-surface-1 has-focus:border-focus-ring
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
class="px-3 py-2 outline-none placeholder:text-muted"
|
||||||
|
{placeholder}
|
||||||
|
bind:value
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
}: { nodeName: string; nodeType: Type; isProject: boolean } = $props();
|
}: { nodeName: string; nodeType: Type; isProject: boolean } = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<input type="radio" />
|
||||||
<div class=" flex flex-row items-center rounded-md bg-bg-lighter-dark p-2">
|
<div class=" flex flex-row items-center rounded-md bg-bg-lighter-dark p-2">
|
||||||
{#if nodeType == Type.Directory}
|
{#if nodeType == Type.Directory}
|
||||||
<Folder class="text-primary-dark" strokeWidth={1} />
|
<Folder class="text-primary-dark" strokeWidth={1} />
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<label
|
<label
|
||||||
class="m-0 flex size-12 items-center justify-center rounded-xl bg-bg-lighter-dark shadow-subtle hover:text-primary-hover-dark has-checked:text-primary-dark has-checked:hover:text-primary-hover-dark light:bg-bg-light-light light:hover:text-primary-hover-light light:has-checked:text-primary-light light:has-checked:hover:text-primary-hover-light"
|
class=" m-0 flex size-12 items-center justify-center rounded-xl bg-surface-2 shadow-subtle duration-100 transition-standard hover:text-primary has-checked:text-primary has-checked:hover:text-primary has-active:button-click"
|
||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
onclick={() => goto(path)}
|
onclick={() => goto(path)}
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { Snippet } from 'svelte';
|
||||||
|
|
||||||
|
let {
|
||||||
|
icon,
|
||||||
|
checked = false,
|
||||||
|
onChange = (value: boolean) => {},
|
||||||
|
disabled = false,
|
||||||
|
busy = false,
|
||||||
|
id = ''
|
||||||
|
}: {
|
||||||
|
icon?: Snippet;
|
||||||
|
checked: boolean;
|
||||||
|
onChange: (value: boolean) => void;
|
||||||
|
disabled?: boolean;
|
||||||
|
busy?: boolean;
|
||||||
|
id?: string;
|
||||||
|
} = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class=" bg-bg-dark m-2 flex max-w-fit flex-col items-center gap-2 rounded-md p-2">
|
||||||
|
{#if icon}
|
||||||
|
{@render icon()}
|
||||||
|
{/if}
|
||||||
|
<label for={id} class="relative block h-6 w-11 rounded-full bg-border">
|
||||||
|
<input
|
||||||
|
{id}
|
||||||
|
role="switch"
|
||||||
|
aria-busy={busy}
|
||||||
|
disabled={disabled || busy}
|
||||||
|
type="checkbox"
|
||||||
|
{checked}
|
||||||
|
onclick={(e) => {
|
||||||
|
if (!disabled && !busy) {
|
||||||
|
checked = !checked;
|
||||||
|
onChange(checked);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
class=" peer sr-only"
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
class=" absolute top-0.5 left-0.5 h-5 w-5 rounded-full bg-white shadow transition-transform content-[''] peer-checked:translate-x-5 peer-checked:bg-primary"
|
||||||
|
></span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
let {list}: {list: any[]} = $props();
|
||||||
|
|
||||||
|
|
||||||
|
function toggleAll() {
|
||||||
|
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<table class=" max-h-44">
|
||||||
|
<thead class=" h-4">
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
<input type="checkbox" onchange={toggleAll} />
|
||||||
|
</th>
|
||||||
|
<th></th>
|
||||||
|
<th></th>
|
||||||
|
<th></th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class=" overflow-y-auto">
|
||||||
|
{#each list as entry}
|
||||||
|
<tr class=" h-4">
|
||||||
|
<td><input type="checkbox" onchange={toggleAll} /></td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { Snippet } from 'svelte';
|
||||||
|
|
||||||
|
let {
|
||||||
|
icon,
|
||||||
|
callback,
|
||||||
|
id,
|
||||||
|
sync
|
||||||
|
}: { icon: Snippet; callback: () => void; id: string; sync: boolean } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class=" bg-bg-light-dark m-2 flex w-auto flex-col items-center gap-2 rounded-md p-2">
|
||||||
|
{@render icon()}
|
||||||
|
<label
|
||||||
|
for={id}
|
||||||
|
class="bg-bg-lighter-dark relative block h-5 w-10 cursor-pointer rounded-full shadow-subtle"
|
||||||
|
>
|
||||||
|
<label class="inline-flex cursor-pointer items-center gap-3 select-none">
|
||||||
|
<input type="checkbox" class="peer sr-only" checked={sync} onclick={callback} {id} />
|
||||||
|
<span
|
||||||
|
class="relative block h-6 w-11 rounded-full bg-border peer-checked:bg-primary after:absolute after:top-0.5 after:left-0.5 after:h-5 after:w-5 after:rounded-full after:bg-white after:shadow after:transition-transform after:content-[''] peer-checked:after:translate-x-5"
|
||||||
|
></span>
|
||||||
|
</label>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<div>
|
||||||
|
<div class="grid grid-cols-[auto_auto_auto] gap-y-4">
|
||||||
|
<!-- Header row (now a subgrid) -->
|
||||||
|
<div class="col-span-full mb-0 grid grid-cols-subgrid rounded-md bg-bg-dark">
|
||||||
|
<div class="px-4 py-2 text-left">
|
||||||
|
<p>Accessible</p>
|
||||||
|
</div>
|
||||||
|
<div class="px-4 py-2 text-left">
|
||||||
|
<p>Username</p>
|
||||||
|
</div>
|
||||||
|
<div class="px-4 py-2 text-left">
|
||||||
|
<p>Group</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Data rows – all follow the same subgrid pattern -->
|
||||||
|
<div class="col-span-full grid grid-cols-subgrid rounded-md bg-bg-light-dark">
|
||||||
|
<div class="px-4 py-2 text-left">
|
||||||
|
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
|
||||||
|
</div>
|
||||||
|
<div class="px-4 py-2 text-left">
|
||||||
|
<p>Username</p>
|
||||||
|
</div>
|
||||||
|
<div class="px-4 py-2 text-left">
|
||||||
|
<p>Group</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-span-full grid grid-cols-subgrid rounded-md bg-bg-light-dark">
|
||||||
|
<div class="px-4 py-2 text-left">
|
||||||
|
<p>Accessible</p>
|
||||||
|
</div>
|
||||||
|
<div class="px-4 py-2 text-left">
|
||||||
|
<p>Username</p>
|
||||||
|
</div>
|
||||||
|
<div class="px-4 py-2 text-left">
|
||||||
|
<p>Group</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { TriangleAlert } from '@lucide/svelte';
|
||||||
|
import Button from '../../Button.svelte';
|
||||||
|
|
||||||
|
let showModal = $state(false);
|
||||||
|
|
||||||
|
let {
|
||||||
|
entityName = '',
|
||||||
|
entityType = 'item',
|
||||||
|
onConfirm = () => {},
|
||||||
|
onClose = () => {},
|
||||||
|
loading = false
|
||||||
|
}: {
|
||||||
|
entityName: string;
|
||||||
|
entityType?: string;
|
||||||
|
onConfirm: () => void;
|
||||||
|
onClose: () => void;
|
||||||
|
loading?: boolean;
|
||||||
|
} = $props();
|
||||||
|
|
||||||
|
function closeModal() {
|
||||||
|
showModal = false;
|
||||||
|
confirmText = '';
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
function confirmModal() {
|
||||||
|
showModal = false;
|
||||||
|
onConfirm();
|
||||||
|
}
|
||||||
|
|
||||||
|
let confirmText = $state('');
|
||||||
|
let isValid = $derived(confirmText === entityName && confirmText.length > 0);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if showModal}
|
||||||
|
<!-- svelte-ignore a11y_autofocus -->
|
||||||
|
<div
|
||||||
|
onclick={(e) => {
|
||||||
|
if (e.target === e.currentTarget) closeModal();
|
||||||
|
}}
|
||||||
|
onkeydown={(e) => {
|
||||||
|
if (e.key === 'Escape') closeModal();
|
||||||
|
}}
|
||||||
|
role="textbox"
|
||||||
|
tabindex="0"
|
||||||
|
class=" fixed inset-0 z-100 flex items-center justify-center bg-black/55"
|
||||||
|
autofocus
|
||||||
|
>
|
||||||
|
<div class="flex flex-col items-center rounded-xl bg-bg-light-dark p-4">
|
||||||
|
<TriangleAlert size={48} strokeWidth={2} class=" mb-4 text-danger-dark"></TriangleAlert>
|
||||||
|
<h2 class=" mb-4 text-xl font-semibold text-text-dark">Delete {entityType}</h2>
|
||||||
|
<p class=" mb-6 w-3/4 text-center text-text-muted-dark">
|
||||||
|
Are you sure you want to delete <span class="font-bold text-text-dark">{entityName}</span
|
||||||
|
>?<br />
|
||||||
|
This action cannot be undone!
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="flex w-full flex-col items-center px-16">
|
||||||
|
<p class="mb-2 text-text-muted-dark">
|
||||||
|
Please type <span class="font-bold text-text-dark">{entityName}</span> to confirm
|
||||||
|
</p>
|
||||||
|
<!-- prettier-ignore -->
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
required
|
||||||
|
class="
|
||||||
|
mb-4 w-full rounded-md border border-transparent focus:border-primary-dark
|
||||||
|
bg-bg-lightest-dark px-3 py-2 shadow-subtle placeholder:text-text-muted-dark
|
||||||
|
outline-none
|
||||||
|
"
|
||||||
|
placeholder={entityName}
|
||||||
|
bind:value={confirmText}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class=" flex justify-end gap-16">
|
||||||
|
<Button onclick={closeModal} class="bg-bg-lightest-dark">Cancel</Button>
|
||||||
|
<Button
|
||||||
|
onkeydown={(e: any) => {
|
||||||
|
if (e.key === 'Enter') confirmModal();
|
||||||
|
}}
|
||||||
|
disabled={!isValid}
|
||||||
|
onclick={confirmModal}
|
||||||
|
class=" bg-danger-dark"
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { getConfig, getGroups, getUsers, setConfig } from '$lib/stores/panel-state.svelte';
|
||||||
|
import SwitchModule from '../SwitchModule.svelte';
|
||||||
|
let toggle = $state(false);
|
||||||
|
let log = () => {};
|
||||||
|
|
||||||
|
async function handleToggle(key: string, newValue: boolean) {
|
||||||
|
const value = newValue ? '1' : '0';
|
||||||
|
try {
|
||||||
|
await setConfig(key, value);
|
||||||
|
} catch (e) {
|
||||||
|
// error already handled in setConfig
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$inspect(getUsers(), 'users');
|
||||||
|
$inspect(getGroups(), 'groups');
|
||||||
|
$inspect(getConfig(), 'config');
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="justify-betwee flex w-full items-center">
|
||||||
|
<SwitchModule
|
||||||
|
id="maintenance"
|
||||||
|
checked={getConfig()['maintenance'] === '1'}
|
||||||
|
onChange={(value) => handleToggle('maintenance', value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<script>
|
||||||
|
import InputElemModule from '../InputElemModule.svelte';
|
||||||
|
|
||||||
|
let value123 = $state('');
|
||||||
|
|
||||||
|
$inspect(value123);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<InputElemModule placeholder={'Test'} value={value123}></InputElemModule>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { ChevronDown } from '@lucide/svelte';
|
||||||
|
import type { UserData } from '../../../routes/admin/util';
|
||||||
|
import Switch from '../../inputs/Switch.svelte';
|
||||||
|
import UserEditForm from './UserEditForm.svelte';
|
||||||
|
|
||||||
|
let { data }: { data: UserData } = $props();
|
||||||
|
|
||||||
|
let accessible = $derived(data.accessible);
|
||||||
|
let detailsToggle: boolean = $state(false);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="col-span-full grid grid-cols-subgrid items-center border-y border-b border-border bg-surface-1"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="relative flex h-full items-center px-4 py-4 text-center after:absolute after:top-0 after:left-0 after:h-full after:w-0.5 after:bg-primary after:opacity-0 after:transition-opacity after:content-[''] has-checked:after:opacity-100"
|
||||||
|
>
|
||||||
|
<input type="checkbox" />
|
||||||
|
</div>
|
||||||
|
<div class="items-center py-4 pr-4 text-left">
|
||||||
|
<p>{data.username}</p>
|
||||||
|
</div>
|
||||||
|
<div class="items-center py-4 pr-4 text-left">
|
||||||
|
<p>{data.uid}</p>
|
||||||
|
</div>
|
||||||
|
<div class="items-center py-4 pr-4 text-left">
|
||||||
|
<p>{data.homePath}</p>
|
||||||
|
</div>
|
||||||
|
<div class="items-center py-4 pr-4 text-left">
|
||||||
|
<p>{data.group}</p>
|
||||||
|
</div>
|
||||||
|
<div class="items-center py-4 pr-4 text-left">
|
||||||
|
<p>{data.gid}</p>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center py-4 pr-4">
|
||||||
|
<Switch
|
||||||
|
id={data.uid + '-user-toggle'}
|
||||||
|
state={accessible}
|
||||||
|
onclick={(e) => {
|
||||||
|
accessible = !accessible;
|
||||||
|
}}
|
||||||
|
></Switch>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center py-4 pr-4">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label="details"
|
||||||
|
onclick={() => {
|
||||||
|
detailsToggle = !detailsToggle;
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class:-rotate-180={detailsToggle}
|
||||||
|
class="transition-rotate duration-100 ease-in hover:translate-y-0.5"
|
||||||
|
>
|
||||||
|
<ChevronDown></ChevronDown>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class=" col-span-full grid origin-top grid-rows-[0fr] overflow-clip border-0 border-border bg-surface-1 transition-all duration-150"
|
||||||
|
class:grid-rows-[1fr]={detailsToggle}
|
||||||
|
class:border-y={detailsToggle}
|
||||||
|
>
|
||||||
|
<div class="min-h-0">
|
||||||
|
<UserEditForm></UserEditForm>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
/*
|
||||||
|
User checkboxes are not getting updated with the checkedSet changes
|
||||||
|
remake proof of concept to full fledged frontend
|
||||||
|
add a edit button to entry
|
||||||
|
|
||||||
|
reversing sort makes ALL the ARROWS be reversed
|
||||||
|
(we only want to indicate the sort direction on the sort comparation value)
|
||||||
|
|
||||||
|
make delete action be on bottom of edit form on the right, and save button on the top right of edit form
|
||||||
|
|
||||||
|
make the accessible indicator with an icon instead
|
||||||
|
|
||||||
|
squish the table in width
|
||||||
|
|
||||||
|
make sort indicators with icons
|
||||||
|
|
||||||
|
make the table be a separate module thats reusable
|
||||||
|
|
||||||
|
make the user entry a reusable module
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
addUserCheck,
|
||||||
|
clearUserChecks,
|
||||||
|
getCheckedUsers,
|
||||||
|
getFilteredUsers,
|
||||||
|
getFocusedUid,
|
||||||
|
openEdit
|
||||||
|
} from '$lib/stores/panel-state.svelte';
|
||||||
|
import { SortUserBy } from '$lib/termos/util/sort';
|
||||||
|
import type { UserData } from '../../../routes/admin/util';
|
||||||
|
import UserRow from './UserRow.svelte';
|
||||||
|
import UsersTableColumn from './UsersTableColumn.svelte';
|
||||||
|
|
||||||
|
let users = $derived(getFilteredUsers());
|
||||||
|
let checkedSet = $derived(getCheckedUsers());
|
||||||
|
let focusedUid = $derived(getFocusedUid());
|
||||||
|
|
||||||
|
let sortBy: SortUserBy = $state(SortUserBy.UID);
|
||||||
|
let sortReverse: boolean = $state(false);
|
||||||
|
|
||||||
|
function handleEdit(user: UserData) {
|
||||||
|
openEdit(user.uid, 'user');
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleAll(e: Event) {
|
||||||
|
const target = e.target as HTMLInputElement;
|
||||||
|
if (target.checked) {
|
||||||
|
for (const u of users) {
|
||||||
|
if (!checkedSet.has(u.uid)) {
|
||||||
|
console.log('checked', u.username);
|
||||||
|
addUserCheck(u.uid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
clearUserChecks();
|
||||||
|
target.checked = false;
|
||||||
|
console.log(checkedSet, users);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleSort(col: SortUserBy): void {
|
||||||
|
if (sortBy === col) {
|
||||||
|
sortReverse = !sortReverse;
|
||||||
|
} else {
|
||||||
|
sortBy = col;
|
||||||
|
sortReverse = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{#if checkedSet.size > 0}
|
||||||
|
<!-- Bulk -->
|
||||||
|
{:else}
|
||||||
|
<!-- Search -->
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
style="grid-template-columns: repeat(32, max-content)"
|
||||||
|
class=" grid w-min border-b border-border"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class=" col-span-full grid grid-cols-subgrid items-center border-b border-border bg-surface-2"
|
||||||
|
>
|
||||||
|
<div class="flex items-center px-4 py-2 text-center">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
onchange={toggleAll}
|
||||||
|
checked={users.length > 0 && checkedSet.size === users.length}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<UsersTableColumn
|
||||||
|
header="Username"
|
||||||
|
{sortBy}
|
||||||
|
sortParam={SortUserBy.USERNAME}
|
||||||
|
{sortReverse}
|
||||||
|
{toggleSort}
|
||||||
|
></UsersTableColumn>
|
||||||
|
<UsersTableColumn
|
||||||
|
header="UID"
|
||||||
|
{sortBy}
|
||||||
|
sortParam={SortUserBy.UID}
|
||||||
|
{sortReverse}
|
||||||
|
{toggleSort}
|
||||||
|
></UsersTableColumn>
|
||||||
|
<UsersTableColumn
|
||||||
|
header="Home"
|
||||||
|
{sortBy}
|
||||||
|
sortParam={SortUserBy.HOME}
|
||||||
|
{sortReverse}
|
||||||
|
{toggleSort}
|
||||||
|
></UsersTableColumn>
|
||||||
|
<UsersTableColumn
|
||||||
|
header="Group"
|
||||||
|
{sortBy}
|
||||||
|
sortParam={SortUserBy.GROUP}
|
||||||
|
{sortReverse}
|
||||||
|
{toggleSort}
|
||||||
|
></UsersTableColumn>
|
||||||
|
<UsersTableColumn
|
||||||
|
header="GID"
|
||||||
|
{sortBy}
|
||||||
|
sortParam={SortUserBy.GROUP}
|
||||||
|
{sortReverse}
|
||||||
|
{toggleSort}
|
||||||
|
></UsersTableColumn>
|
||||||
|
<UsersTableColumn
|
||||||
|
header="Accessible"
|
||||||
|
{sortBy}
|
||||||
|
sortParam={SortUserBy.ACCESSIBLE}
|
||||||
|
{sortReverse}
|
||||||
|
{toggleSort}
|
||||||
|
></UsersTableColumn>
|
||||||
|
</div>
|
||||||
|
{#each users as user}
|
||||||
|
<UserRow data={user}></UserRow>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { SortUserBy } from '$lib/termos/util/sort';
|
||||||
|
import { ChevronsUpDown } from '@lucide/svelte';
|
||||||
|
|
||||||
|
let {
|
||||||
|
header,
|
||||||
|
sortBy,
|
||||||
|
sortParam,
|
||||||
|
sortReverse,
|
||||||
|
toggleSort
|
||||||
|
}: {
|
||||||
|
header: string;
|
||||||
|
sortBy: SortUserBy;
|
||||||
|
sortParam: SortUserBy;
|
||||||
|
sortReverse: boolean;
|
||||||
|
toggleSort: (param: SortUserBy) => void;
|
||||||
|
} = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<button
|
||||||
|
class="flex flex-row items-center gap-2 py-2 pr-2 text-left"
|
||||||
|
onclick={() => toggleSort(sortParam)}
|
||||||
|
>
|
||||||
|
<h4 class="font-medium">{header}</h4>
|
||||||
|
<div class="flex items-center self-center pr-2">
|
||||||
|
<ChevronsUpDown size={16} strokeWidth={2}></ChevronsUpDown>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<main
|
<main
|
||||||
class="text-text m-auto flex min-h-dvh w-full flex-col items-center justify-center overflow-hidden bg-dots-bg bg-size-[20px_20px]"
|
class="text-text m-auto flex min-h-dvh w-full flex-col items-center justify-center overflow-hidden bg-bg-base"
|
||||||
class:dark={$theme === 'dark'}
|
class:dark={$theme === 'dark'}
|
||||||
class:light={$theme === 'light'}
|
class:light={$theme === 'light'}
|
||||||
>
|
>
|
||||||
@@ -49,8 +49,6 @@
|
|||||||
|
|
||||||
<style>
|
<style>
|
||||||
main {
|
main {
|
||||||
transition:
|
transition: all 0.2s ease-in;
|
||||||
--dots-bg-2 0.2s ease-in,
|
|
||||||
--dots-bg-1 0.2s ease-in;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,30 +1,32 @@
|
|||||||
import { db } from "$lib/server/db";
|
import { db } from '$lib/server/db';
|
||||||
import { settings } from "$lib/server/db/schema";
|
import { config } from '$lib/server/db/schema';
|
||||||
import { PASSWD } from "$lib/stores/bash/etc/userData";
|
import { PASSWD } from '$lib/stores/bash/etc/userData';
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from 'drizzle-orm';
|
||||||
import type { Actions } from "./$types";
|
import type { Actions, PageServerLoad } from './$types';
|
||||||
import type { PageServerLoad } from "./panel/projects/$types";
|
|
||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
login: async ({request}) => {
|
login: async ({ request }) => {
|
||||||
const user = PASSWD.find((object) => object.username == "gornodox");
|
const user = PASSWD.find((object) => object.username == 'gornodox');
|
||||||
let data = await request.formData();
|
let data = await request.formData();
|
||||||
let out = data.get("password")?.toString();
|
let out = data.get('password')?.toString();
|
||||||
let error = false;
|
let error = false;
|
||||||
let success = true
|
let success = true;
|
||||||
|
|
||||||
if(out != user?.passwd || out == undefined) {
|
if (out != user?.passwd || out == undefined) {
|
||||||
error = true;
|
error = true;
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { error, success, data: out };
|
return { error, success, data: out };
|
||||||
}
|
}
|
||||||
} satisfies Actions
|
} satisfies Actions;
|
||||||
|
|
||||||
export const load: PageServerLoad = async () => {
|
export const load: PageServerLoad = async () => {
|
||||||
return {
|
return {
|
||||||
settings: await db.select({setting: settings.state}).from(settings).where(eq(settings.var, 'maintenance')).limit(1)
|
config: await db
|
||||||
|
.select({ config: config.value })
|
||||||
|
.from(config)
|
||||||
|
.where(eq(config.value, 'maintenance'))
|
||||||
|
.limit(1)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,35 +1,26 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Settings from '../modules/Settings.svelte';
|
|
||||||
import { isInitializing } from '$lib/stores/terminal/init.svelte';
|
|
||||||
import Login from '../modules/Login.svelte';
|
import Login from '../modules/Login.svelte';
|
||||||
import { mount } from 'svelte';
|
|
||||||
import Terminal from '../modules/Terminal.svelte';
|
|
||||||
import { CircleAlert } from '@lucide/svelte';
|
|
||||||
import Maintenence from '../modules/Maintenence.svelte';
|
import Maintenence from '../modules/Maintenence.svelte';
|
||||||
|
import Settings from '../modules/Settings.svelte';
|
||||||
|
import Terminal from '../modules/Terminal.svelte';
|
||||||
|
|
||||||
let { form, data } = $props();
|
let { form, data } = $props();
|
||||||
|
|
||||||
const MAINTENANCE = $derived(Boolean(data.settings[0].setting));
|
const MAINTENANCE = $derived(Boolean(data.config[0]));
|
||||||
|
|
||||||
//export let isWelcomeSequence = false;
|
|
||||||
|
|
||||||
// svelte-ignore non_reactive_update
|
|
||||||
let terminalComponent: Terminal;
|
|
||||||
|
|
||||||
function welcomeSequence() {
|
function welcomeSequence() {
|
||||||
//isWelcomeSequence = true;
|
//isWelcomeSequence = true;
|
||||||
|
|
||||||
//TODO: do magic :)
|
//TODO: do magic :)
|
||||||
}
|
}
|
||||||
|
|
||||||
function initializer(formData: FormData) {
|
function initializer(formData: FormData) {
|
||||||
console.log(formData);
|
console.log(formData);
|
||||||
|
|
||||||
if(form?.error) return;
|
if (form?.error) return;
|
||||||
const password = formData.get("password")?.toString();
|
/* const password = formData.get('password')?.toString();
|
||||||
const username = formData.get("username")?.toString();
|
const username = formData.get('username')?.toString();
|
||||||
if(!password || !username) throw new Error("password or username is null or undefined");
|
if (!password || !username) throw new Error('password or username is null or undefined');
|
||||||
terminalComponent.init(username, password)
|
terminalComponent.init(username, password); */
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -38,33 +29,36 @@
|
|||||||
<Maintenence />
|
<Maintenence />
|
||||||
{:else}
|
{:else}
|
||||||
<Settings></Settings>
|
<Settings></Settings>
|
||||||
<div id="main" class="h-dvh w-full p-24 relative flex justify-center items-center">
|
<div id="main" class="relative flex h-dvh w-full items-center justify-center p-24">
|
||||||
<div id="wrapper1" class=" absolute z-35 flex flex-col items-center {form?.success ? 'outro' : ''}">
|
<div
|
||||||
<Login init={initializer} form={form}/>
|
id="wrapper1"
|
||||||
|
class=" absolute z-35 flex flex-col items-center {form?.success ? 'outro' : ''}"
|
||||||
|
>
|
||||||
|
<Login init={initializer} {form} />
|
||||||
</div>
|
</div>
|
||||||
<div id="wrapper2" class=" opacity-0 size-4/5 absolute z-4 {form?.success ? 'intro' : ''}">
|
<div id="wrapper2" class=" absolute z-4 size-4/5 opacity-0 {form?.success ? 'intro' : ''}">
|
||||||
<Terminal bind:this={terminalComponent} />
|
<Terminal></Terminal>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.intro {
|
.intro {
|
||||||
animation: fadeIn 0.5s forwards cubic-bezier(.4,.7,0,.99) 1s;
|
animation: fadeIn 0.5s forwards cubic-bezier(0.4, 0.7, 0, 0.99) 1s;
|
||||||
}
|
}
|
||||||
|
|
||||||
.outro {
|
.outro {
|
||||||
animation: fadeOut 0.5s forwards cubic-bezier(.4,.7,0,.99) 1s;
|
animation: fadeOut 0.5s forwards cubic-bezier(0.4, 0.7, 0, 0.99) 1s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes fadeIn {
|
@keyframes fadeIn {
|
||||||
to {
|
to {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes fadeOut {
|
@keyframes fadeOut {
|
||||||
to {
|
to {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
display: none;
|
display: none;
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
import type { Tween } from 'svelte/motion';
|
||||||
|
|
||||||
|
export interface UserData {
|
||||||
|
uid: number;
|
||||||
|
username: string;
|
||||||
|
homeDir: number;
|
||||||
|
homePath: string;
|
||||||
|
gid: number;
|
||||||
|
group: string;
|
||||||
|
accessible: boolean;
|
||||||
|
avatarUrl: string;
|
||||||
|
supplementaryGroups: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GroupData {
|
||||||
|
gid: number;
|
||||||
|
groupname: string;
|
||||||
|
members: number[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UserFormData {
|
||||||
|
uid?: number;
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
confirmPassword: string;
|
||||||
|
homeDir: number;
|
||||||
|
gid: number;
|
||||||
|
supplementaryGroups: number[];
|
||||||
|
accessible: boolean;
|
||||||
|
avatarFile?: File;
|
||||||
|
avatarUrl?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GroupFormData {
|
||||||
|
gid: number;
|
||||||
|
groupname: string;
|
||||||
|
members: number[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ToastMessage {
|
||||||
|
id: number;
|
||||||
|
type: 'success' | 'error' | 'info' | 'warn';
|
||||||
|
title: string;
|
||||||
|
message: string;
|
||||||
|
duration: number;
|
||||||
|
tween?: Tween<number>;
|
||||||
|
initial: number;
|
||||||
|
target: number;
|
||||||
|
hideProgress: boolean;
|
||||||
|
hideDismiss: boolean;
|
||||||
|
onClose?: (tm: ToastMessage) => void;
|
||||||
|
onClick?: (tm: ToastMessage) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Keybind {
|
||||||
|
action: string;
|
||||||
|
combo: string;
|
||||||
|
handler: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function capitalize(word: string): string {
|
||||||
|
if (!word) '';
|
||||||
|
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function request(
|
||||||
|
endpoint: string,
|
||||||
|
options?: {
|
||||||
|
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
||||||
|
body?: any;
|
||||||
|
headers?: Record<string, string>;
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
const config: RequestInit = {
|
||||||
|
method: options?.method || 'GET',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
...options?.headers
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (options?.body) {
|
||||||
|
config.body = JSON.stringify(options.body);
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(`/api/v1/${endpoint}`, config);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorText = await response.text();
|
||||||
|
throw new Error(`Request failed: ${response.status} ${errorText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const text = await response.text();
|
||||||
|
return text ? JSON.parse(text) : null;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { db } from '$lib/server/db';
|
||||||
|
import { config } from '$lib/server/db/schema';
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
const rows = await db.select().from(config);
|
||||||
|
const result: Record<string, string> = {};
|
||||||
|
for (const row of rows) {
|
||||||
|
result[row.key] = row.value;
|
||||||
|
}
|
||||||
|
return new Response(JSON.stringify(result), {
|
||||||
|
headers: { 'Content-Type': 'application/json' }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function POST({ request, getClientAddress }) {
|
||||||
|
const body = await request.json();
|
||||||
|
for (const [key, value] of Object.entries(body)) {
|
||||||
|
await db
|
||||||
|
.insert(config)
|
||||||
|
.values({ key, value: String(value) })
|
||||||
|
.onDuplicateKeyUpdate({ set: { value: String(value) } });
|
||||||
|
}
|
||||||
|
return new Response(JSON.stringify({ success: true }), {
|
||||||
|
headers: { 'Content-Type': 'application/json' }
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { db } from '$lib/server/db';
|
||||||
|
import { fileContents } from '$lib/server/db/schema';
|
||||||
|
import type { RequestEvent } from '@sveltejs/kit';
|
||||||
|
import { eq } from 'drizzle-orm';
|
||||||
|
|
||||||
|
export async function GET(event: RequestEvent): Promise<Response> {
|
||||||
|
if (event.params.guid === undefined)
|
||||||
|
return new Response(`Bad request - no guid specified`, { status: 400 });
|
||||||
|
|
||||||
|
const row = await db
|
||||||
|
.select()
|
||||||
|
.from(fileContents)
|
||||||
|
.where(eq(fileContents.guid, event.params.guid))
|
||||||
|
.limit(1);
|
||||||
|
if (!row.length) {
|
||||||
|
return new Response(`File not found`, { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(new Uint8Array(row[0].data), {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': row[0].mimeType || 'application/octet-stream',
|
||||||
|
'Cache-Control': 'public, max-age=86400'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -2,8 +2,9 @@ import { db } from '$lib/server/db';
|
|||||||
import { filesystem } from '$lib/server/db/schema';
|
import { filesystem } from '$lib/server/db/schema';
|
||||||
import { MD5 } from '$lib/termos/util/hash';
|
import { MD5 } from '$lib/termos/util/hash';
|
||||||
import { eq } from 'drizzle-orm';
|
import { eq } from 'drizzle-orm';
|
||||||
|
import type { RequestEvent } from './$types';
|
||||||
|
|
||||||
export async function GET({ request }): Promise<Response> {
|
export async function GET(event: RequestEvent): Promise<Response> {
|
||||||
const row = await db
|
const row = await db
|
||||||
.select({
|
.select({
|
||||||
data: filesystem.data,
|
data: filesystem.data,
|
||||||
@@ -18,7 +19,7 @@ export async function GET({ request }): Promise<Response> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { data, checksum } = row[0];
|
const { data, checksum } = row[0];
|
||||||
const clientETag = request.headers.get('if-none-match');
|
const clientETag = event.request.headers.get('if-none-match');
|
||||||
|
|
||||||
if (clientETag === `"${checksum}"`) {
|
if (clientETag === `"${checksum}"`) {
|
||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
@@ -37,15 +38,15 @@ export async function GET({ request }): Promise<Response> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function POST({ request }) {
|
export async function POST(event: RequestEvent) {
|
||||||
const newData = await request.text();
|
const newData = await event.request.text();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(newData);
|
JSON.parse(newData);
|
||||||
//TODO: Schema validation
|
//TODO: Schema validation
|
||||||
} catch {
|
} catch {
|
||||||
//TODO: Change that to a proper http headers error
|
//TODO: Change that to a proper http headers error
|
||||||
return new Response(null, {
|
return new Response('Invalid JSON', {
|
||||||
status: 400
|
status: 400
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { db } from '$lib/server/db';
|
||||||
|
import { groups } from '$lib/server/db/schema';
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
const rows = await db.select().from(groups);
|
||||||
|
|
||||||
|
if (!rows.length) {
|
||||||
|
return new Response('No groups stored on the database', { status: 500 });
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(JSON.stringify(rows), {
|
||||||
|
headers: { 'Content-Type': 'application/json' }
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { db } from '$lib/server/db';
|
||||||
|
import { groups } from '$lib/server/db/schema';
|
||||||
|
import type { RequestEvent } from '@sveltejs/kit';
|
||||||
|
import { eq } from 'drizzle-orm';
|
||||||
|
|
||||||
|
export async function GET(event: RequestEvent): Promise<Response> {
|
||||||
|
if (event.params.gid === undefined)
|
||||||
|
return new Response(`Bad request - no gid specified`, { status: 400 });
|
||||||
|
|
||||||
|
const row = await db
|
||||||
|
.select()
|
||||||
|
.from(groups)
|
||||||
|
.where(eq(groups.gid, Number(event.params.gid)))
|
||||||
|
.limit(1);
|
||||||
|
if (!row.length) {
|
||||||
|
return new Response(`Group not found`, { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(JSON.stringify(row), {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import { db } from '$lib/server/db';
|
import { db } from '$lib/server/db';
|
||||||
import { users } from '$lib/server/db/schema';
|
import { users } from '$lib/server/db/schema';
|
||||||
import { json } from '@sveltejs/kit';
|
import { json, type RequestEvent } from '@sveltejs/kit';
|
||||||
|
import { eq } from 'drizzle-orm';
|
||||||
|
|
||||||
export async function GET({ request }): Promise<Response> {
|
export async function GET(): Promise<Response> {
|
||||||
const rows = await db
|
const rows = await db
|
||||||
.select({
|
.select({
|
||||||
uid: users.uid,
|
uid: users.uid,
|
||||||
@@ -15,7 +16,7 @@ export async function GET({ request }): Promise<Response> {
|
|||||||
.from(users);
|
.from(users);
|
||||||
|
|
||||||
if (!rows.length) {
|
if (!rows.length) {
|
||||||
return new Response('Filesystem is not initialized on the database', { status: 500 });
|
return new Response('No users stored on the database', { status: 500 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const result: {}[] = rows.map((u) => ({
|
const result: {}[] = rows.map((u) => ({
|
||||||
@@ -25,3 +26,65 @@ export async function GET({ request }): Promise<Response> {
|
|||||||
|
|
||||||
return json(result);
|
return json(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function POST(event: RequestEvent) {
|
||||||
|
const formData = await event.request.formData();
|
||||||
|
const uid = formData.get('uid');
|
||||||
|
const username = formData.get('username')?.toString();
|
||||||
|
const password = formData.get('password')?.toString();
|
||||||
|
const home = Number(formData.get('home'));
|
||||||
|
const gid = Number(formData.get('gid'));
|
||||||
|
const accessible = Boolean(formData.get('accessible'));
|
||||||
|
const avatarFile = formData.get('avatar') as File | null;
|
||||||
|
|
||||||
|
if (!username || !password || !home || !gid || accessible === undefined) {
|
||||||
|
return new Response('Missing fields', { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
let avatarBuffer: Buffer | null = null;
|
||||||
|
if (avatarFile && avatarFile.size > 0) {
|
||||||
|
avatarBuffer = Buffer.from(await avatarFile.arrayBuffer());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uid) {
|
||||||
|
// Update existing user
|
||||||
|
await db
|
||||||
|
.update(users)
|
||||||
|
.set({
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
home,
|
||||||
|
gid,
|
||||||
|
...(avatarBuffer && { avatar: avatarBuffer })
|
||||||
|
})
|
||||||
|
.where(eq(users.uid, Number(uid)));
|
||||||
|
} else {
|
||||||
|
// Create new user
|
||||||
|
await db.insert(users).values({
|
||||||
|
gid,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
home,
|
||||||
|
accessible,
|
||||||
|
face: avatarBuffer
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const targetUid = uid
|
||||||
|
? Number(uid)
|
||||||
|
: (
|
||||||
|
await db
|
||||||
|
.select({ uid: users.uid })
|
||||||
|
.from(users)
|
||||||
|
.where(eq(users.username, username!))
|
||||||
|
.limit(1)
|
||||||
|
)[0]?.uid;
|
||||||
|
|
||||||
|
if (!targetUid) {
|
||||||
|
return new Response('Failed to retrieve user after save', { status: 500 });
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(JSON.stringify({ targetUid, success: true }), {
|
||||||
|
headers: { 'Content-Type': 'application/json' }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { db } from '$lib/server/db';
|
import { db } from '$lib/server/db';
|
||||||
import { users } from '$lib/server/db/schema';
|
import { users } from '$lib/server/db/schema';
|
||||||
|
import type { RequestEvent } from '@sveltejs/kit';
|
||||||
import { eq } from 'drizzle-orm';
|
import { eq } from 'drizzle-orm';
|
||||||
|
|
||||||
export async function GET({ params, request }): Promise<Response> {
|
export async function GET(event: RequestEvent): Promise<Response> {
|
||||||
const row = await db
|
const row = await db
|
||||||
.select({
|
.select({
|
||||||
uid: users.uid,
|
uid: users.uid,
|
||||||
@@ -13,7 +14,7 @@ export async function GET({ params, request }): Promise<Response> {
|
|||||||
accessible: users.accessible
|
accessible: users.accessible
|
||||||
})
|
})
|
||||||
.from(users)
|
.from(users)
|
||||||
.where(eq(users.uid, Number(params.uid)))
|
.where(eq(users.uid, Number(event.params.uid)))
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
if (!row.length) {
|
if (!row.length) {
|
||||||
|
|||||||
@@ -1,11 +1,26 @@
|
|||||||
|
// src/routes/api/users/[uid]/avatar/+server.ts
|
||||||
import { db } from '$lib/server/db';
|
import { db } from '$lib/server/db';
|
||||||
import { users } from '$lib/server/db/schema';
|
import { users } from '$lib/server/db/schema';
|
||||||
|
import type { RequestEvent } from '@sveltejs/kit';
|
||||||
import { eq } from 'drizzle-orm';
|
import { eq } from 'drizzle-orm';
|
||||||
|
|
||||||
export async function PUT({ params, request }) {
|
export async function GET(event: RequestEvent) {
|
||||||
const uid = Number(params.uid);
|
const row = await db
|
||||||
const arrayBuffer = await request.arrayBuffer();
|
.select({ avatar: users.face })
|
||||||
const buffer = Buffer.from(arrayBuffer);
|
.from(users)
|
||||||
await db.update(users).set({ face: buffer }).where(eq(users.uid, uid));
|
.where(eq(users.uid, Number(event.params.uid)))
|
||||||
return new Response(null, { status: 204 });
|
.limit(1);
|
||||||
|
|
||||||
|
if (!row.length || !row[0].avatar) {
|
||||||
|
return new Response('Not found', { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const buffer = row[0].avatar;
|
||||||
|
|
||||||
|
return new Response(new Uint8Array(buffer), {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'image/png',
|
||||||
|
'Cache-Control': 'public, max-age=3600'
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,49 +1,71 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { page } from '$app/state';
|
||||||
import favicon from '$lib/assets/favicon.svg';
|
import favicon from '$lib/assets/favicon.svg';
|
||||||
import { BookA, ChartLine, ChartNoAxesColumn, FolderArchive, Plus } from '@lucide/svelte';
|
import { fetchAllData } from '$lib/stores/panel-state.svelte';
|
||||||
import { type Snippet } from 'svelte';
|
import { FileSystem } from '$lib/termos/filesystem/filesystem';
|
||||||
|
import {
|
||||||
|
BookA,
|
||||||
|
ChartLine,
|
||||||
|
ChartNoAxesColumn,
|
||||||
|
FolderArchive,
|
||||||
|
Plus,
|
||||||
|
Settings2,
|
||||||
|
UserRoundCog
|
||||||
|
} from '@lucide/svelte';
|
||||||
|
import { onMount, type Snippet } from 'svelte';
|
||||||
import '../../app.css';
|
import '../../app.css';
|
||||||
import SidebarButton from '../../modules/panel/SidebarButton.svelte';
|
import SidebarButton from '../../modules/panel/SidebarButton.svelte';
|
||||||
|
import ToastsModule from '../../modules/ToastsModule.svelte';
|
||||||
|
import { capitalize } from '../admin/util';
|
||||||
let { children, data }: { children: Snippet; data: any } = $props();
|
let { children, data }: { children: Snippet; data: any } = $props();
|
||||||
|
|
||||||
|
// Get last word of pathname (full url) filter if no empty array indexes exist and capitalize it
|
||||||
|
let site: string = $derived(capitalize(page.url.pathname.split('/').filter(Boolean).pop() ?? ''));
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
await FileSystem.init();
|
||||||
|
await fetchAllData();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<link rel="icon" href={favicon} />
|
<link rel="icon" href={favicon} />
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<div class="flex h-dvh w-full flex-row text-text-dark light:text-text-light">
|
<ToastsModule></ToastsModule>
|
||||||
<div class="flex h-full w-fit flex-col items-center bg-bg-dark light:bg-bg-light">
|
<div class="flex h-dvh w-full flex-row text-text-primary">
|
||||||
|
<div class="flex h-full w-fit flex-col items-center bg-surface-1">
|
||||||
<img class="m-3 mb-8" alt="Logo" src={favicon} height="32" width="32" />
|
<img class="m-3 mb-8" alt="Logo" src={favicon} height="32" width="32" />
|
||||||
<form class="flex h-full w-fit flex-col items-center gap-3">
|
<form class="flex h-full w-fit flex-col items-center gap-3">
|
||||||
<label
|
<label
|
||||||
class="m-0 mb-4 flex size-12 items-center justify-center rounded-xl bg-bg-lighter-dark shadow-subtle hover:text-primary-hover-dark has-checked:text-primary-dark has-checked:hover:text-primary-hover-dark light:bg-bg-light-light light:hover:text-primary-hover-light light:has-checked:text-primary-light light:has-checked:hover:text-primary-hover-light"
|
class="m-0 mb-4 flex size-12 items-center justify-center rounded-xl bg-surface-2 shadow-subtle duration-100 transition-standard hover:text-primary has-checked:text-primary has-checked:hover:text-primary-variant has-active:button-click"
|
||||||
>
|
>
|
||||||
<input name="langs" type="radio" class="hidden" id="pl" autocomplete="off" />
|
<input name="langs" type="radio" class="hidden" id="pl" autocomplete="off" />
|
||||||
<Plus strokeWidth={1} />
|
<Plus strokeWidth={1.25} />
|
||||||
</label>
|
</label>
|
||||||
<SidebarButton checked path="/panel/projects">
|
<!-- prettier-ignore -->
|
||||||
<FolderArchive strokeWidth={1} />
|
<SidebarButton /*checked*/ path="/panel/projects">
|
||||||
|
<FolderArchive strokeWidth={1.25} />
|
||||||
|
</SidebarButton>
|
||||||
|
<SidebarButton path="/panel/users">
|
||||||
|
<UserRoundCog strokeWidth={1.25} />
|
||||||
</SidebarButton>
|
</SidebarButton>
|
||||||
<SidebarButton path="/panel/langs">
|
<SidebarButton path="/panel/langs">
|
||||||
<BookA strokeWidth={1} />
|
<BookA strokeWidth={1.25} />
|
||||||
</SidebarButton>
|
</SidebarButton>
|
||||||
<SidebarButton path="/panel/metrics">
|
<SidebarButton path="/panel/metrics">
|
||||||
<ChartLine strokeWidth={1} />
|
<ChartLine strokeWidth={1.25} />
|
||||||
</SidebarButton>
|
</SidebarButton>
|
||||||
<SidebarButton path="/panel/stats">
|
<SidebarButton path="/panel/stats">
|
||||||
<ChartNoAxesColumn strokeWidth={1} />
|
<ChartNoAxesColumn strokeWidth={1.25} />
|
||||||
|
</SidebarButton>
|
||||||
|
<SidebarButton path="/panel/global">
|
||||||
|
<Settings2 strokeWidth={1.25} />
|
||||||
</SidebarButton>
|
</SidebarButton>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class=" w-full">
|
<div class=" m-8 w-full">
|
||||||
|
<h2 class=" m-8 ml-0 font-primary text-3xl font-black text-primary">{site}</h2>
|
||||||
{@render children()}
|
{@render children()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
|
||||||
main {
|
|
||||||
transition:
|
|
||||||
--dots-bg-2 0.2s ease-in,
|
|
||||||
--dots-bg-1 0.2s ease-in;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|||||||
@@ -1,25 +1,14 @@
|
|||||||
import fsData from '$lib/assets/fs/fs.json';
|
|
||||||
import { db } from '$lib/server/db';
|
import { db } from '$lib/server/db';
|
||||||
import { projects, settings } from '$lib/server/db/schema';
|
import { config, projects } 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 { eq } from 'drizzle-orm';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
|
|
||||||
export const load: PageServerLoad = async () => {
|
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 {
|
return {
|
||||||
settings: await db
|
settings: await db
|
||||||
.select({ setting: settings.state })
|
.select({ value: config.value })
|
||||||
.from(settings)
|
.from(config)
|
||||||
.where(eq(settings.var, 'maintenance'))
|
.where(eq(config.key, 'maintenance'))
|
||||||
.limit(1),
|
.limit(1),
|
||||||
projects: await db
|
projects: await db
|
||||||
.select({
|
.select({
|
||||||
@@ -28,7 +17,6 @@ export const load: PageServerLoad = async () => {
|
|||||||
data: projects.data,
|
data: projects.data,
|
||||||
enabled: projects.enabled
|
enabled: projects.enabled
|
||||||
})
|
})
|
||||||
.from(projects),
|
.from(projects)
|
||||||
nodes: nodes
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import { Construction, Eye, EyeOff } from '@lucide/svelte';
|
import { Construction, Eye, EyeOff } from '@lucide/svelte';
|
||||||
import NodeModule from '../../../modules/panel/NodeModule.svelte';
|
import NodeModule from '../../../modules/panel/NodeModule.svelte';
|
||||||
import ProjectModule from '../../../modules/panel/ProjectModule.svelte';
|
import ProjectModule from '../../../modules/panel/ProjectModule.svelte';
|
||||||
|
import ToggleSwitchModule from '../../../modules/panel/ToggleSwitchModule.svelte';
|
||||||
import { setMaintenanceState } from '../settings.remote';
|
import { setMaintenanceState } from '../settings.remote';
|
||||||
|
|
||||||
let { data }: { data: any } = $props();
|
let { data }: { data: any } = $props();
|
||||||
@@ -11,6 +12,10 @@
|
|||||||
|
|
||||||
console.log(data.projects[0].name);
|
console.log(data.projects[0].name);
|
||||||
|
|
||||||
|
function testModule() {
|
||||||
|
console.log('it works!');
|
||||||
|
}
|
||||||
|
|
||||||
function handleToggle() {
|
function handleToggle() {
|
||||||
console.log(maintenance);
|
console.log(maintenance);
|
||||||
maintenance = !maintenance;
|
maintenance = !maintenance;
|
||||||
@@ -24,6 +29,17 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<div class=" flex items-start">
|
||||||
|
<ToggleSwitchModule
|
||||||
|
callback={async () => await setMaintenanceState(Number(!maintenance))}
|
||||||
|
id="maintenence"
|
||||||
|
sync={maintenance}
|
||||||
|
>
|
||||||
|
{#snippet icon()}
|
||||||
|
<Construction strokeWidth={1} />
|
||||||
|
{/snippet}
|
||||||
|
</ToggleSwitchModule>
|
||||||
|
</div>
|
||||||
<div
|
<div
|
||||||
class=" grid-cols-[1.5fr, 1fr] grid w-full"
|
class=" grid-cols-[1.5fr, 1fr] grid w-full"
|
||||||
style="grid-template-areas:
|
style="grid-template-areas:
|
||||||
@@ -46,33 +62,20 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class=" flex flex-col gap-1">
|
<div class=" flex flex-col gap-1">
|
||||||
|
<form>
|
||||||
{#each data.nodes as node}
|
{#each data.nodes as node}
|
||||||
{#if showHidden}
|
{#if showHidden}
|
||||||
|
<label>
|
||||||
<NodeModule nodeName={node.name} nodeType={node.type} isProject={false} />
|
<NodeModule nodeName={node.name} nodeType={node.type} isProject={false} />
|
||||||
|
</label>
|
||||||
{/if}
|
{/if}
|
||||||
{#if !node.name.startsWith('.') && !showHidden}
|
{#if !node.name.startsWith('.') && !showHidden}
|
||||||
|
<label>
|
||||||
<NodeModule nodeName={node.name} nodeType={node.type} isProject={false} />
|
<NodeModule nodeName={node.name} nodeType={node.type} isProject={false} />
|
||||||
|
</label>
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class=" mt-4">
|
|
||||||
<Construction strokeWidth={1} />
|
|
||||||
<label
|
|
||||||
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"
|
|
||||||
/>
|
|
||||||
<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"
|
|
||||||
>
|
|
||||||
</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Plus, Search, SquarePen } from '@lucide/svelte';
|
||||||
|
import Button from '../../../modules/Button.svelte';
|
||||||
|
import UsersTable from '../../../modules/panel/users/UsersTable.svelte';
|
||||||
|
|
||||||
|
function log2() {
|
||||||
|
console.log('test');
|
||||||
|
}
|
||||||
|
|
||||||
|
let searchPrompt = $state();
|
||||||
|
|
||||||
|
$inspect(searchPrompt);
|
||||||
|
|
||||||
|
function log(newValue: any) {
|
||||||
|
console.log(newValue);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- <ContextMenu items={[{ label: 'test123', action: log2 }]} onClose={() => {}}></ContextMenu> -->
|
||||||
|
<div class="mb-4 flex flex-row justify-between">
|
||||||
|
<div
|
||||||
|
class="
|
||||||
|
flex flex-row items-center justify-between
|
||||||
|
overflow-clip rounded-md border border-border
|
||||||
|
bg-surface-1 has-focus:border-focus-ring
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
class=" w-full px-3 py-2 outline-none placeholder:text-muted"
|
||||||
|
placeholder="Search..."
|
||||||
|
bind:value={searchPrompt}
|
||||||
|
/>
|
||||||
|
<Search strokeWidth={2} size={20} class="mx-3"></Search>
|
||||||
|
</div>
|
||||||
|
<Button class="flex flex-row items-center bg-primary text-text-on-primary">
|
||||||
|
<Plus class="ml-1" size={20}></Plus>
|
||||||
|
<span class="mx-2">Add User</span>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div style="grid-template-areas: 'a b';" class=" grid-cols-[2fr 1fr] grid size-full shadow-subtle">
|
||||||
|
<div style="grid-area: a;" class=" size-full">
|
||||||
|
<UsersTable></UsersTable>
|
||||||
|
</div>
|
||||||
|
<div style="grid-area: b;" class=" p-4">
|
||||||
|
<div class="bg-bg-dark rounded-2xl">
|
||||||
|
<div class="flex h-full flex-col items-center justify-center">
|
||||||
|
<SquarePen size={128} strokeWidth={1} class="text-gray-800" />
|
||||||
|
<p class="text-2xl font-bold text-gray-800">Nothing here but us chickens...</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="w-full"></div>
|
||||||
@@ -1,10 +1,27 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { MD5 } from '$lib/termos/util/hash';
|
import { addToast } from '$lib/stores/toasts';
|
||||||
|
import { FileSystem } from '$lib/termos/filesystem/filesystem';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
|
import UsersTable from '../../modules/panel/users/UsersTable.svelte';
|
||||||
|
import Settings from '../../modules/Settings.svelte';
|
||||||
|
import type { ToastMessage } from '../admin/util';
|
||||||
|
|
||||||
console.log(MD5.hash(''));
|
function bye(tm: ToastMessage): void {
|
||||||
console.log(MD5.hash('a'));
|
console.log('Funkcja wywolana');
|
||||||
console.log(MD5.hash('abc'));
|
}
|
||||||
|
|
||||||
onMount(() => {});
|
onMount(async () => {
|
||||||
|
await FileSystem.init();
|
||||||
|
|
||||||
|
document.addEventListener('keydown', (e) => {
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
addToast('success', 'Hi~', '', 5000, undefined, undefined, true, false, bye, bye);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<Settings></Settings>
|
||||||
|
<div class="size-full p-16">
|
||||||
|
<UsersTable></UsersTable>
|
||||||
|
</div>
|
||||||
|
|||||||
@@ -37,60 +37,234 @@
|
|||||||
var(--dots-bg-1) 1px
|
var(--dots-bg-1) 1px
|
||||||
);
|
);
|
||||||
|
|
||||||
/* Background colors */
|
--background-image-pattern-dots: radial-gradient(
|
||||||
--color-bg-dark-dark: oklch(0.1 0.01 292);
|
circle,
|
||||||
--color-bg-dark: oklch(0.15 0.03 292);
|
var(--color-border) 1px,
|
||||||
--color-bg-mid-dark: oklch(0.175 0.03 292);
|
transparent 1px
|
||||||
--color-bg-light-dark: oklch(0.2 0.035 292);
|
);
|
||||||
--color-bg-lighter-dark: oklch(0.25 0.04 292);
|
|
||||||
--color-bg-dark-light: oklch(0.8 0.15 280);
|
|
||||||
--color-bg-light: oklch(0.85 0.2 280);
|
|
||||||
--color-bg-light-light: oklch(0.9 0.3 280);
|
|
||||||
--color-bg-lighter-light: oklch(1 0.3 280);
|
|
||||||
|
|
||||||
/* Text colors */
|
--background-image-pattern-grid:
|
||||||
--color-text-dark: oklch(0.96 0.01 292);
|
linear-gradient(var(--color-border) 1px, transparent 1px),
|
||||||
--color-text-muted-dark: oklch(0.76 0.01 292);
|
linear-gradient(90deg, var(--color-border) 1px, transparent 1px);
|
||||||
--color-text-light: oklch(0.15 0.02 292);
|
|
||||||
--color-text-muted-light: oklch(0.4 0.02 292);
|
|
||||||
|
|
||||||
/* Highlight and border colors */
|
--background-image-pattern-gradient: linear-gradient(
|
||||||
--color-highlight-dark: oklch(0.6 0.02 292);
|
135deg,
|
||||||
--color-border-dark: oklch(0.3 0.02 292);
|
var(--color-lavender-100) 0%,
|
||||||
--color-border-muted-dark: oklch(0.2 0.02 292);
|
var(--color-surface-1) 100%
|
||||||
--color-highlight-light: oklch(1 0.02 280);
|
);
|
||||||
--color-border-light: oklch(0.6 0.02 280);
|
|
||||||
--color-border-muted-light: oklch(0.7 0.02 280);
|
|
||||||
|
|
||||||
/* Primary and secondary colors */
|
/* Lavender scale */
|
||||||
--color-primary-dark: oklch(0.55 0.15 292);
|
--color-lavender-50: var(--color-lavender-50);
|
||||||
--color-primary-hover-dark: oklch(0.65 0.18 292);
|
--color-lavender-100: var(--color-lavender-100);
|
||||||
--color-secondary-dark: oklch(0.7 0.12 120);
|
--color-lavender-200: var(--color-lavender-200);
|
||||||
--color-primary-light: oklch(0.6 0.1 292);
|
--color-lavender-300: var(--color-lavender-300);
|
||||||
--color-primary-hover-light: oklch(0.65 0.1 292);
|
--color-lavender-400: var(--color-lavender-400);
|
||||||
--color-secondary-light: oklch(0.4 0.1 112);
|
--color-lavender-500: var(--color-lavender-500);
|
||||||
|
--color-lavender-600: var(--color-lavender-600);
|
||||||
|
--color-lavender-700: var(--color-lavender-700);
|
||||||
|
--color-lavender-800: var(--color-lavender-800);
|
||||||
|
--color-lavender-900: var(--color-lavender-900);
|
||||||
|
|
||||||
/* Loader colors (no light equivalent, using dark values) */
|
/* Neutral grey scale */
|
||||||
--color-loader-primary-dark: oklch(0.55 0.15 292);
|
--color-gray-50: var(--color-gray-50);
|
||||||
--color-loader-primary-hl-dark: oklch(0.8 0.15 292);
|
--color-gray-100: var(--color-gray-100);
|
||||||
--color-loader-primary-light: oklch(0.55 0.15 292);
|
--color-gray-200: var(--color-gray-200);
|
||||||
--color-loader-primary-hl-light: oklch(0.8 0.15 292);
|
--color-gray-300: var(--color-gray-300);
|
||||||
|
--color-gray-400: var(--color-gray-400);
|
||||||
|
--color-gray-500: var(--color-gray-500);
|
||||||
|
--color-gray-600: var(--color-gray-600);
|
||||||
|
--color-gray-700: var(--color-gray-700);
|
||||||
|
--color-gray-800: var(--color-gray-800);
|
||||||
|
--color-gray-900: var(--color-gray-900);
|
||||||
|
|
||||||
/* Status colors */
|
/* Semantic tokens */
|
||||||
--color-danger-dark: oklch(0.7 0.05 30);
|
--color-primary: var(--color-primary);
|
||||||
--color-warning-dark: oklch(0.7 0.05 100);
|
--color-primary-variant: var(--color-primary-variant);
|
||||||
--color-success-dark: oklch(0.7 0.05 160);
|
--color-secondary: var(--color-secondary);
|
||||||
--color-info-dark: oklch(0.7 0.05 260);
|
--color-secondary-variant: var(--color-secondary-variant);
|
||||||
--color-danger-light: oklch(0.5 0.05 30);
|
--color-info: var(--color-info);
|
||||||
--color-warning-light: oklch(0.5 0.05 100);
|
--color-info-container: var(--color-info-container);
|
||||||
--color-success-light: oklch(0.5 0.05 160);
|
|
||||||
--color-info-light: oklch(0.5 0.05 260);
|
/* Backgrounds */
|
||||||
|
--color-bg-base: var(--color-bg-base);
|
||||||
|
--color-surface-1: var(--color-surface-1);
|
||||||
|
--color-surface-2: var(--color-surface-2);
|
||||||
|
--color-surface-3: var(--color-surface-3);
|
||||||
|
--color-surface-4: var(--color-surface-4);
|
||||||
|
--color-border: var(--color-border);
|
||||||
|
|
||||||
|
/* Typography */
|
||||||
|
--color-text-primary: var(--color-text-primary);
|
||||||
|
--color-text-secondary: var(--color-text-secondary);
|
||||||
|
--color-text-on-primary: var(--color-text-on-primary);
|
||||||
|
--color-muted: var(--color-muted);
|
||||||
|
--color-link: var(--color-link);
|
||||||
|
--color-link-hover: var(--color-link-hover);
|
||||||
|
|
||||||
|
/* States */
|
||||||
|
--color-error: var(--color-error);
|
||||||
|
--color-error-container: var(--color-error-container);
|
||||||
|
--color-success: var(--color-success);
|
||||||
|
--color-success-container: var(--color-success-container);
|
||||||
|
--color-warning: var(--color-warning);
|
||||||
|
--color-warning-container: var(--color-warning-container);
|
||||||
|
|
||||||
|
/* Utilities */
|
||||||
|
--color-focus-ring: var(--color-focus-ring);
|
||||||
|
--color-overlay: var(--color-overlay);
|
||||||
|
--color-shadow: var(--color-shadow);
|
||||||
|
--color-highlight: var(--color-highlight);
|
||||||
|
--color-divider: var(--color-divider);
|
||||||
|
|
||||||
/* Font variables (unchanged) */
|
/* Font variables (unchanged) */
|
||||||
--font-primary: 'Space Mono', monospace;
|
--font-primary: 'Space Mono', monospace;
|
||||||
--font-terminal: 'JetBrains Mono', monospace;
|
--font-terminal: 'JetBrains Mono', monospace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@utiliti sha
|
||||||
|
|
||||||
|
@utility bg-pattern-dots {
|
||||||
|
background-image: var(--background-image-pattern-dots);
|
||||||
|
background-size: 20px 20px;
|
||||||
|
background-repeat: repeat;
|
||||||
|
}
|
||||||
|
|
||||||
|
@utility bg-pattern-grid {
|
||||||
|
background-image: var(--background-image-pattern-grid);
|
||||||
|
background-size: 30px 30px;
|
||||||
|
background-repeat: repeat;
|
||||||
|
}
|
||||||
|
|
||||||
|
@utility bg-pattern-gradient {
|
||||||
|
background-image: var(--background-image-pattern-gradient);
|
||||||
|
background-size: cover;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
}
|
||||||
|
|
||||||
|
@utility transition-standard {
|
||||||
|
transition: all 200ms ease-in;
|
||||||
|
}
|
||||||
|
|
||||||
|
@utility button-click {
|
||||||
|
transform: translateY(0.125rem);
|
||||||
|
filter: brightness(0.9);
|
||||||
|
transition:
|
||||||
|
filter 50ms linear,
|
||||||
|
transform 50ms linear;
|
||||||
|
}
|
||||||
|
|
||||||
|
:root {
|
||||||
|
/*
|
||||||
|
================================================================
|
||||||
|
LIGHT THEME
|
||||||
|
================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Lavender scale */
|
||||||
|
--color-lavender-50: oklch(0.975 0.02 290);
|
||||||
|
--color-lavender-100: oklch(0.945 0.04 290);
|
||||||
|
--color-lavender-200: oklch(0.875 0.08 285);
|
||||||
|
--color-lavender-300: oklch(0.775 0.14 280);
|
||||||
|
--color-lavender-400: oklch(0.665 0.18 275);
|
||||||
|
--color-lavender-500: oklch(0.555 0.2 270);
|
||||||
|
--color-lavender-600: oklch(0.465 0.22 265);
|
||||||
|
--color-lavender-700: oklch(0.39 0.22 260);
|
||||||
|
--color-lavender-800: oklch(0.31 0.18 255);
|
||||||
|
--color-lavender-900: oklch(0.25 0.14 250);
|
||||||
|
|
||||||
|
/* Neutral grey scale (harmonised hue ~270) */
|
||||||
|
--color-gray-50: oklch(0.98 0 0);
|
||||||
|
--color-gray-100: oklch(0.95 0.002 270);
|
||||||
|
--color-gray-200: oklch(0.88 0.003 270);
|
||||||
|
--color-gray-300: oklch(0.78 0.005 270);
|
||||||
|
--color-gray-400: oklch(0.65 0.008 270);
|
||||||
|
--color-gray-500: oklch(0.52 0.01 270);
|
||||||
|
--color-gray-600: oklch(0.4 0.012 270);
|
||||||
|
--color-gray-700: oklch(0.28 0.012 270);
|
||||||
|
--color-gray-800: oklch(0.18 0.008 270);
|
||||||
|
--color-gray-900: oklch(0.13 0.005 270);
|
||||||
|
|
||||||
|
/* Semantic tokens – Light */
|
||||||
|
--color-primary: var(--color-lavender-700);
|
||||||
|
--color-primary-variant: var(--color-lavender-500);
|
||||||
|
--color-secondary: oklch(0.6 0.11 170);
|
||||||
|
--color-secondary-variant: oklch(0.7 0.14 170);
|
||||||
|
--color-info: oklch(0.58 0.13 250);
|
||||||
|
--color-info-container: oklch(0.95 0.04 250);
|
||||||
|
|
||||||
|
/* Background depth */
|
||||||
|
--color-bg-base: oklch(1 0 0);
|
||||||
|
--color-surface-1: oklch(0.975 0.02 290);
|
||||||
|
--color-surface-2: oklch(0.96 0.03 290);
|
||||||
|
--color-surface-3: oklch(0.93 0.06 285);
|
||||||
|
--color-surface-4: oklch(0.89 0.08 280);
|
||||||
|
--color-border: var(--color-lavender-200);
|
||||||
|
|
||||||
|
/* Typography */
|
||||||
|
--color-text-primary: oklch(0.18 0.02 270);
|
||||||
|
--color-text-secondary: oklch(0.42 0.03 270);
|
||||||
|
--color-text-on-primary: oklch(1 0 0);
|
||||||
|
--color-muted: oklch(0.55 0.01 270);
|
||||||
|
--color-link: var(--color-primary-variant);
|
||||||
|
--color-link-hover: var(--color-primary);
|
||||||
|
|
||||||
|
/* Semantic states */
|
||||||
|
--color-error: oklch(0.6 0.2 15);
|
||||||
|
--color-error-container: oklch(0.95 0.03 15);
|
||||||
|
--color-success: oklch(0.55 0.1 160);
|
||||||
|
--color-success-container: oklch(0.93 0.05 155);
|
||||||
|
--color-warning: oklch(0.65 0.15 75);
|
||||||
|
--color-warning-container: oklch(0.96 0.08 75);
|
||||||
|
|
||||||
|
/* Extra utilities */
|
||||||
|
--color-focus-ring: oklch(0.39 0.22 260 / 0.5);
|
||||||
|
--color-overlay: oklch(0 0 0 / 0.5);
|
||||||
|
--color-shadow: oklch(0.18 0.02 270 / 0.1);
|
||||||
|
--color-highlight: oklch(0.775 0.14 280 / 0.4);
|
||||||
|
--color-divider: var(--color-lavender-100);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
================================================================
|
||||||
|
DARK THEME OVERRIDES
|
||||||
|
================================================================
|
||||||
|
*/
|
||||||
|
:root[data-theme='dark'] {
|
||||||
|
--color-primary: var(--color-lavender-300);
|
||||||
|
--color-primary-variant: var(--color-lavender-400);
|
||||||
|
--color-secondary: oklch(0.7 0.14 170);
|
||||||
|
--color-secondary-variant: oklch(0.75 0.1 170);
|
||||||
|
--color-info: oklch(0.72 0.12 240);
|
||||||
|
--color-info-container: oklch(0.28 0.06 245);
|
||||||
|
|
||||||
|
--color-bg-base: oklch(0.13 0.03 270);
|
||||||
|
--color-surface-1: oklch(0.19 0.04 270);
|
||||||
|
--color-surface-2: oklch(0.26 0.05 265);
|
||||||
|
--color-surface-3: oklch(0.34 0.06 260);
|
||||||
|
--color-surface-4: oklch(0.42 0.07 255);
|
||||||
|
--color-border: oklch(0.3 0.04 265);
|
||||||
|
|
||||||
|
--color-text-primary: oklch(0.95 0.02 290);
|
||||||
|
--color-text-secondary: oklch(0.7 0.08 280);
|
||||||
|
--color-text-on-primary: oklch(0.18 0.02 270);
|
||||||
|
--color-muted: oklch(0.6 0.03 270);
|
||||||
|
--color-link: var(--color-primary);
|
||||||
|
--color-link-hover: var(--color-primary-variant);
|
||||||
|
|
||||||
|
--color-error: oklch(0.7 0.18 10);
|
||||||
|
--color-error-container: oklch(0.3 0.06 10);
|
||||||
|
--color-success: oklch(0.72 0.12 155);
|
||||||
|
--color-success-container: oklch(0.26 0.05 150);
|
||||||
|
--color-warning: oklch(0.78 0.13 70);
|
||||||
|
--color-warning-container: oklch(0.35 0.07 65);
|
||||||
|
|
||||||
|
--color-focus-ring: oklch(0.775 0.14 280 / 0.5);
|
||||||
|
--color-overlay: oklch(0 0 0 / 0.7);
|
||||||
|
--color-shadow: oklch(0 0 0 / 0.35);
|
||||||
|
--color-highlight: oklch(0.465 0.22 265 / 0.4);
|
||||||
|
--color-divider: oklch(0.3 0.04 265);
|
||||||
|
}
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
transition: all 0.2s ease-in;
|
transition: all 0.2s ease-in;
|
||||||
--dots-bg-1: oklch(0.1 0.01 292);
|
--dots-bg-1: oklch(0.1 0.01 292);
|
||||||
@@ -126,42 +300,9 @@
|
|||||||
#misc
|
#misc
|
||||||
|
|
||||||
background-image: radial-gradient(circle at center, #9f7aea20 1px, transparent 1px); background-size: 20px 20px;
|
background-image: radial-gradient(circle at center, #9f7aea20 1px, transparent 1px); background-size: 20px 20px;
|
||||||
(dotted background)
|
otted background)
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
main.light {
|
/* Theme transition */
|
||||||
--dots-bg-1: oklch(0.9 0.01 292);
|
|
||||||
--dots-bg-2: oklch(0.8 0.01 292);
|
|
||||||
|
|
||||||
--bg-dark: oklch(0.92 0.2 280);
|
|
||||||
--bg: oklch(0.94 0.3 280);
|
|
||||||
--bg-light: oklch(0.96 0.3 280);
|
|
||||||
|
|
||||||
--text: oklch(0.15 0.02 292);
|
|
||||||
--text-muted: oklch(0.4 0.02 292);
|
|
||||||
|
|
||||||
--highlight: oklch(1 0.02 280);
|
|
||||||
--border: oklch(0.6 0.02 280);
|
|
||||||
--border-muted: oklch(0.7 0.02 280);
|
|
||||||
|
|
||||||
--border-cart: solid 1px var(--bg);
|
|
||||||
--shadow:
|
|
||||||
oklch(0.72 0.01 292 / 0.4) 0px 2px 4px, oklch(0.62 0.01 292 / 0.3) 0px 7px 13px -3px,
|
|
||||||
oklch(0.52 0.01 292 / 0.2) 0px -3px 0px inset;
|
|
||||||
|
|
||||||
--primary: oklch(0.6 0.1 292);
|
|
||||||
--primary-hover: oklch(0.65 0.1 292);
|
|
||||||
--secondary: oklch(0.4 0.1 112);
|
|
||||||
|
|
||||||
--gradient: linear-gradient(0deg, var(--bg), var(--bg-light) 95%);
|
|
||||||
--gradient-hover: linear-gradient(0deg, var(--bg), var(--bg-light));
|
|
||||||
--box-shadow-muted:
|
|
||||||
rgba(14, 30, 37, 0.12) 0px 2px 4px 0px, rgba(14, 30, 37, 0.32) 0px 2px 16px 0px;
|
|
||||||
|
|
||||||
--danger: oklch(0.5 0.05 30);
|
|
||||||
--warning: oklch(0.5 0.05 100);
|
|
||||||
--success: oklch(0.5 0.05 160);
|
|
||||||
--info: oklch(0.5 0.05 260);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||