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 module main
import veb
import os 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 struct User {
pub mut: pub mut:
@@ -25,7 +16,7 @@ pub mut:
pub struct Context { pub struct Context {
veb.Context veb.Context
pub mut: pub mut:
embed Embedded embed util.Embedded
user User user User
session_id string session_id string
} }
@@ -35,7 +26,7 @@ pub struct App {
veb.StaticHandler veb.StaticHandler
veb.Middleware[Context] veb.Middleware[Context]
pub mut: pub mut:
embed Embedded embed util.Embedded
} }
pub struct Auth {} 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')) 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 // auth endpoints
@[get; post] @[get; post]
pub fn (auth &Auth) login(mut ctx Context) veb.Result { pub fn (auth &Auth) login(mut ctx Context) veb.Result {
return ctx.text('') return ctx.text('login')
} }
@[get; post] @[get; post]
pub fn (auth &Auth) logout(mut ctx Context) veb.Result { pub fn (auth &Auth) logout(mut ctx Context) veb.Result {
return ctx.text('') return ctx.text('logout')
} }
@[get; post; put] @[get; post; put]
pub fn (auth &Auth) register(mut ctx Context) veb.Result { pub fn (auth &Auth) register(mut ctx Context) veb.Result {
return ctx.text('') return ctx.text('register')
} }
// utility // utility
@@ -84,20 +70,29 @@ pub fn (mut ctx Context) not_found() veb.Result {
// -- // --
fn populate() &Config { fn populate() &util.Config {
mut cfg := &Config{ def_root := $d('root', '.')
root: $d('root', '.') def_port := int($d('port', 6767))
port: $d('port', 6767)
}
if os.getenv('CDN_ROOT') != '' { def_user := $d('username', 'cdn')
cfg.root = os.getenv('CDN_ROOT').str() def_pass := $d('password', 'totallySafeCdnDatabasePassword1235')
}
if os.getenv('CDN_PORT') != '' {
cfg.port = os.getenv('CDN_PORT').int()
}
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() { fn main() {
@@ -105,7 +100,7 @@ fn main() {
mut app := &App{} mut app := &App{}
mut auth := &Auth{} mut auth := &Auth{}
app.embed = &Embedded{ app.embed = &util.Embedded{
style_css: $embed_file('assets/style/style.css', .zlib).to_string() style_css: $embed_file('assets/style/style.css', .zlib).to_string()
error_css: $embed_file('assets/style/error.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="header">
<div class="breadcrumbs">Folder Path</div> <div class="breadcrumbs">Folder Path</div>
<div class="path-container" id="pathContainer"> <div class="path-container" id="pathContainer">
@{path}
</div> </div>
<div class="controls"> <div class="controls">
<div class="meta"> <div class="meta">
<div id="summary"> <div id="summary">
<span class="meta-item"><b id="dirCount">0</b> directories</span> @{meta}
<span class="meta-item"><b id="fileCount">0</b> files</span>
<span class="meta-item"><b id="totalSize">0 B</b> total</span>
</div> </div>
<button class="btn theme-toggle" onclick="toggleTheme()">🌙</button> <!--<button class="btn theme-toggle" onclick="toggleTheme()">🌙</button>-->
</div> </div>
</div> </div>
</div> </div>
@@ -28,6 +27,7 @@
<div class="content"> <div class="content">
<div class="listing" id="listing"> <div class="listing" id="listing">
<div class="file-list" id="fileList"> <div class="file-list" id="fileList">
@{files}
</div> </div>
</div> </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
}

View File

@@ -1,5 +1,5 @@
Module { Module {
name: 'CDN' name: 'app'
description: '' description: ''
version: '0.0.1' version: '0.0.1'
license: 'MIT' license: 'MIT'