create webdav -> parent_vfs -> ourdb_vfs example

This commit is contained in:
timurgordon
2025-02-17 19:14:00 +03:00
parent 66f29fcb02
commit 84142b60a7
3 changed files with 68 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ module webdav
import vweb
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.vfs.vfscore
@[heap]
struct App {
@@ -11,6 +12,7 @@ struct App {
root_dir pathlib.Path @[vweb_global]
pub mut:
// lock_manager LockManager
vfs VFSImplementation
server_port int
middlewares map[string][]vweb.Middleware
}
@@ -21,6 +23,7 @@ pub mut:
server_port int = 8080
root_dir string @[required]
user_db map[string]string @[required]
vfs VFSImplementation
}
pub fn new_app(args AppArgs) !&App {
@@ -29,6 +32,7 @@ pub fn new_app(args AppArgs) !&App {
user_db: args.user_db.clone()
root_dir: root_dir
server_port: args.server_port
vfs: args.vfs
}
app.middlewares['/'] << logging_middleware

View File

@@ -0,0 +1,33 @@
module webdav
import vweb
import os
import freeflowuniverse.herolib.core.pathlib
import encoding.xml
import freeflowuniverse.herolib.ui.console
import net.urllib
@['/:path...'; get]
fn (mut app App) get_file(path string) vweb.Result {
if !app.vfs.exists(path) {
return app.not_found()
}
fs_entry := app.vfs.get(path) or {
console.print_stderr('failed to get FS Entry ${path}: ${err}')
return app.server_error()
}
file_data := app.vfs.file_read(fs_entry.path)
ext := fs_entry.get_metadata().name.all_after_last('.')
content_type := if v := vweb.mime_types[ext] {
v
} else {
'text/plain'
}
app.set_status(200, 'Ok')
app.send_response_to_client(content_type, file_data)
return vweb.not_found() // this is for returning a dummy result
}