Compare commits

..

9 commits
3.2.2 ... main

Author SHA1 Message Date
a087d27333
Release 3.3.4 2025-06-27 23:25:24 +02:00
42f46b33fd
Remaining Fixes 2025-06-27 23:24:44 +02:00
857c5040c3
Various Fixes + V3.3.3 2025-06-27 20:05:30 +02:00
b710b958f4
Release 3.3.2 2025-06-27 19:45:08 +02:00
2fac2fb7b4
Piefed API compat 2025-06-27 19:44:42 +02:00
f3bb504cfd
Release 3.3.1 2025-06-14 20:52:15 +02:00
42aff098bd
Login Delay 2025-06-14 20:52:05 +02:00
204d413779
Release 3.3.0 2025-06-14 20:21:36 +02:00
10111ff612
Change API Version from Lemmy v3 to Piefed Alpha 2025-06-14 20:21:23 +02:00
13 changed files with 351 additions and 664 deletions

543
Cargo.lock generated
View file

@ -17,15 +17,6 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aho-corasick"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "android-tzdata" name = "android-tzdata"
version = "0.1.1" version = "0.1.1"
@ -41,24 +32,13 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "anyhow"
version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
dependencies = [
"backtrace",
]
[[package]] [[package]]
name = "aob-lemmy-bot" name = "aob-lemmy-bot"
version = "3.2.2" version = "3.3.4"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"chrono", "chrono",
"confy", "confy",
"lemmy_api_common",
"lemmy_db_schema",
"log", "log",
"notify", "notify",
"once_cell", "once_cell",
@ -66,6 +46,8 @@ dependencies = [
"serde", "serde",
"serde_derive", "serde_derive",
"serde_json", "serde_json",
"serde_with",
"strum",
"strum_macros", "strum_macros",
"systemd-journal-logger", "systemd-journal-logger",
"tokio", "tokio",
@ -73,17 +55,6 @@ dependencies = [
"url", "url",
] ]
[[package]]
name = "async-lock"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff6e472cdea888a4bd64f342f09b3f50e1886d32afe8df3d663c01140b811b18"
dependencies = [
"event-listener",
"event-listener-strategy",
"pin-project-lite",
]
[[package]] [[package]]
name = "async-trait" name = "async-trait"
version = "0.1.81" version = "0.1.81"
@ -140,12 +111,6 @@ version = "3.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec"
[[package]]
name = "byteorder"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]] [[package]]
name = "bytes" name = "bytes"
version = "1.5.0" version = "1.5.0"
@ -161,17 +126,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "cfb"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d38f2da7a0a2c4ccf0065be06397cc26a81f4e528be095826eee9d4adbb8c60f"
dependencies = [
"byteorder",
"fnv",
"uuid",
]
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "1.0.0" version = "1.0.0"
@ -193,29 +147,6 @@ dependencies = [
"windows-targets 0.52.0", "windows-targets 0.52.0",
] ]
[[package]]
name = "clearurls"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e291c00af89ac0a5b400d9ba46a682e38015ae3cd8926dbbe85b3b864d550be3"
dependencies = [
"linkify",
"percent-encoding",
"regex",
"serde",
"serde_json",
"url",
]
[[package]]
name = "concurrent-queue"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973"
dependencies = [
"crossbeam-utils",
]
[[package]] [[package]]
name = "confy" name = "confy"
version = "0.6.1" version = "0.6.1"
@ -228,12 +159,6 @@ dependencies = [
"toml", "toml",
] ]
[[package]]
name = "convert_case"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
[[package]] [[package]]
name = "core-foundation" name = "core-foundation"
version = "0.9.4" version = "0.9.4"
@ -259,15 +184,6 @@ dependencies = [
"crossbeam-utils", "crossbeam-utils",
] ]
[[package]]
name = "crossbeam-epoch"
version = "0.9.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
dependencies = [
"crossbeam-utils",
]
[[package]] [[package]]
name = "crossbeam-utils" name = "crossbeam-utils"
version = "0.8.19" version = "0.8.19"
@ -319,17 +235,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "derive-new"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2cdc8d50f426189eef89dac62fabfa0abb27d5cc008f25bf4156a0203325becc"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "directories" name = "directories"
version = "5.0.1" version = "5.0.1"
@ -371,26 +276,6 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "enum-map"
version = "2.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6866f3bfdf8207509a033af1a75a7b08abda06bbaaeae6669323fd5a097df2e9"
dependencies = [
"enum-map-derive",
]
[[package]]
name = "enum-map-derive"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f282cfdfe92516eb26c2af8589c274c7c17681f5ecc03c18255fe741c6aa64eb"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "equivalent" name = "equivalent"
version = "1.0.1" version = "1.0.1"
@ -407,27 +292,6 @@ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "event-listener"
version = "5.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6032be9bd27023a771701cc49f9f053c751055f71efb2e0ae5c15809093675ba"
dependencies = [
"concurrent-queue",
"parking",
"pin-project-lite",
]
[[package]]
name = "event-listener-strategy"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f214dc438f977e6d4e3500aaa277f5ad94ca83fbbd9b1a15713ce2344ccc5a1"
dependencies = [
"event-listener",
"pin-project-lite",
]
[[package]] [[package]]
name = "fastrand" name = "fastrand"
version = "2.0.1" version = "2.0.1"
@ -442,7 +306,7 @@ checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
"redox_syscall 0.4.1", "redox_syscall",
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
@ -507,17 +371,6 @@ version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1"
[[package]]
name = "futures-macro"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "futures-sink" name = "futures-sink"
version = "0.3.30" version = "0.3.30"
@ -538,7 +391,6 @@ checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48"
dependencies = [ dependencies = [
"futures-core", "futures-core",
"futures-io", "futures-io",
"futures-macro",
"futures-sink", "futures-sink",
"futures-task", "futures-task",
"memchr", "memchr",
@ -554,10 +406,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"js-sys",
"libc", "libc",
"wasi", "wasi",
"wasm-bindgen",
] ]
[[package]] [[package]]
@ -901,15 +751,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "infer"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc150e5ce2330295b8616ce0e3f53250e53af31759a9dbedad1621ba29151847"
dependencies = [
"cfb",
]
[[package]] [[package]]
name = "inotify" name = "inotify"
version = "0.9.6" version = "0.9.6"
@ -977,101 +818,6 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lemmy_api_common"
version = "0.19.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06a7554d0a71b37c1f666125918a72fe92103a5f254668a988aaa31ed80d4b7b"
dependencies = [
"anyhow",
"chrono",
"enum-map",
"getrandom",
"infer",
"lemmy_db_schema",
"lemmy_db_views",
"lemmy_db_views_actor",
"lemmy_db_views_moderator",
"lemmy_utils",
"mime_guess",
"moka",
"regex",
"serde",
"serde_with",
"url",
"urlencoding",
]
[[package]]
name = "lemmy_db_schema"
version = "0.19.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5454e0df45ec4831b7c6502d965cb9865ecbe2cb181a20c616ad8235444c06e8"
dependencies = [
"anyhow",
"async-trait",
"chrono",
"derive-new",
"futures-util",
"moka",
"serde",
"serde_with",
"strum",
"tracing",
"typed-builder",
"url",
"uuid",
]
[[package]]
name = "lemmy_db_views"
version = "0.19.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4d348095887630617ef02b823887d422ae2e93dfff7a13a127e7524eec51d99"
dependencies = [
"chrono",
"lemmy_db_schema",
"serde",
"serde_with",
]
[[package]]
name = "lemmy_db_views_actor"
version = "0.19.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd7a42bf16a72d6f313f59116538e1333e6ce5f2efbeb9b834ddb147b2cdf986"
dependencies = [
"chrono",
"lemmy_db_schema",
"serde",
"serde_with",
"strum",
]
[[package]]
name = "lemmy_db_views_moderator"
version = "0.19.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b6a1a841c4ccac1947f7edfbb52b3113d32f218a2eede769ec5dce4a039cd43"
dependencies = [
"lemmy_db_schema",
"serde",
"serde_with",
]
[[package]]
name = "lemmy_utils"
version = "0.19.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ee28dc456fac8d5c7ae67b4f596a1e9e2a0a9a6e1c4f8a024bdfb34cf25dfa5"
dependencies = [
"cfg-if",
"clearurls",
"rosetta-build",
"serde",
"strum",
]
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.155" version = "0.2.155"
@ -1086,16 +832,7 @@ checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8"
dependencies = [ dependencies = [
"bitflags 2.4.1", "bitflags 2.4.1",
"libc", "libc",
"redox_syscall 0.4.1", "redox_syscall",
]
[[package]]
name = "linkify"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1dfa36d52c581e9ec783a7ce2a5e0143da6237be5811a0b3153fedfdbe9f780"
dependencies = [
"memchr",
] ]
[[package]] [[package]]
@ -1110,16 +847,6 @@ version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23fb14cb19457329c82206317a5663005a4d404783dc74f4252769b0d5f42856" checksum = "23fb14cb19457329c82206317a5663005a4d404783dc74f4252769b0d5f42856"
[[package]]
name = "lock_api"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.20" version = "0.4.20"
@ -1141,16 +868,6 @@ version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
name = "mime_guess"
version = "2.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e"
dependencies = [
"mime",
"unicase",
]
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.7.1" version = "0.7.1"
@ -1172,30 +889,6 @@ dependencies = [
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
[[package]]
name = "moka"
version = "0.12.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32cf62eb4dd975d2dde76432fb1075c49e3ee2331cf36f1f8fd4b66550d32b6f"
dependencies = [
"async-lock",
"async-trait",
"crossbeam-channel",
"crossbeam-epoch",
"crossbeam-utils",
"event-listener",
"futures-util",
"once_cell",
"parking_lot",
"quanta",
"rustc_version",
"smallvec",
"tagptr",
"thiserror",
"triomphe",
"uuid",
]
[[package]] [[package]]
name = "native-tls" name = "native-tls"
version = "0.2.11" version = "0.2.11"
@ -1323,35 +1016,6 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
[[package]]
name = "parking"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae"
[[package]]
name = "parking_lot"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
dependencies = [
"cfg-if",
"libc",
"redox_syscall 0.5.3",
"smallvec",
"windows-targets 0.52.0",
]
[[package]] [[package]]
name = "percent-encoding" name = "percent-encoding"
version = "2.3.1" version = "2.3.1"
@ -1411,21 +1075,6 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "quanta"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e5167a477619228a0b284fac2674e3c388cba90631d7b7de620e6f1fcd08da5"
dependencies = [
"crossbeam-utils",
"libc",
"once_cell",
"raw-cpuid",
"wasi",
"web-sys",
"winapi",
]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.35" version = "1.0.35"
@ -1435,15 +1084,6 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "raw-cpuid"
version = "11.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e29830cbb1290e404f24c73af91c5d8d631ce7e128691e9477556b540cd01ecd"
dependencies = [
"bitflags 2.4.1",
]
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.4.1" version = "0.4.1"
@ -1453,15 +1093,6 @@ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
] ]
[[package]]
name = "redox_syscall"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4"
dependencies = [
"bitflags 2.4.1",
]
[[package]] [[package]]
name = "redox_users" name = "redox_users"
version = "0.4.4" version = "0.4.4"
@ -1473,35 +1104,6 @@ dependencies = [
"thiserror", "thiserror",
] ]
[[package]]
name = "regex"
version = "1.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]] [[package]]
name = "reqwest" name = "reqwest"
version = "0.12.4" version = "0.12.4"
@ -1545,35 +1147,12 @@ dependencies = [
"winreg", "winreg",
] ]
[[package]]
name = "rosetta-build"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24191a1fed7ae7a5d89f816366f5c03ebce70a7a4d7158534afdf8dd719749fe"
dependencies = [
"convert_case",
"lazy_static",
"proc-macro2",
"quote",
"regex",
"tinyjson",
]
[[package]] [[package]]
name = "rustc-demangle" name = "rustc-demangle"
version = "0.1.23" version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
[[package]]
name = "rustc_version"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
dependencies = [
"semver",
]
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "0.38.28" version = "0.38.28"
@ -1633,12 +1212,6 @@ dependencies = [
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]] [[package]]
name = "security-framework" name = "security-framework"
version = "2.9.2" version = "2.9.2"
@ -1662,12 +1235,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "semver"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.204" version = "1.0.204"
@ -1793,9 +1360,6 @@ name = "strum"
version = "0.26.3" version = "0.26.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06"
dependencies = [
"strum_macros",
]
[[package]] [[package]]
name = "strum_macros" name = "strum_macros"
@ -1869,12 +1433,6 @@ dependencies = [
"rustix", "rustix",
] ]
[[package]]
name = "tagptr"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417"
[[package]] [[package]]
name = "tempfile" name = "tempfile"
version = "3.8.1" version = "3.8.1"
@ -1883,7 +1441,7 @@ checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"fastrand", "fastrand",
"redox_syscall 0.4.1", "redox_syscall",
"rustix", "rustix",
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
@ -1939,12 +1497,6 @@ dependencies = [
"time-core", "time-core",
] ]
[[package]]
name = "tinyjson"
version = "2.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ab95735ea2c8fd51154d01e39cf13912a78071c2d89abc49a7ef102a7dd725a"
[[package]] [[package]]
name = "tinystr" name = "tinystr"
version = "0.7.6" version = "0.7.6"
@ -2077,21 +1629,9 @@ checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
dependencies = [ dependencies = [
"log", "log",
"pin-project-lite", "pin-project-lite",
"tracing-attributes",
"tracing-core", "tracing-core",
] ]
[[package]]
name = "tracing-attributes"
version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "tracing-core" name = "tracing-core"
version = "0.1.32" version = "0.1.32"
@ -2101,44 +1641,12 @@ dependencies = [
"once_cell", "once_cell",
] ]
[[package]]
name = "triomphe"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "859eb650cfee7434994602c3a68b25d77ad9e68c8a6cd491616ef86661382eb3"
[[package]] [[package]]
name = "try-lock" name = "try-lock"
version = "0.2.5" version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]]
name = "typed-builder"
version = "0.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06fbd5b8de54c5f7c91f6fe4cebb949be2125d7758e630bb58b1d831dbce600"
dependencies = [
"typed-builder-macro",
]
[[package]]
name = "typed-builder-macro"
version = "0.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9534daa9fd3ed0bd911d462a37f172228077e7abf18c18a5f67199d959205f8"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicase"
version = "2.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.12" version = "1.0.12"
@ -2154,15 +1662,8 @@ dependencies = [
"form_urlencoded", "form_urlencoded",
"idna", "idna",
"percent-encoding", "percent-encoding",
"serde",
] ]
[[package]]
name = "urlencoding"
version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
[[package]] [[package]]
name = "utf16_iter" name = "utf16_iter"
version = "1.0.5" version = "1.0.5"
@ -2175,16 +1676,6 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
[[package]]
name = "uuid"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314"
dependencies = [
"getrandom",
"serde",
]
[[package]] [[package]]
name = "value-bag" name = "value-bag"
version = "1.4.2" version = "1.4.2"
@ -2298,22 +1789,6 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]] [[package]]
name = "winapi-util" name = "winapi-util"
version = "0.1.8" version = "0.1.8"
@ -2323,12 +1798,6 @@ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]] [[package]]
name = "windows-core" name = "windows-core"
version = "0.51.1" version = "0.51.1"

View file

@ -1,7 +1,7 @@
[package] [package]
authors = ["Neshura"] authors = ["Neshura"]
name = "aob-lemmy-bot" name = "aob-lemmy-bot"
version = "3.2.2" version = "3.3.4"
edition = "2021" edition = "2021"
description = "Bot for automatically posting new chapters of 'Ascendance of a Bookworm' released by J-Novel Club" description = "Bot for automatically posting new chapters of 'Ascendance of a Bookworm' released by J-Novel Club"
license = "GPL-3.0-or-later" license = "GPL-3.0-or-later"
@ -17,8 +17,6 @@ systemd-units = { enable = false }
[dependencies] [dependencies]
chrono = "^0.4" chrono = "^0.4"
lemmy_api_common = "0.19.9"
lemmy_db_schema = "0.19.9"
once_cell = "^1.19" once_cell = "^1.19"
reqwest = { version = "^0.12", features = ["blocking", "json"] } reqwest = { version = "^0.12", features = ["blocking", "json"] }
serde = "^1.0" serde = "^1.0"
@ -33,3 +31,5 @@ systemd-journal-logger = "^2.1.1"
log = "^0.4" log = "^0.4"
async-trait = "^0.1" async-trait = "^0.1"
notify = "6.1.1" notify = "6.1.1"
serde_with = "3.9.0"
strum = "0.26.3"

View file

@ -1,5 +1,5 @@
use crate::{config::{Config}, HTTP_CLIENT}; use crate::{config::{Config}, HTTP_CLIENT};
use crate::lemmy::{Lemmy}; use crate::piefed::{Piefed};
use crate::post_history::{SeriesHistory}; use crate::post_history::{SeriesHistory};
use chrono::{DateTime, Duration, Utc}; use chrono::{DateTime, Duration, Utc};
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
@ -79,12 +79,15 @@ impl Bot {
} }
pub(crate) async fn run(&mut self) { pub(crate) async fn run(&mut self) {
loop { loop {
let mut lemmy = match Lemmy::new(&self.shared_config).await { let mut piefed = match Piefed::new(&self.shared_config).await {
Ok(data) => data, Ok(data) => data,
Err(_) => continue, Err(_) => {
sleep(Duration::seconds(10).to_std().unwrap()).await;
continue;
},
}; };
lemmy.get_communities().await; piefed.get_communities().await;
self.history = SeriesHistory::load_history(); self.history = SeriesHistory::load_history();
@ -94,7 +97,7 @@ impl Bot {
self.ping_status().await; self.ping_status().await;
let read_copy = self.shared_config.read().expect("Read Lock Failed").clone(); let read_copy = self.shared_config.read().expect("Read Lock Failed").clone();
for series in read_copy.series { for series in read_copy.series {
series.update(&mut self.history, &lemmy, &self.shared_config).await; series.update(&mut self.history, &piefed, &self.shared_config).await;
debug!("Done Updating Series"); debug!("Done Updating Series");
self.wait(1, Wait::Absolute).await; self.wait(1, Wait::Absolute).await;
} }
@ -106,7 +109,7 @@ impl Bot {
self.wait(30, Wait::Absolute).await; self.wait(30, Wait::Absolute).await;
} }
lemmy.logout().await; piefed.logout().await;
} }
} }

View file

@ -2,10 +2,9 @@ use std::path::PathBuf;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
use chrono::{Timelike, Utc}; use chrono::{Timelike, Utc};
use crate::config::PostBody::Description; use crate::config::PostBody::Description;
use lemmy_db_schema::PostFeatureType; use crate::piefed_api::post::PostFeatureType;
use lemmy_db_schema::sensitive::SensitiveString; use crate::piefed::{Piefed, PartInfo, PostType};
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use crate::lemmy::{Lemmy, PartInfo, PostType};
use crate::post_history::{SeriesHistory}; use crate::post_history::{SeriesHistory};
use systemd_journal_logger::connected_to_journal; use systemd_journal_logger::connected_to_journal;
use crate::fetchers::{FetcherTrait, Fetcher}; use crate::fetchers::{FetcherTrait, Fetcher};
@ -50,8 +49,8 @@ macro_rules! error {
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]
pub(crate) struct Config { pub(crate) struct Config {
pub(crate) instance: String, pub(crate) instance: String,
username: SensitiveString, username: String,
password: SensitiveString, password: String,
pub(crate) status_post_url: Option<String>, pub(crate) status_post_url: Option<String>,
pub(crate) config_reload_seconds: u32, pub(crate) config_reload_seconds: u32,
pub(crate) protected_communities: Vec<String>, pub(crate) protected_communities: Vec<String>,
@ -89,11 +88,11 @@ impl Config {
confy::get_configuration_file_path(env!("CARGO_PKG_NAME"), "config").expect("Application will not without confy") confy::get_configuration_file_path(env!("CARGO_PKG_NAME"), "config").expect("Application will not without confy")
} }
pub(crate) fn get_username(&self) -> SensitiveString { pub(crate) fn get_username(&self) -> String {
self.username.clone() self.username.clone()
} }
pub(crate) fn get_password(&self) -> SensitiveString { pub(crate) fn get_password(&self) -> String {
self.password.clone() self.password.clone()
} }
} }
@ -102,8 +101,8 @@ impl Default for Config {
fn default() -> Self { fn default() -> Self {
Config { Config {
instance: "".to_owned(), instance: "".to_owned(),
username: SensitiveString::from("".to_owned()), username: "".to_owned(),
password: SensitiveString::from("".to_owned()), password: "".to_owned(),
status_post_url: None, status_post_url: None,
config_reload_seconds: 21600, config_reload_seconds: 21600,
protected_communities: vec![], protected_communities: vec![],
@ -122,7 +121,7 @@ pub(crate) struct SeriesConfig {
} }
impl SeriesConfig { impl SeriesConfig {
pub(crate) async fn update(&self, history: &mut SeriesHistory, lemmy: &Lemmy, config: &Arc<RwLock<Config>>) { pub(crate) async fn update(&self, history: &mut SeriesHistory, piefed: &Piefed, config: &Arc<RwLock<Config>>) {
let info_msg = format!("Checking {} for Updates", self.slug); let info_msg = format!("Checking {} for Updates", self.slug);
info!(info_msg); info!(info_msg);
@ -167,7 +166,7 @@ impl SeriesConfig {
continue continue
} }
let post_data = post_info.get_post_data(self, lemmy); let post_data = post_info.get_post_data(self, piefed);
let info = format!( let info = format!(
"Posting '{}' to {}", "Posting '{}' to {}",
@ -176,11 +175,11 @@ impl SeriesConfig {
); );
info!(info); info!(info);
let post_id = match lemmy.post(post_data.clone()).await { let post_id = match piefed.post(post_data.clone()).await {
Some(data) => data, Some(data) => data,
None => { None => {
error!("Error posting chapter, applying fix for Issue #27"); error!("Error posting chapter, applying fix for Issue #27");
match lemmy.check_community_for_post(post_data).await { match piefed.check_community_for_post(post_data).await {
Some(data) => data, Some(data) => data,
None => { None => {
error!("Unable to find Post via API"); error!("Unable to find Post via API");
@ -203,17 +202,17 @@ impl SeriesConfig {
post_info.get_post_config(self).name.as_str() post_info.get_post_config(self).name.as_str()
); );
info!(info); info!(info);
let pinned_posts = lemmy.get_community_pinned(lemmy.get_community_id(&post_info.get_post_config(self).name)).await.unwrap_or_else(|| { let pinned_posts = piefed.get_community_pinned(piefed.get_community_id(&post_info.get_post_config(self).name)).await.unwrap_or_else(|| {
error!("Pinning of Post to community failed"); error!("Pinning of Post to community failed");
vec![] vec![]
}); });
if !pinned_posts.is_empty() { if !pinned_posts.is_empty() {
let community_pinned_post = &pinned_posts[0]; let community_pinned_post = &pinned_posts[0];
if lemmy.unpin(community_pinned_post.post.id, PostFeatureType::Community).await.is_none() { if piefed.unpin(community_pinned_post.post.id, PostFeatureType::Community).await.is_none() {
error!("Error un-pinning post"); error!("Error un-pinning post");
} }
} }
if lemmy.pin(post_id, PostFeatureType::Community).await.is_none() { if piefed.pin(post_id, PostFeatureType::Community).await.is_none() {
error!("Error pinning post"); error!("Error pinning post");
} }
} else if read_config } else if read_config
@ -227,39 +226,6 @@ impl SeriesConfig {
warn!(message); warn!(message);
} }
if post_info.get_post_config(self).pin_settings.pin_new_post_local {
let info = format!("Pinning '{}' to Instance", post_info.get_info().title);
info!(info);
let pinned_posts = match lemmy.get_local_pinned().await {
Some(data) => {data}
None => {
error!("Error fetching pinned posts");
vec![]
}
};
if !pinned_posts.is_empty() {
for pinned_post in pinned_posts {
if read_config
.protected_communities
.contains(&pinned_post.community.name)
{
continue;
} else {
let community_pinned_post = &pinned_post;
if lemmy.unpin(community_pinned_post.post.id, PostFeatureType::Local).await.is_none() {
error!("Error pinning post");
continue;
}
break;
}
}
}
if lemmy.pin(post_id, PostFeatureType::Local).await.is_none() {
error!("Error pinning post");
};
}
let mut series_history = history.get_series(self.slug.as_str()); let mut series_history = history.get_series(self.slug.as_str());
let mut part_history = series_history.get_part(post_info.get_part_info().unwrap_or(PartInfo::NoParts).as_string().as_str()); let mut part_history = series_history.get_part(post_info.get_part_info().unwrap_or(PartInfo::NoParts).as_string().as_str());
@ -291,7 +257,6 @@ pub(crate) struct PostConfig {
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub(crate) struct PinConfig { pub(crate) struct PinConfig {
pub(crate) pin_new_post_local: bool,
pub(crate) pin_new_post_community: bool, pub(crate) pin_new_post_community: bool,
} }

View file

@ -5,9 +5,9 @@ use std::collections::HashMap;
use std::ops::Sub; use std::ops::Sub;
use async_trait::async_trait; use async_trait::async_trait;
use crate::fetchers::{FetcherTrait}; use crate::fetchers::{FetcherTrait};
use crate::lemmy::{PartInfo, PostInfo, PostInfoInner, PostType}; use crate::piefed::{PartInfo, PostInfo, PostInfoInner, PostType};
use systemd_journal_logger::connected_to_journal; use systemd_journal_logger::connected_to_journal;
use crate::lemmy::PartInfo::{NoParts, Part}; use crate::piefed::PartInfo::{NoParts, Part};
macro_rules! error { macro_rules! error {
($msg:tt) => { ($msg:tt) => {

View file

@ -3,7 +3,7 @@ use serde_derive::{Deserialize, Serialize};
use strum_macros::Display; use strum_macros::Display;
use crate::fetchers::Fetcher::Jnc; use crate::fetchers::Fetcher::Jnc;
use crate::fetchers::jnovel::JNovelFetcher; use crate::fetchers::jnovel::JNovelFetcher;
use crate::lemmy::{PostInfo}; use crate::piefed::{PostInfo};
pub mod jnovel; pub mod jnovel;

View file

@ -7,9 +7,10 @@ use crate::bot::Bot;
mod bot; mod bot;
mod config; mod config;
mod lemmy; mod piefed;
mod post_history; mod post_history;
mod fetchers; mod fetchers;
mod piefed_api;
pub static HTTP_CLIENT: Lazy<Client> = Lazy::new(|| { pub static HTTP_CLIENT: Lazy<Client> = Lazy::new(|| {
Client::builder() Client::builder()

View file

@ -1,16 +1,13 @@
use std::cmp::Ordering; use std::cmp::Ordering;
use crate::config::{Config, PostBody, PostConfig, SeriesConfig}; use crate::config::{Config, PostBody, PostConfig, SeriesConfig};
use crate::{HTTP_CLIENT}; use crate::{HTTP_CLIENT};
use lemmy_api_common::community::{ListCommunities, ListCommunitiesResponse}; use crate::piefed_api::user::{Login, LoginResponse};
use lemmy_api_common::lemmy_db_views::structs::PostView; use crate::piefed_api::post::{PostView, CreatePost, FeaturePost, GetPosts, GetPostsResponse, PostFeatureType, ListingType, SortType, PostSortType};
use lemmy_api_common::person::{Login, LoginResponse}; use crate::piefed_api::types::{CommunityId, LanguageId, PostId};
use lemmy_api_common::post::{CreatePost, FeaturePost, GetPosts, GetPostsResponse}; use crate::piefed_api::community::{ListCommunitiesParams, ListCommunitiesResponse};
use lemmy_db_schema::newtypes::{CommunityId, LanguageId, PostId};
use lemmy_db_schema::{ListingType, PostFeatureType, SortType};
use reqwest::StatusCode; use reqwest::StatusCode;
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::{RwLock}; use std::sync::{RwLock};
use lemmy_db_schema::sensitive::SensitiveString;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use systemd_journal_logger::connected_to_journal; use systemd_journal_logger::connected_to_journal;
@ -41,8 +38,8 @@ macro_rules! error {
}; };
} }
pub(crate) struct Lemmy { pub(crate) struct Piefed {
jwt_token: SensitiveString, jwt_token: String,
instance: String, instance: String,
communities: HashMap<String, CommunityId>, communities: HashMap<String, CommunityId>,
} }
@ -155,7 +152,7 @@ impl PostInfo {
} }
} }
pub(crate) fn get_post_data(&self, series: &SeriesConfig, lemmy: &Lemmy) -> CreatePost { pub(crate) fn get_post_data(&self, series: &SeriesConfig, lemmy: &Piefed) -> CreatePost {
let post_config = self.get_post_config(series); let post_config = self.get_post_config(series);
let post_body = match &post_config.post_body { let post_body = match &post_config.post_body {
@ -167,15 +164,13 @@ impl PostInfo {
let community_id: CommunityId = lemmy.get_community_id(&post_config.name); let community_id: CommunityId = lemmy.get_community_id(&post_config.name);
CreatePost { CreatePost {
name: self.get_info().title.clone(), title: self.get_info().title.clone(),
community_id, community_id,
url: Some(self.get_info().url), url: Some(self.get_info().url),
custom_thumbnail: self.get_info().thumbnail, //custom_thumbnail: self.get_info().thumbnail,
body: post_body, body: post_body,
alt_text: None, nsfw: false,
honeypot: None, language_id: LanguageId(37), // TODO get this id once every few hours per API request, the ordering of IDs suggests that the EN Id might change in the future
nsfw: None,
language_id: Some(LanguageId(37)), // TODO get this id once every few hours per API request, the ordering of IDs suggests that the EN Id might change in the future
} }
} }
} }
@ -214,20 +209,19 @@ impl PartialOrd for PostInfo {
} }
} }
impl Lemmy { impl Piefed {
pub(crate) fn get_community_id(&self, name: &str) -> CommunityId { pub(crate) fn get_community_id(&self, name: &str) -> CommunityId {
*self.communities.get(name).expect("Given community is invalid") *self.communities.get(name).expect("Given community is invalid")
} }
pub(crate) async fn new(config: &RwLock<Config>) -> Result<Self, ()> { pub(crate) async fn new(config: &RwLock<Config>) -> Result<Self, ()> {
let read_config = config.read().expect("Read Lock Failed").clone(); let read_config = config.read().expect("Read Lock Failed").clone();
let login_params = Login { let login_params = Login {
username_or_email: read_config.get_username(), username: read_config.get_username(),
password: read_config.get_password(), password: read_config.get_password(),
totp_2fa_token: None,
}; };
let response = match HTTP_CLIENT let response = match HTTP_CLIENT
.post(read_config.instance.to_owned() + "/api/v3/user/login") .post(read_config.instance.to_owned() + "/api/alpha/user/login")
.json(&login_params) .json(&login_params)
.send() .send()
.await .await
@ -243,11 +237,11 @@ impl Lemmy {
match response.status() { match response.status() {
StatusCode::OK => { StatusCode::OK => {
let data: LoginResponse = response let data: LoginResponse = response
.json() .json::<LoginResponse>()
.await .await
.expect("Successful Login Request should return JSON"); .expect("Successful Login Request should return JSON");
match data.jwt { match data.jwt {
Some(token) => Ok(Lemmy { Some(token) => Ok(Piefed {
jwt_token: token.clone(), jwt_token: token.clone(),
instance: read_config.instance.to_owned(), instance: read_config.instance.to_owned(),
communities: HashMap::new(), communities: HashMap::new(),
@ -268,12 +262,12 @@ impl Lemmy {
} }
pub(crate) async fn logout(&self) { pub(crate) async fn logout(&self) {
let _ = self.post_data_json("/api/v3/user/logout", &"").await; let _ = self.post_data_json("/api/alpha/user/logout", &"").await;
} }
pub(crate) async fn post(&self, post: CreatePost) -> Option<PostId> { pub(crate) async fn post(&self, post: CreatePost) -> Option<PostId> {
let response: String = match self.post_data_json("/api/v3/post", &post).await { let response: String = match self.post_data_json("/api/alpha/post", &post).await {
Some(data) => data, Some(data) => data,
None => return None, None => return None,
}; };
@ -286,7 +280,7 @@ impl Lemmy {
} }
async fn feature(&self, params: FeaturePost) -> Option<PostView> { async fn feature(&self, params: FeaturePost) -> Option<PostView> {
let response: String = match self.post_data_json("/api/v3/post/feature", &params).await { let response: String = match self.post_data_json("/api/alpha/post/feature", &params).await {
Some(data) => data, Some(data) => data,
None => return None, None => return None,
}; };
@ -323,7 +317,7 @@ impl Lemmy {
..Default::default() ..Default::default()
}; };
let response: String = match self.get_data_query("/api/v3/post/list", &list_params).await { let response: String = match self.get_data_query("/api/alpha/post/list", &list_params).await {
Some(data) => data, Some(data) => data,
None => return None, None => return None,
}; };
@ -335,41 +329,21 @@ impl Lemmy {
Some(json_data Some(json_data
.posts .posts
.iter() .iter()
.filter(|post| post.post.featured_community) .filter(|post| post.post.sticky)
.cloned()
.collect())
}
pub(crate) async fn get_local_pinned(&self) -> Option<Vec<PostView>> {
let list_params = GetPosts {
type_: Some(ListingType::Local),
..Default::default()
};
let response: String = match self.get_data_query("/api/v3/post/list", &list_params).await {
Some(data) => data,
None => return None,
};
let json_data: GetPostsResponse = match self.parse_json(&response).await {
Some(data) => data,
None => return None,
};
Some(json_data
.posts
.iter()
.filter(|post| post.post.featured_local)
.cloned() .cloned()
.collect()) .collect())
} }
pub(crate) async fn get_communities(&mut self) { pub(crate) async fn get_communities(&mut self) {
let list_params = ListCommunities { let list_params = ListCommunitiesParams {
type_: Some(ListingType::Local), type_: Some(ListingType::Local),
..Default::default() sort: Some(SortType::New),
show_nsfw: Some(false),
page: Some(0),
limit: Some(100)
}; };
let response: String = match self.get_data_query("/api/v3/community/list", &list_params).await { let response: String = match self.get_data_query("/api/alpha/community/list", &list_params).await {
Some(data) => data, Some(data) => data,
None => return, None => return,
}; };
@ -390,21 +364,16 @@ impl Lemmy {
pub(crate) async fn check_community_for_post(&self, post: CreatePost) -> Option<PostId> { pub(crate) async fn check_community_for_post(&self, post: CreatePost) -> Option<PostId> {
let get_params: GetPosts = GetPosts { let get_params: GetPosts = GetPosts {
type_: None, type_: None,
sort: Some(SortType::New), sort: Some(PostSortType::New),
page: None, page: None,
limit: None, limit: None,
community_id: Some(post.community_id), community_id: Some(post.community_id),
person_id: None,
community_name: None, community_name: None,
saved_only: None,
liked_only: None, liked_only: None,
disliked_only: None,
show_hidden: None,
show_read: None,
show_nsfw: None,
page_cursor: None,
}; };
let response: String = match self.get_data_query("/api/v3/post/list", &get_params).await { let response: String = match self.get_data_query("/api/alpha/post/list", &get_params).await {
Some(data) => data, Some(data) => data,
None => { None => {
error!("Unable to query post list"); error!("Unable to query post list");
@ -420,11 +389,11 @@ impl Lemmy {
}; };
for api_post in json_data.posts { for api_post in json_data.posts {
if api_post.post.name == post.name { if api_post.post.title == post.title {
return Some(api_post.post.id); return Some(api_post.post.id);
} }
} }
let msg = format!("Unable to find post {}", post.name); let msg = format!("Unable to find post {}", post.title);
info!(msg); info!(msg);
None None
} }

View file

@ -0,0 +1,63 @@
use serde_derive::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use crate::piefed_api::post::{ListingType, SortType};
use crate::piefed_api::types::{CommunityId, PostId, SubscribedType};
#[skip_serializing_none]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct CommunityCounts {
pub id: CommunityId,
pub post_count: i32,
pub post_reply_count: i32,
pub subscriptions_count: i32,
pub published: String,
}
#[skip_serializing_none]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct Community {
pub actor_id: String,
pub ap_domain: String,
pub banned: bool,
pub banner: Option<String>,
pub deleted: bool,
pub description: Option<String>,
pub hidden: bool,
pub icon: Option<String>,
pub id: CommunityId,
pub instance_id: u32,
pub local: bool,
pub name: String,
pub nsfw: bool,
pub published: String,
pub removed: bool,
pub restricted_to_mods: bool,
pub title: String,
pub updated: String,
}
#[skip_serializing_none]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct ListCommunitiesParams {
pub type_: Option<ListingType>,
pub sort: Option<SortType>,
pub show_nsfw: Option<bool>,
pub page: Option<i32>,
pub limit: Option<i32>,
}
#[skip_serializing_none]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct ListCommunitiesResponse {
pub communities: Vec<CommunityView>,
}
#[skip_serializing_none]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct CommunityView {
pub community: Community,
pub subscribed: SubscribedType,
pub blocked: bool,
pub counts: CommunityCounts,
pub activity_alert: bool
}

4
src/piefed_api/mod.rs Normal file
View file

@ -0,0 +1,4 @@
pub mod user;
pub mod post;
pub mod types;
pub mod community;

161
src/piefed_api/post.rs Normal file
View file

@ -0,0 +1,161 @@
use serde_derive::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use strum_macros::{Display, EnumString};
use crate::piefed_api::community::Community;
use crate::piefed_api::types::{CommunityId, LanguageId, PaginationCursor, PersonId, PostId, SubscribedType};
use crate::piefed_api::user::Person;
#[derive(
EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash,
)]
pub enum PostFeatureType {
#[default]
Local,
Community,
}
#[derive(
EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Hash,
)]
pub enum ListingType {
All,
#[default]
Local,
Subscribed,
ModeratorView,
}
#[derive(
EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Hash,
)]
pub enum SortType {
#[default]
Active,
Hot,
New,
Old,
TopDay,
TopWeek,
TopMonth,
TopYear,
TopAll,
MostComments,
NewComments,
TopHour,
TopSixHour,
TopTwelveHour,
TopThreeMonths,
TopSixMonths,
TopNineMonths,
Controversial,
Scaled,
}
#[derive(
EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Hash,
)]
pub enum PostSortType {
#[default]
Active,
Hot,
New,
Old,
Top,
MostComments,
NewComments,
Controversial,
Scaled,
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, Hash)]
pub struct GetPosts {
pub type_: Option<ListingType>,
pub sort: Option<PostSortType>,
pub page: Option<PaginationCursor>,
pub limit: Option<i64>,
pub community_id: Option<CommunityId>,
pub person_id: Option<PersonId>,
pub community_name: Option<String>,
pub liked_only: Option<bool>,
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GetPostsResponse {
pub posts: Vec<PostView>,
}
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
pub struct FeaturePost {
pub post_id: PostId,
pub featured: bool,
pub feature_type: PostFeatureType,
}
#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)]
pub struct CreatePost {
pub title: String,
pub community_id: CommunityId,
pub url: Option<String>,
pub body: Option<String>,
pub nsfw: bool,
pub language_id: LanguageId,
}
#[skip_serializing_none]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct PostView {
pub post: Post,
pub creator: Person,
pub community: Community,
pub creator_banned_from_community: bool,
pub banned_from_community: bool,
pub creator_is_moderator: bool,
pub creator_is_admin: bool,
pub counts: PostCounts,
pub subscribed: SubscribedType,
pub saved: bool,
pub activity_alert: bool,
pub read: bool,
pub hidden: bool,
pub my_vote: i32,
pub unread_comments: i32,
}
#[skip_serializing_none]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct PostCounts {
pub post_id: PostId,
pub comments: i32,
pub score: i32,
pub upvotes: i32,
pub downvotes: i32,
pub published: String,
pub newest_comment_time: String,
}
#[skip_serializing_none]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct Post {
pub id: PostId,
pub title: String,
pub url: Option<String>,
pub body: Option<String>,
pub user_id: PersonId,
pub community_id: CommunityId,
pub removed: bool,
pub locked: bool,
pub published: String,
pub updated: Option<String>,
pub deleted: bool,
pub nsfw: bool,
pub thumbnail_url: Option<String>,
pub ap_id: String,
pub local: bool,
pub language_id: Option<LanguageId>,
pub sticky: bool,
pub alt_text: Option<String>,
}

19
src/piefed_api/types.rs Normal file
View file

@ -0,0 +1,19 @@
use serde_derive::{Deserialize, Serialize};
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)]
pub struct CommunityId(pub i32);
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)]
pub struct PersonId(pub i32);
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)]
/// The post id.
pub struct PostId(pub i32);
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)]
pub struct LanguageId(pub i32);
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
pub struct PaginationCursor(pub String);
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
pub enum SubscribedType {
Subscribed,
NotSubscribed,
}

33
src/piefed_api/user.rs Normal file
View file

@ -0,0 +1,33 @@
use serde_derive::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use crate::piefed_api::types::PersonId;
#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)]
pub struct Login {
pub username: String,
pub password: String,
}
#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct LoginResponse {
pub jwt: Option<String>,
}
#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
pub struct Person {
pub actor_id: String,
pub avatar: Option<String>,
pub banned: bool,
pub banner: Option<String>,
pub bot: bool,
pub deleted: bool,
pub id: PersonId,
pub instance_id: u32,
pub local: bool,
pub published: String,
pub title: String,
pub user_name: String,
}