Adds a more realistic config for development.

This commit is contained in:
2023-08-15 10:02:30 +02:00
parent a439faa3fe
commit e4d1b83108
9 changed files with 70 additions and 42 deletions

View File

@@ -22,11 +22,11 @@ a {
} }
.title { .title {
color: var(--text-title); color: var(--text-title) !important;
} }
.subtitle { .subtitle {
color: var(--text-subtitle); color: var(--text-subtitle) !important;
} }
h1 { h1 {

View File

@@ -13,43 +13,47 @@ links:
url: 'https://example.com' url: 'https://example.com'
services: services:
- title: '/Media'
icon: 'fas fa-photo-film'
items:
- title: 'Jellyfin'
subtitle: 'Media server for movies and shows'
target: '_blank'
url: 'https://eagle.tuleu.me'
type: jellyfin
keywords: 'cloud storage files'
- title: 'Sonarr'
subtitle: 'Shows tracker'
target: '_blank'
url: 'http://sonarr.lan'
type: sonarr
keywords: 'shows tracker torrent usenet'
- title: 'Radarr'
subtitle: 'Movie tracker'
target: '_blank'
url: 'http://radarr.lan'
type: sonarr
keywords: 'movies tracker torrent usenet'
- title: '/Cloud' - title: '/Cloud'
subtitle: 'Private Cloud Utilities'
icon: 'fas fa-cloud' icon: 'fas fa-cloud'
items: items:
- title: 'NAS' - title: 'NAS'
subtitle: 'Network Attached Storage' subtitle: 'Network Attached Storage'
icon: 'fas fa-hard-drive' icon: 'fas fa-hard-drive'
target: '_blank' target: '_blank'
url: '/NAS' url: 'https://owl.tuleu.me'
type: prowlarr keywords: 'cloud nas files storage'
keywords: 'cloud storage files' - title: '/Infra'
icon: 'fas fa-network-wired'
- title: 'PiHole'
subtitle: 'A DNS Hole'
logo: 'https://cdn.rawgit.com/pi-hole/graphics/master/Vortex/Vortex.svg'
target: '_blank'
url: '/pihole'
type: 'pihole'
keywords: 'cloud storage files'
- title: '/Cloud'
subtitle: 'Private Cloud Utilities'
icon: 'fas fa-cloud'
items: items:
- title: 'NAS'
subtitle: 'Network Attached Storage'
icon: 'fas fa-hard-drive'
target: '_blank'
url: '/NAS'
keywords: 'cloud storage files'
- title: 'PiHole' - title: 'PiHole'
subtitle: 'A DNS Hole' subtitle: 'A DNS to send telemetry and ads to the void'
icon: 'fas fa-hard-drive'
target: '_blank' target: '_blank'
url: '/pihole' url: 'https://pihole.lan/admin'
type: 'pihole' type: 'pihole'
keywords: 'cloud storage files' keywords: 'dns ads blocker internet'

View File

@@ -3,7 +3,6 @@
export let brand: BrandConfig = {}; export let brand: BrandConfig = {};
export let color = 'var(--text)'; export let color = 'var(--text)';
console.log(brand);
function masked() { function masked() {
return brand.logo != undefined && brand.asmask == true; return brand.logo != undefined && brand.asmask == true;

View File

@@ -7,6 +7,8 @@
export let data: any; export let data: any;
const component = getServiceComponent(service.type || ''); const component = getServiceComponent(service.type || '');
console.log(service);
</script> </script>
<div class="card"> <div class="card">

View File

@@ -17,6 +17,8 @@ export interface ServiceConfig extends SectionConfig {
url: string; url: string;
target?: string; target?: string;
type?: string; type?: string;
tag: string;
keywords: string;
[x: string]: unknown; [x: string]: unknown;
} }

View File

@@ -1,5 +1,11 @@
import { describe, expect, it } from 'vitest'; import { describe, expect, it } from 'vitest';
import { defaultConfig, stripPrivateFields, serverConfig, clientConfig, merge } from './config'; import {
defaultConfig,
stripPrivateFields,
serverConfig,
clientConfig,
mergeConfig
} from './config';
import type { Config } from '$lib/config'; import type { Config } from '$lib/config';
describe('Config', () => { describe('Config', () => {
@@ -9,7 +15,7 @@ describe('Config', () => {
}); });
it('should be able to merge with POJO', () => { it('should be able to merge with POJO', () => {
const merged: Config = merge<Config>(defaultConfig, { const merged: Config = mergeConfig(defaultConfig, {
subtitle: "Homer's favorite neighboor", subtitle: "Homer's favorite neighboor",
colors: { colors: {
light: { notInDefault: 'foo' } light: { notInDefault: 'foo' }
@@ -20,7 +26,8 @@ describe('Config', () => {
items: [ items: [
{ {
title: 'anoy homer', title: 'anoy homer',
customKey: 'all the time' customKey: 'all the time',
keywords: 'a b cc'
} }
] ]
} }
@@ -39,6 +46,7 @@ describe('Config', () => {
expect(merged.services[0].items).toHaveLength(1); expect(merged.services[0].items).toHaveLength(1);
expect(merged.services[0].items[0].title).toEqual('anoy homer'); expect(merged.services[0].items[0].title).toEqual('anoy homer');
expect(merged.services[0].items[0].customKey).toEqual('all the time'); expect(merged.services[0].items[0].customKey).toEqual('all the time');
expect(merged.services[0].items[0].keywords).toEqual('a b cc');
}); });
it('should be able to strip custom keys', () => { it('should be able to strip custom keys', () => {

View File

@@ -17,7 +17,9 @@ const requiredService: Required<ServiceConfig> = {
asmask: false, asmask: false,
url: '', url: '',
target: '', target: '',
type: '' type: '',
tag: '',
keywords: [],
}; };
const requiredServiceGroup: Required<ServiceGroupConfig> = { const requiredServiceGroup: Required<ServiceGroupConfig> = {
@@ -55,7 +57,7 @@ export const requiredConfig: Required<Config> = {
type SPOJO = Record<string, unknown>; type SPOJO = Record<string, unknown>;
export function merge<Type extends SPOJO>(a: Type, b: SPOJO): Type { function merge<Type extends SPOJO>(a: Type, b: SPOJO): Type {
const res: Type = { ...a }; const res: Type = { ...a };
for (const [key, value] of Object.entries(b)) { for (const [key, value] of Object.entries(b)) {
if ( if (
@@ -80,6 +82,11 @@ export function merge<Type extends SPOJO>(a: Type, b: SPOJO): Type {
return res; return res;
} }
export function mergeConfig(a: Config, b: SPOJO): Config {
return merge<Config>(a,b);
}
const defaultLightConfig: ColorConfig = {}; const defaultLightConfig: ColorConfig = {};
defaultLightConfig['highlight-primary'] = '#3367d6'; defaultLightConfig['highlight-primary'] = '#3367d6';
defaultLightConfig['highlight-secondary'] = '#4285f4'; defaultLightConfig['highlight-secondary'] = '#4285f4';
@@ -118,11 +125,16 @@ export const defaultConfig: Config = {
dark: defaultDarkConfig dark: defaultDarkConfig
}, },
links: [],
services: [] services: []
}; };
function strip<Type extends SPOJO>(toStrip: Type, reference: Type): Type { function strip<Type extends SPOJO>(toStrip: Type, reference: Type): Type {
const res: Type = { ...toStrip }; const res: Type = { ...toStrip };
if ( reference == undefined ) {
return res;
}
const referenceNames = Object.entries(reference).map(([key, value]) => key); const referenceNames = Object.entries(reference).map(([key, value]) => key);
for (const [key, value] of Object.entries(res)) { for (const [key, value] of Object.entries(res)) {
@@ -145,6 +157,7 @@ function strip<Type extends SPOJO>(toStrip: Type, reference: Type): Type {
continue; continue;
} }
// it is a child object, we strip it further // it is a child object, we strip it further
const childReference: SPOJO = reference[key] as SPOJO; const childReference: SPOJO = reference[key] as SPOJO;
(res as SPOJO)[key] = strip(value as SPOJO, childReference); (res as SPOJO)[key] = strip(value as SPOJO, childReference);
@@ -171,7 +184,7 @@ export function clientConfig(): Config {
return _clientConfig; return _clientConfig;
} }
let _serverConfig = merge<Config>(defaultConfig, configData); let _serverConfig = mergeConfig(defaultConfig, configData);
let _clientConfig = stripPrivateFields(_serverConfig); let _clientConfig = stripPrivateFields(_serverConfig);
@@ -181,7 +194,7 @@ export function watchDymamicConfig() {
const reloadConfig = async () => { const reloadConfig = async () => {
try { try {
const dynamicConfig = yml.load(await readFile(__filepath, 'utf8')); const dynamicConfig = yml.load(await readFile(__filepath, 'utf8'));
_serverConfig = merge<Config>(defaultConfig, dynamicConfig); _serverConfig = mergeConfig(defaultConfig, dynamicConfig);
_clientConfig = stripPrivateFields(_serverConfig); _clientConfig = stripPrivateFields(_serverConfig);
} catch (err) { } catch (err) {
console.error('could not read or parse config: ' + err); console.error('could not read or parse config: ' + err);

View File

@@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
export const data = undefined; export let data;
</script> </script>
<p>pihole status</p> pihole status

View File

@@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
export const data = undefined; export let data;
</script> </script>
<p>Prowlarr content</p> Prowlarr content