moved structs to extra file, added config db keys

This commit is contained in:
2025-11-25 17:13:02 +01:00
parent 76402e6f2f
commit 12658c14c3
4 changed files with 58 additions and 41 deletions

View File

@@ -1,20 +1,11 @@
module main
import veb
import os
import log
import veb
import util
// import app.src.util // IDE display version
struct Config {
pub mut:
root string
port int
}
struct Embedded {
pub mut:
style_css string
error_css string
}
//
pub struct User {
pub mut:
@@ -25,7 +16,7 @@ pub mut:
pub struct Context {
veb.Context
pub mut:
embed Embedded
embed util.Embedded
user User
session_id string
}
@@ -35,7 +26,7 @@ pub struct App {
veb.StaticHandler
veb.Middleware[Context]
pub mut:
embed Embedded
embed util.Embedded
}
pub struct Auth {}
@@ -48,26 +39,21 @@ pub fn (app &App) root(mut ctx Context, path string) veb.Result {
return ctx.html($tmpl('template/dashboard.html'))
}
@['/error']
pub fn (app &App) error(mut ctx Context) veb.Result {
return ctx.html(ctx.error_page(500, 'Internal Server Error', 'Oops! Seems like something went wrong here.'))
}
// auth endpoints
@[get; post]
pub fn (auth &Auth) login(mut ctx Context) veb.Result {
return ctx.text('')
return ctx.text('login')
}
@[get; post]
pub fn (auth &Auth) logout(mut ctx Context) veb.Result {
return ctx.text('')
return ctx.text('logout')
}
@[get; post; put]
pub fn (auth &Auth) register(mut ctx Context) veb.Result {
return ctx.text('')
return ctx.text('register')
}
// utility
@@ -84,20 +70,29 @@ pub fn (mut ctx Context) not_found() veb.Result {
// --
fn populate() &Config {
mut cfg := &Config{
root: $d('root', '.')
port: $d('port', 6767)
}
fn populate() &util.Config {
def_root := $d('root', '.')
def_port := int($d('port', 6767))
if os.getenv('CDN_ROOT') != '' {
cfg.root = os.getenv('CDN_ROOT').str()
}
if os.getenv('CDN_PORT') != '' {
cfg.port = os.getenv('CDN_PORT').int()
}
def_user := $d('username', 'cdn')
def_pass := $d('password', 'totallySafeCdnDatabasePassword1235')
return cfg
return &util.Config{
root: if os.getenv('CDN_ROOT') != '' { os.getenv('CDN_ROOT').str() } else { def_root }
port: if os.getenv('CDN_PORT') != '' { os.getenv('CDN_PORT').int() } else { def_port }
database: &util.Database{
username: if os.getenv('CDN_DB_USERNAME') != '' {
os.getenv('CDN_DB_USERNAME').str()
} else {
def_user
}
password: if os.getenv('CDN_DB_PASSWORD') != '' {
os.getenv('CDN_DB_PASSWORD').str()
} else {
def_pass
}
}
}
}
fn main() {
@@ -105,7 +100,7 @@ fn main() {
mut app := &App{}
mut auth := &Auth{}
app.embed = &Embedded{
app.embed = &util.Embedded{
style_css: $embed_file('assets/style/style.css', .zlib).to_string()
error_css: $embed_file('assets/style/error.css', .zlib).to_string()
}

View File

@@ -12,15 +12,14 @@
<div class="header">
<div class="breadcrumbs">Folder Path</div>
<div class="path-container" id="pathContainer">
@{path}
</div>
<div class="controls">
<div class="meta">
<div id="summary">
<span class="meta-item"><b id="dirCount">0</b> directories</span>
<span class="meta-item"><b id="fileCount">0</b> files</span>
<span class="meta-item"><b id="totalSize">0 B</b> total</span>
@{meta}
</div>
<button class="btn theme-toggle" onclick="toggleTheme()">🌙</button>
<!--<button class="btn theme-toggle" onclick="toggleTheme()">🌙</button>-->
</div>
</div>
</div>
@@ -28,6 +27,7 @@
<div class="content">
<div class="listing" id="listing">
<div class="file-list" id="fileList">
@{files}
</div>
</div>
</div>

22
app/src/util/structs.v Normal file
View File

@@ -0,0 +1,22 @@
// src/controller/structs/structs.v
module util
pub struct Database {
pub:
username string
password string
}
pub struct Config {
pub mut:
root string
port int
pub:
database Database
}
pub struct Embedded {
pub mut:
style_css string
error_css string
}

7
app/src/v.mod Normal file
View File

@@ -0,0 +1,7 @@
Module {
name: 'app'
description: ''
version: '0.0.1'
license: 'MIT'
dependencies: []
}