- Rust 81.8%
- Jinja 17.1%
- CSS 1.1%
|
|
||
|---|---|---|
| .sqlx | ||
| assets | ||
| migrations | ||
| src | ||
| .gitignore | ||
| askama.toml | ||
| build.rs | ||
| Cargo.lock | ||
| Cargo.toml | ||
| LICENSE | ||
| README.md | ||
THRust
A work-in-progress rewrite of The House - Reloaded using poem, sqlx and askama.
Why?
My last rewrite of The House had extremely questionable design decisions, little to no performance optimizations, and was written in Python. This Rust rewrite is supposed to address all these issues. Yes, I didn't rewrite it in Go, because I really wanted that extra 10% of performance that I will probably never notice.
This one will no longer store unhashed auth tokens in the database, nor have O(n) time complexity for every route that needs a database call, and will finally have simple pagination. It's also supposed to be much more performant than its Python counterpart, and be an excellent learning project for me.
I also switched up the development stack completely from my previous API rewrite attempt. I switched from actix-web to poem because it's easier to play with and prohibits unsafe, from diesel to sqlx because it's fun and async, and I added askama for templates. I avoided tera for askama's compile-time safety guarantees.
Setup
Clone the repository and then $ cargo build (with or without the --release flag) and grab the binary.
Running $ ./thrust with no custom configuration will create a data directory in the current working directory for storing the SQLite database, and an uploads directory inside of it to store user uploads, then run the web server with the default configuration.
THRust can be configured extensively, but not everyone needs that. A server administrator would probably only need to configure a cookie secret so user sessions are valid after restarting the server.
Configuration
You can configure THRust by passing command line arguments (see thrust --help).
You can also use the --config option to pass the path to a TOML configuration file, similar to the following:
address = "0.0.0.0:7301"
database-url = "sqlite://prod.db"
uploads-path = "./user-uploads"
You can also set the following environment variables:
THRUST_DATABASE_URLmust be set to a valid URI of a SQLite database (default:sqlite://data/thrust.db)THRUST_ADDRESScan be a valid address with the formathost:port(default:127.0.0.1:9456)THRUST_UPLOADS_DIRcan be the path to a directory for storing user uploads (default:./data/uploads)THRUST_CUSTOM_ABOUTcan be the path to a custom about.html file (default: disabled)THRUST_SITE_NAMEcan be the name of the forum (default:The House)THRUST_COOKIE_SECRETcan be a 64-character long string for signing the session cookie (default: random key every run)THRUST_ENABLE_ADMIN_SECRETmust beyesin order to enable the functionality below (default: disabled)THRUST_ADMIN_SECRETcan be a secure password, as it allows you to promote your member account to an administrator account using the/promoteroute (default: disabled)THRUST_THREADS_PER_PAGEcan be the desired number of threads shown when displaying a category (default: 15)THRUST_REPLIES_PER_PAGEcan be the desired number of replies shown in the user inbox (default: 15)
THRust will register and prefer configuration options using the following hierarchy:
command line arguments > configuration file > environment variables > default values
Progress
There's still some work to be done:
- Basic login & registration
- Set up all database models
- Pagination
- 1:1 Feature support with THR
- Token Auth & External API
And a few quick TODOs to finish:
- Add the ability to block/mute users and the ability to hide threads
- Use askama macros to generate the comment tree itself in
view_thread? - Remove and replace the few O(n) queries in the
indexandview_categoryroutes
License
THRust is licensed under the GNU Affero General Public License V3.0.