Files
herolib/lib/vfs/webdav/methods_vfs.v
Mahmoud Emad 7b453962ca feat: Enhance WebDAV server and add VFS encoder/decoder tests
- Add user authentication to the WebDAV server using a user
  database.
- Implement encoding and decoding functionality for directories,
  files, and symlinks in the OurDBFS VFS.
- Add comprehensive unit tests for the encoder and decoder
  functions.
- Improve the OurDBFS factory method to handle directory creation
  more robustly using pathlib.
- Add `delete` and `link_delete` methods to the `NestedVFS` and
  `OurDBVFS` implementations (though currently unimplemented).
- Improve WebDAV file handling to correctly determine and set the
  content type.  The previous implementation was incomplete and
  returned a dummy response.
- Update VFS test to actually test functionality.
- Remove unnecessary `root_dir` parameter from the WebDAV app.
2025-02-18 17:40:37 +02:00

34 lines
806 B
V

module webdav
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.ui.console
import encoding.xml
import net.urllib
import os
import vweb
@['/: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.get_path()) or { return app.server_error() }
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.str())
return vweb.not_found() // this is for returning a dummy result
}