Experimental Calckey frontend serving

This commit is contained in:
Natty 2023-07-07 21:22:30 +02:00
parent 08f9681d64
commit d6091bffee
Signed by: natty
GPG Key ID: BF6CB659ADEE60EC
860 changed files with 169468 additions and 96 deletions

3
.dev/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
data
config
logs

32
.dev/Caddyfile Normal file
View File

@ -0,0 +1,32 @@
nattyarch.local {
log {
}
handle /.well-known/webfinger {
reverse_proxy 127.0.0.1:4939
}
handle /.well-known/nodeinfo {
reverse_proxy 127.0.0.1:4939
}
handle /nodeinfo/* {
reverse_proxy 127.0.0.1:4939
}
@render_html {
not path /api* /proxy* /files* /avatar* /identicon*
header Accept text/html*
}
@static {
path /favicon.ico /favicon.png /favicon.svg /manifest.json /api-doc /sw.js /static-assets* /client-assets* /assets* /twemoji* /url
}
reverse_proxy @render_html 127.0.0.1:4938
reverse_proxy @static 127.0.0.1:4938
reverse_proxy 127.0.0.1:4937
}

14
.dev/docker-compose.yaml Normal file
View File

@ -0,0 +1,14 @@
version: "3"
services:
caddy:
image: docker.io/caddy:2.6.2-alpine
restart: unless-stopped
ports:
- "80:80"
network_mode: "host"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- ./data:/data
- ./config:/config
- ./logs:/logs

22
.dockerignore Normal file
View File

@ -0,0 +1,22 @@
*.log
npm-debug.log*
.pnpm-debug.log*
/fe_calckey/frontend/built
node_modules/
.npm
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
.temp
.cache
.pnp.*
/target

467
Cargo.lock generated
View File

@ -30,6 +30,24 @@ dependencies = [
"version_check",
]
[[package]]
name = "aho-corasick"
version = "0.7.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
dependencies = [
"memchr",
]
[[package]]
name = "aho-corasick"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41"
dependencies = [
"memchr",
]
[[package]]
name = "aliasable"
version = "0.1.3"
@ -45,12 +63,6 @@ dependencies = [
"libc",
]
[[package]]
name = "anyhow"
version = "1.0.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
[[package]]
name = "arrayvec"
version = "0.7.2"
@ -116,6 +128,7 @@ dependencies = [
"bitflags",
"bytes",
"futures-util",
"headers",
"http",
"http-body",
"hyper",
@ -262,6 +275,16 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "bstr"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6798148dccfbff0fae41c7574d2fa8f1ef3492fba0face179de5d8d447d67b05"
dependencies = [
"memchr",
"serde",
]
[[package]]
name = "bumpalo"
version = "3.12.2"
@ -330,6 +353,28 @@ dependencies = [
"winapi",
]
[[package]]
name = "chrono-tz"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29c39203181991a7dd4343b8005bd804e7a9a37afb8ac070e43771e8c820bbde"
dependencies = [
"chrono",
"chrono-tz-build",
"phf",
]
[[package]]
name = "chrono-tz-build"
version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f509c3a87b33437b05e2458750a0700e5bdd6956176773e6c7d6dd15a283a0c"
dependencies = [
"parse-zoneinfo",
"phf",
"phf_codegen",
]
[[package]]
name = "ck"
version = "0.1.0"
@ -382,6 +427,12 @@ dependencies = [
"typenum",
]
[[package]]
name = "deunicode"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "850878694b7933ca4c9569d30a34b55031b9b139ee1fc7b94a527c4ef960d690"
[[package]]
name = "digest"
version = "0.10.6"
@ -549,6 +600,30 @@ dependencies = [
"wasi 0.11.0+wasi-snapshot-preview1",
]
[[package]]
name = "globset"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc"
dependencies = [
"aho-corasick 0.7.20",
"bstr",
"fnv",
"log",
"regex",
]
[[package]]
name = "globwalk"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93e3af942408868f6934a7b85134a3230832b9977cf66125df2f9edcfce4ddcc"
dependencies = [
"bitflags",
"ignore",
"walkdir",
]
[[package]]
name = "h2"
version = "0.3.20"
@ -595,6 +670,31 @@ dependencies = [
"hashbrown 0.13.2",
]
[[package]]
name = "headers"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3e372db8e5c0d213e0cd0b9be18be2aca3d44cf2fe30a9d46a65581cd454584"
dependencies = [
"base64 0.13.1",
"bitflags",
"bytes",
"headers-core",
"http",
"httpdate",
"mime",
"sha1",
]
[[package]]
name = "headers-core"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429"
dependencies = [
"http",
]
[[package]]
name = "heck"
version = "0.3.3"
@ -686,6 +786,12 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]]
name = "humansize"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02296996cb8796d7c6e3bc2d9211b7802812d36999a51bb754123ead7d37d026"
[[package]]
name = "hyper"
version = "0.14.26"
@ -743,6 +849,23 @@ dependencies = [
"unicode-normalization",
]
[[package]]
name = "ignore"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492"
dependencies = [
"globset",
"lazy_static",
"log",
"memchr",
"regex",
"same-file",
"thread_local",
"walkdir",
"winapi-util",
]
[[package]]
name = "indexmap"
version = "1.9.3"
@ -819,19 +942,44 @@ dependencies = [
[[package]]
name = "magnetar"
version = "0.1.1"
version = "0.2.0"
dependencies = [
"anyhow",
"axum",
"dotenvy",
"hyper",
"magnetar_calckey_model",
"magnetar_common",
"magnetar_core",
"magnetar_nodeinfo",
"magnetar_webfinger",
"miette",
"percent-encoding",
"serde",
"serde_json",
"thiserror",
"tokio",
"toml 0.7.4",
"tower",
"tower-http",
"tracing",
"tracing-subscriber",
]
[[package]]
name = "magnetar_calckey_fe"
version = "0.2.0"
dependencies = [
"axum",
"chrono",
"dotenvy",
"hyper",
"magnetar_common",
"miette",
"percent-encoding",
"serde",
"serde_json",
"tera",
"thiserror",
"tokio",
"toml 0.7.4",
"tower",
@ -842,31 +990,41 @@ dependencies = [
[[package]]
name = "magnetar_calckey_model"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"anyhow",
"chrono",
"ck",
"dotenvy",
"log",
"sea-orm",
"serde",
"serde_json",
"thiserror",
"tokio",
"tracing",
]
[[package]]
name = "magnetar_common"
version = "0.2.0"
dependencies = [
"magnetar_core",
"percent-encoding",
"serde",
"thiserror",
"toml 0.7.4",
]
[[package]]
name = "magnetar_core"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"serde",
"serde_json",
"url",
]
[[package]]
name = "magnetar_nodeinfo"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"serde",
"serde_json",
@ -874,7 +1032,7 @@ dependencies = [
[[package]]
name = "magnetar_webfinger"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"magnetar_core",
"serde",
@ -911,12 +1069,45 @@ version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "miette"
version = "5.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a236ff270093b0b67451bc50a509bd1bad302cb1d3c7d37d5efe931238581fa9"
dependencies = [
"miette-derive",
"once_cell",
"thiserror",
"unicode-width",
]
[[package]]
name = "miette-derive"
version = "5.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4901771e1d44ddb37964565c654a3223ba41a594d02b8da471cc4464912b5cfa"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.16",
]
[[package]]
name = "mime"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
name = "mime_guess"
version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef"
dependencies = [
"mime",
"unicase",
]
[[package]]
name = "minimal-lexical"
version = "0.2.1"
@ -1078,6 +1269,15 @@ dependencies = [
"windows-sys 0.45.0",
]
[[package]]
name = "parse-zoneinfo"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c705f256449c60da65e11ff6626e0c16a0a0b96aaa348de61376b249bc340f41"
dependencies = [
"regex",
]
[[package]]
name = "paste"
version = "1.0.12"
@ -1090,6 +1290,89 @@ version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
[[package]]
name = "pest"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f73935e4d55e2abf7f130186537b19e7a4abc886a0252380b59248af473a3fc9"
dependencies = [
"thiserror",
"ucd-trie",
]
[[package]]
name = "pest_derive"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aef623c9bbfa0eedf5a0efba11a5ee83209c326653ca31ff019bec3a95bfff2b"
dependencies = [
"pest",
"pest_generator",
]
[[package]]
name = "pest_generator"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3e8cba4ec22bada7fc55ffe51e2deb6a0e0db2d0b7ab0b103acc80d2510c190"
dependencies = [
"pest",
"pest_meta",
"proc-macro2",
"quote",
"syn 2.0.16",
]
[[package]]
name = "pest_meta"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a01f71cb40bd8bb94232df14b946909e14660e33fc05db3e50ae2a82d7ea0ca0"
dependencies = [
"once_cell",
"pest",
"sha2",
]
[[package]]
name = "phf"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc"
dependencies = [
"phf_shared",
]
[[package]]
name = "phf_codegen"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a"
dependencies = [
"phf_generator",
"phf_shared",
]
[[package]]
name = "phf_generator"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0"
dependencies = [
"phf_shared",
"rand",
]
[[package]]
name = "phf_shared"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b"
dependencies = [
"siphasher",
"uncased",
]
[[package]]
name = "pin-project"
version = "1.1.0"
@ -1261,6 +1544,8 @@ version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af83e617f331cc6ae2da5443c602dfa5af81e517212d9d611a5b3ba1777b5370"
dependencies = [
"aho-corasick 1.0.2",
"memchr",
"regex-syntax 0.7.1",
]
@ -1388,6 +1673,15 @@ version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]]
name = "scopeguard"
version = "1.1.0"
@ -1624,6 +1918,12 @@ version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a"
[[package]]
name = "siphasher"
version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
[[package]]
name = "slab"
version = "0.4.8"
@ -1633,6 +1933,15 @@ dependencies = [
"autocfg",
]
[[package]]
name = "slug"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3bc762e6a4b6c6fcaade73e77f9ebc6991b676f88bb2358bddb56560f073373"
dependencies = [
"deunicode",
]
[[package]]
name = "smallvec"
version = "1.10.0"
@ -1814,6 +2123,28 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
[[package]]
name = "tera"
version = "1.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3df578c295f9ec044ff1c829daf31bb7581d5b3c2a7a3d87419afe1f2531438c"
dependencies = [
"chrono",
"chrono-tz",
"globwalk",
"humansize",
"lazy_static",
"percent-encoding",
"pest",
"pest_derive",
"rand",
"regex",
"serde",
"serde_json",
"slug",
"unic-segment",
]
[[package]]
name = "thiserror"
version = "1.0.40"
@ -2035,7 +2366,13 @@ dependencies = [
"http",
"http-body",
"http-range-header",
"httpdate",
"mime",
"mime_guess",
"percent-encoding",
"pin-project-lite",
"tokio",
"tokio-util",
"tower-layer",
"tower-service",
"tracing",
@ -2128,6 +2465,80 @@ version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
[[package]]
name = "ucd-trie"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81"
[[package]]
name = "uncased"
version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b9bc53168a4be7402ab86c3aad243a84dd7381d09be0eddc81280c1da95ca68"
dependencies = [
"version_check",
]
[[package]]
name = "unic-char-property"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8c57a407d9b6fa02b4795eb81c5b6652060a15a7903ea981f3d723e6c0be221"
dependencies = [
"unic-char-range",
]
[[package]]
name = "unic-char-range"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0398022d5f700414f6b899e10b8348231abf9173fa93144cbc1a43b9793c1fbc"
[[package]]
name = "unic-common"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80d7ff825a6a654ee85a63e80f92f054f904f21e7d12da4e22f9834a4aaa35bc"
[[package]]
name = "unic-segment"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4ed5d26be57f84f176157270c112ef57b86debac9cd21daaabbe56db0f88f23"
dependencies = [
"unic-ucd-segment",
]
[[package]]
name = "unic-ucd-segment"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2079c122a62205b421f499da10f3ee0f7697f012f55b675e002483c73ea34700"
dependencies = [
"unic-char-property",
"unic-char-range",
"unic-ucd-version",
]
[[package]]
name = "unic-ucd-version"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96bd2f2237fe450fcd0a1d2f5f4e91711124f7857ba2e964247776ebeeb7b0c4"
dependencies = [
"unic-common",
]
[[package]]
name = "unicase"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
dependencies = [
"version_check",
]
[[package]]
name = "unicode-bidi"
version = "0.3.13"
@ -2155,6 +2566,12 @@ version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"
[[package]]
name = "unicode-width"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
[[package]]
name = "unicode_categories"
version = "0.1.1"
@ -2176,7 +2593,6 @@ dependencies = [
"form_urlencoded",
"idna",
"percent-encoding",
"serde",
]
[[package]]
@ -2200,6 +2616,16 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "walkdir"
version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698"
dependencies = [
"same-file",
"winapi-util",
]
[[package]]
name = "want"
version = "0.3.0"
@ -2331,6 +2757,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"

View File

@ -1,9 +1,9 @@
[package]
name = "magnetar"
description = "An exploratory ActivityPub project"
version = "0.1.1"
version.workspace = true
edition.workspace = true
license = "AGPL-3.0-only"
edition = "2021"
[workspace]
members = [
@ -11,31 +11,60 @@ members = [
"ext_nodeinfo",
"ext_webfinger",
"ext_calckey_model",
"fe_calckey",
"magnetar_common",
"core"
]
[dependencies]
magnetar_core = { path = "./core", version = "0.1" }
magnetar_webfinger = { path = "./ext_webfinger", version = "0.1"}
magnetar_nodeinfo = { path = "./ext_nodeinfo", version = "0.1"}
magnetar_calckey_model = { path = "./ext_calckey_model", version = "0.1" }
anyhow = "1.0"
dotenvy = "0.15"
[workspace.package]
version = "0.2.0"
edition = "2021"
[workspace.dependencies]
axum = "0.6"
hyper = { version = "0.14", features = ["full"] }
tokio = { version = "1.24", features = ["full"] }
tower = "0.4"
tower-http = { version = "0.4", features = ["cors", "trace"] }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing = "0.1"
chrono = "0.4"
dotenvy = "0.15"
hyper = "0.14"
log = "0.4"
miette = "5.9"
percent-encoding = "2.2"
serde = { version = "1.0", features = ["derive"] }
sea-orm = "0.11"
serde = "1"
serde_json = "1"
tera = { version = "1", default-features = false }
thiserror = "1"
tokio = "1.24"
toml = "0.7"
tower = "0.4"
tower-http = "0.4"
tracing = "0.1"
tracing-subscriber = "0.3"
url = "2.3"
serde_json = "1.0"
[dependencies]
magnetar_core = { path = "./core" }
magnetar_common = { path = "./magnetar_common" }
magnetar_webfinger = { path = "./ext_webfinger" }
magnetar_nodeinfo = { path = "./ext_nodeinfo" }
magnetar_calckey_model = { path = "./ext_calckey_model" }
dotenvy = { workspace = true }
axum = { workspace = true }
hyper = { workspace = true, features = ["full"] }
tokio = { workspace = true, features = ["full"] }
tower = { workspace = true }
tower-http = { workspace = true, features = ["cors", "trace", "fs"] }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
tracing = { workspace = true }
thiserror = { workspace = true }
miette = { workspace = true }
percent-encoding = { workspace = true }
serde = { workspace = true, features = ["derive"] }
toml = { workspace = true }
serde_json = { workspace = true }

View File

@ -1,3 +1,16 @@
FROM docker.io/alpine:3.18 as build_fe
RUN apk add --no-cache --no-progress git alpine-sdk nodejs-current npm
WORKDIR /fe_calckey
COPY ./fe_calckey/frontend ./frontend
WORKDIR /fe_calckey/frontend
RUN corepack enable && corepack prepare pnpm@latest --activate && pnpm i --frozen-lockfile
RUN env NODE_ENV=production sh -c "pnpm run build && pnpm run gulp"
FROM docker.io/rust:1.69-bullseye as build
RUN update-ca-certificates
@ -17,7 +30,7 @@ WORKDIR /magnetar
COPY ./ .
RUN cargo build --release --locked
RUN cargo build --release --locked --workspace --bins
FROM docker.io/debian:bullseye-slim
@ -28,12 +41,22 @@ COPY --from=build /etc/group /etc/group
WORKDIR /magnetar
WORKDIR /magnetar/fe_calckey/frontend
COPY --from=build_fe /fe_calckey/frontend/built ./built
COPY --from=build_fe /fe_calckey/frontend/assets ./assets
COPY --from=build_fe /fe_calckey/frontend/client/assets ./client/assets
COPY --from=build_fe /fe_calckey/frontend/assets-be ./assets-be
WORKDIR /magnetar
RUN chown -R 10001:10001 .
COPY --from=build /magnetar/target/release/magnetar ./
COPY --from=build /magnetar/target/release/magnetar_calckey_fe ./
USER magnetar:magnetar
EXPOSE 4938/tcp
EXPOSE 4939/tcp
CMD ["/magnetar/magnetar"]
ENTRYPOINT ["/magnetar/magnetar"]

View File

@ -47,6 +47,14 @@
# Environment variable: MAG_C_BIND_ADDR
# networking.bind_addr = "::"
# -----------------------------[ CALCKEY FRONTEND ]----------------------------
# [Optional]
# The port of the frontend.
# Default: 4938
# Environment variable: MAG_C_CK_FE_PORT
# calckey_frontend.port = 4938
# ----------------------------------[ DATA ]-----------------------------------
# [REQUIRED]

View File

@ -1,14 +1,13 @@
[package]
name = "magnetar_core"
description = "A library to power an exploratory ActivityPub project"
version = "0.1.0"
version.workspace = true
edition.workspace = true
license = "AGPL-3.0-only"
edition = "2021"
[lib]
crate-type = ["rlib"]
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
url = { version = "2.3", features = ["serde"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }

View File

@ -1,7 +1,7 @@
[package]
name = "magnetar_calckey_model"
version = "0.1.0"
edition = "2021"
version.workspace = true
edition.workspace = true
[lib]
crate-type = ["rlib"]
@ -9,11 +9,11 @@ crate-type = ["rlib"]
[dependencies]
ck = { path = "./entity_ck" }
anyhow = "1"
dotenvy = "0.15"
log = "0.4"
tokio = { version = "1.24", features = ["full"] }
sea-orm = { version = "0.11", features = ["sqlx-postgres", "runtime-tokio-rustls", "macros"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"
chrono = "0.4"
dotenvy = { workspace = true}
tokio = { workspace = true, features = ["full"] }
sea-orm = { workspace = true, features = ["sqlx-postgres", "runtime-tokio-rustls", "macros"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
chrono = { workspace = true }
tracing = { workspace = true }
thiserror = { workspace = true }

View File

@ -1,6 +1,7 @@
use ck::user;
use log::LevelFilter;
use sea_orm::{ColumnTrait, ConnectOptions, DatabaseConnection, EntityTrait, QueryFilter};
use thiserror::Error;
use tracing::log::LevelFilter;
#[derive(Debug)]
pub struct ConnectorConfig {
@ -10,8 +11,14 @@ pub struct ConnectorConfig {
#[derive(Clone, Debug)]
pub struct CalckeyModel(DatabaseConnection);
#[derive(Debug, Error)]
pub enum CalckeyDbError {
#[error("Database error: {0}")]
DbError(#[from] sea_orm::DbErr),
}
impl CalckeyModel {
pub async fn new(config: ConnectorConfig) -> anyhow::Result<Self> {
pub async fn new(config: ConnectorConfig) -> Result<Self, CalckeyDbError> {
let opt = ConnectOptions::new(config.url)
.max_connections(64)
.min_connections(8)
@ -26,7 +33,7 @@ impl CalckeyModel {
&self,
name: &str,
instance: Option<&str>,
) -> anyhow::Result<Option<user::Model>> {
) -> Result<Option<user::Model>, CalckeyDbError> {
let name = name.to_lowercase();
let instance = instance.map(str::to_lowercase);
@ -47,7 +54,7 @@ impl CalckeyModel {
Ok(user)
}
pub async fn get_user_by_uri(&self, uri: &str) -> anyhow::Result<Option<user::Model>> {
pub async fn get_user_by_uri(&self, uri: &str) -> Result<Option<user::Model>, CalckeyDbError> {
Ok(user::Entity::find()
.filter(user::Column::Uri.eq(uri))
.one(&self.0)

View File

@ -1,8 +1,11 @@
[package]
name = "magnetar_nodeinfo"
version = "0.1.0"
edition = "2021"
version.workspace = true
edition.workspace = true
[lib]
crate-type = ["rlib"]
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }

View File

@ -1,9 +1,12 @@
[package]
name = "magnetar_webfinger"
version = "0.1.0"
edition = "2021"
version.workspace = true
edition.workspace = true
[lib]
crate-type = ["rlib"]
[dependencies]
magnetar_core = { path = "../core", version = "0.1" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
magnetar_core = { path = "../core" }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true}

30
fe_calckey/Cargo.toml Normal file
View File

@ -0,0 +1,30 @@
[package]
name = "magnetar_calckey_fe"
version.workspace = true
edition.workspace = true
[dependencies]
magnetar_common = { path = "../magnetar_common" }
thiserror = { workspace = true }
miette = { workspace = true }
dotenvy = { workspace = true }
axum = { workspace = true, features = ["headers"] }
hyper = { workspace = true, features = ["full"] }
tokio = { workspace = true, features = ["full"] }
tower = { workspace = true }
tower-http = { workspace = true, features = ["cors", "trace", "fs"] }
tera = { workspace = true, default-features = false, features = ["builtins"] }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
tracing = { workspace = true }
percent-encoding = { workspace = true }
serde = { workspace = true, features = ["derive"] }
toml = { workspace = true }
serde_json = { workspace = true }
chrono = { workspace = true }

68
fe_calckey/frontend/.gitignore vendored Normal file
View File

@ -0,0 +1,68 @@
# Visual Studio Code
/.vscode
!/.vscode/extensions.json
# Intelij-IDEA
/.idea
packages/backend/.idea/backend.iml
packages/backend/.idea/modules.xml
packages/backend/.idea/vcs.xml
# Node.js
node_modules
report.*.json
# Cypress
cypress/screenshots
cypress/videos
# Coverage
coverage
# config
/.config/*
!/.config/example.yml
!/.config/devenv.yml
!/.config/docker_example.env
!/.config/helm_values_example.yml
#docker dev config
/dev/docker-compose.yml
# misskey
built
db
elasticsearch
redis
npm-debug.log
*.pem
run.bat
api-docs.json
*.log
*.code-workspace
.DS_Store
files
ormconfig.json
packages/backend/assets/instance.css
packages/backend/assets/sounds/None.mp3
!packages/backend/src/db
# blender backups
*.blend1
*.blend2
*.blend3
*.blend4
*.blend5
# old yarn
.yarn
yarn*
# Nix Development shell items
.devenv
.direnv
# Cargo cache for Docker
/.cargo-cache
/.cargo-target

View File

@ -0,0 +1 @@
v18.16.0

View File

@ -0,0 +1 @@
use-lockfile-v6=true

View File

@ -0,0 +1,3 @@
twemoji
template/boot.js
template/style.css

View File

@ -0,0 +1,307 @@
/**
* BOOT LOADER
* サーバーからレスポンスされるHTMLに埋め込まれるスクリプトで以下の役割を持ちます
* - 翻訳ファイルをフェッチする
* - バージョンに基づいて適切なメインスクリプトを読み込む
* - キャッシュされたコンパイル済みテーマを適用する
* - クライアントの設定値に基づいて対応するHTMLクラス等を設定する
* テーマをこの段階で設定するのはメインスクリプトが読み込まれる間もテーマを適用したいためです
* : webpackは介さないためこのファイルではrequireやimportは使えません
*/
"use strict";
// ブロックの中に入れないと、定義した変数がブラウザのグローバルスコープに登録されてしまい邪魔なので
(async () => {
window.onerror = (e) => {
console.error(e);
renderError("SOMETHING_HAPPENED", e);
};
window.onunhandledrejection = (e) => {
console.error(e);
renderError("SOMETHING_HAPPENED_IN_PROMISE", e);
};
//#region Detect language & fetch translations
const v = localStorage.getItem("v") || VERSION;
const supportedLangs = LANGS;
let lang = localStorage.getItem("lang");
if (lang == null || !supportedLangs.includes(lang)) {
if (supportedLangs.includes(navigator.language)) {
lang = navigator.language;
} else {
lang = supportedLangs.find((x) => x.split("-")[0] === navigator.language);
// Fallback
if (lang == null) lang = "en-US";
}
}
const res = await fetch(`/assets/locales/${lang}.${v}.json`);
if (res.status === 200) {
localStorage.setItem("lang", lang);
localStorage.setItem("locale", await res.text());
localStorage.setItem("localeVersion", v);
} else {
await checkUpdate();
renderError("LOCALE_FETCH");
return;
}
//#endregion
//#region Script
function importAppScript() {
import(`/assets/${CLIENT_ENTRY}`).catch(async (e) => {
await checkUpdate();
console.error(e);
renderError("APP_IMPORT", e);
});
}
// タイミングによっては、この時点でDOMの構築が済んでいる場合とそうでない場合とがある
if (document.readyState !== "loading") {
importAppScript();
} else {
window.addEventListener("DOMContentLoaded", () => {
importAppScript();
});
}
//#endregion
//#region Theme
const theme = localStorage.getItem("theme");
if (theme) {
for (const [k, v] of Object.entries(JSON.parse(theme))) {
document.documentElement.style.setProperty(`--${k}`, v.toString());
// HTMLの theme-color 適用
if (k === "htmlThemeColor") {
for (const tag of document.head.children) {
if (
tag.tagName === "META" &&
tag.getAttribute("name") === "theme-color"
) {
tag.setAttribute("content", v);
break;
}
}
}
}
}
const colorSchema = localStorage.getItem("colorSchema");
if (colorSchema) {
document.documentElement.style.setProperty("color-schema", colorSchema);
}
//#endregion
let fontSize = localStorage.getItem("fontSize");
if (fontSize) {
if (fontSize < 10) {
// need to do this for now, as values before were 1, 2, 3 depending on the option
localStorage.setItem("fontSize", null);
fontSize = localStorage.getItem("fontSize");
}
document.documentElement.style.fontSize = fontSize + "px";
}
const useSystemFont = localStorage.getItem("useSystemFont");
if (useSystemFont) {
document.documentElement.classList.add("useSystemFont");
}
const wallpaper = localStorage.getItem("wallpaper");
if (wallpaper) {
document.documentElement.style.backgroundImage = `url(${wallpaper})`;
}
const customCss = localStorage.getItem("customCss");
if (customCss && customCss.length > 0) {
const style = document.createElement("style");
style.innerHTML = customCss;
document.head.appendChild(style);
}
async function addStyle(styleText) {
let css = document.createElement("style");
css.appendChild(document.createTextNode(styleText));
document.head.appendChild(css);
}
function renderError(code, details) {
let errorsElement = document.getElementById("errors");
if (!errorsElement) {
document.body.innerHTML = `
<svg class="icon-warning" xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-alert-triangle" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M12 9v2m0 4v.01"></path>
<path d="M5 19h14a2 2 0 0 0 1.84 -2.75l-7.1 -12.25a2 2 0 0 0 -3.5 0l-7.1 12.25a2 2 0 0 0 1.75 2.75"></path>
</svg>
<h1>An error has occurred!</h1>
<button class="button-big" onclick="location.reload(true);">
<span class="button-label-big">Refresh</span>
</button>
<p class="dont-worry">Don't worry, it's (probably) not your fault.</p>
<p>Please make sure your browser is up-to-date and any AdBlockers are off.</p>
<p>If the problem persists after refreshing, please contact your instance's administrator</p>
<br>
<div id="errors"></div>
`;
errorsElement = document.getElementById("errors");
}
const detailsElement = document.createElement("details");
detailsElement.innerHTML = `
<br>
<summary>
<code>ERROR CODE: ${code}</code>
</summary>
<code>${JSON.stringify(details)}</code>`;
errorsElement.appendChild(detailsElement);
addStyle(`
* {
font-family: BIZ UDGothic, Roboto, HelveticaNeue, Arial, sans-serif;
}
#calckey_app,
#splash {
display: none !important;
}
body,
html {
background-color: #191724;
color: #e0def4;
justify-content: center;
margin: auto;
padding: 10px;
text-align: center;
}
button {
border-radius: 999px;
padding: 0px 12px 0px 12px;
border: none;
cursor: pointer;
margin-bottom: 12px;
}
.button-big {
background: linear-gradient(90deg, rgb(196, 167, 231), rgb(235, 188, 186));
line-height: 50px;
}
.button-big:hover {
background: rgb(49, 116, 143);
}
.button-small {
background: #444;
line-height: 40px;
}
.button-small:hover {
background: #555;
}
.button-label-big {
color: #191724;
font-weight: bold;
font-size: 20px;
padding: 12px;
}
.button-label-small {
color: rgb(156, 207, 216);
font-size: 16px;
padding: 12px;
}
a {
color: rgb(156, 207, 216);
text-decoration: none;
}
p,
li {
font-size: 16px;
}
.dont-worry,
#msg {
font-size: 18px;
}
.icon-warning {
color: #f6c177;
height: 4rem;
padding-top: 2rem;
}
h1 {
font-size: 32px;
}
code {
font-family: Fira, FiraCode, monospace;
}
details {
background: #1f1d2e;
margin-bottom: 2rem;
padding: 0.5rem 1rem;
width: 40rem;
border-radius: 10px;
justify-content: center;
margin: auto;
}
summary {
cursor: pointer;
}
summary > * {
display: inline;
}
@media screen and (max-width: 500px) {
details {
width: 50%;
}
`);
}
async function checkUpdate() {
try {
const res = await fetch( (_REMOTE_URL || "") + "/api/meta", {
method: "POST",
cache: "no-cache",
});
const meta = await res.json();
if (meta.version != v) {
localStorage.setItem("v", meta.version);
refresh();
}
} catch (e) {
console.error(e);
renderError("UPDATE_CHECK", e);
throw e;
}
}
function refresh() {
// Clear cache (service worker)
try {
navigator.serviceWorker.controller.postMessage("clear");
navigator.serviceWorker.getRegistrations().then((registrations) => {
registrations.forEach((registration) => registration.unregister());
});
} catch (e) {
console.error(e);
}
location.reload();
}
})();

View File

@ -0,0 +1,72 @@
{
"short_name": "Calckey",
"name": "Calckey",
"description": "An open source, decentralized social media platform that's free forever!",
"start_url": "/",
"display": "standalone",
"background_color": "#1f1d2e",
"theme_color": "#31748f",
"orientation": "portrait-primary",
"icons": [
{
"src": "/static-assets/icons/192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any"
},
{
"src": "/static-assets/icons/512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any"
},
{
"src": "/static-assets/icons/maskable.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "/static-ass