fix warnings + upgrade toolchain
parent
c07ac7ceac
commit
b02d3f3da7
|
@ -38,3 +38,6 @@ rusqlite = { version = "0.29.0", features = ["chrono"] }
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
rusqlite = { version = "0.29.0", features = ["bundled", "chrono"] }
|
rusqlite = { version = "0.29.0", features = ["bundled", "chrono"] }
|
||||||
|
|
||||||
|
[lints.clippy]
|
||||||
|
map_flatten = "allow"
|
||||||
|
|
36
flake.lock
36
flake.lock
|
@ -16,12 +16,15 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"flake-utils_2": {
|
"flake-utils_2": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1659877975,
|
"lastModified": 1705309234,
|
||||||
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
|
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "flake-utils",
|
"repo": "flake-utils",
|
||||||
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
|
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -48,11 +51,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs_2": {
|
"nixpkgs_2": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1665296151,
|
"lastModified": 1706487304,
|
||||||
"narHash": "sha256-uOB0oxqxN9K7XGF1hcnY+PQnlQJ+3bP2vCn/+Ru/bbc=",
|
"narHash": "sha256-LE8lVX28MV2jWJsidW13D2qrHU/RUUONendL2Q/WlJg=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "14ccaaedd95a488dd7ae142757884d8e125b3363",
|
"rev": "90f456026d284c22b3e3497be980b2e47d0b28ac",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -75,11 +78,11 @@
|
||||||
"nixpkgs": "nixpkgs_2"
|
"nixpkgs": "nixpkgs_2"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1676169013,
|
"lastModified": 1717985971,
|
||||||
"narHash": "sha256-mhUWa6TUg6Qjba1OdxPuW1ctCuU4O4lSObVc6UUUE0E=",
|
"narHash": "sha256-24h/qKp0aeI+Ew13WdRF521kY24PYa5HOvw0mlrABjk=",
|
||||||
"owner": "oxalica",
|
"owner": "oxalica",
|
||||||
"repo": "rust-overlay",
|
"repo": "rust-overlay",
|
||||||
"rev": "ef4cd733dc6b595cab5092f5004a489c5fd80b07",
|
"rev": "abfe5b3126b1b7e9e4daafc1c6478d17f0b584e7",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -87,6 +90,21 @@
|
||||||
"repo": "rust-overlay",
|
"repo": "rust-overlay",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": "root",
|
"root": "root",
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
nightly
|
stable
|
||||||
|
|
58
src/auth.rs
58
src/auth.rs
|
@ -27,19 +27,16 @@ pub(crate) struct User {
|
||||||
pub(crate) name: String,
|
pub(crate) name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
||||||
pub(crate) struct AppPermissions(pub(crate) u8);
|
pub(crate) struct AppPermissions(pub(crate) u8);
|
||||||
impl Default for AppPermissions {
|
|
||||||
fn default() -> AppPermissions {
|
|
||||||
AppPermissions(0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AppPermissions {
|
impl AppPermissions {
|
||||||
pub(crate) fn can(&self, perm: AppPermission) -> bool {
|
pub(crate) fn can(&self, perm: AppPermission) -> bool {
|
||||||
(self.0 & (perm as u8) > 0) || (self.0 & (AppPermission::Admin as u8) > 0)
|
(self.0 & (perm as u8) > 0) || (self.0 & (AppPermission::Admin as u8) > 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: eventually use this
|
||||||
|
#[allow(dead_code)]
|
||||||
pub(crate) fn add(&mut self, perm: Permission) {
|
pub(crate) fn add(&mut self, perm: Permission) {
|
||||||
self.0 |= perm as u8;
|
self.0 |= perm as u8;
|
||||||
}
|
}
|
||||||
|
@ -59,13 +56,17 @@ impl AppPermission {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for AppPermission {
|
impl std::fmt::Display for AppPermission {
|
||||||
fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
write!(
|
||||||
AppPermission::None => todo!(),
|
f,
|
||||||
AppPermission::AddGuild => "Add Guild".to_string(),
|
"{}",
|
||||||
AppPermission::Admin => "Admin".to_string(),
|
match self {
|
||||||
}
|
AppPermission::None => todo!(),
|
||||||
|
AppPermission::AddGuild => "Add Guild".to_string(),
|
||||||
|
AppPermission::Admin => "Admin".to_string(),
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,13 +82,8 @@ impl FromStr for AppPermission {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
#[derive(Default, Debug, Clone, Copy, Serialize, Deserialize)]
|
||||||
pub(crate) struct Permissions(pub(crate) u8);
|
pub(crate) struct Permissions(pub(crate) u8);
|
||||||
impl Default for Permissions {
|
|
||||||
fn default() -> Permissions {
|
|
||||||
Permissions(0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Permissions {
|
impl Permissions {
|
||||||
pub(crate) fn can(&self, perm: Permission) -> bool {
|
pub(crate) fn can(&self, perm: Permission) -> bool {
|
||||||
|
@ -116,16 +112,20 @@ impl Permission {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for Permission {
|
impl std::fmt::Display for Permission {
|
||||||
fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
write!(
|
||||||
Permission::None => todo!(),
|
f,
|
||||||
Permission::UploadSounds => "Upload Sounds".to_string(),
|
"{}",
|
||||||
Permission::DeleteSounds => "Delete Sounds".to_string(),
|
match self {
|
||||||
Permission::Soundboard => "Soundboard".to_string(),
|
Permission::None => todo!(),
|
||||||
Permission::AddChannel => "Add Channel".to_string(),
|
Permission::UploadSounds => "Upload Sounds".to_string(),
|
||||||
Permission::Moderator => "Moderator".to_string(),
|
Permission::DeleteSounds => "Delete Sounds".to_string(),
|
||||||
}
|
Permission::Soundboard => "Soundboard".to_string(),
|
||||||
|
Permission::AddChannel => "Add Channel".to_string(),
|
||||||
|
Permission::Moderator => "Moderator".to_string(),
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -138,6 +138,7 @@ impl Database {
|
||||||
|
|
||||||
// NOTE(pcleavelin): for some reason this needs to be a let-binding or else
|
// NOTE(pcleavelin): for some reason this needs to be a let-binding or else
|
||||||
// the compiler complains about it being dropped too early (maybe I should update the compiler version)
|
// the compiler complains about it being dropped too early (maybe I should update the compiler version)
|
||||||
|
#[allow(clippy::useless_conversion)]
|
||||||
let guilds = query
|
let guilds = query
|
||||||
.query_map(&[(":username", username)], |row| {
|
.query_map(&[(":username", username)], |row| {
|
||||||
Ok(Guild {
|
Ok(Guild {
|
||||||
|
@ -167,6 +168,7 @@ impl Database {
|
||||||
|
|
||||||
// NOTE(pcleavelin): for some reason this needs to be a let-binding or else
|
// NOTE(pcleavelin): for some reason this needs to be a let-binding or else
|
||||||
// the compiler complains about it being dropped too early (maybe I should update the compiler version)
|
// the compiler complains about it being dropped too early (maybe I should update the compiler version)
|
||||||
|
#[allow(clippy::useless_conversion)]
|
||||||
let intros = query
|
let intros = query
|
||||||
.query_map(
|
.query_map(
|
||||||
&[
|
&[
|
||||||
|
@ -206,6 +208,7 @@ impl Database {
|
||||||
|
|
||||||
// NOTE(pcleavelin): for some reason this needs to be a let-binding or else
|
// NOTE(pcleavelin): for some reason this needs to be a let-binding or else
|
||||||
// the compiler complains about it being dropped too early (maybe I should update the compiler version)
|
// the compiler complains about it being dropped too early (maybe I should update the compiler version)
|
||||||
|
#[allow(clippy::useless_conversion)]
|
||||||
let intros = query
|
let intros = query
|
||||||
.query_map(
|
.query_map(
|
||||||
&[
|
&[
|
||||||
|
@ -305,13 +308,14 @@ impl Database {
|
||||||
|
|
||||||
// NOTE(pcleavelin): for some reason this needs to be a let-binding or else
|
// NOTE(pcleavelin): for some reason this needs to be a let-binding or else
|
||||||
// the compiler complains about it being dropped too early (maybe I should update the compiler version)
|
// the compiler complains about it being dropped too early (maybe I should update the compiler version)
|
||||||
|
#[allow(clippy::useless_conversion)]
|
||||||
let intros = query
|
let intros = query
|
||||||
.query_map(
|
.query_map(
|
||||||
&[
|
&[
|
||||||
// :vomit:
|
// :vomit:
|
||||||
(":guild_id", &guild_id.to_string()),
|
(":guild_id", &guild_id.to_string()),
|
||||||
],
|
],
|
||||||
|row| Ok(row.get(0)?),
|
|row| row.get(0),
|
||||||
)?
|
)?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect::<Result<Vec<String>>>();
|
.collect::<Result<Vec<String>>>();
|
||||||
|
@ -328,7 +332,7 @@ impl Database {
|
||||||
let all_user_intros = self.get_all_user_intros(guild_id)?.into_iter();
|
let all_user_intros = self.get_all_user_intros(guild_id)?.into_iter();
|
||||||
|
|
||||||
let intros = all_user_intros
|
let intros = all_user_intros
|
||||||
.filter(|intro| &intro.username == &username && &intro.channel_name == channel_name)
|
.filter(|intro| intro.username == username && intro.channel_name == channel_name)
|
||||||
.map(|intro| intro.intro)
|
.map(|intro| intro.intro)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|
14
src/htmx.rs
14
src/htmx.rs
|
@ -1,3 +1,5 @@
|
||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub trait Build {
|
pub trait Build {
|
||||||
|
@ -191,7 +193,7 @@ impl Build for HtmxBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if self.tag != Tag::JustText && self.tag != Tag::Empty {
|
if self.tag != Tag::JustText && self.tag != Tag::Empty {
|
||||||
string.push_str(">");
|
string.push('>');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,23 +231,23 @@ impl HtmxBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hx_get(mut self, uri: &str) -> Self {
|
pub fn hx_get(self, uri: &str) -> Self {
|
||||||
self.attribute("hx-get", uri)
|
self.attribute("hx-get", uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hx_post(mut self, uri: &str) -> Self {
|
pub fn hx_post(self, uri: &str) -> Self {
|
||||||
self.attribute("hx-post", uri)
|
self.attribute("hx-post", uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hx_swap(mut self, swap_method: SwapMethod) -> Self {
|
pub fn hx_swap(self, swap_method: SwapMethod) -> Self {
|
||||||
self.attribute("hx-swap", swap_method.as_str())
|
self.attribute("hx-swap", swap_method.as_str())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hx_trigger(mut self, trigger: &str) -> Self {
|
pub fn hx_trigger(self, trigger: &str) -> Self {
|
||||||
self.attribute("hx-trigger", trigger)
|
self.attribute("hx-trigger", trigger)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hx_target(mut self, target: &str) -> Self {
|
pub fn hx_target(self, target: &str) -> Self {
|
||||||
self.attribute("hx-target", target)
|
self.attribute("hx-target", target)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#![feature(stmt_expr_attributes)]
|
// #![feature(stmt_expr_attributes)]
|
||||||
#![feature(proc_macro_hygiene)]
|
// #![feature(proc_macro_hygiene)]
|
||||||
#![feature(async_closure)]
|
// #![feature(async_closure)]
|
||||||
|
|
||||||
mod auth;
|
mod auth;
|
||||||
mod db;
|
mod db;
|
||||||
|
@ -315,7 +315,7 @@ async fn main() -> std::io::Result<()> {
|
||||||
|
|
||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
|
|
||||||
let mut settings = serde_json::from_str::<Settings>(
|
let settings = serde_json::from_str::<Settings>(
|
||||||
&std::fs::read_to_string("config/settings.json").expect("no config/settings.json"),
|
&std::fs::read_to_string("config/settings.json").expect("no config/settings.json"),
|
||||||
)
|
)
|
||||||
.expect("error parsing settings file");
|
.expect("error parsing settings file");
|
||||||
|
|
12
src/page.rs
12
src/page.rs
|
@ -1,15 +1,14 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
auth::{self},
|
auth,
|
||||||
db::{self, User},
|
db::{self, User},
|
||||||
htmx::{Build, HtmxBuilder, Tag},
|
htmx::{Build, HtmxBuilder, Tag},
|
||||||
settings::ApiState,
|
settings::ApiState,
|
||||||
};
|
};
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{Path, Query, State},
|
extract::{Path, State},
|
||||||
response::{Html, Redirect},
|
response::{Html, Redirect},
|
||||||
};
|
};
|
||||||
use iter_tools::Itertools;
|
use iter_tools::Itertools;
|
||||||
use serde::Deserialize;
|
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
fn page_header(title: &str) -> HtmxBuilder {
|
fn page_header(title: &str) -> HtmxBuilder {
|
||||||
|
@ -478,10 +477,9 @@ async fn permissions_editor(state: &ApiState, guild_id: u64) -> HtmxBuilder {
|
||||||
|
|
||||||
b = b.builder(Tag::TableData, |b| {
|
b = b.builder(Tag::TableData, |b| {
|
||||||
b.builder(Tag::Input, |b| {
|
b.builder(Tag::Input, |b| {
|
||||||
let mut b = b.attribute("type", "checkbox").attribute(
|
let mut b = b
|
||||||
"name",
|
.attribute("type", "checkbox")
|
||||||
&format!("{}#{}", permission.0, perm.to_string()),
|
.attribute("name", &format!("{}#{}", permission.0, perm));
|
||||||
);
|
|
||||||
|
|
||||||
if permission.1.can(auth::Permission::Moderator) {
|
if permission.1.can(auth::Permission::Moderator) {
|
||||||
b = b.flag("disabled");
|
b = b.flag("disabled");
|
||||||
|
|
|
@ -27,7 +27,7 @@ impl FromRequestParts<ApiState> for db::User {
|
||||||
Parts { headers, .. }: &mut Parts,
|
Parts { headers, .. }: &mut Parts,
|
||||||
state: &ApiState,
|
state: &ApiState,
|
||||||
) -> Result<Self, Self::Rejection> {
|
) -> Result<Self, Self::Rejection> {
|
||||||
let jar = CookieJar::from_headers(&headers);
|
let jar = CookieJar::from_headers(headers);
|
||||||
|
|
||||||
if let Some(token) = jar.get("access_token") {
|
if let Some(token) = jar.get("access_token") {
|
||||||
match state.db.lock().await.get_user_from_api_key(token.value()) {
|
match state.db.lock().await.get_user_from_api_key(token.value()) {
|
||||||
|
|
Loading…
Reference in New Issue