This commit is contained in:
FantasyPvP
2024-12-10 11:57:08 +00:00
parent 1707309d95
commit fb1c13bfa0
81 changed files with 2900 additions and 582 deletions
+1
View File
@@ -1 +1,2 @@
/target
*.env
Binary file not shown.
Binary file not shown.
-1
View File
@@ -1 +0,0 @@
MANIFEST-000040
Binary file not shown.
+467 -10
View File
@@ -191,6 +191,9 @@ name = "arrayvec"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
dependencies = [
"serde",
]
[[package]]
name = "ascii-canvas"
@@ -445,6 +448,12 @@ version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.6.0"
@@ -555,6 +564,12 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "bytecount"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ce89b21cab1437276d2650d57e971f9d548a2d9037cc231abdc0562b97498ce"
[[package]]
name = "bytemuck"
version = "1.20.0"
@@ -576,6 +591,37 @@ dependencies = [
"serde",
]
[[package]]
name = "camino"
version = "1.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3"
dependencies = [
"serde",
]
[[package]]
name = "cargo-platform"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e35af189006b9c0f00a064685c727031e3ed2d8020f7ba284d78cc2671bd36ea"
dependencies = [
"serde",
]
[[package]]
name = "cargo_metadata"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa"
dependencies = [
"camino",
"cargo-platform",
"semver",
"serde",
"serde_json",
]
[[package]]
name = "castaway"
version = "0.2.3"
@@ -668,15 +714,20 @@ name = "chatapp-backend"
version = "0.1.0"
dependencies = [
"chrono",
"dotenv",
"futures",
"rand",
"rocket",
"rocket_cors",
"rocket_ws",
"serde",
"serde_json",
"serenity",
"sha2",
"surrealdb",
"tokio",
"toml",
"tracing-subscriber",
]
[[package]]
@@ -731,6 +782,17 @@ dependencies = [
"inout",
]
[[package]]
name = "command_attr"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fcc89439e1bb4e19050a9586a767781a3060000d2f3296fd2a40597ad9421c5"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "concurrent-queue"
version = "2.5.0"
@@ -763,6 +825,16 @@ dependencies = [
"version_check",
]
[[package]]
name = "core-foundation"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.7"
@@ -778,6 +850,24 @@ dependencies = [
"libc",
]
[[package]]
name = "crc32fast"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
dependencies = [
"cfg-if",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-deque"
version = "0.8.5"
@@ -875,6 +965,7 @@ dependencies = [
"lock_api",
"once_cell",
"parking_lot_core",
"serde",
]
[[package]]
@@ -925,7 +1016,7 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b035a542cf7abf01f2e3c4d5a7acbaebfefe120ae4efc7bde3df98186e4b8af7"
dependencies = [
"bitflags",
"bitflags 2.6.0",
"proc-macro2",
"proc-macro2-diagnostics",
"quote",
@@ -990,6 +1081,12 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
[[package]]
name = "dotenv"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]]
name = "earcutr"
version = "0.4.3"
@@ -1046,6 +1143,15 @@ dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "error-chain"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc"
dependencies = [
"version_check",
]
[[package]]
name = "event-listener"
version = "5.3.1"
@@ -1093,6 +1199,16 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
[[package]]
name = "flate2"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c"
dependencies = [
"crc32fast",
"miniz_oxide",
]
[[package]]
name = "float_next_after"
version = "1.0.0"
@@ -1253,6 +1369,15 @@ dependencies = [
"thread_local",
]
[[package]]
name = "fxhash"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
dependencies = [
"byteorder",
]
[[package]]
name = "generator"
version = "0.7.5"
@@ -1603,6 +1728,20 @@ dependencies = [
"want",
]
[[package]]
name = "hyper-rustls"
version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590"
dependencies = [
"futures-util",
"http 0.2.12",
"hyper 0.14.31",
"rustls 0.21.12",
"tokio",
"tokio-rustls 0.24.1",
]
[[package]]
name = "hyper-rustls"
version = "0.27.3"
@@ -1618,7 +1757,7 @@ dependencies = [
"tokio",
"tokio-rustls 0.26.0",
"tower-service",
"webpki-roots",
"webpki-roots 0.26.7",
]
[[package]]
@@ -1957,6 +2096,12 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "levenshtein"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760"
[[package]]
name = "lexicmp"
version = "0.1.0"
@@ -1984,7 +2129,7 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
dependencies = [
"bitflags",
"bitflags 2.6.0",
"libc",
]
@@ -2143,6 +2288,21 @@ dependencies = [
"unicase",
]
[[package]]
name = "mini-moka"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c325dfab65f261f386debee8b0969da215b3fa0037e74c8a1234db7ba986d803"
dependencies = [
"crossbeam-channel",
"crossbeam-utils",
"dashmap",
"skeptic",
"smallvec",
"tagptr",
"triomphe",
]
[[package]]
name = "miniz_oxide"
version = "0.8.0"
@@ -2680,6 +2840,17 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "pulldown-cmark"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57206b407293d2bcd3af849ce869d52068623f19e1b5ff8e8778e3309439682b"
dependencies = [
"bitflags 2.6.0",
"memchr",
"unicase",
]
[[package]]
name = "quick_cache"
version = "0.5.2"
@@ -2838,7 +3009,7 @@ version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f"
dependencies = [
"bitflags",
"bitflags 2.6.0",
]
[[package]]
@@ -2925,6 +3096,50 @@ dependencies = [
"bytecheck",
]
[[package]]
name = "reqwest"
version = "0.11.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62"
dependencies = [
"base64 0.21.7",
"bytes",
"encoding_rs",
"futures-core",
"futures-util",
"h2",
"http 0.2.12",
"http-body 0.4.6",
"hyper 0.14.31",
"hyper-rustls 0.24.2",
"ipnet",
"js-sys",
"log",
"mime",
"mime_guess",
"once_cell",
"percent-encoding",
"pin-project-lite",
"rustls 0.21.12",
"rustls-pemfile 1.0.4",
"serde",
"serde_json",
"serde_urlencoded",
"sync_wrapper 0.1.2",
"system-configuration",
"tokio",
"tokio-rustls 0.24.1",
"tokio-util",
"tower-service",
"url",
"wasm-bindgen",
"wasm-bindgen-futures",
"wasm-streams",
"web-sys",
"webpki-roots 0.25.4",
"winreg",
]
[[package]]
name = "reqwest"
version = "0.12.9"
@@ -2939,7 +3154,7 @@ dependencies = [
"http-body 1.0.1",
"http-body-util",
"hyper 1.5.1",
"hyper-rustls",
"hyper-rustls 0.27.3",
"hyper-util",
"ipnet",
"js-sys",
@@ -2956,7 +3171,7 @@ dependencies = [
"serde",
"serde_json",
"serde_urlencoded",
"sync_wrapper",
"sync_wrapper 1.0.2",
"tokio",
"tokio-rustls 0.26.0",
"tokio-util",
@@ -2966,7 +3181,7 @@ dependencies = [
"wasm-bindgen-futures",
"wasm-streams",
"web-sys",
"webpki-roots",
"webpki-roots 0.26.7",
"windows-registry",
]
@@ -3133,6 +3348,23 @@ dependencies = [
"version_check",
]
[[package]]
name = "rocket_cors"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfac3a1df83f8d4fc96aa41dba3b86c786417b7fc0f52ec76295df2ba781aa69"
dependencies = [
"http 0.2.12",
"log",
"regex",
"rocket",
"serde",
"serde_derive",
"unicase",
"unicase_serde",
"url",
]
[[package]]
name = "rocket_http"
version = "0.5.1"
@@ -3246,7 +3478,7 @@ version = "0.38.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6"
dependencies = [
"bitflags",
"bitflags 2.6.0",
"errno",
"libc",
"linux-raw-sys",
@@ -3265,6 +3497,20 @@ dependencies = [
"sct",
]
[[package]]
name = "rustls"
version = "0.22.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432"
dependencies = [
"log",
"ring",
"rustls-pki-types",
"rustls-webpki 0.102.8",
"subtle",
"zeroize",
]
[[package]]
name = "rustls"
version = "0.23.19"
@@ -3398,6 +3644,16 @@ version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b"
[[package]]
name = "secrecy"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9bd1c54ea06cfd2f6b63219704de0b9b4f72dcc2b8fdef820be6cd799780e91e"
dependencies = [
"serde",
"zeroize",
]
[[package]]
name = "semver"
version = "1.0.23"
@@ -3431,6 +3687,15 @@ dependencies = [
"serde",
]
[[package]]
name = "serde_cow"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e7bbbec7196bfde255ab54b65e34087c0849629280028238e67ee25d6a4b7da"
dependencies = [
"serde",
]
[[package]]
name = "serde_derive"
version = "1.0.215"
@@ -3506,6 +3771,43 @@ dependencies = [
"syn 2.0.90",
]
[[package]]
name = "serenity"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d72ec4323681bf9a3cabe40fd080abc2435859b502a1b5aa9bf693f125bfa76"
dependencies = [
"arrayvec",
"async-trait",
"base64 0.22.1",
"bitflags 2.6.0",
"bytes",
"chrono",
"command_attr",
"dashmap",
"flate2",
"futures",
"fxhash",
"levenshtein",
"mime_guess",
"parking_lot",
"percent-encoding",
"reqwest 0.11.27",
"secrecy",
"serde",
"serde_cow",
"serde_json",
"static_assertions",
"time",
"tokio",
"tokio-tungstenite 0.21.0",
"tracing",
"typemap_rev",
"typesize",
"url",
"uwl",
]
[[package]]
name = "sha1"
version = "0.10.6"
@@ -3576,6 +3878,21 @@ version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d"
[[package]]
name = "skeptic"
version = "0.13.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16d23b015676c90a0f01c197bfdc786c20342c73a0afdda9025adb0bc42940a8"
dependencies = [
"bytecount",
"cargo_metadata",
"error-chain",
"glob",
"pulldown-cmark",
"tempfile",
"walkdir",
]
[[package]]
name = "slab"
version = "0.4.9"
@@ -3693,6 +4010,12 @@ dependencies = [
"loom",
]
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "static_assertions_next"
version = "1.1.2"
@@ -3788,7 +4111,7 @@ dependencies = [
"path-clean",
"pharos",
"reblessive",
"reqwest",
"reqwest 0.12.9",
"revision",
"ring",
"rust_decimal",
@@ -3929,6 +4252,12 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "sync_wrapper"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160"
[[package]]
name = "sync_wrapper"
version = "1.0.2"
@@ -3949,6 +4278,33 @@ dependencies = [
"syn 2.0.90",
]
[[package]]
name = "system-configuration"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7"
dependencies = [
"bitflags 1.3.2",
"core-foundation",
"system-configuration-sys",
]
[[package]]
name = "system-configuration-sys"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "tagptr"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417"
[[package]]
name = "tap"
version = "1.0.1"
@@ -4144,6 +4500,17 @@ dependencies = [
"tokio",
]
[[package]]
name = "tokio-rustls"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f"
dependencies = [
"rustls 0.22.4",
"rustls-pki-types",
"tokio",
]
[[package]]
name = "tokio-rustls"
version = "0.26.0"
@@ -4174,8 +4541,12 @@ checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38"
dependencies = [
"futures-util",
"log",
"rustls 0.22.4",
"rustls-pki-types",
"tokio",
"tokio-rustls 0.25.0",
"tungstenite 0.21.0",
"webpki-roots 0.26.7",
]
[[package]]
@@ -4191,7 +4562,7 @@ dependencies = [
"tokio",
"tokio-rustls 0.26.0",
"tungstenite 0.23.0",
"webpki-roots",
"webpki-roots 0.26.7",
]
[[package]]
@@ -4254,6 +4625,7 @@ version = "0.1.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
dependencies = [
"log",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
@@ -4320,6 +4692,12 @@ dependencies = [
"web-sys",
]
[[package]]
name = "triomphe"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef8f7726da4807b58ea5c96fdc122f80702030edc33b35aff9190a51148ccc85"
[[package]]
name = "try-lock"
version = "0.2.5"
@@ -4339,6 +4717,8 @@ dependencies = [
"httparse",
"log",
"rand",
"rustls 0.22.4",
"rustls-pki-types",
"sha1",
"thiserror 1.0.69",
"url",
@@ -4366,12 +4746,47 @@ dependencies = [
"utf-8",
]
[[package]]
name = "typemap_rev"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74b08b0c1257381af16a5c3605254d529d3e7e109f3c62befc5d168968192998"
[[package]]
name = "typenum"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "typesize"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "549e54551d85ba6718a95333d9bc4367f69793d7aba638de30f8d25a1f554a1d"
dependencies = [
"chrono",
"dashmap",
"hashbrown 0.14.5",
"mini-moka",
"parking_lot",
"secrecy",
"serde_json",
"time",
"typesize-derive",
"url",
]
[[package]]
name = "typesize-derive"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd9fc0ad9e03a2b0c2e2a0eafaecccef2121829e1ab6ce9c9d790e6c6766bd1c"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.90",
]
[[package]]
name = "ubyte"
version = "0.10.4"
@@ -4415,6 +4830,16 @@ version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e51b68083f157f853b6379db119d1c1be0e6e4dec98101079dec41f6f5cf6df"
[[package]]
name = "unicase_serde"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ef53697679d874d69f3160af80bc28de12730a985d57bdf2b47456ccb8b11f1"
dependencies = [
"serde",
"unicase",
]
[[package]]
name = "unicode-ident"
version = "1.0.14"
@@ -4483,6 +4908,7 @@ dependencies = [
"form_urlencoded",
"idna",
"percent-encoding",
"serde",
]
[[package]]
@@ -4520,6 +4946,12 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "uwl"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4bf03e0ca70d626ecc4ba6b0763b934b6f2976e8c744088bb3c1d646fbb1ad0"
[[package]]
name = "valuable"
version = "0.1.0"
@@ -4677,6 +5109,12 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "webpki-roots"
version = "0.25.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1"
[[package]]
name = "webpki-roots"
version = "0.26.7"
@@ -4765,6 +5203,15 @@ dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets 0.48.5",
]
[[package]]
name = "windows-sys"
version = "0.52.0"
@@ -4913,6 +5360,16 @@ dependencies = [
"memchr",
]
[[package]]
name = "winreg"
version = "0.50.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1"
dependencies = [
"cfg-if",
"windows-sys 0.48.0",
]
[[package]]
name = "write16"
version = "1.0.0"
+5
View File
@@ -14,3 +14,8 @@ surrealdb = "2.1.2"
chrono = "0.4.38"
rand = "0.8.5"
sha2 = "0.10.8"
rocket_cors = "0.6.0-alpha2"
serenity = "0.12.4"
dotenv = "0.15.0"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
toml = "0.8.19"
+11
View File
@@ -0,0 +1,11 @@
[chatsync]
socket_path = "/tmp/minecraft_chat/chat.sock"
[discord]
channel_id = 1315044374127841374
[server.dev]
url = "http://localhost:8080"
[server.prod]
url = "https://zxq5.dev"
+8
View File
@@ -0,0 +1,8 @@
[default]
address = "0.0.0.0"
port = 8000
[release]
address = "0.0.0.0"
port = 8000
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
MANIFEST-000155
@@ -0,0 +1 @@
2024/12/07-22:42:26.540786 140431350968320 [WARN] [db/db_impl/db_impl_open.cc:2254] DB::Open() failed: IO error: While lock file: database.db/LOCK: Resource temporarily unavailable
Binary file not shown.
+87
View File
@@ -1,3 +1,17 @@
DEFINE FUNCTION auth::credentials::validate($username: string, $password: string) {
LET $user = (SELECT id, passhash FROM User WHERE username = $username)[0];
IF $user
{
RETURN {
authenticated: crypto::argon2::compare($user.passhash, $password),
id: $user.id
};
}
ELSE
{ NONE }
;
}
DEFINE FUNCTION auth::sessiontoken::new($user: uuid) {
LET $token = rand::string(64);
@@ -10,3 +24,76 @@ DEFINE FUNCTION auth::sessiontoken::new($user: uuid) {
};
}
DEFINE FUNCTION auth::sessiontoken::validate($token: string) {
LET $exists = (SELECT * FROM SessionToken WHERE token = $token)[0];
IF $exists = NONE {
RETURN NONE;
}
IF time::now() > $exists.expires {
DELETE SessionToken:exists.id;
RETURN NONE;
};
RETURN $exists.user;
}
DEFINE FUNCTION auth::accesstoken::new($user: uuid, $max_uses: option<int>) {
IF $max_uses = NONE {
LET $max_uses = 1;
};
LET $token = rand::string(64);
CREATE AccessToken CONTENT {
id: rand::uuid::v4(),
max_uses: 1,
token: $token,
created: time::now(),
expires: time::now() + 7d,
creator: Entity:user
uses: 0,
};
RETURN $token;
}
DEFINE FUNCTION auth::user::signup(
$email: string,
$username: string,
$password: string,
$displayname: option<string>,
$accesstoken: option<string>,
){
LET $entity_id = rand::uuid::v4();
IF $displayname = NONE {
LET $displayname = $username;
};
CREATE Entity CONTENT {
id: $entity_id,
deleted: false,
displayname: $displayname,
joined: time::now(),
username: $username,
};
LET $human_id = rand::uuid::v4();
CREATE Human CONTENT {
id: $human_id,
email: $email,
passhash: crypto::argon2::generate($password),
entity: Entity:entity_id
};
IF !$accesstoken = NONE {
RELATE Human:human_id -> UserJoinedBy -> AccessToken:(SELECT id FROM AccessToken WHERE token = $accesstoken)[0]
}
RETURN $human_id
}
+32
View File
@@ -0,0 +1,32 @@
DEFINE FUNCTION message::send($from: uuid, $channel: uuid, $content: string, $reply_to: option<uuid>) {
LET $content_id = rand::uuid::v4();
CREATE MessageStringContent CONTENT {
id: $content_id,
content: $content
};
LET $message_id = rand::uuid::v4();
CREATE Message CONTENT {
id: $message_id,
channel: Channel:channel,
edited: false,
sent: time::now(),
reply_to: $reply_to,
};
RELATE Message:message_id -> HasContent -> MessageStringContent:content_id;
RELATE Entity:from -> SentMessage -> Message:message_id;
}
DEFINE FUNCTION message::edit($user: uuid, $message: uuid, $content: string) {
LET $id = (SELECT id
FROM Entity:user
->SentMessage
->(Message WHERE id = $message)
->HasContent
->MessageStringContent)[0];
UPDATE MessageStringContent SET content = $content WHERE id = $id.id;
UPDATE Message:message SET edited = true;
}
+51
View File
@@ -0,0 +1,51 @@
DEFINE FUNCTION user::human::new(
$email: string,
$username: string,
$password: string,
$displayname: option<string>,
$accesstoken: option<string>,
){
LET $entity_id = rand::uuid::v4();
IF $displayname = NONE {
LET $displayname = $username;
};
CREATE Entity CONTENT {
id: $entity_id,
deleted: false,
displayname: $displayname,
joined: time::now(),
username: $username,
};
LET $human_id = rand::uuid::v4();
CREATE Human CONTENT {
id: $human_id,
email: $email,
passhash: crypto::argon2::generate($password),
entity: Entity:entity_id
};
IF !$accesstoken = NONE {
RELATE Human:human_id -> UserJoinedBy -> AccessToken:(SELECT id FROM AccessToken WHERE token = $accesstoken)[0]
}
RETURN $human_id
}
DEFINE FUNCTION objects::human::get($id: uuid) {
LET $human = (SELECT * FROM Human WHERE id = $id)[0];
LET $entity = (SELECT * FROM Entity WHERE id = $human.entity)[0];
RETURN {
id: $human.id,
email: $human.email,
passhash: $human.passhash,
username: $entity.username,
displayname: $entity.displayname,
joined: $entity.joined
}
}
@@ -0,0 +1,482 @@
-- ------------------------------
-- OPTION
-- ------------------------------
OPTION IMPORT;
-- ------------------------------
-- FUNCTIONS
-- ------------------------------
DEFINE FUNCTION fn::auth::credentials::validate($username: string, $password: string) -> option<object> {
LET $user = (SELECT id, passhash FROM User WHERE username = $username)[0];
IF $user {
RETURN {
authenticated: crypto::argon2::compare($user.passhash, $password),
id: $user.id
};
} ELSE {
RETURN NONE
};
} PERMISSIONS FULL;
DEFINE FUNCTION fn::auth::sessiontoken::new($user: uuid) {
LET $token = rand::string(64);
CREATE SessionToken CONTENT {
created: time::now(),
expires: time::now() + 1w,
id: rand::uuid::v4(),
token: $token,
user: Entity:user
};
} PERMISSIONS FULL;
DEFINE FUNCTION fn::auth::sessiontoken::validate($token: string) {
LET $exists = (SELECT * FROM SessionToken WHERE token = $token)[0];
IF $exists = NONE { RETURN NONE; };
IF time::now() > $exists.expires {
DELETE SessionToken:exists.id;
RETURN NONE;
};
RETURN $exists.user;
} PERMISSIONS FULL;
DEFINE FUNCTION fn::channel::new() {} PERMISSIONS FULL;
DEFINE FUNCTION fn::friend::accept($from: uuid, $to: uuid) {
IF (SELECT * FROM HasFriendRequest WHERE in = Entity:from AND out = Entity:to)[0] = NONE { RETURN NONE; } ELSE { DELETE HasFriendRequest WHERE in = Entity:from AND out = Entity:to; };
LET $fsid: uuid = rand::uuid::v4();
CREATE Friendship SET id = $fsid, channel_id = fn::channel::new(), since = time::now();
RELATE Entity:from -> HasFriendship -> Friendship:fsid CONTENT {
nickname = Entity:from.displayname
};
RELATE Entity:to -> HasFriendship -> Friendship:fsid CONTENT {
nickname = Entity:to.displayname
};
} PERMISSIONS FULL;
DEFINE FUNCTION fn::friend::reject($from: uuid, $to: uuid) {
DELETE Entity:from->FriendRequest WHERE out = Entity:to;
} PERMISSIONS FULL;
DEFINE FUNCTION fn::friend::remove($from: uuid, $to: uuid) {
DELETE Entity:from->HasFriendship->Friendship WHERE <-HasFriendship.out = Entity:to;
} PERMISSIONS FULL;
DEFINE FUNCTION fn::friend::request($from: uuid, $to: uuid) {
RELATE Entity:from -> HasFriendRequest -> Entity:to CONTENT {
created = time::now()
};
} PERMISSIONS FULL;
DEFINE FUNCTION fn::icon::default() -> string {
RETURN '/static/public/server_default.png';
} PERMISSIONS FULL;
DEFINE FUNCTION fn::message::edit($user: uuid, $message: uuid, $content: string) {
LET $id = (SELECT id FROM Entity:user->SentMessage->(Message WHERE id = $message)->HasContent->MessageStringContent)[0];
UPDATE MessageStringContent SET content = $content WHERE id = $id.id;
UPDATE Message:message SET edited = true;
} PERMISSIONS FULL;
DEFINE FUNCTION fn::server::join($entity: uuid, $server: uuid) {
LET $user = (SELECT displayname FROM Entity WHERE id = $entity);
RELATE Entity:entity -> HasServer -> Server:server CONTENT {
joined: time::now(), nickname: $user.displayname
};
} PERMISSIONS FULL;
DEFINE FUNCTION fn::server::leave($server: uuid, $entity: uuid) {
DELETE HasServer WHERE out = Server:server AND in = Entity:entity;
DELETE HasRole WHERE in = Entity:entity AND ->Role.server = Server:server;
} PERMISSIONS FULL;
DEFINE FUNCTION fn::server::new($name: string, $creator: uuid) {
LET $id = rand::uuid::v4();
CREATE Server CONTENT {
created: time::now(),
icon_uri: fn::icon::default(),
id: $id,
name: $name,
owner: $creator
};
fn::server::join($id, $creator);
} PERMISSIONS FULL;
DEFINE FUNCTION fn::sessiontoken::new() -> string {
LET $token = rand::string(64);
CREATE SessionToken CONTENT {
created: time::now(),
expires: time::now() + 1w,
id: rand::uuid::v4(),
token: $token,
user: Entity:user
};
} PERMISSIONS FULL;
-- ------------------------------
-- TABLE: AccessToken
-- ------------------------------
DEFINE TABLE AccessToken TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD created ON AccessToken TYPE datetime PERMISSIONS FULL;
DEFINE FIELD creator ON AccessToken TYPE record<Human> PERMISSIONS FULL;
DEFINE FIELD expires ON AccessToken TYPE datetime PERMISSIONS FULL;
DEFINE FIELD id ON AccessToken TYPE uuid PERMISSIONS FULL;
DEFINE FIELD max_uses ON AccessToken TYPE option<int> PERMISSIONS FULL;
DEFINE FIELD token ON AccessToken TYPE string PERMISSIONS FULL;
DEFINE FIELD uses ON AccessToken TYPE int PERMISSIONS FULL;
-- ------------------------------
-- TABLE: Channel
-- ------------------------------
DEFINE TABLE Channel TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD id ON Channel TYPE uuid PERMISSIONS FULL;
-- ------------------------------
-- TABLE: DataPool
-- ------------------------------
DEFINE TABLE DataPool TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD `value` ON DataPool TYPE string PERMISSIONS FULL;
DEFINE FIELD id ON DataPool TYPE uuid PERMISSIONS FULL;
DEFINE FIELD key ON DataPool TYPE string PERMISSIONS FULL;
DEFINE FIELD owner ON DataPool TYPE record<Entity> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: Entity
-- ------------------------------
DEFINE TABLE Entity TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD deleted ON Entity TYPE bool VALUE false PERMISSIONS FULL;
DEFINE FIELD displayname ON Entity TYPE string PERMISSIONS FULL;
DEFINE FIELD id ON Entity TYPE uuid PERMISSIONS FULL;
DEFINE FIELD joined ON Entity TYPE datetime PERMISSIONS FULL;
DEFINE FIELD username ON Entity TYPE string PERMISSIONS FULL;
-- ------------------------------
-- TABLE: Faction
-- ------------------------------
DEFINE TABLE Faction TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD id ON Faction TYPE uuid PERMISSIONS FULL;
DEFINE FIELD name ON Faction TYPE string PERMISSIONS FULL;
DEFINE FIELD owner ON Faction TYPE record<Entity> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: Friendship
-- ------------------------------
DEFINE TABLE Friendship TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD dm_channel ON Friendship TYPE record<Channel> PERMISSIONS FULL;
DEFINE FIELD id ON Friendship TYPE uuid PERMISSIONS FULL;
DEFINE FIELD since ON Friendship TYPE datetime PERMISSIONS FULL;
-- ------------------------------
-- TABLE: GroupChat
-- ------------------------------
DEFINE TABLE GroupChat TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD channel ON GroupChat TYPE record<Channel> PERMISSIONS FULL;
DEFINE FIELD icon_uri ON GroupChat TYPE string PERMISSIONS FULL;
DEFINE FIELD name ON GroupChat TYPE string PERMISSIONS FULL;
DEFINE FIELD owner ON GroupChat TYPE record<Entity> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: HasChannel
-- ------------------------------
DEFINE TABLE HasChannel TYPE RELATION IN Server OUT Channel SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON HasChannel TYPE record<Server> PERMISSIONS FULL;
DEFINE FIELD out ON HasChannel TYPE record<Channel> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: HasContent
-- ------------------------------
DEFINE TABLE HasContent TYPE RELATION IN Message OUT MessageStringContent SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON HasContent TYPE record<Message> PERMISSIONS FULL;
DEFINE FIELD out ON HasContent TYPE record<MessageStringContent> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: HasDomain
-- ------------------------------
DEFINE TABLE HasDomain TYPE RELATION IN DataPool OUT Server | GroupChat | Friendship SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON HasDomain TYPE record<DataPool> PERMISSIONS FULL;
DEFINE FIELD out ON HasDomain TYPE record<Server | GroupChat | Friendship> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: HasFriendRequest
-- ------------------------------
DEFINE TABLE HasFriendRequest TYPE RELATION IN Entity OUT Entity SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD created ON HasFriendRequest TYPE datetime PERMISSIONS FULL;
DEFINE FIELD in ON HasFriendRequest TYPE record<Entity> PERMISSIONS FULL;
DEFINE FIELD out ON HasFriendRequest TYPE record<Entity> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: HasFriendship
-- ------------------------------
DEFINE TABLE HasFriendship TYPE RELATION IN Entity OUT Friendship SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON HasFriendship TYPE record<Entity> PERMISSIONS FULL;
DEFINE FIELD nickname ON HasFriendship TYPE string PERMISSIONS FULL;
DEFINE FIELD out ON HasFriendship TYPE record<Friendship> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: HasGroupChat
-- ------------------------------
DEFINE TABLE HasGroupChat TYPE RELATION IN Entity OUT GroupChat SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON HasGroupChat TYPE record<Entity> PERMISSIONS FULL;
DEFINE FIELD out ON HasGroupChat TYPE record<GroupChat> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: HasPermission
-- ------------------------------
DEFINE TABLE HasPermission TYPE RELATION IN HasServer | ServerRole OUT Permission SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON HasPermission TYPE record<HasServer | ServerRole> PERMISSIONS FULL;
DEFINE FIELD out ON HasPermission TYPE record<Permission> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: HasRole
-- ------------------------------
DEFINE TABLE HasRole TYPE RELATION IN Entity OUT ServerRole SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON HasRole TYPE record<Entity> PERMISSIONS FULL;
DEFINE FIELD out ON HasRole TYPE record<ServerRole> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: HasServer
-- ------------------------------
DEFINE TABLE HasServer TYPE RELATION IN Entity OUT Server SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON HasServer TYPE record<Entity> PERMISSIONS FULL;
DEFINE FIELD joined ON HasServer TYPE datetime PERMISSIONS FULL;
DEFINE FIELD nickname ON HasServer TYPE string PERMISSIONS FULL;
DEFINE FIELD out ON HasServer TYPE record<Server> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: HasTitle
-- ------------------------------
DEFINE TABLE HasTitle TYPE RELATION IN Entity OUT Title SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON HasTitle TYPE record<Entity> PERMISSIONS FULL;
DEFINE FIELD out ON HasTitle TYPE record<Title> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: Human
-- ------------------------------
DEFINE TABLE Human TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD email ON Human TYPE string PERMISSIONS FULL;
DEFINE FIELD entity ON Human TYPE record<Entity> PERMISSIONS FULL;
DEFINE FIELD id ON Human TYPE uuid PERMISSIONS FULL;
DEFINE FIELD passhash ON Human TYPE string PERMISSIONS FULL;
-- ------------------------------
-- TABLE: Message
-- ------------------------------
DEFINE TABLE Message TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD channel ON Message TYPE record<Channel> PERMISSIONS FULL;
DEFINE FIELD edited ON Message TYPE bool PERMISSIONS FULL;
DEFINE FIELD id ON Message TYPE uuid PERMISSIONS FULL;
DEFINE FIELD reply_to ON Message TYPE option<record<Message>> PERMISSIONS FULL;
DEFINE FIELD sent ON Message TYPE datetime PERMISSIONS FULL;
-- ------------------------------
-- TABLE: MessageStringContent
-- ------------------------------
DEFINE TABLE MessageStringContent TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD content ON MessageStringContent TYPE string PERMISSIONS FULL;
DEFINE FIELD id ON MessageStringContent TYPE uuid PERMISSIONS FULL;
-- ------------------------------
-- TABLE: Permission
-- ------------------------------
DEFINE TABLE Permission TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD id ON Permission TYPE uuid PERMISSIONS FULL;
DEFINE FIELD name ON Permission TYPE string PERMISSIONS FULL;
DEFINE FIELD server ON Permission TYPE record<Server> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: Plugin
-- ------------------------------
DEFINE TABLE Plugin TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD created ON Plugin TYPE datetime PERMISSIONS FULL;
DEFINE FIELD id ON Plugin TYPE uuid PERMISSIONS FULL;
DEFINE FIELD name ON Plugin TYPE string PERMISSIONS FULL;
-- ------------------------------
-- TABLE: PluginEntity
-- ------------------------------
DEFINE TABLE PluginEntity TYPE RELATION IN Plugin OUT Entity SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON PluginEntity TYPE record<Plugin> PERMISSIONS FULL;
DEFINE FIELD out ON PluginEntity TYPE record<Entity> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: SentMessage
-- ------------------------------
DEFINE TABLE SentMessage TYPE RELATION IN Entity OUT Message SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON SentMessage TYPE record<Entity> PERMISSIONS FULL;
DEFINE FIELD out ON SentMessage TYPE record<Message> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: Server
-- ------------------------------
DEFINE TABLE Server TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD created ON Server TYPE datetime PERMISSIONS FULL;
DEFINE FIELD icon_uri ON Server TYPE string PERMISSIONS FULL;
DEFINE FIELD id ON Server TYPE uuid PERMISSIONS FULL;
DEFINE FIELD name ON Server TYPE string PERMISSIONS FULL;
DEFINE FIELD owner ON Server TYPE record<Entity> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: ServerRole
-- ------------------------------
DEFINE TABLE ServerRole TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD colour ON ServerRole TYPE string PERMISSIONS FULL;
DEFINE FIELD name ON ServerRole TYPE string PERMISSIONS FULL;
DEFINE FIELD server ON ServerRole TYPE record<Server> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: SessionToken
-- ------------------------------
DEFINE TABLE SessionToken TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD created ON SessionToken TYPE datetime PERMISSIONS FULL;
DEFINE FIELD expires ON SessionToken TYPE datetime PERMISSIONS FULL;
DEFINE FIELD id ON SessionToken TYPE uuid PERMISSIONS FULL;
DEFINE FIELD token ON SessionToken TYPE string PERMISSIONS FULL;
DEFINE FIELD user ON SessionToken TYPE record<Human> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: Title
-- ------------------------------
DEFINE TABLE Title TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD colour ON Title TYPE string PERMISSIONS FULL;
DEFINE FIELD faction ON Title TYPE record<Faction> PERMISSIONS FULL;
DEFINE FIELD name ON Title TYPE string PERMISSIONS FULL;
-- ------------------------------
-- TABLE: UserJoinedBy
-- ------------------------------
DEFINE TABLE UserJoinedBy TYPE RELATION IN Human OUT AccessToken SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON UserJoinedBy TYPE record<Human> PERMISSIONS FULL;
DEFINE FIELD out ON UserJoinedBy TYPE record<AccessToken> PERMISSIONS FULL;
+90 -32
View File
@@ -1,14 +1,12 @@
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use rand::{thread_rng, Rng};
use rocket::{http::{CookieJar, Status}, options, post, request::{FromRequest, Outcome}, serde::json::Json, Request};
use rocket::{http::{Cookie, CookieJar, Status}, options, post, request::{FromRequest, Outcome}, serde::json::Json, Request};
use serde::Deserialize;
use sha2::{Digest, Sha256};
use surrealdb::RecordId;
use crate::{database::DB, user::{
User, AuthResponse
}};
use crate::{database::DB, user::User};
#[derive(Deserialize)]
pub struct UserLoginForm {
@@ -22,45 +20,105 @@ pub fn login_options() -> Status {
}
#[post("/login", data = "<user>")]
pub async fn login(user: Json<UserLoginForm>, jar: &CookieJar<'_>) -> Status {
println!("Logging in: {}", user.username);
if let Ok(response) = User::authenticate(user.username.clone(), user.password.clone()).await {
if response.matches {
let token = SessionToken::new(response.user_id).await;
jar.add_private(("auth", token.token));
println!("success!");
return Status::Ok
} else {
println!("does not match");
#[post("/login", data = "<form>")]
pub async fn login(form: Json<UserLoginForm>, jar: &CookieJar<'_>) -> Status {
match User::login(form.username.clone(), form.password.clone()).await {
Ok(token) => {
println!("logged in");
jar.add_private(Cookie::new("auth-token", token));
Status::Ok
}
Err(e) => {
println!("login failed: {}", e);
Status::Unauthorized
}
} else {
println!("response err");
}
println!("failed!");
return Status::Unauthorized
}
#[derive(Deserialize)]
pub struct UserSignupForm {
username: String,
password: String,
token: String,
}
#[options("/signup")]
pub fn signup_options() -> Status {
Status::Ok
}
#[post("/signup", data = "<user>")]
pub async fn signup(user: Json<UserLoginForm>, jar: &CookieJar<'_>) -> Status {
println!("signing up: {}", user.username);
User::create(user.username.clone(), user.password.clone()).await;
login(user, jar).await
pub async fn signup(user: Json<UserSignupForm>, jar: &CookieJar<'_>) -> Status {
match User::signup(
user.username.clone(),
user.username.clone(),
user.password.clone(),
user.username.clone()
).await {
Ok(token) => {
println!("signed up");
jar.add_private(Cookie::new("auth-token", token));
Status::Ok
}
Err(e) => {
println!("signup failed: {}", e);
Status::Conflict
}
}
}
pub type SessionTokenGuard = User;
#[derive(Debug, Clone)]
@@ -76,7 +134,7 @@ impl<'r> FromRequest<'r> for SessionTokenGuard {
type Error = ();
async fn from_request(req: &'r Request<'_>) -> Outcome<Self, Self::Error> {
if let Some(cookie) = req.cookies().get_private("auth") {
if let Some(cookie) = req.cookies().get_private("auth-token") {
let token = cookie.value().to_string();
return match DB
.query("
+133
View File
@@ -0,0 +1,133 @@
use std::{fs, os::unix::fs::PermissionsExt, path::Path};
use rocket::{get, serde::json::Json};
use rocket::tokio::{
self,
net::{UnixListener, UnixStream},
io::{AsyncReadExt, AsyncWriteExt},
sync::Mutex,
};
use std::sync::Arc;
use serde::{Deserialize, Serialize};
use crate::messenger::MessengerServer;
const SOCKET_PATH: &str = "/tmp/minecraft_chat/chat.sock";
const SOCKET_DIR: &str = "/tmp/minecraft_chat";
#[derive(Deserialize)]
struct MinecraftMessage {
player: String,
content: String,
}
#[derive(Serialize)]
struct Response {
status: String,
}
#[derive(Serialize)]
pub struct Status {
status: String,
timestamp: i64,
}
// This function ensures the socket directory exists with correct permissions
pub fn init_socket() {
// Create socket directory if it doesn't exist
let socket_dir = "/tmp/minecraft_chat";
if !std::path::Path::new(socket_dir).exists() {
fs::create_dir(socket_dir).expect("Failed to create socket directory");
// Set directory permissions to 755 (rwxr-xr-x)
fs::set_permissions(socket_dir, fs::Permissions::from_mode(0o755))
.expect("Failed to set directory permissions");
}
}
pub fn get_socket_path() -> String {
"/tmp/minecraft_chat/chat.sock".to_string()
}
pub async fn start_unix_socket(messenger: Arc<Mutex<MessengerServer>>) {
// Ensure the socket directory exists with correct permissions
if !Path::new(SOCKET_DIR).exists() {
fs::create_dir(SOCKET_DIR).expect("Failed to create socket directory");
fs::set_permissions(SOCKET_DIR, fs::Permissions::from_mode(0o755))
.expect("Failed to set directory permissions");
}
// Remove existing socket file if it exists
if Path::new(SOCKET_PATH).exists() {
fs::remove_file(SOCKET_PATH).expect("Failed to remove existing socket");
}
// Create and bind to the Unix socket
let listener = UnixListener::bind(SOCKET_PATH).expect("Failed to bind to Unix socket");
// Set socket file permissions to 777 for testing (adjust as needed)
fs::set_permissions(SOCKET_PATH, fs::Permissions::from_mode(0o777))
.expect("Failed to set socket permissions");
println!("Unix socket listening at {}", SOCKET_PATH);
while let Ok((stream, _)) = listener.accept().await {
let messenger = messenger.clone();
tokio::spawn(async move {
handle_connection(stream, messenger).await;
});
}
}
async fn handle_connection(mut stream: UnixStream, messenger: Arc<Mutex<MessengerServer>>) {
let mut buffer = [0; 1024];
match stream.read(&mut buffer).await {
Ok(n) => {
if let Ok(message_str) = String::from_utf8(buffer[..n].to_vec()) {
if let Ok(message) = serde_json::from_str::<MinecraftMessage>(&message_str) {
// Forward the message to the chat system
let response = handle_minecraft_message(message, messenger).await;
// Send response
if let Ok(response_json) = serde_json::to_string(&response) {
let _ = stream.write_all(response_json.as_bytes()).await;
}
}
}
}
Err(e) => eprintln!("Error reading from Unix socket: {}", e),
}
}
async fn handle_minecraft_message(msg: MinecraftMessage, messenger: Arc<Mutex<MessengerServer>>) -> Response {
// Create a real-time message
use crate::messenger::RealTimeMessage;
use std::time::{SystemTime, UNIX_EPOCH};
let message = RealTimeMessage {
message_id: 0,
user_id: "minecraft".to_string(),
display_name: msg.player,
created_at: SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis() as i64,
content: msg.content,
};
// Send the message to channel 1 (or adjust as needed)
messenger.lock().await.send(1, message).await;
Response {
status: "ok".to_string(),
}
}
#[get("/minecraft/chat")]
pub fn chat() -> Json<Status> {
Json(Status {
status: "ok".to_string(),
timestamp: std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs() as i64,
})
}
+31
View File
@@ -0,0 +1,31 @@
pub mod listener;
use listener::init_socket;
use rocket::fairing::Fairing;
use std::sync::Arc;
use rocket::tokio::sync::Mutex;
use crate::messenger::MessengerServer;
pub struct ChatSyncFairing {
pub messenger: Arc<Mutex<MessengerServer>>,
}
#[rocket::async_trait]
impl Fairing for ChatSyncFairing {
fn info(&self) -> rocket::fairing::Info {
rocket::fairing::Info {
name: "Chat Sync",
kind: rocket::fairing::Kind::Liftoff,
}
}
async fn on_liftoff(&self, _rocket: &rocket::Rocket<rocket::Orbit>) {
let messenger = self.messenger.clone();
init_socket();
tokio::spawn(async move {
listener::start_unix_socket(messenger).await;
});
}
}
+77
View File
@@ -0,0 +1,77 @@
use std::sync::LazyLock;
use serde::{Deserialize, Serialize};
use toml::Table;
#[derive(Debug, Serialize, Deserialize)]
pub struct Config {
socket_path: String,
channel_id: u64,
pub dev_url: String,
pub prod_url: String
}
impl Config {
pub fn load() -> Config {
let content = match std::fs::read_to_string("Deploy.toml") {
Ok(content) => content,
Err(e) => {
eprintln!("Failed to read Deploy.toml: {}", e);
return Config::default();
},
};
let table: Table = match content.parse::<Table>() {
Ok(table) => table,
Err(e) => {
eprintln!("Failed to parse Deploy.toml: {}", e);
return Config::default();
},
};
let mut config = Config::default();
if let Some(socket_path) = table.get("chatsync") {
if let Some(socket_path) = socket_path.as_table() {
if let Some(path) = socket_path.get("socket_path") {
config.socket_path = path.to_string();
}
}
}
// get urls
if let Some(server) = table.get("server") {
if let Some(server) = server.as_table() {
if let Some(url) = server.get("dev") {
if let Some(url) = url.as_table() {
if let Some(url) = url.get("url") {
config.dev_url = url.to_string();
println!("OK!")
}
}
}
if let Some(url) = server.get("prod") {
if let Some(url) = url.as_table() {
if let Some(url) = url.get("url") {
config.prod_url = url.to_string();
}
}
}
}
}
config
}
}
impl Default for Config {
fn default() -> Self {
Config {
socket_path: "/tmp/minecraft_chat/chat.sock".to_string(),
channel_id: 1315044374127841374,
dev_url: "http://localhost:8080".to_string(),
prod_url: "https://zxq5.dev".to_string()
}
}
}
+20
View File
@@ -0,0 +1,20 @@
#[derive(Debug)]
pub enum BackendError {
DbError(String),
}
impl std::fmt::Display for BackendError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
BackendError::DbError(message) => write!(f, "{}", message),
}
}
}
impl std::error::Error for BackendError {}
impl From<surrealdb::Error> for BackendError {
fn from(err: surrealdb::Error) -> Self {
BackendError::DbError(err.to_string())
}
}
+5
View File
@@ -0,0 +1,5 @@
#[get("/license/<username>")]
pub async fn get_meme_license(username: String) -> String {
format!("Meme license for {}", username)
}
View File
+49 -24
View File
@@ -1,43 +1,68 @@
use auth::{login, login_options, signup, signup_options};
use rocket::{fs::FileServer, launch, routes};
use std::sync::Arc;
use config::Config;
use rocket::http::Method;
use rocket::tokio::sync::Mutex;
use rocket::{fs::FileServer, launch, routes};
use rocket_cors::{AllowedHeaders, AllowedOrigins, CorsOptions};
use std::sync::Arc;
mod messenger;
mod auth;
mod user;
mod database;
mod error;
mod features;
mod messenger;
mod servers;
mod user;
mod chatsync;
mod config;
use messenger::{MessengerServer, connect};
pub(crate) use error::BackendError;
use messenger::{connect, MessengerServer};
use chatsync::ChatSyncFairing;
#[launch]
async fn rocket() -> _ {
let messenger = Arc::new(Mutex::new(MessengerServer::new()));
let chat_sync = ChatSyncFairing {
messenger: messenger.clone(),
};
let config = Config::load();
let cors = CorsOptions::default()
.allowed_origins(AllowedOrigins::some_exact(&[
&config.dev_url,
&config.prod_url,
]))
.allowed_methods(
vec![Method::Get, Method::Post, Method::Options]
.into_iter()
.map(From::from)
.collect(),
)
.allowed_headers(AllowedHeaders::some(&[
"Authorization",
"Accept",
"Content-Type",
]))
.allow_credentials(true);
database::init().await.unwrap();
rocket::build()
.manage(messenger)
.mount("/", routes![
.mount("/static", FileServer::from("static"))
.mount(
"/api",
routes![
connect,
login,
signup,
login_options,
signup,
signup_options,
])
.mount("/static", FileServer::from("static"))
.attach(rocket::fairing::AdHoc::on_response("CORS", |_, res| Box::pin(async move {
res.set_header(rocket::http::Header::new(
"Access-Control-Allow-Origin",
"*"
));
res.set_header(rocket::http::Header::new(
"Access-Control-Allow-Methods",
"GET, POST, OPTIONS"
));
res.set_header(rocket::http::Header::new(
"Access-Control-Allow-Headers",
"*"
));
})))
],
)
.manage(messenger)
.manage(config)
.attach(cors.to_cors().unwrap())
.attach(chat_sync)
}
+18 -14
View File
@@ -1,5 +1,6 @@
use std::{collections::HashMap, sync::Arc, time::{SystemTime, UNIX_EPOCH}};
use chrono::Utc;
use rocket::{
futures::{
channel::mpsc,
@@ -16,31 +17,36 @@ use rocket::{
use serde::Serialize;
use rocket_ws::{Channel, WebSocket, stream::DuplexStream};
use surrealdb::{RecordId, Uuid};
use surrealdb::{RecordId, Uuid, Datetime};
use crate::{auth::SessionTokenGuard, user::User};
#[get("/messenger/connect/<channel_id>")]
pub async fn connect<'r> (
user: SessionTokenGuard,
#[get("/messenger/connect/<channel_id>/<user_id>")]
pub async fn connect<'r> (
// user: SessionTokenGuard,
user_id: String,
ws: WebSocket,
messenger: &'r rocket::State<Arc<Mutex<MessengerServer>>>,
channel_id: i32,
mut shutdown: Shutdown,
) -> Result<Channel<'r>, Status> {
) -> Result<Channel<'r>, Status> {
let messenger = Arc::clone(messenger.inner());
Ok(ws.channel(move | channel| {
Box::pin(async move {
let user = User {
id: RecordId::from_table_key("User", Uuid::new_v4().to_string()),
email: "".to_string(),
username: user_id,
passhash: "test".to_string(),
displayname: "test".to_string(),
joined: Datetime::from(Utc::now()),
};
let (sender, receiver) = mpsc::channel::<RealTimeMessage>(100);
let (ws_sender, ws_receiver) = channel.split();
println!("REGISTERING: {}", user.id);
messenger.lock().await.register(user.id.clone(), channel_id, sender);
tokio::select! {
@@ -49,13 +55,11 @@ use crate::{auth::SessionTokenGuard, user::User};
_ = &mut shutdown => {},
}
// Once the client disconnects, or the server is shutdown they are deregistered from the channel.
println!("DEREGISTERING: {}", user.id);
messenger.lock().await.deregister(user.id);
Ok(())
})
}))
}
}
@@ -72,7 +76,7 @@ pub async fn inbound_message(
let message = RealTimeMessage {
message_id: 0,
user_id: user.id.key().to_string(),
user_id: user.id.key().to_string().trim_start_matches('⟨').trim_end_matches('⟩').to_string(),
display_name: user.username.clone(),
created_at: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis() as i64,
content: text,
+21
View File
@@ -0,0 +1,21 @@
use rocket::{get, serde::json::Json};
use serde::Serialize;
#[get("/servers")]
pub fn servers() -> Json<Vec<Server>> {
Json(vec![
Server { id: "0".to_string(), name: "Test Server".to_string() },
Server { id: "1".to_string(), name: "Test Server2".to_string() },
Server { id: "2".to_string(), name: "Test Server3".to_string() },
Server { id: "3".to_string(), name: "Test Server4".to_string() },
Server { id: "4".to_string(), name: "Test Server5".to_string() },
Server { id: "5".to_string(), name: "Test Server6".to_string() },
Server { id: "6".to_string(), name: "Test Server7".to_string() },
])
}
#[derive(Serialize)]
struct Server {
id: String,
name: String,
}
+107 -54
View File
@@ -1,78 +1,131 @@
use serde::{Deserialize, Serialize};
use surrealdb::RecordId;
use crate::database::DB;
use surrealdb::{Datetime, RecordId};
use chrono::Utc;
use crate::{database::DB, BackendError};
#[derive(Debug, Deserialize, Serialize)]
pub struct User {
pub id: RecordId,
pub username: String,
pub email: String,
pub passhash: String,
pub displayname: String,
pub joined: i64,
pub joined: Datetime,
}
#[derive(Debug, Deserialize)]
pub struct AuthResponse {
pub matches: bool,
pub user_id: RecordId,
#[derive(Debug, Deserialize, Serialize)]
struct Entity {
id: RecordId,
deleted: bool,
displayname: String,
joined: Datetime,
username: String
}
#[derive(Debug, Deserialize, Serialize)]
struct Human {
id: RecordId,
email: String,
passhash: String
}
impl User {
pub async fn authenticate(username: String, password: String) -> Result<AuthResponse, ()> {
pub async fn signup(
username: String,
email: String,
password: String,
displayname: String
) -> Result<String, BackendError> {
// let entity = DB
// .create("Entity")
// .content(Entity {
// id: RecordId::from(("Entity", Id::rand())),
// deleted: false,
// displayname: displayname,
// joined: Datetime::now(),
// username: username,
// })
// .await;
return Ok(String::new());
// match DB
// .query("
// LET $entity_id = CREATE Entity CONTENT {
// deleted: false,
// displayname: $displayname,
// joined: time::now(),
// username: $username,
// } RETURN AFTER.id;
// LET $human_id = CREATE Human CONTENT {
// email: $email,
// passhash: crypto::argon2::generate($password),
// } RETURN AFTER.id;
// LET $node1 = type::thing('Entity', $entity_id);
// LET $node2 = type::thing('Human', $human_id);
// RELATE $node2 -> HasEntity -> $node1;
// LET $session_token = CREATE SessionToken CONTENT {
// id: rand::uuid::v4(),
// created: time::now(),
// expires: time::now() + 7d,
// token: rand::string(64),
// user: type::thing('Human', $human_id),
// } RETURN AFTER.token;
// RETURN $session_token;
// ")
// .bind(("username", username))
// .bind(("email", email))
// .bind(("password", password))
// .bind(("displayname", displayname))
// .await
// .unwrap()
// .take::<Option<String>>(0)
// .map_err(|e| BackendError::from(e))
// {
// Ok(Some(user)) => Ok(user),
// Ok(None) => panic!("NO TOKEN RETURNED"),
// _ => Err(BackendError::DbError("Failed to create user".to_string())),
// }
}
pub async fn login(username: String, password: String) -> Result<String, BackendError> {
match DB
.query("
LET $user = (SELECT id, passhash FROM User WHERE username = $username)[0];
RETURN {
matches: crypto::argon2::compare($user.passhash, $password),
user_id: $user.id
}"
)
.bind(("username", username))
LET $human = (SELECT id, passhash FROM Human WHERE email = $email)[0];
IF !crypto::argon2::compare($human.passhash, $password) {
RETURN NONE;
};
LET $session_token = rand::string(64);
CREATE SessionToken CONTENT {
id: rand::uuid::v4(),
created: time::now(),
expires: time::now() + 7d,
token: $session_token,
user: type::thing('Human', $human.id),
};
RETURN $session_token;
")
.bind(("email", username))
.bind(("password", password))
.await
.map_err(|_| ())?
.take::<Option<AuthResponse>>(0)
{
Ok(Some(response)) => Ok(response),
Ok(None) => {
println!("User not found");
Err(())
}
Err(e) => {
println!("Error authenticating user: {}", e);
Err(())
}
_ => Err(()),
}
}
pub async fn create(username: String, password: String) -> Result<String, ()> {
match DB
.query("
CREATE User:uuid() SET
username = $username,
displayname = $displayname,
passhash = crypto::argon2::generate($passhash),
joined = $joined;
SELECT * FROM User WHERE username = $username
")
.bind(("username", username.clone()))
.bind(("passhash", password))
.bind(("displayname", username))
.bind(("joined", Utc::now().timestamp()))
.await
.unwrap()
.take::<Option<User>>(0)
.take::<Option<String>>(0)
.map_err(|e| BackendError::from(e))
{
Ok(Some(user)) => {
let k = user.id.key().to_string();
println!("Created User: {}", k);
Ok(k)
},
_ => Err(())
Ok(Some(user)) => Ok(user),
_ => Err(BackendError::DbError("Failed to create user".to_string())),
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 696 KiB

+5 -1
View File
@@ -20,7 +20,11 @@ web-sys = { version = "0.3", features = [
"CloseEvent",
"Window",
"Location",
"History"
"History",
"HtmlCanvasElement",
"HtmlImageElement",
"CanvasRenderingContext2d",
"ImageData"
]}
futures = "0.3"
chrono = "0.4"
+2
View File
@@ -0,0 +1,2 @@
[serve]
port = 8080
@@ -119,6 +119,28 @@ const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
wasm.__wbindgen_export_7.get(state.dtor)(state.a, state.b)
});
function makeClosure(arg0, arg1, dtor, f) {
const state = { a: arg0, b: arg1, cnt: 1, dtor };
const real = (...args) => {
// First up with a closure we increment the internal reference
// count. This ensures that the Rust closure environment won't
// be deallocated while we're invoking it.
state.cnt++;
try {
return f(state.a, state.b, ...args);
} finally {
if (--state.cnt === 0) {
wasm.__wbindgen_export_7.get(state.dtor)(state.a, state.b);
state.a = 0;
CLOSURE_DTORS.unregister(state);
}
}
};
real.original = state;
CLOSURE_DTORS.register(real, state, state);
return real;
}
function makeMutClosure(arg0, arg1, dtor, f) {
const state = { a: arg0, b: arg1, cnt: 1, dtor };
const real = (...args) => {
@@ -144,28 +166,6 @@ function makeMutClosure(arg0, arg1, dtor, f) {
return real;
}
function makeClosure(arg0, arg1, dtor, f) {
const state = { a: arg0, b: arg1, cnt: 1, dtor };
const real = (...args) => {
// First up with a closure we increment the internal reference
// count. This ensures that the Rust closure environment won't
// be deallocated while we're invoking it.
state.cnt++;
try {
return f(state.a, state.b, ...args);
} finally {
if (--state.cnt === 0) {
wasm.__wbindgen_export_7.get(state.dtor)(state.a, state.b);
state.a = 0;
CLOSURE_DTORS.unregister(state);
}
}
};
real.original = state;
CLOSURE_DTORS.register(real, state, state);
return real;
}
function debugString(val) {
// primitive types
const type = typeof val;
@@ -231,23 +231,19 @@ function debugString(val) {
return className;
}
function __wbg_adapter_42(arg0, arg1, arg2) {
wasm.closure130_externref_shim(arg0, arg1, arg2);
wasm.closure400_externref_shim(arg0, arg1, arg2);
}
function __wbg_adapter_45(arg0, arg1, arg2) {
wasm.closure540_externref_shim(arg0, arg1, arg2);
function __wbg_adapter_47(arg0, arg1, arg2) {
wasm.closure612_externref_shim(arg0, arg1, arg2);
}
function __wbg_adapter_48(arg0, arg1, arg2) {
wasm.closure616_externref_shim(arg0, arg1, arg2);
function __wbg_adapter_50(arg0, arg1, arg2) {
wasm.closure700_externref_shim(arg0, arg1, arg2);
}
function __wbg_adapter_51(arg0, arg1, arg2) {
wasm.closure638_externref_shim(arg0, arg1, arg2);
}
function __wbg_adapter_54(arg0, arg1, arg2) {
wasm.closure647_externref_shim(arg0, arg1, arg2);
function __wbg_adapter_53(arg0, arg1, arg2) {
wasm.closure717_externref_shim(arg0, arg1, arg2);
}
async function __wbg_load(module, imports) {
@@ -386,13 +382,6 @@ function __wbg_get_imports() {
const ret = Array.from(arg0);
return ret;
};
imports.wbg.__wbg_getItem_561976eef304cebe = function() { return handleError(function (arg0, arg1, arg2, arg3) {
const ret = arg1.getItem(getStringFromWasm0(arg2, arg3));
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len1 = WASM_VECTOR_LEN;
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
}, arguments) };
imports.wbg.__wbg_getRandomValues_bcb4912f16000dc4 = function() { return handleError(function (arg0, arg1) {
arg0.getRandomValues(arg1);
}, arguments) };
@@ -571,14 +560,15 @@ function __wbg_get_imports() {
const ret = arg0.__yew_listener_id;
return isLikeNone(ret) ? 0x100000001 : (ret) >>> 0;
};
imports.wbg.__wbg_localStorage_05bfbeeb8946b5bf = function() { return handleError(function (arg0) {
const ret = arg0.localStorage;
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
}, arguments) };
imports.wbg.__wbg_location_54d35e8c85dcfb9c = function(arg0) {
const ret = arg0.location;
return ret;
};
imports.wbg.__wbg_log_c3d56bb0009edd6a = function(arg0, arg1) {
var v0 = getArrayJsValueFromWasm0(arg0, arg1).slice();
wasm.__wbindgen_free(arg0, arg1 * 4, 4);
console.log(...v0);
};
imports.wbg.__wbg_message_142844ca2fe283e3 = function(arg0) {
const ret = arg0.message;
return ret;
@@ -924,24 +914,24 @@ function __wbg_get_imports() {
const ret = false;
return ret;
};
imports.wbg.__wbindgen_closure_wrapper280 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 131, __wbg_adapter_42);
imports.wbg.__wbindgen_closure_wrapper1214 = function(arg0, arg1, arg2) {
const ret = makeClosure(arg0, arg1, 613, __wbg_adapter_47);
return ret;
};
imports.wbg.__wbindgen_closure_wrapper5502 = function(arg0, arg1, arg2) {
const ret = makeClosure(arg0, arg1, 541, __wbg_adapter_45);
imports.wbg.__wbindgen_closure_wrapper1482 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 701, __wbg_adapter_50);
return ret;
};
imports.wbg.__wbindgen_closure_wrapper7256 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 617, __wbg_adapter_48);
imports.wbg.__wbindgen_closure_wrapper1516 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 718, __wbg_adapter_53);
return ret;
};
imports.wbg.__wbindgen_closure_wrapper7485 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 639, __wbg_adapter_51);
imports.wbg.__wbindgen_closure_wrapper681 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 401, __wbg_adapter_42);
return ret;
};
imports.wbg.__wbindgen_closure_wrapper7756 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 648, __wbg_adapter_54);
imports.wbg.__wbindgen_closure_wrapper683 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 401, __wbg_adapter_42);
return ret;
};
imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
Binary file not shown.
Binary file not shown.
@@ -1,30 +1,4 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--blur-amount: 10px;
--border-radius: 15px;
--glow-color: rgba(255, 255, 255, 0.3);
--message-bubble-color: rgba(255, 255, 255, 0.1);
--border-color: rgba(255, 255, 255, 0.1);
--shadow-color: rgba(0, 0, 0, 0.2);
}
html, body {
margin: 0;
padding: 0;
height: 100vh;
width: 100%;
overflow: hidden;
background: linear-gradient(135deg, #1a2a6c, #2a4858, #141E30);
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
color: white;
}
.app-container {
.base-container {
height: 100vh;
width: 100vw;
display: flex;
@@ -32,17 +6,18 @@ html, body {
overflow: hidden;
}
.chat-container {
.app-container {
flex: 1;
margin: 0 2rem;
padding: 1rem;
display: flex;
flex-direction: column;
gap: 1rem;
width: 100%;
width: calc(100% - 4rem);
max-width: 1400px;
margin-left: auto;
margin-right: auto;
height: calc(100vh - 80px); /* Account for navbar height */
overflow: hidden;
}
@@ -60,6 +35,37 @@ html, body {
flex-direction: column;
gap: 1rem;
width: 100%;
min-height: 0; /* This is crucial for flex child scrolling */
}
.meme-license-container {
flex: 1;
overflow-y: auto;
padding: 0;
background: rgba(255, 255, 255, 0.05);
backdrop-filter: blur(var(--blur-amount));
-webkit-backdrop-filter: blur(var(--blur-amount));
border-radius: 40px;
border: 1px solid var(--border-color);
box-shadow: 0 4px 24px var(--shadow-color);
display: flex;
flex-direction: row;
gap: 1rem;
width: 100%;
min-height: 0; /* This is crucial for flex child scrolling */
}
.ui-server-list {
height: 100%;
overflow-y: auto;
margin: 16px;
padding: 1rem;
background: rgba(255, 255, 255, 0.05);
backdrop-filter: blur(var(--blur-amount));
-webkit-backdrop-filter: blur(var(--blur-amount));
border-radius: var(--border-radius);
border: 1px solid var(--border-color);
box-shadow: 0 4px 24px var(--shadow-color);
}
.message {
@@ -103,17 +109,17 @@ html, body {
.username {
font-weight: 600;
font-size: 0.9rem;
color: #fff;
color: var(--text-color, #fff);
text-shadow: 0 2px 4px var(--shadow-color);
}
.timestamp {
color: rgba(255, 255, 255, 0.6);
color: var(--text-secondary, rgba(255, 255, 255, 0.6));
font-size: 0.8rem;
}
.message-content {
color: rgba(255, 255, 255, 0.9);
color: var(--text-color, rgba(255, 255, 255, 0.9));
font-size: 0.95rem;
}
@@ -132,41 +138,68 @@ html, body {
.message-input {
flex: 1;
background: rgba(255, 255, 255, 0.1);
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
padding: 0.8rem 1rem;
color: white;
background: var(--background-element, rgba(255, 255, 255, 0.1));
border: none;
padding: 0.4rem 1.5rem;
color: var(--text-color, white);
font-size: 1rem;
resize: vertical;
min-height: 1.5rem;
max-height: 150px;
transition: all 0.3s ease;
box-shadow: 0 2px 8px var(--shadow-color);
}
.message-input:hover, .message-input:focus {
border-color: var(--glow-color);
box-shadow: 0 0 15px var(--glow-color);
outline: none;
background-color: rgba(255, 255, 255, 0.3);
}
.send-button {
background: rgba(255, 255, 255, 0.1);
.ui-button {
background: var(--background-element, rgba(255, 255, 255, 0.1));
padding: 0.4rem 1.5rem;
color: var(--text-color, white);
font-size: 1rem;
cursor: pointer;
border: none;
transition: all 0.3s ease;
}
.ui-group {
display: flex;
flex-direction: row;
background: var(--background-element, rgba(255, 255, 255, 0.1));
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
width: 100%;
color: var(--text-color, white);
font-size: 1rem;
transition: all 0.3s ease;
box-shadow: 0 2px 8px var(--shadow-color);
overflow: hidden;
}
.ui-layout-horizontal {
display: flex;
flex-direction: row;
gap: 1rem;
margin: 0;
padding: 0;
width: 100%;
}
.ui-element-standalone {
background: var(--background-element, rgba(255, 255, 255, 0.1));
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
padding: 0.8rem 1.5rem;
color: white;
color: var(--text-color, white);
font-size: 1rem;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 2px 8px var(--shadow-color);
}
.send-button:hover {
border-color: var(--glow-color);
box-shadow: 0 0 15px var(--glow-color);
background: rgba(255, 255, 255, 0.2);
.ui-button:hover {
background-color: rgba(255, 255, 255, 0.3);
}
.navbar {
@@ -174,122 +207,113 @@ html, body {
justify-content: space-between;
align-items: center;
padding: 1rem 2rem;
background: rgba(255, 255, 255, 0.1);
background: var(--background-element, rgba(255, 255, 255, 0.1));
backdrop-filter: blur(var(--blur-amount));
-webkit-backdrop-filter: blur(var(--blur-amount));
border: none;
border-bottom: 1px solid var(--border-color);
box-shadow: 0 4px 24px var(--shadow-color);
margin: 0;
box-shadow: 0 2px 8px var(--shadow-color);
position: relative;
z-index: 1000;
}
.nav-brand {
font-size: 1.5rem;
font-weight: bold;
color: white;
text-shadow: 0 2px 4px var(--shadow-color);
white-space: nowrap;
}
/* Login styles */
.login-container {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 90%;
max-width: 400px;
}
.login-form {
display: flex;
flex-direction: column;
gap: 1rem;
padding: 2rem;
background: rgba(255, 255, 255, 0.1);
.selector {
position: relative;
display: inline-block;
background: rgba(255, 255, 255, 0.01);
width: max-content;
/* background: var(--background-element, rgba(255, 255, 255, 0.1)); */
backdrop-filter: blur(var(--blur-amount));
-webkit-backdrop-filter: blur(var(--blur-amount));
border-radius: var(--border-radius);
border: 1px solid var(--border-color);
box-shadow: 0 4px 24px var(--shadow-color);
}
.login-title {
font-size: 1.5rem;
font-weight: bold;
text-align: center;
color: white;
text-shadow: 0 2px 4px var(--shadow-color);
margin-bottom: 1rem;
}
.login-input {
background: rgba(255, 255, 255, 0.1);
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
padding: 0.8rem 1rem;
color: white;
font-size: 1rem;
transition: all 0.3s ease;
box-shadow: 0 2px 8px var(--shadow-color);
}
.login-input:hover, .login-input:focus {
border-color: var(--glow-color);
box-shadow: 0 0 15px var(--glow-color);
outline: none;
}
.login-input::placeholder {
color: rgba(255, 255, 255, 0.6);
}
.login-button {
background: rgba(255, 255, 255, 0.1);
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
padding: 0.8rem 1.5rem;
color: white;
color: var(--text-color, white);
font-size: 1rem;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 2px 8px var(--shadow-color);
text-align: center;
text-decoration: none;
z-index: 1001;
}
.login-button:hover {
border-color: var(--glow-color);
box-shadow: 0 0 15px var(--glow-color);
background: rgba(255, 255, 255, 0.2);
}
.selector-items {
display: none;
position: absolute;
top: calc(100% + 1px);
left: -1px;
right: -1px;
.login-text {
color: rgba(255, 255, 255, 0.9);
text-align: center;
margin: 0.5rem 0;
}
.login-link {
color: white;
text-decoration: none;
transition: all 0.3s ease;
}
.login-link:hover {
text-shadow: 0 0 10px var(--glow-color);
}
.login-error {
background: rgba(255, 0, 0, 0.1);
border: 1px solid rgba(255, 0, 0, 0.3);
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
padding: 0.8rem 1.5rem;
color: white;
font-size: 1rem;
text-align: center;
box-shadow: 0 4px 12px var(--shadow-color);
z-index: 1002;
backdrop-filter: blur(var(--blur-amount));
-webkit-backdrop-filter: blur(var(--blur-amount));
box-shadow: 0 2px 8px var(--shadow-color);
overflow: hidden;
}
.selector:hover .selector-items {
display: block;
}
.selector-button {
background: none;
width: 100%;
padding: 0.4rem 1.5rem;
border: none;
color: var(--text-color, white);
font-size: 0.9rem;
cursor: pointer;
transition: all 0.2s ease;
text-align: center;
white-space: nowrap;
}
.selector-label {
background: none;
width: 100%;
padding: 0.4rem 1.5rem;
border: none;
color: var(--text-color, white);
font-size: 0.9rem;
cursor: pointer;
transition: all 0.2s ease;
text-align: center;
white-space: nowrap;
position: relative;
padding-right: 2rem;
border-radius: var(--border-radius);
}
.selector-label::after {
content: "▼";
position: absolute;
right: 0.8rem;
top: 50%;
transform: translateY(-50%);
font-size: 0.8rem;
opacity: 0.7;
}
.selector-button:hover {
color: var(--glow-color);
background-color: rgba(255, 255, 255, 0.1);
}
.selector-button.active {
color: var(--glow-color);
font-weight: 500;
}
/* Custom scrollbar */
+104
View File
@@ -0,0 +1,104 @@
/* Form styles */
.form-container {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 90%;
max-width: 400px;
}
.form-form {
display: flex;
flex-direction: column;
gap: 1rem;
padding: 2rem;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(var(--blur-amount));
-webkit-backdrop-filter: blur(var(--blur-amount));
border-radius: var(--border-radius);
border: 1px solid var(--border-color);
box-shadow: 0 4px 24px var(--shadow-color);
}
.form-title {
font-size: 1.5rem;
font-weight: bold;
text-align: center;
color: var(--text-color);
text-shadow: 0 2px 4px var(--shadow-color);
margin-bottom: 1rem;
}
.form-input {
background: rgba(255, 255, 255, 0.1);
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
padding: 0.8rem 1rem;
color: var(--text-color);
font-size: 1rem;
transition: all 0.3s ease;
box-shadow: 0 2px 8px var(--shadow-color);
}
.form-input:hover, .form-input:focus {
border-color: var(--glow-color);
box-shadow: 0 0 15px var(--glow-color);
outline: none;
}
.form-input::placeholder {
color: var(--text-color);
text-align: center;
}
.form-button {
background: rgba(255, 255, 255, 0.1);
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
padding: 0.8rem 1.5rem;
color: var(--text-color);
font-size: 1rem;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 2px 8px var(--shadow-color);
text-align: center;
text-decoration: none;
}
.form-button:hover {
border-color: var(--glow-color);
box-shadow: 0 0 15px var(--glow-color);
background: rgba(255, 255, 255, 0.2);
}
.form-text {
color: var(--text-color);
text-align: center;
margin: 0.5rem 0;
}
.form-link {
color: var(--text-color);
text-decoration: none;
transition: all 0.3s ease;
}
.form-link:hover {
text-shadow: 0 0 10px var(--glow-color);
}
.form-error {
background: rgba(255, 0, 0, 0.1);
border: 1px solid rgba(255, 0, 0, 0.3);
border-radius: var(--border-radius);
padding: 0.8rem 1.5rem;
color: var(--text-color);
font-size: 1rem;
text-align: center;
backdrop-filter: blur(var(--blur-amount));
-webkit-backdrop-filter: blur(var(--blur-amount));
box-shadow: 0 2px 8px var(--shadow-color);
}
+45
View File
@@ -0,0 +1,45 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
--blur-amount: 10px;
--border-radius: 15px;
--shadow-color: rgba(0, 0, 0, 0.4);
}
*[theme="default"] {
--background: linear-gradient(135deg, #1a2a6c, #2a4858, #141E30);
--glow-color: rgba(255, 255, 255, 0.3);
--message-bubble-color: rgba(255, 255, 255, 0.1);
--border-color: rgba(255, 255, 255, 0.1);
--text-color: #ffffff;
}
*[theme="light"] {
--background: #ffffff;
--glow-color: rgba(100, 149, 237, 0.3);
--message-bubble-color: rgba(100, 149, 237, 0.1);
--border-color: rgba(100, 149, 237, 0.2);
--text-color: #000000;
}
*[theme="dark"] {
--background: linear-gradient(135deg, #121212, #1a1a1a, #232323);
--glow-color: rgba(147, 112, 219, 0.4);
--message-bubble-color: rgba(147, 112, 219, 0.15);
--border-color: rgba(255, 255, 255, 0.1);
--text-color: #ffffff;
}
html, body {
margin: 0;
padding: 0;
height: 100vh;
width: 100%;
overflow: hidden;
background: var(--background);
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
color: var(--text-color, white);
}
+7 -5
View File
@@ -5,14 +5,16 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat App</title>
<link rel="stylesheet" href="/styles-a0f557a2c187e84.css" integrity="sha384&#x2D;IY1p3eyyGzgt1dx8oous21mdUqg5fUoBJDo0cnEt0Dzc0zNGKH5Z&#x2F;fRO8S&#x2F;o&#x2F;z&#x2B;X"/>
<link rel="modulepreload" href="/chatapp-frontend-2d9721327d80d1a4.js" crossorigin=anonymous integrity="sha384-NUMxiXeKeAJvxebMe8KYjMxliEtODVyz5/Z481fZRPDW2uYnad9e2ra9tGdLMFpa"><link rel="preload" href="/chatapp-frontend-2d9721327d80d1a4_bg.wasm" crossorigin=anonymous integrity="sha384-2mAsbkb1UNVlDtYPNO/P2i3j3N0eQcSD4sqqXRdf0Y5CtCnprvY5LjoqgSeLoJul" as="fetch" type="application/wasm"></head>
<link rel="stylesheet" href="/components-c4a55600848b6fb1.css" integrity="sha384&#x2D;Mmjo1ZomS0FElJau47rDNd04eUSEv&#x2B;T87iRK8eeVFIde&#x2B;LiwQrTeAxKj59XzYmS0"/>
<link rel="stylesheet" href="/global-7cfadbee4d5b1bff.css" integrity="sha384&#x2D;GWbuMob1xic&#x2F;G9k3FZveeVrVpzetubRiLpE&#x2B;4CtBpx5J2DZNCanPoio&#x2B;UXP2JwLS"/>
<link rel="stylesheet" href="/form-3a77ed11d71d542d.css" integrity="sha384&#x2D;lGHpEuixlt7WvJpZs7XP&#x2F;wQBg2&#x2F;v7C84a6g4l&#x2B;T1HkuUXDhYhqa5QqVli&#x2B;HKVWUi"/>
<link rel="modulepreload" href="/chatapp-frontend-2879b3175985551e.js" crossorigin=anonymous integrity="sha384-xlUUO7QtKu3SefdFpX08aFCGPCxeKLHtvHmbI/KU3AQFTKDOBLeNcVN9mu7mT68u"><link rel="preload" href="/chatapp-frontend-2879b3175985551e_bg.wasm" crossorigin=anonymous integrity="sha384-+mwYLmuuW0jPSy0jqOY+Qya/mYwxANqWd3CYV11ajVWiHIDvr4gfJOZ/oZnbdK8t" as="fetch" type="application/wasm"></head>
<body>
<div id="root"></div>
<script type="module" nonce="2WTPFE+DH5nuGYeLSROE+A==">
import init, * as bindings from '/chatapp-frontend-2d9721327d80d1a4.js';
const wasm = await init('/chatapp-frontend-2d9721327d80d1a4_bg.wasm');
<script type="module" nonce="0K6lbx5zqmDuxEdTEHz1Eg==">
import init, * as bindings from '/chatapp-frontend-2879b3175985551e.js';
const wasm = await init('/chatapp-frontend-2879b3175985551e_bg.wasm');
window.wasmBindings = bindings;
+3 -1
View File
@@ -5,7 +5,9 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat App</title>
<link data-trunk rel="css" href="styles.css">
<link data-trunk rel="css" href="style/components.css">
<link data-trunk rel="css" href="style/global.css">
<link data-trunk rel="css" href="style/form.css">
</head>
<body>
<div id="root"></div>
+19
View File
@@ -0,0 +1,19 @@
use yew::{function_component, html, Callback, Html, MouseEvent, Properties};
#[derive(PartialEq, Properties)]
pub struct Props {
pub onclick: Callback<MouseEvent>,
pub text: String,
pub class: Option<String>
}
#[function_component(Button)]
pub fn button(props: &Props) -> Html {
html! {
<button
class={props.class.clone().unwrap_or("button".to_string())}
onclick={props.onclick.clone()}>
{props.text.clone()}
</button>
}
}
+25 -33
View File
@@ -1,30 +1,30 @@
use gloo::console::log;
use serde::{Deserialize, Serialize};
use yew::prelude::*;
use web_sys::HtmlInputElement;
use chrono::prelude::*;
use crate::hooks::websocket::use_websocket;
use crate::{components::{navbar::Navbar, serverlist::ServerList}, hooks::websocket::use_websocket};
use crate::{WS_URL, API_URL};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RealTimeMessage {
pub message_id: i32,
pub user_id: i32,
pub user_id: String,
pub display_name: String,
pub created_at: i64,
pub content: String,
}
#[function_component(Chat)]
pub fn chat() -> Html {
let ws = use_websocket("ws://localhost:8000/messenger/connect/1");
let input_ref = use_node_ref();
let dark_theme = use_state(|| true);
#[derive(PartialEq, Properties)]
pub struct Props {
pub id: String
}
// let theme_toggle = {
// let dark_theme = dark_theme.clone();
// Callback::from(move |_| {
// dark_theme.set(!*dark_theme);
// })
// };
#[function_component(Chat)]
pub fn chat(props: &Props) -> Html {
let id = props.id.clone();
let ws = use_websocket(format!("{WS_URL}/messenger/connect/1/{id}").as_str());
let input_ref = use_node_ref();
let onsubmit = {
let ws = ws.ws.clone();
@@ -43,30 +43,22 @@ pub fn chat() -> Html {
};
html! {
<div class={classes!("app-container", if *dark_theme { "dark-theme" } else { "light-theme" })}>
<nav class="navbar">
<div class="nav-brand">{"Chat App"}</div>
// <div class="theme-toggle">
// <button onclick={theme_toggle} class="theme-button">
// if *dark_theme {
// {"🌞"}
// } else {
// {"🌙"}
// }
// </button>
// </div>
</nav>
<div class="chat-container">
<div class="ui-layout-horizontal">
// <ServerList/>
<div class="app-container">
<div class="messages-container">
{ws.messages.messages().iter().map(|msg| {
let timestamp = Local.timestamp_millis_opt(msg.created_at).unwrap();
let formatted_time = timestamp.format("%d/%m/%y %H:%M").to_string();
let userid = msg.user_id;
let userid = msg.user_id.clone();
html! {
<div class="message">
// load profile, if not - load fallback / default
<div class="profile-picture" style={ format!(
"background-image: url('http://localhost:8000/static/pfp/{userid}.png')"
"background-image:
url('{API_URL}/static/pfp/{}.png'),
url('{API_URL}/static/public/default_pfp.png')",
userid
)}></div>
<div class="message-bubble">
<div class="message-header">
@@ -84,14 +76,14 @@ pub fn chat() -> Html {
{format!("Error: {}", error)}
</div>
}
<form {onsubmit} class="message-form">
<form {onsubmit} class="ui-layout-horizontal">
<input
type="text"
ref={input_ref}
class="message-input"
class="message-input ui-element-standalone"
placeholder="Type a message..."
/>
<button type="submit" class="send-button">{"Send"}</button>
<button type="submit" class="ui-button ui-element-standalone">{"Send"}</button>
</form>
</div>
</div>
+35
View File
@@ -0,0 +1,35 @@
use yew::{function_component, html, Html, Properties};
use crate::API_URL;
#[derive(PartialEq, Properties)]
pub struct Props {
pub incident: String
}
#[function_component(Incidents)]
pub fn incidents(props: &Props) -> Html {
let content = match props.incident.as_str() {
"boats" => (
"The Boat Incident.",
"the boat incident involved many boats being dropped on panic attack's tower. he then proceedeed to accidentally blow himself up along with all his stuff using a tnt cannon."
),
_ => ("", "")
};
html! {
<div class="app-container">
<div class="meme-license-container" style="min-height: 500px;">
<div style="display: flex; flex-grow: 1; flex-direction: column; align-items: center; padding: 2rem; gap: 2rem">
<h1 style="font-size: 4vw; text-align: center">{content.0}</h1>
<div style="display: flex; flex-direction: column; align-items: left; width: max-content; justify-content: center">
<div style="display: flex; flex-direction: row; align-items: center; width: max-content; gap: 1rem">
<p style="text-align: left; width: 50vw; font-size: 1.5vw">{content.1}</p>
// <p style="text-align: left; width: max-content; font-size: 1.5vw">{value}</p>
</div>
</div>
</div>
</div>
</div>
}
}
+12 -11
View File
@@ -7,6 +7,7 @@ use web_sys::HtmlInputElement;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::spawn_local;
use crate::API_URL;
use crate::Route;
#[function_component(Login)]
@@ -32,7 +33,7 @@ pub fn login_page() -> Html {
let login_success = login_success_clone.clone();
spawn_local(async move {
match login(username, password).await {
Ok(_) => navigator.push(&Route::Chat),
Ok(_) => navigator.push(&Route::Chat { id: "test".to_string() }),
Err(_) => login_success.set(false),
}
});
@@ -47,12 +48,12 @@ pub fn login_page() -> Html {
};
html! {
<div class="login-container">
<form {onsubmit} class="login-form">
<h2 class="login-title">{"Login"}</h2>
<div class="form-container">
<form {onsubmit} class="form-form">
<h2 class="form-title">{"Login"}</h2>
<input
ref={username_ref}
class="login-input"
class="form-input"
type="text"
id="username"
name="username"
@@ -60,27 +61,27 @@ pub fn login_page() -> Html {
/>
<input
ref={password_ref}
class="login-input"
class="form-input"
type="password"
id="password"
name="password"
placeholder="Password"
/>
<button class="login-button" type="submit">{"Login"}</button>
<button class="form-button" type="submit">{"Login"}</button>
{
if !(*login_success) {
html! {
<p class="login-error">{"Incorrect username or password"}</p>
<p class="form-error">{"Incorrect username or password"}</p>
}
} else {
html! {}
}
}
<p class="login-text">{"Don't have an account?"}</p>
<p class="form-text">{"Don't have an account?"}</p>
<a onclick={go_to_signup}
href=""
class="login-button"
class="form-button"
>
{"Create Account"}
</a>
@@ -101,7 +102,7 @@ async fn login(username: String, password: String) -> Result<(), String> {
password,
};
match Request::post("http://127.0.0.1:8000/login")
match Request::post(format!("{API_URL}/login").as_str())
.json(&login_request)
.map_err(|e| e.to_string())?
.send()
+51
View File
@@ -0,0 +1,51 @@
use yew::{function_component, html, Html, Properties};
use crate::API_URL;
#[derive(PartialEq, Properties)]
pub struct Props {
pub username: String
}
#[function_component(MemeLicense)]
pub fn meme_license(props: &Props) -> Html {
html! {
<div class="app-container">
<div class="meme-license-container" style="min-height: 500px;">
<div class="profile-picture" style={ format!(
"background-image:
url('{API_URL}/static/pfp/{}.png'),
url('{API_URL}/static/public/default_pfp.png');
height: 25vw;
max-height: 100%;
width: revert;
aspect-ratio: 1/1;
border-radius: 40px 0px 40px 0px;
flex-shrink: 0;
box-shadow: 0 2px 8px var(--shadow-color);
",
props.username
)}></div>
<div style="display: flex; flex-grow: 1; flex-direction: column; align-items: center; padding: 2rem; gap: 2rem">
<h1 style="font-size: 4vw; text-align: center">{"Meme Stealing License"}</h1>
<div style="display: flex; flex-direction: column; align-items: left; width: max-content; justify-content: center">
{[
("Username", props.username.as_str()),
("Valid From", "2024"),
("Expires", "2026"),
("Issuer", "Steven"),
].iter()
.map(|(field, value)| html! {
<div style="display: flex; flex-direction: row; align-items: center; width: max-content; gap: 1rem">
<p style="text-align: left; width: 10vw; font-size: 1.5vw">{field}</p>
<p style="text-align: left; width: max-content; font-size: 1.5vw">{value}</p>
</div>
})
.collect::<Html>()
}
</div>
</div>
</div>
</div>
}
}
+43
View File
@@ -0,0 +1,43 @@
use yew::{function_component, html, use_context, Html, Callback};
use yew_router::hooks::use_navigator;
use crate::{
components::selector::Selector,
hooks::theme::{use_theme, Theme, ThemeManager}, Route
};
#[function_component(Navbar)]
pub fn navbar() -> Html {
let ctx = use_context::<ThemeManager>().unwrap();
let on_select_theme = {
Callback::from(move |selected: Theme| {
ctx.set_theme.emit(selected);
})
};
let go_to_route = {
let navigator = use_navigator().unwrap();
Callback::from(move |selected: Route| {
navigator.push(&selected);
})
};
html! {
<nav class="navbar ui-layout-horizontal">
<div class="nav-brand">{"ZXQ5.Dev"}</div>
<div style="width: 100%;"/>
<Selector<Theme>
text={"Theme".to_string()}
args={vec![Theme::Default, Theme::Light, Theme::Dark]}
onselect={on_select_theme}
/>
<Selector<Route>
text={"My Account".to_string()}
args={vec![Route::Login, Route::Signup]}
onselect={go_to_route}
/>
</nav>
}
}
+34
View File
@@ -0,0 +1,34 @@
use std::fmt::Display;
use yew::prelude::*;
use crate::components::button::Button;
#[derive(Properties, PartialEq)]
pub struct Props<T: Display + Clone + PartialEq + 'static> {
pub args: Vec<T>,
pub onselect: Callback<T>,
pub text: String,
}
#[function_component(Selector)]
pub fn selector<T: Display + Clone + PartialEq + 'static>(props: &Props<T>) -> Html {
html! {
<div class="selector">
<div class="selector-label">{&props.text}</div>
<div class="selector-items">
{props.args.iter().map(|arg| {
let onclick = {
let arg = arg.clone();
let onselect = props.onselect.clone();
Callback::from(move |_| {
onselect.emit(arg.clone())
})
};
html! {
<Button class={Some("selector-button".to_string())} text={arg.to_string()} onclick={onclick} />
}
}).collect::<Html>()}
</div>
</div>
}
}
+68
View File
@@ -0,0 +1,68 @@
use std::fmt::Display;
use gloo_net::http::Request;
use serde::{Deserialize, Serialize};
use yew::prelude::*;
use crate::{components::button::Button, API_URL};
#[derive(Clone, Debug, Serialize, Deserialize)]
struct Server {
id: String,
name: String,
}
#[function_component(ServerList)]
pub fn serverlist() -> Html {
let servers = use_state(|| Vec::<Server>::new());
{
let servers = servers.clone();
use_effect_with((), move |_| {
let servers = servers.clone();
wasm_bindgen_futures::spawn_local(async move {
let fetched = if let Ok(fetched) = Request::get(format!("{API_URL}/servers").as_str())
.send()
.await
{
fetched.json()
.await
.unwrap()
} else {
Vec::new()
};
servers.set(fetched);
});
})
}
let onselect = {
let servers = servers.clone();
Callback::from(move |server: Server| {
servers.set(vec![server]);
})
};
html! {
<div class="ui-server-list">
<p style="text-align: center; padding: 1rem;"> {"Servers"} </p>
{ servers.iter().map(|server| {
html! {
<Button
text={server.name.clone()}
onclick={
let onselect = onselect.clone();
let server = server.clone();
Callback::from(move |_| {
onselect.emit(server.clone());
})
}
class={Some("selector-button".to_string())}
/>
}
}).collect::<Html>() }
</div>
}
}
+33 -22
View File
@@ -7,7 +7,7 @@ use web_sys::HtmlInputElement;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::spawn_local;
use crate::Route;
use crate::{Route, API_URL};
#[function_component(Signup)]
pub fn signup_page() -> Html {
@@ -15,11 +15,13 @@ pub fn signup_page() -> Html {
let username_ref = use_node_ref();
let password_ref = use_node_ref();
let confirm_password_ref = use_node_ref();
let token_ref = use_node_ref();
let signup_error = use_state(|| None::<String>);
let navigator_clone = navigator.clone();
let username_ref_clone = username_ref.clone();
let password_ref_clone = password_ref.clone();
let token_ref_clone = token_ref.clone();
let confirm_password_ref_clone = confirm_password_ref.clone();
let signup_error_clone = signup_error.clone();
@@ -28,8 +30,9 @@ pub fn signup_page() -> Html {
let username = username_ref_clone.cast::<HtmlInputElement>().unwrap().value();
let password = password_ref_clone.cast::<HtmlInputElement>().unwrap().value();
let confirm_password = confirm_password_ref_clone.cast::<HtmlInputElement>().unwrap().value();
let token = token_ref_clone.cast::<HtmlInputElement>().unwrap().value();
if username.is_empty() || password.is_empty() {
if username.is_empty() || password.is_empty() || token.is_empty() {
signup_error_clone.set(Some("Please fill in all fields".to_string()));
return;
}
@@ -42,8 +45,12 @@ pub fn signup_page() -> Html {
let navigator = navigator_clone.clone();
let signup_error = signup_error_clone.clone();
spawn_local(async move {
match signup(username, password).await {
Ok(_) => navigator.push(&Route::Chat),
match signup(SignupRequest {
username,
password,
token
}).await {
Ok(_) => navigator.push(&Route::Chat { id: "test".to_string() }),
Err(e) => signup_error.set(Some(e)),
}
});
@@ -57,12 +64,12 @@ pub fn signup_page() -> Html {
};
html! {
<div class="login-container">
<form {onsubmit} class="login-form">
<h2 class="login-title">{"Sign Up"}</h2>
<div class="form-container">
<form {onsubmit} class="form-form">
<h2 class="form-title">{"Sign Up"}</h2>
<input
ref={username_ref}
class="login-input"
class="form-input"
type="text"
id="username"
name="username"
@@ -70,7 +77,7 @@ pub fn signup_page() -> Html {
/>
<input
ref={password_ref}
class="login-input"
class="form-input"
type="password"
id="password"
name="password"
@@ -78,27 +85,35 @@ pub fn signup_page() -> Html {
/>
<input
ref={confirm_password_ref}
class="login-input"
class="form-input"
type="password"
id="confirm_password"
name="confirm_password"
placeholder="Confirm Password"
/>
<button class="login-button" type="submit">{"Sign Up"}</button>
<input
ref={token_ref}
class="form-input"
type="password"
id="access_token"
name="access_token"
placeholder="Access Token"
/>
<button class="form-button" type="submit">{"Sign Up"}</button>
{
if let Some(error) = (*signup_error).clone() {
html! {
<p class="login-error">{error}</p>
<p class="form-error">{error}</p>
}
} else {
html! {}
}
}
<p class="login-text">{"Already have an account?"}</p>
<p class="form-text">{"Already have an account?"}</p>
<a onclick={go_to_login}
href=""
class="login-button"
class="form-button"
>
{"Login"}
</a>
@@ -111,16 +126,12 @@ pub fn signup_page() -> Html {
struct SignupRequest {
username: String,
password: String,
token: String,
}
async fn signup(username: String, password: String) -> Result<(), String> {
let signup_request = SignupRequest {
username,
password,
};
match Request::post("http://127.0.0.1:8000/signup")
.json(&signup_request)
async fn signup(req: SignupRequest) -> Result<(), String> {
match Request::post(format!("{API_URL}/signup").as_str())
.json(&req)
.map_err(|e| e.to_string())?
.send()
.await
+73
View File
@@ -0,0 +1,73 @@
use std::fmt;
use yew::prelude::*;
use web_sys;
use gloo::console::log;
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum Theme {
Default,
Light,
Dark,
}
impl Theme {
pub fn as_str(&self) -> &'static str {
match self {
Theme::Default => "default",
Theme::Light => "light",
Theme::Dark => "dark",
}
}
}
impl fmt::Display for Theme {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.as_str())
}
}
#[derive(Clone, PartialEq)]
pub struct ThemeManager {
pub current: Theme,
pub set_theme: Callback<Theme>,
}
impl ThemeManager {
pub fn new(set_theme: Callback<Theme>) -> Self {
Self {
current: Theme::Default,
set_theme,
}
}
}
#[derive(Clone)]
pub struct UseThemeHandle {
pub set_theme: Callback<Theme>,
}
#[hook]
pub fn use_theme(initial: Theme) -> UseThemeHandle {
let theme = use_state(|| initial);
let set_theme = {
let theme = theme.clone();
Callback::from(move |new_theme: Theme| {
if let Some(window) = web_sys::window() {
if let Some(doc) = window.document() {
if let Some(body) = doc.body() {
if let Err(e) = body.set_attribute("theme", new_theme.as_str()) {
log!("Failed to set theme:", e);
}
}
}
}
theme.set(new_theme);
})
};
UseThemeHandle {
set_theme,
}
}
+95 -12
View File
@@ -1,21 +1,49 @@
use hooks::theme::{use_theme, Theme, ThemeManager};
use yew::prelude::*;
use yew_router::prelude::*;
use gloo::storage::{LocalStorage, Storage};
use gloo::{console::log, storage::{LocalStorage, Storage}};
#[cfg(debug_assertions)]
pub(crate) const API_URL: &str = "http://localhost:8000";
#[cfg(debug_assertions)]
pub(crate) const WS_URL: &str = "ws://localhost:8000";
#[cfg(not(debug_assertions))]
pub(crate) const API_URL: &str = "https://api.zxq5.dev";
#[cfg(not(debug_assertions))]
pub(crate) const WS_URL: &str = "wss://api.zxq5.dev";
mod hooks {
pub mod websocket;
pub mod theme;
}
mod components {
pub mod chat;
pub mod signup;
pub mod login;
pub mod navbar;
pub mod button;
pub mod selector;
pub mod serverlist;
pub mod meme_license;
pub mod incidents;
pub mod form;
}
use components::{
chat::Chat,
login::Login,
signup::Signup,
navbar::Navbar,
button::Button,
selector::Selector,
serverlist::ServerList,
meme_license::MemeLicense,
incidents::Incidents,
form::Form,
};
#[derive(Clone, Routable, PartialEq)]
@@ -26,35 +54,90 @@ enum Route {
Login,
#[at("/signup")]
Signup,
#[at("/chat")]
Chat,
#[at("/chat/:id")]
Chat { id: String },
#[at("/profile")]
Profile,
#[at("/logout")]
Logout,
#[at("/invite")]
Invite,
#[at("/license/:username")]
MemeLicense { username: String },
#[at("/incidents/:incident")]
Incidents { incident: String },
#[not_found]
#[at("/404")]
NotFound,
}
impl std::fmt::Display for Route {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", match self {
Route::Root => "Home",
Route::Login => "Login",
Route::Signup => "Signup",
Route::Chat { id: _ } => "Chat",
Route::NotFound => "404",
Route::Profile => "Profile",
Route::Logout => "Logout",
Route::Invite => "Invite",
Route::MemeLicense { username: _ } => "Meme License",
Route::Incidents { incident: _ } => "Incidents",
})
}
}
fn switch(route: Route) -> Html {
match route {
// // check if user is logged in
// if user not logged in:
// html! {}
html ! {
<div class="base-container">
<Navbar/>
{ match route {
Route::Root => html! { <Redirect<Route> to={Route::Login}/> },
Route::Login => html! { <Login /> },
Route::Signup => html! { <Signup /> },
Route::Chat => {
if let Ok(token) = LocalStorage::get::<String>("auth_token") {
html! { <Chat /> }
} else {
html! { <Redirect<Route> to={Route::Login}/> }
}
}
Route::NotFound => html! { <h1>{"404 Not Found"}</h1> },
// Route::Chat { id: token } => {
// if let Ok(token) = LocalStorage::get::<String>("auth-token") {
// html! { <Chat id={token}/> }
// } else {
// html! { <Redirect<Route> to={Route::Login}/> }
// }
// }
Route::Chat { id: token } => html! { <Chat id={token}/> },
Route::Incidents { incident: incident } => html! { <Incidents incident={incident}/> },
Route::MemeLicense { username: username } => html! { <MemeLicense username={username}/> },
_ => html! { <h1>{"404 Not Found"}</h1> },
}}
</div>
}
}
#[function_component(App)]
fn app() -> Html {
let theme_handle = use_theme(Theme::Default);
let ctx = use_state(|| ThemeManager::new(theme_handle.set_theme));
{
let ctx = ctx.clone();
use_effect_with((), move |_| {
ctx.set_theme.emit(Theme::Default);
});
}
html! {
<ContextProvider<ThemeManager> context={(*ctx).clone()}>
<BrowserRouter>
<Switch<Route> render={switch} />
</BrowserRouter>
</ContextProvider<ThemeManager>>
}
}
@@ -1,30 +1,4 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--blur-amount: 10px;
--border-radius: 15px;
--glow-color: rgba(255, 255, 255, 0.3);
--message-bubble-color: rgba(255, 255, 255, 0.1);
--border-color: rgba(255, 255, 255, 0.1);
--shadow-color: rgba(0, 0, 0, 0.2);
}
html, body {
margin: 0;
padding: 0;
height: 100vh;
width: 100%;
overflow: hidden;
background: linear-gradient(135deg, #1a2a6c, #2a4858, #141E30);
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
color: white;
}
.app-container {
.base-container {
height: 100vh;
width: 100vw;
display: flex;
@@ -32,17 +6,18 @@ html, body {
overflow: hidden;
}
.chat-container {
.app-container {
flex: 1;
margin: 0 2rem;
padding: 1rem;
display: flex;
flex-direction: column;
gap: 1rem;
width: 100%;
width: calc(100% - 4rem);
max-width: 1400px;
margin-left: auto;
margin-right: auto;
height: calc(100vh - 80px); /* Account for navbar height */
overflow: hidden;
}
@@ -60,6 +35,37 @@ html, body {
flex-direction: column;
gap: 1rem;
width: 100%;
min-height: 0; /* This is crucial for flex child scrolling */
}
.meme-license-container {
flex: 1;
overflow-y: auto;
padding: 0;
background: rgba(255, 255, 255, 0.05);
backdrop-filter: blur(var(--blur-amount));
-webkit-backdrop-filter: blur(var(--blur-amount));
border-radius: 40px;
border: 1px solid var(--border-color);
box-shadow: 0 4px 24px var(--shadow-color);
display: flex;
flex-direction: row;
gap: 1rem;
width: 100%;
min-height: 0; /* This is crucial for flex child scrolling */
}
.ui-server-list {
height: 100%;
overflow-y: auto;
margin: 16px;
padding: 1rem;
background: rgba(255, 255, 255, 0.05);
backdrop-filter: blur(var(--blur-amount));
-webkit-backdrop-filter: blur(var(--blur-amount));
border-radius: var(--border-radius);
border: 1px solid var(--border-color);
box-shadow: 0 4px 24px var(--shadow-color);
}
.message {
@@ -103,17 +109,17 @@ html, body {
.username {
font-weight: 600;
font-size: 0.9rem;
color: #fff;
color: var(--text-color, #fff);
text-shadow: 0 2px 4px var(--shadow-color);
}
.timestamp {
color: rgba(255, 255, 255, 0.6);
color: var(--text-secondary, rgba(255, 255, 255, 0.6));
font-size: 0.8rem;
}
.message-content {
color: rgba(255, 255, 255, 0.9);
color: var(--text-color, rgba(255, 255, 255, 0.9));
font-size: 0.95rem;
}
@@ -132,41 +138,68 @@ html, body {
.message-input {
flex: 1;
background: rgba(255, 255, 255, 0.1);
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
padding: 0.8rem 1rem;
color: white;
background: var(--background-element, rgba(255, 255, 255, 0.1));
border: none;
padding: 0.4rem 1.5rem;
color: var(--text-color, white);
font-size: 1rem;
resize: vertical;
min-height: 1.5rem;
max-height: 150px;
transition: all 0.3s ease;
box-shadow: 0 2px 8px var(--shadow-color);
}
.message-input:hover, .message-input:focus {
border-color: var(--glow-color);
box-shadow: 0 0 15px var(--glow-color);
outline: none;
background-color: rgba(255, 255, 255, 0.3);
}
.send-button {
background: rgba(255, 255, 255, 0.1);
.ui-button {
background: var(--background-element, rgba(255, 255, 255, 0.1));
padding: 0.4rem 1.5rem;
color: var(--text-color, white);
font-size: 1rem;
cursor: pointer;
border: none;
transition: all 0.3s ease;
}
.ui-group {
display: flex;
flex-direction: row;
background: var(--background-element, rgba(255, 255, 255, 0.1));
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
width: 100%;
color: var(--text-color, white);
font-size: 1rem;
transition: all 0.3s ease;
box-shadow: 0 2px 8px var(--shadow-color);
overflow: hidden;
}
.ui-layout-horizontal {
display: flex;
flex-direction: row;
gap: 1rem;
margin: 0;
padding: 0;
width: 100%;
}
.ui-element-standalone {
background: var(--background-element, rgba(255, 255, 255, 0.1));
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
padding: 0.8rem 1.5rem;
color: white;
color: var(--text-color, white);
font-size: 1rem;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 2px 8px var(--shadow-color);
}
.send-button:hover {
border-color: var(--glow-color);
box-shadow: 0 0 15px var(--glow-color);
background: rgba(255, 255, 255, 0.2);
.ui-button:hover {
background-color: rgba(255, 255, 255, 0.3);
}
.navbar {
@@ -174,122 +207,113 @@ html, body {
justify-content: space-between;
align-items: center;
padding: 1rem 2rem;
background: rgba(255, 255, 255, 0.1);
background: var(--background-element, rgba(255, 255, 255, 0.1));
backdrop-filter: blur(var(--blur-amount));
-webkit-backdrop-filter: blur(var(--blur-amount));
border: none;
border-bottom: 1px solid var(--border-color);
box-shadow: 0 4px 24px var(--shadow-color);
margin: 0;
box-shadow: 0 2px 8px var(--shadow-color);
position: relative;
z-index: 1000;
}
.nav-brand {
font-size: 1.5rem;
font-weight: bold;
color: white;
text-shadow: 0 2px 4px var(--shadow-color);
white-space: nowrap;
}
/* Login styles */
.login-container {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 90%;
max-width: 400px;
}
.login-form {
display: flex;
flex-direction: column;
gap: 1rem;
padding: 2rem;
background: rgba(255, 255, 255, 0.1);
.selector {
position: relative;
display: inline-block;
background: rgba(255, 255, 255, 0.01);
width: max-content;
/* background: var(--background-element, rgba(255, 255, 255, 0.1)); */
backdrop-filter: blur(var(--blur-amount));
-webkit-backdrop-filter: blur(var(--blur-amount));
border-radius: var(--border-radius);
border: 1px solid var(--border-color);
box-shadow: 0 4px 24px var(--shadow-color);
}
.login-title {
font-size: 1.5rem;
font-weight: bold;
text-align: center;
color: white;
text-shadow: 0 2px 4px var(--shadow-color);
margin-bottom: 1rem;
}
.login-input {
background: rgba(255, 255, 255, 0.1);
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
padding: 0.8rem 1rem;
color: white;
font-size: 1rem;
transition: all 0.3s ease;
box-shadow: 0 2px 8px var(--shadow-color);
}
.login-input:hover, .login-input:focus {
border-color: var(--glow-color);
box-shadow: 0 0 15px var(--glow-color);
outline: none;
}
.login-input::placeholder {
color: rgba(255, 255, 255, 0.6);
}
.login-button {
background: rgba(255, 255, 255, 0.1);
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
padding: 0.8rem 1.5rem;
color: white;
color: var(--text-color, white);
font-size: 1rem;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 2px 8px var(--shadow-color);
text-align: center;
text-decoration: none;
z-index: 1001;
}
.login-button:hover {
border-color: var(--glow-color);
box-shadow: 0 0 15px var(--glow-color);
background: rgba(255, 255, 255, 0.2);
}
.selector-items {
display: none;
position: absolute;
top: calc(100% + 1px);
left: -1px;
right: -1px;
.login-text {
color: rgba(255, 255, 255, 0.9);
text-align: center;
margin: 0.5rem 0;
}
.login-link {
color: white;
text-decoration: none;
transition: all 0.3s ease;
}
.login-link:hover {
text-shadow: 0 0 10px var(--glow-color);
}
.login-error {
background: rgba(255, 0, 0, 0.1);
border: 1px solid rgba(255, 0, 0, 0.3);
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
padding: 0.8rem 1.5rem;
color: white;
font-size: 1rem;
text-align: center;
box-shadow: 0 4px 12px var(--shadow-color);
z-index: 1002;
backdrop-filter: blur(var(--blur-amount));
-webkit-backdrop-filter: blur(var(--blur-amount));
box-shadow: 0 2px 8px var(--shadow-color);
overflow: hidden;
}
.selector:hover .selector-items {
display: block;
}
.selector-button {
background: none;
width: 100%;
padding: 0.4rem 1.5rem;
border: none;
color: var(--text-color, white);
font-size: 0.9rem;
cursor: pointer;
transition: all 0.2s ease;
text-align: center;
white-space: nowrap;
}
.selector-label {
background: none;
width: 100%;
padding: 0.4rem 1.5rem;
border: none;
color: var(--text-color, white);
font-size: 0.9rem;
cursor: pointer;
transition: all 0.2s ease;
text-align: center;
white-space: nowrap;
position: relative;
padding-right: 2rem;
border-radius: var(--border-radius);
}
.selector-label::after {
content: "▼";
position: absolute;
right: 0.8rem;
top: 50%;
transform: translateY(-50%);
font-size: 0.8rem;
opacity: 0.7;
}
.selector-button:hover {
color: var(--glow-color);
background-color: rgba(255, 255, 255, 0.1);
}
.selector-button.active {
color: var(--glow-color);
font-weight: 500;
}
/* Custom scrollbar */
+104
View File
@@ -0,0 +1,104 @@
/* Form styles */
.form-container {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 90%;
max-width: 400px;
}
.form-form {
display: flex;
flex-direction: column;
gap: 1rem;
padding: 2rem;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(var(--blur-amount));
-webkit-backdrop-filter: blur(var(--blur-amount));
border-radius: var(--border-radius);
border: 1px solid var(--border-color);
box-shadow: 0 4px 24px var(--shadow-color);
}
.form-title {
font-size: 1.5rem;
font-weight: bold;
text-align: center;
color: var(--text-color);
text-shadow: 0 2px 4px var(--shadow-color);
margin-bottom: 1rem;
}
.form-input {
background: rgba(255, 255, 255, 0.1);
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
padding: 0.8rem 1rem;
color: var(--text-color);
font-size: 1rem;
transition: all 0.3s ease;
box-shadow: 0 2px 8px var(--shadow-color);
}
.form-input:hover, .form-input:focus {
border-color: var(--glow-color);
box-shadow: 0 0 15px var(--glow-color);
outline: none;
}
.form-input::placeholder {
color: var(--text-color);
text-align: center;
}
.form-button {
background: rgba(255, 255, 255, 0.1);
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
padding: 0.8rem 1.5rem;
color: var(--text-color);
font-size: 1rem;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 2px 8px var(--shadow-color);
text-align: center;
text-decoration: none;
}
.form-button:hover {
border-color: var(--glow-color);
box-shadow: 0 0 15px var(--glow-color);
background: rgba(255, 255, 255, 0.2);
}
.form-text {
color: var(--text-color);
text-align: center;
margin: 0.5rem 0;
}
.form-link {
color: var(--text-color);
text-decoration: none;
transition: all 0.3s ease;
}
.form-link:hover {
text-shadow: 0 0 10px var(--glow-color);
}
.form-error {
background: rgba(255, 0, 0, 0.1);
border: 1px solid rgba(255, 0, 0, 0.3);
border-radius: var(--border-radius);
padding: 0.8rem 1.5rem;
color: var(--text-color);
font-size: 1rem;
text-align: center;
backdrop-filter: blur(var(--blur-amount));
-webkit-backdrop-filter: blur(var(--blur-amount));
box-shadow: 0 2px 8px var(--shadow-color);
}
+45
View File
@@ -0,0 +1,45 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
--blur-amount: 10px;
--border-radius: 15px;
--shadow-color: rgba(0, 0, 0, 0.4);
}
*[theme="default"] {
--background: linear-gradient(135deg, #1a2a6c, #2a4858, #141E30);
--glow-color: rgba(255, 255, 255, 0.3);
--message-bubble-color: rgba(255, 255, 255, 0.1);
--border-color: rgba(255, 255, 255, 0.1);
--text-color: #ffffff;
}
*[theme="light"] {
--background: #ffffff;
--glow-color: rgba(100, 149, 237, 0.3);
--message-bubble-color: rgba(100, 149, 237, 0.1);
--border-color: rgba(100, 149, 237, 0.2);
--text-color: #000000;
}
*[theme="dark"] {
--background: linear-gradient(135deg, #121212, #1a1a1a, #232323);
--glow-color: rgba(147, 112, 219, 0.4);
--message-bubble-color: rgba(147, 112, 219, 0.15);
--border-color: rgba(255, 255, 255, 0.1);
--text-color: #ffffff;
}
html, body {
margin: 0;
padding: 0;
height: 100vh;
width: 100%;
overflow: hidden;
background: var(--background);
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
color: var(--text-color, white);
}