refactor: Migrate from vweb to veb web framework
- Update all references from `vweb` to `veb` - Add `veb.StaticHandler` to `Playground` struct - Ensure error propagation for static file serving calls - Apply consistent indentation across various module definitions - Adjust documentation and comments for `veb` framework
This commit is contained in:
@@ -50,10 +50,10 @@ const infinite_timeout = time.infinite
|
||||
const no_timeout = time.Duration(0)
|
||||
no_timeout should be given to functions when no timeout is wanted (i.e. all functions return instantly)
|
||||
const err_timed_out = error_with_code('net: op timed out', errors_base + 9)
|
||||
const tcp_default_read_timeout = 30 * time.second
|
||||
const tcp_default_read_timeout = 30 *time.second
|
||||
const err_option_not_settable = error_with_code('net: set_option_xxx option not settable',
|
||||
errors_base + 2)
|
||||
const tcp_default_write_timeout = 30 * time.second
|
||||
const tcp_default_write_timeout = 30* time.second
|
||||
fn addr_from_socket_handle(handle int) Addr
|
||||
addr_from_socket_handle returns an address, based on the given integer socket `handle`
|
||||
fn close(handle int) !
|
||||
@@ -305,9 +305,7 @@ fn (mut l TcpListener) accept() !&TcpConn
|
||||
fn (mut l TcpListener) accept_only() !&TcpConn
|
||||
accept_only accepts a tcp connection from an external source to the listener `l`. Unlike `accept`, `accept_only` *will not call* `.set_sock()!` on the result, and is thus faster.
|
||||
|
||||
|
||||
|
||||
Note: you *need* to call `.set_sock()!` manually, before using theconnection after calling `.accept_only()!`, but that does not have to happen in the same thread that called `.accept_only()!`. The intention of this API, is to have a more efficient way to accept connections, that are later processed by a thread pool, while the main thread remains active, so that it can accept other connections. See also vlib/vweb/vweb.v .
|
||||
Note: you *need* to call `.set_sock()!` manually, before using theconnection after calling `.accept_only()!`, but that does not have to happen in the same thread that called `.accept_only()!`. The intention of this API, is to have a more efficient way to accept connections, that are later processed by a thread pool, while the main thread remains active, so that it can accept other connections. See also vlib/veb/veb.v .
|
||||
|
||||
If you do not need that, just call `.accept()!` instead, which will call `.set_sock()!` for you.
|
||||
fn (c &TcpListener) accept_deadline() !time.Time
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# **WebDAV Server in V**
|
||||
|
||||
This project implements a WebDAV server using the `vweb` framework and modules from `crystallib`. The server supports essential WebDAV file operations such as reading, writing, copying, moving, and deleting files and directories. It also includes **authentication** and **request logging** for better control and debugging.
|
||||
This project implements a WebDAV server using the `veb` framework and modules from `crystallib`. The server supports essential WebDAV file operations such as reading, writing, copying, moving, and deleting files and directories. It also includes **authentication** and **request logging** for better control and debugging.
|
||||
|
||||
---
|
||||
|
||||
@@ -47,6 +47,7 @@ sudo mount -t davfs <server_url> <mount_point>
|
||||
```
|
||||
|
||||
For example:
|
||||
|
||||
```bash
|
||||
sudo mount -t davfs http://localhost:8080 /mnt/webdav
|
||||
```
|
||||
@@ -82,6 +83,7 @@ Authorization: Basic <base64-encoded-credentials>
|
||||
|
||||
**Example**:
|
||||
For the credentials `admin:admin`, the header would look like this:
|
||||
|
||||
```http
|
||||
Authorization: Basic YWRtaW46YWRtaW4=
|
||||
```
|
||||
@@ -103,25 +105,32 @@ You can configure the WebDAV server using the following parameters when calling
|
||||
## **Example Workflow**
|
||||
|
||||
1. Start the server:
|
||||
|
||||
```bash
|
||||
v run webdav_server.v
|
||||
```
|
||||
|
||||
2. Mount the server using `davfs`:
|
||||
|
||||
```bash
|
||||
sudo mount -t davfs http://localhost:8080 /mnt/webdav
|
||||
```
|
||||
|
||||
3. Perform operations:
|
||||
- Create a new file:
|
||||
|
||||
```bash
|
||||
echo "Hello WebDAV!" > /mnt/webdav/hello.txt
|
||||
```
|
||||
|
||||
- List files:
|
||||
|
||||
```bash
|
||||
ls /mnt/webdav
|
||||
```
|
||||
|
||||
- Delete a file:
|
||||
|
||||
```bash
|
||||
rm /mnt/webdav/hello.txt
|
||||
```
|
||||
@@ -150,7 +159,6 @@ You can configure the WebDAV server using the following parameters when calling
|
||||
- Integration with persistent databases for user credentials.
|
||||
- TLS/SSL support for secure connections.
|
||||
|
||||
|
||||
# WebDAV Property Model
|
||||
|
||||
This file implements the WebDAV property model as defined in [RFC 4918](https://tools.ietf.org/html/rfc4918). It provides a set of property types that represent various WebDAV properties used in PROPFIND and PROPPATCH operations.
|
||||
@@ -173,6 +181,7 @@ pub interface Property {
|
||||
```
|
||||
|
||||
All WebDAV properties must implement:
|
||||
|
||||
- `xml()`: Returns the full XML representation of the property with its value
|
||||
- `xml_name()`: Returns just the XML tag name of the property (used in property requests)
|
||||
|
||||
@@ -200,7 +209,6 @@ The file implements the following WebDAV property types:
|
||||
|
||||
These property types are used when responding to WebDAV PROPFIND requests to describe resources in the WebDAV server.
|
||||
|
||||
|
||||
# WebDAV Locker
|
||||
|
||||
This file implements a locking mechanism for resources in a WebDAV context. It provides functionality to manage locks on resources, ensuring that they are not modified by multiple clients simultaneously.
|
||||
|
||||
@@ -4,12 +4,13 @@ import x.json2 as json
|
||||
// import freeflowuniverse.herolib.develop.gittools
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import vweb
|
||||
import veb
|
||||
import os
|
||||
|
||||
pub struct Playground {
|
||||
vweb.Context
|
||||
build pathlib.Path @[vweb_global]
|
||||
veb.Context
|
||||
veb.StaticHandler
|
||||
build pathlib.Path @[veb_global]
|
||||
}
|
||||
|
||||
@[params]
|
||||
@@ -50,11 +51,11 @@ pub fn new_playground(config PlaygroundConfig) !&Playground {
|
||||
build: build_dir
|
||||
}
|
||||
pg.serve_examples(config.specs) or { return error('failed to serve examples:\n${err}') }
|
||||
pg.mount_static_folder_at('${build_dir.path}/static', '/static')
|
||||
pg.mount_static_folder_at('${build_dir.path}/static', '/static')!
|
||||
|
||||
mut env_file := pathlib.get_file(path: '${build_dir.path}/env.js')!
|
||||
env_file.write(encode_env(config.specs)!)!
|
||||
pg.serve_static('/env.js', env_file.path)
|
||||
pg.serve_static('/env.js', env_file.path)!
|
||||
return &pg
|
||||
}
|
||||
|
||||
@@ -86,11 +87,11 @@ fn (mut pg Playground) serve_examples(specs_ []pathlib.Path) ! {
|
||||
return error('Failed to decode OpenRPC Spec ${spec}:\n${err}')
|
||||
}
|
||||
name := texttools.name_fix(o.info.title)
|
||||
pg.serve_static('/specs/${name}.json', spec.path)
|
||||
pg.serve_static('/specs/${name}.json', spec.path)!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut pg Playground) index() vweb.Result {
|
||||
pub fn (mut pg Playground) index() veb.Result {
|
||||
mut index := pathlib.get_file(path: '${pg.build.path}/index.html') or { panic(err) }
|
||||
return pg.html(index.read() or { panic(err) })
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import net.http
|
||||
import time
|
||||
import json
|
||||
|
||||
// session controller that be be added to vweb projects
|
||||
// session controller that be be added to veb projects
|
||||
pub struct EmailClient {
|
||||
url string @[required]
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module authentication
|
||||
|
||||
import vweb
|
||||
import veb
|
||||
import time
|
||||
import json
|
||||
import log
|
||||
@@ -8,13 +8,13 @@ import freeflowuniverse.herolib.ui.console
|
||||
|
||||
const agent = 'Email Authentication Controller'
|
||||
|
||||
// email authentication controller that be be added to vweb projects
|
||||
// email authentication controller that be be added to veb projects
|
||||
@[heap]
|
||||
pub struct Controller {
|
||||
vweb.Context
|
||||
callback string @[vweb_global]
|
||||
veb.Context
|
||||
callback string @[veb_global]
|
||||
mut:
|
||||
authenticator Authenticator @[vweb_global]
|
||||
authenticator Authenticator @[veb_global]
|
||||
}
|
||||
|
||||
@[params]
|
||||
@@ -32,7 +32,7 @@ pub fn new_controller(params ControllerParams) Controller {
|
||||
|
||||
// route responsible for verifying email, email form should be posted here
|
||||
@[POST]
|
||||
pub fn (mut app Controller) send_verification_mail() !vweb.Result {
|
||||
pub fn (mut app Controller) send_verification_mail() !veb.Result {
|
||||
config := json.decode(SendMailConfig, app.req.data)!
|
||||
app.authenticator.send_verification_mail(config) or { panic(err) }
|
||||
return app.ok('')
|
||||
@@ -40,7 +40,7 @@ pub fn (mut app Controller) send_verification_mail() !vweb.Result {
|
||||
|
||||
// route responsible for verifying email, email form should be posted here
|
||||
@[POST]
|
||||
pub fn (mut app Controller) is_verified() vweb.Result {
|
||||
pub fn (mut app Controller) is_verified() veb.Result {
|
||||
address := app.req.data
|
||||
// checks if email verified every 2 seconds
|
||||
for {
|
||||
@@ -55,7 +55,7 @@ pub fn (mut app Controller) is_verified() vweb.Result {
|
||||
|
||||
// route responsible for verifying email, email form should be posted here
|
||||
@[POST]
|
||||
pub fn (mut app Controller) email_authentication() vweb.Result {
|
||||
pub fn (mut app Controller) email_authentication() veb.Result {
|
||||
config_ := json.decode(SendMailConfig, app.req.data) or {
|
||||
app.set_status(422, 'Request payload does not follow anticipated formatting.')
|
||||
return app.text('Request payload does not follow anticipated formatting.')
|
||||
@@ -84,7 +84,7 @@ pub fn (mut app Controller) email_authentication() vweb.Result {
|
||||
|
||||
// route responsible for verifying email, email form should be posted here
|
||||
@[POST]
|
||||
pub fn (mut app Controller) verify() vweb.Result {
|
||||
pub fn (mut app Controller) verify() veb.Result {
|
||||
config_ := json.decode(SendMailConfig, app.req.data) or {
|
||||
app.set_status(422, 'Request payload does not follow anticipated formatting.')
|
||||
return app.text('Request payload does not follow anticipated formatting.')
|
||||
@@ -126,7 +126,7 @@ pub:
|
||||
}
|
||||
|
||||
@[POST]
|
||||
pub fn (mut app Controller) authenticate() !vweb.Result {
|
||||
pub fn (mut app Controller) authenticate() !veb.Result {
|
||||
attempt := json.decode(AuthAttempt, app.req.data)!
|
||||
app.authenticator.authenticate(attempt.address, attempt.cypher) or {
|
||||
app.set_status(401, err.msg())
|
||||
@@ -136,7 +136,7 @@ pub fn (mut app Controller) authenticate() !vweb.Result {
|
||||
}
|
||||
|
||||
@['/authentication_link/:address/:cypher']
|
||||
pub fn (mut app Controller) authentication_link(address string, cypher string) !vweb.Result {
|
||||
pub fn (mut app Controller) authentication_link(address string, cypher string) !veb.Result {
|
||||
app.authenticator.authenticate(address, cypher) or {
|
||||
app.set_status(401, err.msg())
|
||||
return app.text('Failed to authenticate')
|
||||
|
||||
@@ -10,7 +10,7 @@ import crypto.rand
|
||||
import os
|
||||
|
||||
// JWT code in this page is from
|
||||
// https://github.com/vlang/v/blob/master/examples/vweb_orm_jwt/src/auth_services.v
|
||||
// https://github.com/vlang/v/blob/master/examples/veb_orm_jwt/src/auth_services.v
|
||||
// credit to https://github.com/enghitalo
|
||||
|
||||
pub struct JsonWebToken {
|
||||
|
||||
@@ -2,7 +2,7 @@ module @{name}
|
||||
|
||||
import os
|
||||
import cli { Command }
|
||||
import vweb
|
||||
import veb
|
||||
import freeflowuniverse.herolib.schemas.openrpc
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
|
||||
@@ -54,7 +54,7 @@ fn playground(cmd Command) ! {
|
||||
dest: pathlib.get_dir(path: playground_path)!
|
||||
specs: [pathlib.get_file(path:openrpc_path)!]
|
||||
)!
|
||||
vweb.run(pg, 8080)
|
||||
veb.run(pg, 8080)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env -S v -n -cg -w -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.baobab.stages.accountant
|
||||
import vweb
|
||||
import veb
|
||||
import freeflowuniverse.herolib.schemas.openrpc
|
||||
import os
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
@@ -13,4 +13,4 @@ pg := openrpc.new_playground(
|
||||
dest: pathlib.get_dir(path: playground_path)!
|
||||
specs: [pathlib.get_file(path:openrpc_path)!]
|
||||
)!
|
||||
vweb.run(pg, 8080)
|
||||
veb.run(pg, 8080)
|
||||
Reference in New Issue
Block a user