├── .github └── workflows │ └── cd.yml ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── ltv.sample.toml └── src ├── api.rs ├── app.rs ├── auth.rs ├── config.rs ├── event.rs ├── main.rs ├── ui.rs └── utils.rs /.github/workflows/cd.yml: -------------------------------------------------------------------------------- 1 | name: Continuous Deployment 2 | 3 | on: 4 | push: 5 | tags: 6 | - "v*.*.*" 7 | 8 | jobs: 9 | publish: 10 | name: Publishing for ${{ matrix.os }} 11 | runs-on: ${{ matrix.os }} 12 | strategy: 13 | matrix: 14 | os: [ubuntu-latest] 15 | rust: [stable] 16 | include: 17 | - os: ubuntu-latest 18 | artifact_prefix: linux 19 | target: x86_64-unknown-linux-gnu 20 | binary_postfix: "" 21 | 22 | steps: 23 | - name: Installing Rust toolchain 24 | uses: actions-rs/toolchain@v1 25 | with: 26 | toolchain: ${{ matrix.rust }} 27 | override: true 28 | - name: Installing needed Ubuntu dependencies 29 | if: matrix.os == 'ubuntu-latest' 30 | run: | 31 | sudo apt-get update 32 | sudo apt-get install -y -qq pkg-config libssl-dev libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev 33 | - name: Checking out sources 34 | uses: actions/checkout@v1 35 | - name: Running cargo build 36 | uses: actions-rs/cargo@v1 37 | with: 38 | command: build 39 | toolchain: ${{ matrix.rust }} 40 | args: --release --target ${{ matrix.target }} 41 | 42 | - name: Packaging final binary 43 | shell: bash 44 | run: | 45 | cd target/${{ matrix.target }}/release 46 | BINARY_NAME=ltv${{ matrix.binary_postfix }} 47 | strip $BINARY_NAME 48 | RELEASE_NAME=ltv-${{ matrix.artifact_prefix }} 49 | tar czvf $RELEASE_NAME.tar.gz $BINARY_NAME 50 | if [[ ${{ runner.os }} == 'Windows' ]]; then 51 | certutil -hashfile $RELEASE_NAME.tar.gz sha256 | grep -E [A-Fa-f0-9]{64} > $RELEASE_NAME.sha256 52 | else 53 | shasum -a 256 $RELEASE_NAME.tar.gz > $RELEASE_NAME.sha256 54 | fi 55 | - name: Releasing assets 56 | uses: softprops/action-gh-release@v1 57 | with: 58 | files: | 59 | target/${{ matrix.target }}/release/ltv-${{ matrix.artifact_prefix }}.tar.gz 60 | target/${{ matrix.target }}/release/ltv-${{ matrix.artifact_prefix }}.sha256 61 | env: 62 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "autocfg" 7 | version = "1.0.1" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" 10 | 11 | [[package]] 12 | name = "base64" 13 | version = "0.13.0" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" 16 | 17 | [[package]] 18 | name = "bitflags" 19 | version = "1.3.2" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 22 | 23 | [[package]] 24 | name = "bumpalo" 25 | version = "3.7.1" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "d9df67f7bf9ef8498769f994239c45613ef0c5899415fb58e9add412d2c1a538" 28 | 29 | [[package]] 30 | name = "bytes" 31 | version = "1.1.0" 32 | source = "registry+https://github.com/rust-lang/crates.io-index" 33 | checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" 34 | 35 | [[package]] 36 | name = "cassowary" 37 | version = "0.3.0" 38 | source = "registry+https://github.com/rust-lang/crates.io-index" 39 | checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" 40 | 41 | [[package]] 42 | name = "cc" 43 | version = "1.0.70" 44 | source = "registry+https://github.com/rust-lang/crates.io-index" 45 | checksum = "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa0dc0" 46 | 47 | [[package]] 48 | name = "cfg-if" 49 | version = "1.0.0" 50 | source = "registry+https://github.com/rust-lang/crates.io-index" 51 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 52 | 53 | [[package]] 54 | name = "chrono" 55 | version = "0.4.19" 56 | source = "registry+https://github.com/rust-lang/crates.io-index" 57 | checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" 58 | dependencies = [ 59 | "libc", 60 | "num-integer", 61 | "num-traits", 62 | "time", 63 | "winapi", 64 | ] 65 | 66 | [[package]] 67 | name = "core-foundation" 68 | version = "0.9.1" 69 | source = "registry+https://github.com/rust-lang/crates.io-index" 70 | checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" 71 | dependencies = [ 72 | "core-foundation-sys", 73 | "libc", 74 | ] 75 | 76 | [[package]] 77 | name = "core-foundation-sys" 78 | version = "0.8.2" 79 | source = "registry+https://github.com/rust-lang/crates.io-index" 80 | checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" 81 | 82 | [[package]] 83 | name = "directories" 84 | version = "3.0.2" 85 | source = "registry+https://github.com/rust-lang/crates.io-index" 86 | checksum = "e69600ff1703123957937708eb27f7a564e48885c537782722ed0ba3189ce1d7" 87 | dependencies = [ 88 | "dirs-sys", 89 | ] 90 | 91 | [[package]] 92 | name = "dirs-sys" 93 | version = "0.3.6" 94 | source = "registry+https://github.com/rust-lang/crates.io-index" 95 | checksum = "03d86534ed367a67548dc68113a0f5db55432fdfbb6e6f9d77704397d95d5780" 96 | dependencies = [ 97 | "libc", 98 | "redox_users", 99 | "winapi", 100 | ] 101 | 102 | [[package]] 103 | name = "encoding_rs" 104 | version = "0.8.28" 105 | source = "registry+https://github.com/rust-lang/crates.io-index" 106 | checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" 107 | dependencies = [ 108 | "cfg-if", 109 | ] 110 | 111 | [[package]] 112 | name = "fnv" 113 | version = "1.0.7" 114 | source = "registry+https://github.com/rust-lang/crates.io-index" 115 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 116 | 117 | [[package]] 118 | name = "foreign-types" 119 | version = "0.3.2" 120 | source = "registry+https://github.com/rust-lang/crates.io-index" 121 | checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" 122 | dependencies = [ 123 | "foreign-types-shared", 124 | ] 125 | 126 | [[package]] 127 | name = "foreign-types-shared" 128 | version = "0.1.1" 129 | source = "registry+https://github.com/rust-lang/crates.io-index" 130 | checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" 131 | 132 | [[package]] 133 | name = "form_urlencoded" 134 | version = "1.0.1" 135 | source = "registry+https://github.com/rust-lang/crates.io-index" 136 | checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" 137 | dependencies = [ 138 | "matches", 139 | "percent-encoding", 140 | ] 141 | 142 | [[package]] 143 | name = "futures-channel" 144 | version = "0.3.17" 145 | source = "registry+https://github.com/rust-lang/crates.io-index" 146 | checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888" 147 | dependencies = [ 148 | "futures-core", 149 | ] 150 | 151 | [[package]] 152 | name = "futures-core" 153 | version = "0.3.17" 154 | source = "registry+https://github.com/rust-lang/crates.io-index" 155 | checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" 156 | 157 | [[package]] 158 | name = "futures-io" 159 | version = "0.3.17" 160 | source = "registry+https://github.com/rust-lang/crates.io-index" 161 | checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" 162 | 163 | [[package]] 164 | name = "futures-sink" 165 | version = "0.3.17" 166 | source = "registry+https://github.com/rust-lang/crates.io-index" 167 | checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11" 168 | 169 | [[package]] 170 | name = "futures-task" 171 | version = "0.3.17" 172 | source = "registry+https://github.com/rust-lang/crates.io-index" 173 | checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99" 174 | 175 | [[package]] 176 | name = "futures-util" 177 | version = "0.3.17" 178 | source = "registry+https://github.com/rust-lang/crates.io-index" 179 | checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481" 180 | dependencies = [ 181 | "autocfg", 182 | "futures-core", 183 | "futures-io", 184 | "futures-task", 185 | "memchr", 186 | "pin-project-lite", 187 | "pin-utils", 188 | "slab", 189 | ] 190 | 191 | [[package]] 192 | name = "getrandom" 193 | version = "0.2.3" 194 | source = "registry+https://github.com/rust-lang/crates.io-index" 195 | checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" 196 | dependencies = [ 197 | "cfg-if", 198 | "libc", 199 | "wasi", 200 | ] 201 | 202 | [[package]] 203 | name = "h2" 204 | version = "0.3.4" 205 | source = "registry+https://github.com/rust-lang/crates.io-index" 206 | checksum = "d7f3675cfef6a30c8031cf9e6493ebdc3bb3272a3fea3923c4210d1830e6a472" 207 | dependencies = [ 208 | "bytes", 209 | "fnv", 210 | "futures-core", 211 | "futures-sink", 212 | "futures-util", 213 | "http", 214 | "indexmap", 215 | "slab", 216 | "tokio", 217 | "tokio-util", 218 | "tracing", 219 | ] 220 | 221 | [[package]] 222 | name = "hashbrown" 223 | version = "0.11.2" 224 | source = "registry+https://github.com/rust-lang/crates.io-index" 225 | checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" 226 | 227 | [[package]] 228 | name = "hermit-abi" 229 | version = "0.1.19" 230 | source = "registry+https://github.com/rust-lang/crates.io-index" 231 | checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" 232 | dependencies = [ 233 | "libc", 234 | ] 235 | 236 | [[package]] 237 | name = "http" 238 | version = "0.2.5" 239 | source = "registry+https://github.com/rust-lang/crates.io-index" 240 | checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b" 241 | dependencies = [ 242 | "bytes", 243 | "fnv", 244 | "itoa", 245 | ] 246 | 247 | [[package]] 248 | name = "http-body" 249 | version = "0.4.3" 250 | source = "registry+https://github.com/rust-lang/crates.io-index" 251 | checksum = "399c583b2979440c60be0821a6199eca73bc3c8dcd9d070d75ac726e2c6186e5" 252 | dependencies = [ 253 | "bytes", 254 | "http", 255 | "pin-project-lite", 256 | ] 257 | 258 | [[package]] 259 | name = "httparse" 260 | version = "1.5.1" 261 | source = "registry+https://github.com/rust-lang/crates.io-index" 262 | checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" 263 | 264 | [[package]] 265 | name = "httpdate" 266 | version = "1.0.1" 267 | source = "registry+https://github.com/rust-lang/crates.io-index" 268 | checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" 269 | 270 | [[package]] 271 | name = "hyper" 272 | version = "0.14.13" 273 | source = "registry+https://github.com/rust-lang/crates.io-index" 274 | checksum = "15d1cfb9e4f68655fa04c01f59edb405b6074a0f7118ea881e5026e4a1cd8593" 275 | dependencies = [ 276 | "bytes", 277 | "futures-channel", 278 | "futures-core", 279 | "futures-util", 280 | "h2", 281 | "http", 282 | "http-body", 283 | "httparse", 284 | "httpdate", 285 | "itoa", 286 | "pin-project-lite", 287 | "socket2", 288 | "tokio", 289 | "tower-service", 290 | "tracing", 291 | "want", 292 | ] 293 | 294 | [[package]] 295 | name = "hyper-tls" 296 | version = "0.5.0" 297 | source = "registry+https://github.com/rust-lang/crates.io-index" 298 | checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" 299 | dependencies = [ 300 | "bytes", 301 | "hyper", 302 | "native-tls", 303 | "tokio", 304 | "tokio-native-tls", 305 | ] 306 | 307 | [[package]] 308 | name = "idna" 309 | version = "0.2.3" 310 | source = "registry+https://github.com/rust-lang/crates.io-index" 311 | checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" 312 | dependencies = [ 313 | "matches", 314 | "unicode-bidi", 315 | "unicode-normalization", 316 | ] 317 | 318 | [[package]] 319 | name = "indexmap" 320 | version = "1.7.0" 321 | source = "registry+https://github.com/rust-lang/crates.io-index" 322 | checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" 323 | dependencies = [ 324 | "autocfg", 325 | "hashbrown", 326 | ] 327 | 328 | [[package]] 329 | name = "ipnet" 330 | version = "2.3.1" 331 | source = "registry+https://github.com/rust-lang/crates.io-index" 332 | checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9" 333 | 334 | [[package]] 335 | name = "itoa" 336 | version = "0.4.8" 337 | source = "registry+https://github.com/rust-lang/crates.io-index" 338 | checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" 339 | 340 | [[package]] 341 | name = "js-sys" 342 | version = "0.3.55" 343 | source = "registry+https://github.com/rust-lang/crates.io-index" 344 | checksum = "7cc9ffccd38c451a86bf13657df244e9c3f37493cce8e5e21e940963777acc84" 345 | dependencies = [ 346 | "wasm-bindgen", 347 | ] 348 | 349 | [[package]] 350 | name = "lazy_static" 351 | version = "1.4.0" 352 | source = "registry+https://github.com/rust-lang/crates.io-index" 353 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 354 | 355 | [[package]] 356 | name = "libc" 357 | version = "0.2.102" 358 | source = "registry+https://github.com/rust-lang/crates.io-index" 359 | checksum = "a2a5ac8f984bfcf3a823267e5fde638acc3325f6496633a5da6bb6eb2171e103" 360 | 361 | [[package]] 362 | name = "log" 363 | version = "0.4.14" 364 | source = "registry+https://github.com/rust-lang/crates.io-index" 365 | checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" 366 | dependencies = [ 367 | "cfg-if", 368 | ] 369 | 370 | [[package]] 371 | name = "ltv" 372 | version = "0.1.0" 373 | dependencies = [ 374 | "chrono", 375 | "directories", 376 | "reqwest", 377 | "rpassword", 378 | "serde", 379 | "serde_json", 380 | "termion", 381 | "toml", 382 | "tui", 383 | ] 384 | 385 | [[package]] 386 | name = "matches" 387 | version = "0.1.9" 388 | source = "registry+https://github.com/rust-lang/crates.io-index" 389 | checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" 390 | 391 | [[package]] 392 | name = "memchr" 393 | version = "2.4.1" 394 | source = "registry+https://github.com/rust-lang/crates.io-index" 395 | checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" 396 | 397 | [[package]] 398 | name = "mime" 399 | version = "0.3.16" 400 | source = "registry+https://github.com/rust-lang/crates.io-index" 401 | checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" 402 | 403 | [[package]] 404 | name = "mio" 405 | version = "0.7.13" 406 | source = "registry+https://github.com/rust-lang/crates.io-index" 407 | checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" 408 | dependencies = [ 409 | "libc", 410 | "log", 411 | "miow", 412 | "ntapi", 413 | "winapi", 414 | ] 415 | 416 | [[package]] 417 | name = "miow" 418 | version = "0.3.7" 419 | source = "registry+https://github.com/rust-lang/crates.io-index" 420 | checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" 421 | dependencies = [ 422 | "winapi", 423 | ] 424 | 425 | [[package]] 426 | name = "native-tls" 427 | version = "0.2.8" 428 | source = "registry+https://github.com/rust-lang/crates.io-index" 429 | checksum = "48ba9f7719b5a0f42f338907614285fb5fd70e53858141f69898a1fb7203b24d" 430 | dependencies = [ 431 | "lazy_static", 432 | "libc", 433 | "log", 434 | "openssl", 435 | "openssl-probe", 436 | "openssl-sys", 437 | "schannel", 438 | "security-framework", 439 | "security-framework-sys", 440 | "tempfile", 441 | ] 442 | 443 | [[package]] 444 | name = "ntapi" 445 | version = "0.3.6" 446 | source = "registry+https://github.com/rust-lang/crates.io-index" 447 | checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" 448 | dependencies = [ 449 | "winapi", 450 | ] 451 | 452 | [[package]] 453 | name = "num-integer" 454 | version = "0.1.44" 455 | source = "registry+https://github.com/rust-lang/crates.io-index" 456 | checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" 457 | dependencies = [ 458 | "autocfg", 459 | "num-traits", 460 | ] 461 | 462 | [[package]] 463 | name = "num-traits" 464 | version = "0.2.14" 465 | source = "registry+https://github.com/rust-lang/crates.io-index" 466 | checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" 467 | dependencies = [ 468 | "autocfg", 469 | ] 470 | 471 | [[package]] 472 | name = "num_cpus" 473 | version = "1.13.0" 474 | source = "registry+https://github.com/rust-lang/crates.io-index" 475 | checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" 476 | dependencies = [ 477 | "hermit-abi", 478 | "libc", 479 | ] 480 | 481 | [[package]] 482 | name = "numtoa" 483 | version = "0.1.0" 484 | source = "registry+https://github.com/rust-lang/crates.io-index" 485 | checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" 486 | 487 | [[package]] 488 | name = "once_cell" 489 | version = "1.8.0" 490 | source = "registry+https://github.com/rust-lang/crates.io-index" 491 | checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" 492 | 493 | [[package]] 494 | name = "openssl" 495 | version = "0.10.36" 496 | source = "registry+https://github.com/rust-lang/crates.io-index" 497 | checksum = "8d9facdb76fec0b73c406f125d44d86fdad818d66fef0531eec9233ca425ff4a" 498 | dependencies = [ 499 | "bitflags", 500 | "cfg-if", 501 | "foreign-types", 502 | "libc", 503 | "once_cell", 504 | "openssl-sys", 505 | ] 506 | 507 | [[package]] 508 | name = "openssl-probe" 509 | version = "0.1.4" 510 | source = "registry+https://github.com/rust-lang/crates.io-index" 511 | checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" 512 | 513 | [[package]] 514 | name = "openssl-sys" 515 | version = "0.9.67" 516 | source = "registry+https://github.com/rust-lang/crates.io-index" 517 | checksum = "69df2d8dfc6ce3aaf44b40dec6f487d5a886516cf6879c49e98e0710f310a058" 518 | dependencies = [ 519 | "autocfg", 520 | "cc", 521 | "libc", 522 | "pkg-config", 523 | "vcpkg", 524 | ] 525 | 526 | [[package]] 527 | name = "percent-encoding" 528 | version = "2.1.0" 529 | source = "registry+https://github.com/rust-lang/crates.io-index" 530 | checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" 531 | 532 | [[package]] 533 | name = "pin-project-lite" 534 | version = "0.2.7" 535 | source = "registry+https://github.com/rust-lang/crates.io-index" 536 | checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" 537 | 538 | [[package]] 539 | name = "pin-utils" 540 | version = "0.1.0" 541 | source = "registry+https://github.com/rust-lang/crates.io-index" 542 | checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" 543 | 544 | [[package]] 545 | name = "pkg-config" 546 | version = "0.3.19" 547 | source = "registry+https://github.com/rust-lang/crates.io-index" 548 | checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" 549 | 550 | [[package]] 551 | name = "ppv-lite86" 552 | version = "0.2.10" 553 | source = "registry+https://github.com/rust-lang/crates.io-index" 554 | checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" 555 | 556 | [[package]] 557 | name = "proc-macro2" 558 | version = "1.0.29" 559 | source = "registry+https://github.com/rust-lang/crates.io-index" 560 | checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d" 561 | dependencies = [ 562 | "unicode-xid", 563 | ] 564 | 565 | [[package]] 566 | name = "quote" 567 | version = "1.0.9" 568 | source = "registry+https://github.com/rust-lang/crates.io-index" 569 | checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" 570 | dependencies = [ 571 | "proc-macro2", 572 | ] 573 | 574 | [[package]] 575 | name = "rand" 576 | version = "0.8.4" 577 | source = "registry+https://github.com/rust-lang/crates.io-index" 578 | checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" 579 | dependencies = [ 580 | "libc", 581 | "rand_chacha", 582 | "rand_core", 583 | "rand_hc", 584 | ] 585 | 586 | [[package]] 587 | name = "rand_chacha" 588 | version = "0.3.1" 589 | source = "registry+https://github.com/rust-lang/crates.io-index" 590 | checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" 591 | dependencies = [ 592 | "ppv-lite86", 593 | "rand_core", 594 | ] 595 | 596 | [[package]] 597 | name = "rand_core" 598 | version = "0.6.3" 599 | source = "registry+https://github.com/rust-lang/crates.io-index" 600 | checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" 601 | dependencies = [ 602 | "getrandom", 603 | ] 604 | 605 | [[package]] 606 | name = "rand_hc" 607 | version = "0.3.1" 608 | source = "registry+https://github.com/rust-lang/crates.io-index" 609 | checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" 610 | dependencies = [ 611 | "rand_core", 612 | ] 613 | 614 | [[package]] 615 | name = "redox_syscall" 616 | version = "0.2.10" 617 | source = "registry+https://github.com/rust-lang/crates.io-index" 618 | checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" 619 | dependencies = [ 620 | "bitflags", 621 | ] 622 | 623 | [[package]] 624 | name = "redox_termios" 625 | version = "0.1.2" 626 | source = "registry+https://github.com/rust-lang/crates.io-index" 627 | checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f" 628 | dependencies = [ 629 | "redox_syscall", 630 | ] 631 | 632 | [[package]] 633 | name = "redox_users" 634 | version = "0.4.0" 635 | source = "registry+https://github.com/rust-lang/crates.io-index" 636 | checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" 637 | dependencies = [ 638 | "getrandom", 639 | "redox_syscall", 640 | ] 641 | 642 | [[package]] 643 | name = "remove_dir_all" 644 | version = "0.5.3" 645 | source = "registry+https://github.com/rust-lang/crates.io-index" 646 | checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" 647 | dependencies = [ 648 | "winapi", 649 | ] 650 | 651 | [[package]] 652 | name = "reqwest" 653 | version = "0.11.4" 654 | source = "registry+https://github.com/rust-lang/crates.io-index" 655 | checksum = "246e9f61b9bb77df069a947682be06e31ac43ea37862e244a69f177694ea6d22" 656 | dependencies = [ 657 | "base64", 658 | "bytes", 659 | "encoding_rs", 660 | "futures-core", 661 | "futures-util", 662 | "http", 663 | "http-body", 664 | "hyper", 665 | "hyper-tls", 666 | "ipnet", 667 | "js-sys", 668 | "lazy_static", 669 | "log", 670 | "mime", 671 | "native-tls", 672 | "percent-encoding", 673 | "pin-project-lite", 674 | "serde", 675 | "serde_json", 676 | "serde_urlencoded", 677 | "tokio", 678 | "tokio-native-tls", 679 | "url", 680 | "wasm-bindgen", 681 | "wasm-bindgen-futures", 682 | "web-sys", 683 | "winreg", 684 | ] 685 | 686 | [[package]] 687 | name = "rpassword" 688 | version = "5.0.1" 689 | source = "registry+https://github.com/rust-lang/crates.io-index" 690 | checksum = "ffc936cf8a7ea60c58f030fd36a612a48f440610214dc54bc36431f9ea0c3efb" 691 | dependencies = [ 692 | "libc", 693 | "winapi", 694 | ] 695 | 696 | [[package]] 697 | name = "ryu" 698 | version = "1.0.5" 699 | source = "registry+https://github.com/rust-lang/crates.io-index" 700 | checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" 701 | 702 | [[package]] 703 | name = "schannel" 704 | version = "0.1.19" 705 | source = "registry+https://github.com/rust-lang/crates.io-index" 706 | checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" 707 | dependencies = [ 708 | "lazy_static", 709 | "winapi", 710 | ] 711 | 712 | [[package]] 713 | name = "security-framework" 714 | version = "2.4.2" 715 | source = "registry+https://github.com/rust-lang/crates.io-index" 716 | checksum = "525bc1abfda2e1998d152c45cf13e696f76d0a4972310b22fac1658b05df7c87" 717 | dependencies = [ 718 | "bitflags", 719 | "core-foundation", 720 | "core-foundation-sys", 721 | "libc", 722 | "security-framework-sys", 723 | ] 724 | 725 | [[package]] 726 | name = "security-framework-sys" 727 | version = "2.4.2" 728 | source = "registry+https://github.com/rust-lang/crates.io-index" 729 | checksum = "a9dd14d83160b528b7bfd66439110573efcfbe281b17fc2ca9f39f550d619c7e" 730 | dependencies = [ 731 | "core-foundation-sys", 732 | "libc", 733 | ] 734 | 735 | [[package]] 736 | name = "serde" 737 | version = "1.0.130" 738 | source = "registry+https://github.com/rust-lang/crates.io-index" 739 | checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" 740 | dependencies = [ 741 | "serde_derive", 742 | ] 743 | 744 | [[package]] 745 | name = "serde_derive" 746 | version = "1.0.130" 747 | source = "registry+https://github.com/rust-lang/crates.io-index" 748 | checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" 749 | dependencies = [ 750 | "proc-macro2", 751 | "quote", 752 | "syn", 753 | ] 754 | 755 | [[package]] 756 | name = "serde_json" 757 | version = "1.0.68" 758 | source = "registry+https://github.com/rust-lang/crates.io-index" 759 | checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8" 760 | dependencies = [ 761 | "itoa", 762 | "ryu", 763 | "serde", 764 | ] 765 | 766 | [[package]] 767 | name = "serde_urlencoded" 768 | version = "0.7.0" 769 | source = "registry+https://github.com/rust-lang/crates.io-index" 770 | checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" 771 | dependencies = [ 772 | "form_urlencoded", 773 | "itoa", 774 | "ryu", 775 | "serde", 776 | ] 777 | 778 | [[package]] 779 | name = "slab" 780 | version = "0.4.4" 781 | source = "registry+https://github.com/rust-lang/crates.io-index" 782 | checksum = "c307a32c1c5c437f38c7fd45d753050587732ba8628319fbdf12a7e289ccc590" 783 | 784 | [[package]] 785 | name = "socket2" 786 | version = "0.4.2" 787 | source = "registry+https://github.com/rust-lang/crates.io-index" 788 | checksum = "5dc90fe6c7be1a323296982db1836d1ea9e47b6839496dde9a541bc496df3516" 789 | dependencies = [ 790 | "libc", 791 | "winapi", 792 | ] 793 | 794 | [[package]] 795 | name = "syn" 796 | version = "1.0.76" 797 | source = "registry+https://github.com/rust-lang/crates.io-index" 798 | checksum = "c6f107db402c2c2055242dbf4d2af0e69197202e9faacbef9571bbe47f5a1b84" 799 | dependencies = [ 800 | "proc-macro2", 801 | "quote", 802 | "unicode-xid", 803 | ] 804 | 805 | [[package]] 806 | name = "tempfile" 807 | version = "3.2.0" 808 | source = "registry+https://github.com/rust-lang/crates.io-index" 809 | checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" 810 | dependencies = [ 811 | "cfg-if", 812 | "libc", 813 | "rand", 814 | "redox_syscall", 815 | "remove_dir_all", 816 | "winapi", 817 | ] 818 | 819 | [[package]] 820 | name = "termion" 821 | version = "1.5.6" 822 | source = "registry+https://github.com/rust-lang/crates.io-index" 823 | checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e" 824 | dependencies = [ 825 | "libc", 826 | "numtoa", 827 | "redox_syscall", 828 | "redox_termios", 829 | ] 830 | 831 | [[package]] 832 | name = "time" 833 | version = "0.1.43" 834 | source = "registry+https://github.com/rust-lang/crates.io-index" 835 | checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" 836 | dependencies = [ 837 | "libc", 838 | "winapi", 839 | ] 840 | 841 | [[package]] 842 | name = "tinyvec" 843 | version = "1.4.0" 844 | source = "registry+https://github.com/rust-lang/crates.io-index" 845 | checksum = "5241dd6f21443a3606b432718b166d3cedc962fd4b8bea54a8bc7f514ebda986" 846 | dependencies = [ 847 | "tinyvec_macros", 848 | ] 849 | 850 | [[package]] 851 | name = "tinyvec_macros" 852 | version = "0.1.0" 853 | source = "registry+https://github.com/rust-lang/crates.io-index" 854 | checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" 855 | 856 | [[package]] 857 | name = "tokio" 858 | version = "1.12.0" 859 | source = "registry+https://github.com/rust-lang/crates.io-index" 860 | checksum = "c2c2416fdedca8443ae44b4527de1ea633af61d8f7169ffa6e72c5b53d24efcc" 861 | dependencies = [ 862 | "autocfg", 863 | "bytes", 864 | "libc", 865 | "memchr", 866 | "mio", 867 | "num_cpus", 868 | "pin-project-lite", 869 | "winapi", 870 | ] 871 | 872 | [[package]] 873 | name = "tokio-native-tls" 874 | version = "0.3.0" 875 | source = "registry+https://github.com/rust-lang/crates.io-index" 876 | checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" 877 | dependencies = [ 878 | "native-tls", 879 | "tokio", 880 | ] 881 | 882 | [[package]] 883 | name = "tokio-util" 884 | version = "0.6.8" 885 | source = "registry+https://github.com/rust-lang/crates.io-index" 886 | checksum = "08d3725d3efa29485e87311c5b699de63cde14b00ed4d256b8318aa30ca452cd" 887 | dependencies = [ 888 | "bytes", 889 | "futures-core", 890 | "futures-sink", 891 | "log", 892 | "pin-project-lite", 893 | "tokio", 894 | ] 895 | 896 | [[package]] 897 | name = "toml" 898 | version = "0.5.8" 899 | source = "registry+https://github.com/rust-lang/crates.io-index" 900 | checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" 901 | dependencies = [ 902 | "serde", 903 | ] 904 | 905 | [[package]] 906 | name = "tower-service" 907 | version = "0.3.1" 908 | source = "registry+https://github.com/rust-lang/crates.io-index" 909 | checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" 910 | 911 | [[package]] 912 | name = "tracing" 913 | version = "0.1.28" 914 | source = "registry+https://github.com/rust-lang/crates.io-index" 915 | checksum = "84f96e095c0c82419687c20ddf5cb3eadb61f4e1405923c9dc8e53a1adacbda8" 916 | dependencies = [ 917 | "cfg-if", 918 | "pin-project-lite", 919 | "tracing-core", 920 | ] 921 | 922 | [[package]] 923 | name = "tracing-core" 924 | version = "0.1.20" 925 | source = "registry+https://github.com/rust-lang/crates.io-index" 926 | checksum = "46125608c26121c81b0c6d693eab5a420e416da7e43c426d2e8f7df8da8a3acf" 927 | dependencies = [ 928 | "lazy_static", 929 | ] 930 | 931 | [[package]] 932 | name = "try-lock" 933 | version = "0.2.3" 934 | source = "registry+https://github.com/rust-lang/crates.io-index" 935 | checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" 936 | 937 | [[package]] 938 | name = "tui" 939 | version = "0.16.0" 940 | source = "git+https://github.com/LunaticHacker/tui-rs?branch=for-ltv#2ebc0fb97c9bbf74955d6c57220d0bda268a2393" 941 | dependencies = [ 942 | "bitflags", 943 | "cassowary", 944 | "termion", 945 | "unicode-segmentation", 946 | "unicode-width", 947 | ] 948 | 949 | [[package]] 950 | name = "unicode-bidi" 951 | version = "0.3.6" 952 | source = "registry+https://github.com/rust-lang/crates.io-index" 953 | checksum = "246f4c42e67e7a4e3c6106ff716a5d067d4132a642840b242e357e468a2a0085" 954 | 955 | [[package]] 956 | name = "unicode-normalization" 957 | version = "0.1.19" 958 | source = "registry+https://github.com/rust-lang/crates.io-index" 959 | checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" 960 | dependencies = [ 961 | "tinyvec", 962 | ] 963 | 964 | [[package]] 965 | name = "unicode-segmentation" 966 | version = "1.8.0" 967 | source = "registry+https://github.com/rust-lang/crates.io-index" 968 | checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" 969 | 970 | [[package]] 971 | name = "unicode-width" 972 | version = "0.1.9" 973 | source = "registry+https://github.com/rust-lang/crates.io-index" 974 | checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" 975 | 976 | [[package]] 977 | name = "unicode-xid" 978 | version = "0.2.2" 979 | source = "registry+https://github.com/rust-lang/crates.io-index" 980 | checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" 981 | 982 | [[package]] 983 | name = "url" 984 | version = "2.2.2" 985 | source = "registry+https://github.com/rust-lang/crates.io-index" 986 | checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" 987 | dependencies = [ 988 | "form_urlencoded", 989 | "idna", 990 | "matches", 991 | "percent-encoding", 992 | ] 993 | 994 | [[package]] 995 | name = "vcpkg" 996 | version = "0.2.15" 997 | source = "registry+https://github.com/rust-lang/crates.io-index" 998 | checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" 999 | 1000 | [[package]] 1001 | name = "want" 1002 | version = "0.3.0" 1003 | source = "registry+https://github.com/rust-lang/crates.io-index" 1004 | checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" 1005 | dependencies = [ 1006 | "log", 1007 | "try-lock", 1008 | ] 1009 | 1010 | [[package]] 1011 | name = "wasi" 1012 | version = "0.10.2+wasi-snapshot-preview1" 1013 | source = "registry+https://github.com/rust-lang/crates.io-index" 1014 | checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" 1015 | 1016 | [[package]] 1017 | name = "wasm-bindgen" 1018 | version = "0.2.78" 1019 | source = "registry+https://github.com/rust-lang/crates.io-index" 1020 | checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" 1021 | dependencies = [ 1022 | "cfg-if", 1023 | "serde", 1024 | "serde_json", 1025 | "wasm-bindgen-macro", 1026 | ] 1027 | 1028 | [[package]] 1029 | name = "wasm-bindgen-backend" 1030 | version = "0.2.78" 1031 | source = "registry+https://github.com/rust-lang/crates.io-index" 1032 | checksum = "a317bf8f9fba2476b4b2c85ef4c4af8ff39c3c7f0cdfeed4f82c34a880aa837b" 1033 | dependencies = [ 1034 | "bumpalo", 1035 | "lazy_static", 1036 | "log", 1037 | "proc-macro2", 1038 | "quote", 1039 | "syn", 1040 | "wasm-bindgen-shared", 1041 | ] 1042 | 1043 | [[package]] 1044 | name = "wasm-bindgen-futures" 1045 | version = "0.4.28" 1046 | source = "registry+https://github.com/rust-lang/crates.io-index" 1047 | checksum = "8e8d7523cb1f2a4c96c1317ca690031b714a51cc14e05f712446691f413f5d39" 1048 | dependencies = [ 1049 | "cfg-if", 1050 | "js-sys", 1051 | "wasm-bindgen", 1052 | "web-sys", 1053 | ] 1054 | 1055 | [[package]] 1056 | name = "wasm-bindgen-macro" 1057 | version = "0.2.78" 1058 | source = "registry+https://github.com/rust-lang/crates.io-index" 1059 | checksum = "d56146e7c495528bf6587663bea13a8eb588d39b36b679d83972e1a2dbbdacf9" 1060 | dependencies = [ 1061 | "quote", 1062 | "wasm-bindgen-macro-support", 1063 | ] 1064 | 1065 | [[package]] 1066 | name = "wasm-bindgen-macro-support" 1067 | version = "0.2.78" 1068 | source = "registry+https://github.com/rust-lang/crates.io-index" 1069 | checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab" 1070 | dependencies = [ 1071 | "proc-macro2", 1072 | "quote", 1073 | "syn", 1074 | "wasm-bindgen-backend", 1075 | "wasm-bindgen-shared", 1076 | ] 1077 | 1078 | [[package]] 1079 | name = "wasm-bindgen-shared" 1080 | version = "0.2.78" 1081 | source = "registry+https://github.com/rust-lang/crates.io-index" 1082 | checksum = "0237232789cf037d5480773fe568aac745bfe2afbc11a863e97901780a6b47cc" 1083 | 1084 | [[package]] 1085 | name = "web-sys" 1086 | version = "0.3.55" 1087 | source = "registry+https://github.com/rust-lang/crates.io-index" 1088 | checksum = "38eb105f1c59d9eaa6b5cdc92b859d85b926e82cb2e0945cd0c9259faa6fe9fb" 1089 | dependencies = [ 1090 | "js-sys", 1091 | "wasm-bindgen", 1092 | ] 1093 | 1094 | [[package]] 1095 | name = "winapi" 1096 | version = "0.3.9" 1097 | source = "registry+https://github.com/rust-lang/crates.io-index" 1098 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 1099 | dependencies = [ 1100 | "winapi-i686-pc-windows-gnu", 1101 | "winapi-x86_64-pc-windows-gnu", 1102 | ] 1103 | 1104 | [[package]] 1105 | name = "winapi-i686-pc-windows-gnu" 1106 | version = "0.4.0" 1107 | source = "registry+https://github.com/rust-lang/crates.io-index" 1108 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 1109 | 1110 | [[package]] 1111 | name = "winapi-x86_64-pc-windows-gnu" 1112 | version = "0.4.0" 1113 | source = "registry+https://github.com/rust-lang/crates.io-index" 1114 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 1115 | 1116 | [[package]] 1117 | name = "winreg" 1118 | version = "0.7.0" 1119 | source = "registry+https://github.com/rust-lang/crates.io-index" 1120 | checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" 1121 | dependencies = [ 1122 | "winapi", 1123 | ] 1124 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ltv" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | termion = "1.5" 10 | tui = "0.16.0" 11 | reqwest = { version = "0.11", features = ["blocking", "json"] } 12 | serde = { version = "1.0", features = ["derive"] } 13 | serde_json = "1.0" 14 | directories = "3.0.2" 15 | toml = "0.5.8" 16 | rpassword = "5.0.1" 17 | chrono = "0.4" 18 | 19 | [patch.crates-io] 20 | tui = {git = "https://github.com/LunaticHacker/tui-rs", branch = "for-ltv"} 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Lemmy-Terminal-Viewer 2 | 3 | Terminal User Interface for lemmy for Linux Terminals (should work in MacOs but i can't test) 4 | 5 | ## Install and Usage 6 | 7 | ### Linux 8 | 9 | * Download ```ltv-linux.tar.gz``` from [releases](https://github.com/LunaticHacker/lemmy-terminal-viewer/releases) 10 | * Navigate to download location 11 | * Extract it with ```tar -xf ltv-linux.tar.gz ``` 12 | * You can now execute the file using ```./ltv``` 13 | * To Install globally move the executable to /usr/bin with ```sudo mv ./ltv /usr/bin``` 14 | 15 | ### Mac 16 | Build the project yourself with cargo (no offical support) 17 | 18 | ### Loggin In 19 | 20 | You can log in to as many accounts as you want in any number of instances 21 | 22 | To add an account run 23 | 24 | ``` 25 | ltv login 26 | ``` 27 | You will be prompted to provide login details, if you successfully authenticate you will be redirected to your Feed; 28 | 29 | To log in to an already added account, run 30 | ``` 31 | ltv instance.url username_or_email 32 | ``` 33 | 34 | Or you can always browse without logging in by running 35 | ``` 36 | ltv instance.url 37 | ``` 38 | 39 | ### Setting up configs (Optional) 40 | Path for storing configs 41 | 42 | On Linux: ``` /home/alice/.config/ltv/``` 43 | 44 | On Mac: 45 | ```/Users/Alice/Library/Application Support/dev.ltv.ltv/``` 46 | 47 | copy the [sample config](ltv.sample.toml) rename it to ltv.toml and save to the path given above 48 | and finally make the changes you desire. All configs are explained in the sample config 49 | 50 | ### Navigation 51 | 52 | - Navigation is based on Arrow keys (for now) 53 | 54 | - use ⬆️ and ⬇️ keys to traverse lists of posts and comments 55 | 56 | - when viewing a post press ⬇️ to see it's comments 57 | 58 | - press ➡️ to see a comment's replies and ⬅️ to go back 59 | 60 | ### Browsing communities 61 | 62 | In the default view press " i " to enter edit-mode to select community, enter the name of community and press ➡️ to submit. use ⬅️ to exit editing mode. 63 | -------------------------------------------------------------------------------- /ltv.sample.toml: -------------------------------------------------------------------------------- 1 | # Important: Do NOT remove any fields. Missing fields will not be set to Default (for now) 2 | # possible values for sort: Active,Hot,MostComments,New,NewComments,TopAll,TopDay,TopMonth,TopWeek,TopYear 3 | # possible values for type: All,Local,Subscribed 4 | # The theme colours can be an rgb string of the form "255, 255, 255" or a string that references the colours from your terminal theme: Reset, Black, Red, Green, Yellow, Blue, Magenta, Cyan, Gray, DarkGray, LightRed, LightGreen, LightYellow, LightBlue, LightMagenta, LightCyan, White 5 | default_instance='https://lemmy.ml' # Default instance to use when no params are provided on startup 6 | [params] 7 | limit='10' # How many posts to fetch 8 | sort='Active' # How to sort the posts 9 | type_='All' # A filter to fetch posts from either your Subscribed communities or your Local instance 10 | 11 | [theme] 12 | primary="LightGreen" # Used for most of the data 13 | secondary="White" # Used for metadata 14 | bg="Black" # Background of the terminal 15 | -------------------------------------------------------------------------------- /src/api.rs: -------------------------------------------------------------------------------- 1 | use super::utils; 2 | use serde::Deserialize; 3 | //Structs for Posts 4 | #[derive(Deserialize, Debug)] 5 | pub struct Post { 6 | pub id: i32, 7 | pub name: String, 8 | pub url: Option, 9 | pub body: Option, 10 | pub creator_id: i32, 11 | pub community_id: i32, 12 | pub removed: bool, 13 | pub locked: bool, 14 | pub published: Option, 15 | pub updated: Option, 16 | pub deleted: bool, 17 | pub nsfw: bool, 18 | pub stickied: bool, 19 | pub embed_title: Option, 20 | pub embed_description: Option, 21 | pub embed_html: Option, 22 | pub thumbnail_url: Option, 23 | pub ap_id: Option, 24 | pub local: bool, 25 | } 26 | #[derive(Deserialize)] 27 | pub struct PostInfo { 28 | pub post: Post, 29 | pub creator: Creator, 30 | pub community: Community, 31 | pub counts: PostCounts, 32 | //There are more fields but we don't care 33 | } 34 | #[derive(Deserialize)] 35 | pub struct PostObj { 36 | pub posts: Vec, 37 | } 38 | //Structs for Comments 39 | #[derive(Deserialize, Debug, Default, Clone)] 40 | pub struct Comment { 41 | pub id: i32, 42 | pub content: String, 43 | pub parent_id: Option, 44 | pub published: String, 45 | } 46 | 47 | #[derive(Deserialize, Default, Clone)] 48 | pub struct CommentInfo { 49 | pub comment: Comment, 50 | pub creator: Creator, 51 | pub counts: CommentCounts, 52 | //There are more fields but we don't care 53 | } 54 | 55 | #[derive(Deserialize)] 56 | pub struct CommentObj { 57 | pub comments: Vec, 58 | //There are more fields but we don't care 59 | } 60 | #[derive(Default, Clone)] 61 | pub struct CommentTree { 62 | pub comment: CommentInfo, 63 | pub children: Vec, 64 | } 65 | impl CommentTree { 66 | fn new(comment: &CommentInfo) -> Self { 67 | Self { 68 | comment: comment.clone(), 69 | children: vec![], 70 | } 71 | } 72 | 73 | fn fill_children(mut self, comments: &Vec) -> Self { 74 | for i in 0..comments.len() { 75 | let clone = comments.clone(); 76 | if comments[i].comment.parent_id.unwrap_or_default() == self.comment.comment.id { 77 | self.children 78 | .push(CommentTree::new(&comments[i]).fill_children(&clone)); 79 | } 80 | } 81 | return self; 82 | } 83 | } 84 | #[derive(Deserialize)] 85 | struct LoginResponse { 86 | jwt: Option, 87 | } 88 | #[derive(serde::Serialize)] 89 | pub struct LoginForm { 90 | username_or_email: String, 91 | password: String, 92 | } 93 | impl LoginForm { 94 | pub fn new(login: String, pass: String) -> Self { 95 | Self { 96 | username_or_email: login, 97 | password: pass, 98 | } 99 | } 100 | } 101 | #[derive(Deserialize, Default, Clone)] 102 | pub struct Creator { 103 | pub name: String, 104 | } 105 | #[derive(Deserialize, Default, Clone)] 106 | pub struct Community { 107 | pub name: String, 108 | } 109 | #[derive(Deserialize, Default, Clone)] 110 | pub struct PostCounts { 111 | pub comments: i64, 112 | } 113 | #[derive(Deserialize, Default, Clone)] 114 | pub struct CommentCounts { 115 | pub score: i64, 116 | } 117 | //Api Fetching Functions 118 | 119 | pub fn get_posts(url: String, auth: &str, config: &str) -> Result, reqwest::Error> { 120 | let response; 121 | if auth.is_empty() { 122 | response = reqwest::blocking::get(url + config)?; 123 | } else { 124 | response = reqwest::blocking::get(url + "auth=" + &auth + config)? 125 | } 126 | return Ok(response.json::()?.posts); 127 | } 128 | pub fn get_comments(url: String, auth: &str) -> Result, reqwest::Error> { 129 | let response; 130 | if auth.is_empty() { 131 | response = reqwest::blocking::get(url)?; 132 | } else { 133 | response = reqwest::blocking::get(url + "auth=" + &auth)? 134 | } 135 | let comments = response.json::()?.comments; 136 | let clone = comments.clone(); 137 | let filtered_comments: Vec = comments 138 | .into_iter() 139 | .filter(|c| !c.comment.parent_id.is_some()) 140 | .collect(); 141 | let result = utils::map_tree(filtered_comments); 142 | //result.iter().map(|r|r.fill_children(&clone)).collect() 143 | return Ok(result 144 | .into_iter() 145 | .map(|r| r.fill_children(&clone)) 146 | .collect()); 147 | } 148 | 149 | pub fn login(url: String, login: String, pass: String) -> Result { 150 | let client = reqwest::blocking::Client::new(); 151 | let response = client.post(url).json(&LoginForm::new(login, pass)).send()?; 152 | return Ok(response.json::()?.jwt.unwrap_or_default()); 153 | } 154 | -------------------------------------------------------------------------------- /src/app.rs: -------------------------------------------------------------------------------- 1 | use super::api::{CommentTree, PostInfo}; 2 | use std::collections::HashMap; 3 | use tui::widgets::ListState; 4 | //Enum for Different Modes 5 | pub enum InputMode { 6 | Normal, 7 | Editing, 8 | PostView, 9 | CommentView, 10 | } 11 | /// App holds the state of the application 12 | pub struct LApp { 13 | /// Current value of the input box 14 | pub input: String, 15 | /// Current input mode 16 | pub input_mode: InputMode, 17 | //List of Posts 18 | pub posts: Vec, 19 | //State for indexing the list 20 | pub state: ListState, 21 | //List of Comments 22 | pub comments: Vec, 23 | //State for indexing comments 24 | pub comment_state: ListState, 25 | //State for indexing replies 26 | pub replies_state: ListState, 27 | //List of replies 28 | pub replies: Vec, 29 | //instance url 30 | pub instance: String, 31 | //cursor to navigate nested comments 32 | pub cursor: Vec, 33 | //jwt key 34 | pub auth: String, 35 | //theme 36 | pub theme: HashMap, 37 | } 38 | 39 | impl Default for LApp { 40 | fn default() -> Self { 41 | Self { 42 | input: String::new(), 43 | input_mode: InputMode::Normal, 44 | posts: Vec::new(), 45 | comments: Vec::new(), 46 | replies: Vec::new(), 47 | state: ListState::default(), 48 | comment_state: ListState::default(), 49 | replies_state: ListState::default(), 50 | instance: String::from("https://lemmy.ml"), 51 | cursor: Vec::new(), 52 | auth: String::from(""), 53 | theme: HashMap::new(), 54 | } 55 | } 56 | } 57 | 58 | impl LApp { 59 | // Select the next item. This will not be reflected until the widget is drawn in the 60 | // `Terminal::draw` callback using `Frame::render_stateful_widget`. 61 | pub fn next(&mut self) { 62 | let i = match self.state.selected() { 63 | Some(i) => { 64 | if i >= self.posts.len() - 1 { 65 | 0 66 | } else { 67 | i + 1 68 | } 69 | } 70 | None => 0, 71 | }; 72 | self.state.select(Some(i)); 73 | } 74 | pub fn previous(&mut self) { 75 | let i = match self.state.selected() { 76 | Some(i) => { 77 | if i == 0 { 78 | self.posts.len() - 1 79 | } else { 80 | i - 1 81 | } 82 | } 83 | None => 0, 84 | }; 85 | self.state.select(Some(i)); 86 | } 87 | 88 | // Unselect the currently selected item if any. The implementation of `ListState` makes 89 | // sure that the stored offset is also reset. 90 | pub fn unselect(&mut self) { 91 | self.state.select(None); 92 | } 93 | } 94 | impl LApp { 95 | // TODO: Refactor this into one function. 96 | pub fn c_next(&mut self) { 97 | if self.replies.is_empty() { 98 | let i = match self.comment_state.selected() { 99 | Some(i) => { 100 | if i >= self.comments.len() - 1 { 101 | 0 102 | } else { 103 | i + 1 104 | } 105 | } 106 | None => 0, 107 | }; 108 | self.comment_state.select(Some(i)); 109 | } else { 110 | let i = match self.replies_state.selected() { 111 | Some(i) => { 112 | if i >= self.replies.len() - 1 { 113 | 0 114 | } else { 115 | i + 1 116 | } 117 | } 118 | None => 0, 119 | }; 120 | self.replies_state.select(Some(i)); 121 | } 122 | } 123 | pub fn c_previous(&mut self) { 124 | if self.replies.is_empty() { 125 | let i = match self.comment_state.selected() { 126 | Some(i) => { 127 | if i == 0 { 128 | self.comments.len() - 1 129 | } else { 130 | i - 1 131 | } 132 | } 133 | None => 0, 134 | }; 135 | self.comment_state.select(Some(i)); 136 | } else { 137 | let i = match self.replies_state.selected() { 138 | Some(i) => { 139 | if i == 0 { 140 | self.replies.len() - 1 141 | } else { 142 | i - 1 143 | } 144 | } 145 | None => 0, 146 | }; 147 | self.replies_state.select(Some(i)); 148 | } 149 | } 150 | 151 | // Unselect the currently selected item if any. The implementation of `ListState` makes 152 | // sure that the stored offset is also reset. 153 | pub fn c_unselect(&mut self) { 154 | self.comment_state.select(None); 155 | } 156 | pub fn r_unselect(&mut self) { 157 | self.replies_state.select(None); 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /src/auth.rs: -------------------------------------------------------------------------------- 1 | use super::api; 2 | use directories::ProjectDirs; 3 | use serde::{Deserialize, Serialize}; 4 | use std::collections::HashMap; 5 | use std::fs; 6 | use std::io::{stdin, stdout, Error, ErrorKind, Write}; 7 | use toml; 8 | 9 | #[derive(Default, Deserialize, Serialize, Debug)] 10 | pub struct AuthConfig { 11 | pub instancelist: InstanceList, 12 | } 13 | 14 | #[derive(Default, Deserialize, Serialize, Debug)] 15 | pub struct InstanceList { 16 | pub instances: HashMap, 17 | } 18 | #[derive(Default, Deserialize, Serialize, Debug)] 19 | pub struct UserList { 20 | pub userlist: HashMap, 21 | } 22 | 23 | pub fn login() -> Result<(String, String), Error> { 24 | let reader = stdin(); 25 | let mut instance = String::new(); 26 | let mut login = String::new(); 27 | print!("Enter your instance: "); 28 | stdout().flush().unwrap(); 29 | reader.read_line(&mut instance).ok().expect(""); 30 | instance.pop(); 31 | print!("Enter your username or email: "); 32 | stdout().flush().unwrap(); 33 | reader.read_line(&mut login).ok().expect(""); 34 | login.pop(); 35 | print!("Enter your password: "); 36 | stdout().flush().unwrap(); 37 | let pass = rpassword::read_password().unwrap_or_default(); 38 | instance = super::utils::prepend_https(instance); 39 | match api::login( 40 | format!("{}/api/v3/user/login", instance), 41 | login.clone(), 42 | pass, 43 | ) { 44 | Ok(jwt) => { 45 | if !jwt.is_empty() { 46 | println!("Login successful"); 47 | if let Some(proj_dirs) = ProjectDirs::from("dev", "ltv", "ltv") { 48 | fs::create_dir_all(proj_dirs.config_dir())?; 49 | let mut config_file = fs::OpenOptions::new() 50 | .write(true) 51 | .create(true) 52 | .open(&proj_dirs.config_dir().join("auth.toml"))?; 53 | let config = fs::read_to_string(&proj_dirs.config_dir().join("auth.toml")) 54 | .unwrap_or_default(); 55 | let mut toml: AuthConfig = toml::from_str(&config).unwrap_or_default(); 56 | toml.instancelist 57 | .instances 58 | .entry(instance.clone()) 59 | .or_insert(UserList::default()) 60 | .userlist 61 | .insert(login, jwt.clone()); 62 | let new_config = toml::to_string(&toml).unwrap_or_default(); 63 | if let Ok(_) = write!(config_file, "{}", new_config) { 64 | Ok((instance, jwt)) 65 | } else { 66 | Err(Error::new(ErrorKind::Other, "Couldn't save login details")) 67 | } 68 | } else { 69 | Err(Error::new(ErrorKind::Other, "Couldn't save login details")) 70 | } 71 | } else { 72 | Err(Error::new(ErrorKind::Other, "Login Failed")) 73 | } 74 | } 75 | Err(e) => { 76 | println!("Something went wrong {}", e); 77 | Err(Error::new(ErrorKind::Other, e)) 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/config.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | #[derive(serde::Deserialize, Clone)] 3 | pub struct Config { 4 | pub params: HashMap, 5 | pub default_instance: String, 6 | pub theme: HashMap, 7 | } 8 | //Default Configs 9 | impl Default for Config { 10 | fn default() -> Self { 11 | let mut params = HashMap::new(); 12 | params.insert(String::from("limit"), String::from("10")); 13 | params.insert(String::from("sort"), String::from("Active")); 14 | params.insert(String::from("type_"), String::from("All")); 15 | let mut theme = HashMap::new(); 16 | theme.insert(String::from("primary"), String::from("LightGreen")); 17 | theme.insert(String::from("secondary"), String::from("White")); 18 | theme.insert(String::from("bg"), String::from("Black")); 19 | Self { 20 | params: params, 21 | default_instance: String::from("https://lemmy.ml"), 22 | theme: theme, 23 | } 24 | } 25 | } 26 | impl Config { 27 | pub fn stringify(self) -> String { 28 | let mut str: String = String::from(""); 29 | for (key, value) in &self.params { 30 | str += &format!("&{}={}", key, value); 31 | } 32 | return str; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/event.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | use std::sync::mpsc; 3 | use std::thread; 4 | use std::time::Duration; 5 | 6 | use termion::event::Key; 7 | use termion::input::TermRead; 8 | 9 | pub enum Event { 10 | Input(I), 11 | Tick, 12 | } 13 | 14 | /// A small event handler that wrap termion input and tick events. Each event 15 | /// type is handled in its own thread and returned to a common `Receiver` 16 | #[allow(dead_code)] 17 | pub struct Events { 18 | rx: mpsc::Receiver>, 19 | input_handle: thread::JoinHandle<()>, 20 | tick_handle: thread::JoinHandle<()>, 21 | } 22 | 23 | #[derive(Debug, Clone, Copy)] 24 | pub struct Config { 25 | pub tick_rate: Duration, 26 | } 27 | 28 | impl Default for Config { 29 | fn default() -> Config { 30 | Config { 31 | tick_rate: Duration::from_millis(250), 32 | } 33 | } 34 | } 35 | 36 | impl Events { 37 | pub fn new() -> Events { 38 | Events::with_config(Config::default()) 39 | } 40 | 41 | pub fn with_config(config: Config) -> Events { 42 | let (tx, rx) = mpsc::channel(); 43 | let input_handle = { 44 | let tx = tx.clone(); 45 | thread::spawn(move || { 46 | let stdin = io::stdin(); 47 | for evt in stdin.keys() { 48 | if let Ok(key) = evt { 49 | if let Err(err) = tx.send(Event::Input(key)) { 50 | eprintln!("{}", err); 51 | return; 52 | } 53 | } 54 | } 55 | }) 56 | }; 57 | let tick_handle = { 58 | thread::spawn(move || loop { 59 | if let Err(err) = tx.send(Event::Tick) { 60 | eprintln!("{}", err); 61 | break; 62 | } 63 | thread::sleep(config.tick_rate); 64 | }) 65 | }; 66 | Events { 67 | rx, 68 | input_handle, 69 | tick_handle, 70 | } 71 | } 72 | 73 | pub fn next(&self) -> Result, mpsc::RecvError> { 74 | self.rx.recv() 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | mod api; 2 | mod app; 3 | mod auth; 4 | mod config; 5 | mod event; 6 | mod ui; 7 | mod utils; 8 | use app::{InputMode, LApp}; 9 | use directories::ProjectDirs; 10 | use event::{Event, Events}; 11 | use std::env; 12 | use std::fs; 13 | use std::io; 14 | use termion::{event::Key, raw::IntoRawMode, screen::AlternateScreen}; 15 | use tui::backend::TermionBackend; 16 | use tui::Terminal; 17 | 18 | fn main() -> Result<(), io::Error> { 19 | let mut app = LApp::default(); 20 | let args: Vec = env::args().collect(); 21 | let mut conf: config::Config = config::Config::default(); 22 | 23 | if let Some(proj_dirs) = ProjectDirs::from("dev", "ltv", "ltv") { 24 | let config_dir = proj_dirs.config_dir(); 25 | 26 | let config_file = fs::read_to_string(config_dir.join("ltv.toml")); 27 | 28 | conf = match config_file { 29 | Ok(file) => toml::from_str(&file).unwrap(), 30 | Err(_) => config::Config::default(), 31 | }; 32 | app.instance = utils::prepend_https(conf.default_instance.clone()); 33 | app.theme = utils::colorify(conf.theme.clone()); 34 | } 35 | 36 | match args.len() { 37 | 2 => { 38 | if &args[1] == "login" { 39 | match auth::login() { 40 | Ok(tuple) => { 41 | app.instance = tuple.0; 42 | app.auth = tuple.1; 43 | } 44 | Err(e) => return Err(e), 45 | }; 46 | } else { 47 | app.instance = utils::prepend_https(args[1].clone()); 48 | } 49 | } 50 | 3 => { 51 | app.instance = utils::prepend_https(args[1].clone()); 52 | if let Some(proj_dirs) = ProjectDirs::from("dev", "ltv", "ltv") { 53 | let config: auth::AuthConfig = toml::from_str( 54 | &fs::read_to_string(&proj_dirs.config_dir().join("ltv.toml")) 55 | .unwrap_or_default(), 56 | ) 57 | .unwrap_or_default(); 58 | app.auth = config.instancelist.instances[&app.instance].userlist[&args[2]].clone(); 59 | } 60 | } 61 | _ => {} 62 | } 63 | app.posts = api::get_posts( 64 | format!("{}/api/v3/post/list?", &app.instance), 65 | &app.auth, 66 | &conf.clone().stringify(), 67 | ) 68 | .unwrap_or_default(); 69 | // Set up terminal output 70 | let stdout = io::stdout().into_raw_mode()?; 71 | let backend = TermionBackend::new(AlternateScreen::from(stdout)); 72 | let mut terminal = Terminal::new(backend)?; 73 | 74 | //init event handler 75 | let events = Events::new(); 76 | 77 | terminal.clear()?; 78 | 'outer: loop { 79 | // Lock the terminal and start a drawing session. 80 | terminal.autoresize()?; 81 | terminal 82 | .draw(|mut frame| { 83 | if let InputMode::PostView = app.input_mode { 84 | ui::draw_post(&mut app, &mut frame) 85 | } else if let InputMode::CommentView = app.input_mode { 86 | ui::draw_comment(&mut app, &mut frame) 87 | } else { 88 | ui::draw_normal(&mut app, &mut frame); 89 | } 90 | }) 91 | .unwrap(); 92 | //Event handling, TODO: Refactor this abomination 93 | if let Event::Input(input) = events.next().unwrap() { 94 | if let InputMode::Normal = &app.input_mode { 95 | if let Key::Char('q') = input { 96 | break 'outer; 97 | } else if let Key::Char('i') = input { 98 | app.unselect(); 99 | app.input_mode = InputMode::Editing; 100 | } else if let Key::Up = input { 101 | app.previous() 102 | } else if let Key::Down = input { 103 | app.next() 104 | } else if let Key::Right = input { 105 | if !app.posts.is_empty() { 106 | app.input_mode = InputMode::PostView 107 | } 108 | } else if let Key::Left = input { 109 | app.posts = api::get_posts( 110 | format!("{}/api/v3/post/list?", &app.instance), 111 | &app.auth, 112 | &conf.clone().stringify(), 113 | ) 114 | .unwrap_or_default(); 115 | } else if let Key::Char('1') = input { 116 | //unwrap is fine we will have a config always 117 | let limit = conf.params.get("limit").unwrap(); 118 | let type_ = conf.params.get("type_").unwrap(); 119 | app.posts = api::get_posts( 120 | format!("{}/api/v3/post/list?", &app.instance), 121 | &app.auth, 122 | &format!("&limit={}&type_={}&sort=New", limit, type_), 123 | ) 124 | .unwrap_or_default(); 125 | app.unselect(); 126 | } else if let Key::Char('2') = input { 127 | //unwrap is fine we will have a config always 128 | let limit = conf.params.get("limit").unwrap(); 129 | let type_ = conf.params.get("type_").unwrap(); 130 | app.posts = api::get_posts( 131 | format!("{}/api/v3/post/list?", &app.instance), 132 | &app.auth, 133 | &format!("&limit={}&type_={}&sort=Hot", limit, type_), 134 | ) 135 | .unwrap_or_default(); 136 | app.unselect(); 137 | } else if let Key::Char('3') = input { 138 | //unwrap is fine we will have a config always 139 | let limit = conf.params.get("limit").unwrap(); 140 | let type_ = conf.params.get("type_").unwrap(); 141 | app.posts = api::get_posts( 142 | format!("{}/api/v3/post/list?", &app.instance), 143 | &app.auth, 144 | &format!("&limit={}&type_={}&sort=Active", limit, type_), 145 | ) 146 | .unwrap_or_default(); 147 | app.unselect(); 148 | } else if let Key::Char('4') = input { 149 | //unwrap is fine we will have a config always 150 | let limit = conf.params.get("limit").unwrap(); 151 | let type_ = conf.params.get("type_").unwrap(); 152 | app.posts = api::get_posts( 153 | format!("{}/api/v3/post/list?", &app.instance), 154 | &app.auth, 155 | &format!("&limit={}&type_={}&sort=New", limit, type_), 156 | ) 157 | .unwrap_or_default(); 158 | app.posts.reverse(); 159 | app.unselect(); 160 | } 161 | } else if let InputMode::Editing = &app.input_mode { 162 | if let Key::Left = input { 163 | app.input_mode = InputMode::Normal; 164 | } else if let Key::Right = input { 165 | app.posts = api::get_posts( 166 | format!( 167 | "{}/api/v3/post/list?community_name={}", 168 | &app.instance, app.input 169 | ), 170 | &app.auth, 171 | &conf.clone().stringify(), 172 | ) 173 | .unwrap_or_default(); 174 | app.input_mode = InputMode::Normal; 175 | } else if let termion::event::Key::Char(c) = input { 176 | app.input.push(c); 177 | } else if let Key::Backspace = input { 178 | app.input.pop(); 179 | } 180 | } else if let InputMode::PostView = &app.input_mode { 181 | if let Key::Left = input { 182 | app.comments = Vec::new(); 183 | app.input_mode = InputMode::Normal; 184 | } else if let Key::Char('q') = input { 185 | break 'outer; 186 | } else if let Key::Down = input { 187 | app.c_unselect(); 188 | let comments = api::get_comments( 189 | format!( 190 | "{}/api/v3/post?id={}&", 191 | &app.instance, 192 | app.posts[app.state.selected().unwrap_or_default()].post.id 193 | ), 194 | &app.auth, 195 | ) 196 | .unwrap_or_default(); 197 | app.comments = comments; 198 | app.input_mode = InputMode::CommentView; 199 | } 200 | } else if let InputMode::CommentView = &app.input_mode { 201 | if let Key::Up = input { 202 | if !app.comments.is_empty() { 203 | app.c_previous() 204 | } 205 | } else if let Key::Down = input { 206 | if !app.comments.is_empty() { 207 | app.c_next() 208 | } 209 | } else if let Key::Left = input { 210 | if app.cursor.len() == 1 { 211 | app.r_unselect(); 212 | app.replies = Vec::new(); 213 | app.cursor.pop(); 214 | } else if app.cursor.len() > 1 { 215 | app.cursor.pop(); 216 | app.r_unselect(); 217 | app.replies = utils::get_comments(app.cursor.clone(), app.comments.clone()); 218 | } else { 219 | app.r_unselect(); 220 | app.replies = Vec::new(); 221 | app.input_mode = InputMode::PostView; 222 | } 223 | } else if let Key::Right = input { 224 | if !app.comments.is_empty() { 225 | if app.cursor.is_empty() 226 | && !app.comments[app.comment_state.selected().unwrap_or_default()] 227 | .children 228 | .is_empty() 229 | { 230 | app.replies = app.comments[app.comment_state.selected().unwrap_or(0)] 231 | .children 232 | .clone(); 233 | app.cursor 234 | .push(app.comment_state.selected().unwrap_or_default()); 235 | } else { 236 | if !app.replies.is_empty() { 237 | if !app.replies[app.replies_state.selected().unwrap_or_default()] 238 | .children 239 | .is_empty() 240 | { 241 | app.cursor 242 | .push(app.replies_state.selected().unwrap_or_default()); 243 | app.replies = utils::get_comments( 244 | app.cursor.clone(), 245 | app.comments.clone(), 246 | ); 247 | app.r_unselect(); 248 | } 249 | } 250 | } 251 | } 252 | } else if let Key::Char('1') = input { 253 | if app.replies.is_empty() { 254 | utils::sort(utils::SortType::New, &mut app.comments); 255 | app.c_unselect() 256 | } 257 | } else if let Key::Char('2') = input { 258 | if app.replies.is_empty() { 259 | utils::sort(utils::SortType::Old, &mut app.comments); 260 | app.c_unselect() 261 | } 262 | } else if let Key::Char('3') = input { 263 | if app.replies.is_empty() { 264 | utils::sort(utils::SortType::Hot, &mut app.comments); 265 | app.c_unselect() 266 | } 267 | } else if let Key::Char('q') = input { 268 | break 'outer; 269 | } 270 | } 271 | } 272 | } 273 | terminal.clear() 274 | } 275 | -------------------------------------------------------------------------------- /src/ui.rs: -------------------------------------------------------------------------------- 1 | use super::app::{InputMode, LApp}; 2 | use tui::backend::Backend; 3 | use tui::layout::{Constraint, Direction, Layout}; 4 | use tui::style::{Modifier, Style}; 5 | use tui::text::{Span, Spans, Text, WrappedText}; 6 | use tui::widgets::{Block, Borders, List, ListItem, Paragraph, Wrap}; 7 | use tui::Frame; 8 | //constants for themes 9 | const PRIMARY: &str = "primary"; 10 | const SECONDARY: &str = "secondary"; 11 | const BG: &str = "bg"; 12 | 13 | //renders the ui when InputMode is Normal 14 | pub fn draw_normal(app: &mut LApp, frame: &mut Frame) 15 | where 16 | B: Backend, 17 | { 18 | let chunks = Layout::default() 19 | .direction(Direction::Vertical) 20 | .constraints( 21 | [ 22 | Constraint::Length(3), 23 | Constraint::Length(1), 24 | Constraint::Length(7), 25 | ] 26 | .as_ref(), 27 | ) 28 | .split(frame.size()); 29 | let input_block = Paragraph::new(tui::text::Text::from(app.input.clone())) 30 | .style(match app.input_mode { 31 | InputMode::Normal => Style::default() 32 | .fg(*app.theme.get(PRIMARY).unwrap()) 33 | .bg(*app.theme.get(BG).unwrap()), 34 | InputMode::Editing => Style::default() 35 | .fg(*app.theme.get(SECONDARY).unwrap()) 36 | .bg(*app.theme.get(BG).unwrap()), 37 | InputMode::PostView => Style::default(), 38 | InputMode::CommentView => Style::default(), 39 | }) 40 | .block(Block::default().borders(Borders::ALL)); 41 | 42 | frame.render_widget(input_block, chunks[0]); 43 | 44 | let mut items = vec![]; 45 | for post in &app.posts { 46 | let mut t = WrappedText::new(frame.size().width - 10); 47 | t.extend(Text::from(vec![ 48 | Spans::from(vec![ 49 | Span::styled( 50 | &post.creator.name, 51 | Style::default().fg(*app.theme.get(SECONDARY).unwrap()), 52 | ), 53 | Span::styled( 54 | " to ", 55 | Style::default().fg(*app.theme.get(SECONDARY).unwrap()), 56 | ), 57 | Span::styled( 58 | &post.community.name, 59 | Style::default().fg(*app.theme.get(SECONDARY).unwrap()), 60 | ), 61 | ]), 62 | Spans::from(post.post.name.as_ref()), 63 | Spans::from(vec![ 64 | Span::styled( 65 | format!("{}", post.counts.comments), 66 | Style::default().fg(*app.theme.get(SECONDARY).unwrap()), 67 | ), 68 | Span::styled( 69 | " Comments", 70 | Style::default().fg(*app.theme.get(SECONDARY).unwrap()), 71 | ), 72 | ]), 73 | Spans::from(""), 74 | ])); 75 | items.push(ListItem::new(t)) 76 | } 77 | let list = List::new(items) 78 | .block(Block::default().title("Posts").borders(Borders::ALL)) 79 | .style( 80 | Style::default() 81 | .fg(*app.theme.get(PRIMARY).unwrap()) 82 | .bg(*app.theme.get(BG).unwrap()), 83 | ) 84 | .highlight_symbol(tui::symbols::line::VERTICAL) 85 | .repeat_highlight_symbol(true); 86 | 87 | frame.render_stateful_widget(list, chunks[2], &mut app.state); 88 | 89 | let sort_text = Paragraph::new(" New[1] Hot[2] Active[3] Old[4]").style( 90 | Style::default() 91 | .fg(*app.theme.get(PRIMARY).unwrap()) 92 | .bg(*app.theme.get(BG).unwrap()), 93 | ); 94 | frame.render_widget(sort_text, chunks[1]); 95 | } 96 | //renders the ui when InputMode is PostView 97 | pub fn draw_post(app: &mut LApp, frame: &mut Frame) 98 | where 99 | B: Backend, 100 | { 101 | let chunks; 102 | let body = &app.posts[app.state.selected().unwrap_or(0)].post.body; 103 | let url = &app.posts[app.state.selected().unwrap_or(0)].post.url; 104 | if let (Some(str), Some(url)) = (body.as_ref(), url.as_ref()) { 105 | chunks = Layout::default() 106 | .direction(Direction::Vertical) 107 | .constraints([Constraint::Percentage(30), Constraint::Percentage(70)]) 108 | .split(frame.size()); 109 | 110 | let lines = Text::styled(url, Style::default()); 111 | let para_ = Paragraph::new(lines) 112 | .block(Block::default().borders(Borders::ALL)) 113 | .style( 114 | Style::default() 115 | .fg(*app.theme.get(PRIMARY).unwrap()) 116 | .bg(*app.theme.get(BG).unwrap()), 117 | ); 118 | let lines = Text::styled(str, Style::default()); 119 | let para = Paragraph::new(lines) 120 | .block(Block::default().borders(Borders::ALL)) 121 | .style( 122 | Style::default() 123 | .fg(*app.theme.get(PRIMARY).unwrap()) 124 | .bg(*app.theme.get(BG).unwrap()), 125 | ) 126 | .wrap(Wrap { trim: true }); 127 | frame.render_widget(para_, chunks[0]); 128 | frame.render_widget(para, chunks[1]) 129 | } else if let (None, Some(url)) = (body.as_ref(), url.as_ref()) { 130 | chunks = Layout::default() 131 | .direction(Direction::Vertical) 132 | .constraints([Constraint::Percentage(100)]) 133 | .split(frame.size()); 134 | 135 | let lines = Text::styled(url, Style::default()); 136 | let para = Paragraph::new(lines) 137 | .block(Block::default().borders(Borders::ALL)) 138 | .style( 139 | Style::default() 140 | .fg(*app.theme.get(PRIMARY).unwrap()) 141 | .bg(*app.theme.get(BG).unwrap()), 142 | ); 143 | frame.render_widget(para, chunks[0]) 144 | } else if let (Some(str), None) = (body.as_ref(), url.as_ref()) { 145 | chunks = Layout::default() 146 | .direction(Direction::Vertical) 147 | .constraints([Constraint::Percentage(100)]) 148 | .split(frame.size()); 149 | let lines = Text::styled(str, Style::default()); 150 | let para = Paragraph::new(lines) 151 | .block(Block::default().borders(Borders::ALL)) 152 | .style( 153 | Style::default() 154 | .fg(*app.theme.get(PRIMARY).unwrap()) 155 | .bg(*app.theme.get(BG).unwrap()), 156 | ) 157 | .wrap(Wrap { trim: true }); 158 | frame.render_widget(para, chunks[0]) 159 | } else { 160 | chunks = Layout::default() 161 | .direction(Direction::Vertical) 162 | .constraints([Constraint::Percentage(100)]) 163 | .split(frame.size()); 164 | let lines = Text::styled( 165 | &app.posts[app.state.selected().unwrap_or(0)].post.name, 166 | Style::default(), 167 | ); 168 | let para = Paragraph::new(lines) 169 | .block(Block::default().borders(Borders::ALL)) 170 | .style( 171 | Style::default() 172 | .fg(*app.theme.get(PRIMARY).unwrap()) 173 | .bg(*app.theme.get(BG).unwrap()), 174 | ) 175 | .wrap(Wrap { trim: true }); 176 | frame.render_widget(para, chunks[0]) 177 | } 178 | } 179 | //renders the ui when InputMode is CommentView 180 | pub fn draw_comment(app: &mut LApp, frame: &mut Frame) 181 | where 182 | B: Backend, 183 | { 184 | let mut items = vec![]; 185 | for comment in &app.comments { 186 | let mut t = WrappedText::new(frame.size().width - 10); 187 | t.extend(Text::from(vec![ 188 | Spans::from(vec![Span::styled( 189 | &comment.comment.creator.name, 190 | Style::default() 191 | .fg(*app.theme.get(SECONDARY).unwrap()) 192 | .bg(*app.theme.get(BG).unwrap()) 193 | .add_modifier(Modifier::UNDERLINED), 194 | )]), 195 | Spans::from(comment.comment.comment.content.as_ref()), 196 | Spans::from(vec![ 197 | Span::styled( 198 | format!("{}", comment.children.len()), 199 | Style::default().fg(*app.theme.get(SECONDARY).unwrap()), 200 | ), 201 | Span::styled( 202 | " Replies", 203 | Style::default().fg(*app.theme.get(SECONDARY).unwrap()), 204 | ), 205 | ]), 206 | Spans::from(""), 207 | ])); 208 | items.push(ListItem::new(t)) 209 | } 210 | if let (_, true) = (&app.comments, app.replies.is_empty()) { 211 | let chunks = Layout::default() 212 | .direction(Direction::Vertical) 213 | .constraints([Constraint::Length(1), Constraint::Length(7)]) 214 | .split(frame.size()); 215 | let list = List::new(items) 216 | .block(Block::default().title("Comments").borders(Borders::ALL)) 217 | .style( 218 | Style::default() 219 | .fg(*app.theme.get(PRIMARY).unwrap()) 220 | .bg(*app.theme.get(BG).unwrap()), 221 | ) 222 | .highlight_symbol(tui::symbols::line::VERTICAL) 223 | .repeat_highlight_symbol(true); 224 | let sort_text = Paragraph::new(" New[1] Old[2] Hot[3]").style( 225 | Style::default() 226 | .fg(*app.theme.get(PRIMARY).unwrap()) 227 | .bg(*app.theme.get(BG).unwrap()), 228 | ); 229 | frame.render_widget(sort_text, chunks[0]); 230 | frame.render_stateful_widget(list, chunks[1], &mut app.comment_state); 231 | } else if let (_, false) = (&app.comments, app.replies.is_empty()) { 232 | let chunks = Layout::default() 233 | .direction(Direction::Vertical) 234 | .constraints([Constraint::Percentage(100)]) 235 | .split(frame.size()); 236 | 237 | let mut items = vec![]; 238 | 239 | for comment in &app.replies { 240 | let mut t = WrappedText::new(frame.size().width - 10); 241 | t.extend(Text::from(vec![ 242 | Spans::from(vec![Span::styled( 243 | &comment.comment.creator.name, 244 | Style::default() 245 | .fg(*app.theme.get(SECONDARY).unwrap()) 246 | .bg(*app.theme.get(BG).unwrap()) 247 | .add_modifier(Modifier::UNDERLINED), 248 | )]), 249 | Spans::from(comment.comment.comment.content.as_ref()), 250 | Spans::from(vec![ 251 | Span::styled( 252 | format!("{}", comment.children.len()), 253 | Style::default().fg(*app.theme.get(SECONDARY).unwrap()), 254 | ), 255 | Span::styled( 256 | " Replies", 257 | Style::default().fg(*app.theme.get(SECONDARY).unwrap()), 258 | ), 259 | ]), 260 | Spans::from(""), 261 | ])); 262 | items.push(ListItem::new(t)) 263 | } 264 | 265 | let list = List::new(items) 266 | .block(Block::default().title("Replies").borders(Borders::ALL)) 267 | .style( 268 | Style::default() 269 | .fg(*app.theme.get(PRIMARY).unwrap()) 270 | .bg(*app.theme.get(BG).unwrap()), 271 | ) 272 | .highlight_symbol(tui::symbols::line::VERTICAL) 273 | .repeat_highlight_symbol(true); 274 | frame.render_stateful_widget(list, chunks[0], &mut app.replies_state); 275 | } 276 | } 277 | -------------------------------------------------------------------------------- /src/utils.rs: -------------------------------------------------------------------------------- 1 | use super::api::{CommentInfo, CommentTree}; 2 | use chrono::NaiveDateTime; 3 | use std::collections::HashMap; 4 | use std::str::FromStr; 5 | use tui::style::Color; 6 | pub enum SortType { 7 | Hot, 8 | Old, 9 | New, 10 | } 11 | pub fn map_tree(list: Vec) -> Vec { 12 | list.into_iter() 13 | .map(|ct| CommentTree { 14 | comment: ct, 15 | children: vec![], 16 | }) 17 | .collect() 18 | } 19 | pub fn prepend_https(mut str: String) -> String { 20 | if str.starts_with("localhost:") || str.starts_with("127.0.0.1") { 21 | str.insert_str(0, "http://"); 22 | return str; 23 | } 24 | if !str.starts_with("https://") { 25 | str.insert_str(0, "https://"); 26 | return str; 27 | } else { 28 | str 29 | } 30 | } 31 | 32 | pub fn get_comments(cursor: Vec, list: Vec) -> Vec { 33 | let mut result = list; 34 | for item in cursor { 35 | result = result[item].children.clone(); 36 | } 37 | return result; 38 | } 39 | fn parse_theme(theme_item: &str) -> Result { 40 | let color = match theme_item { 41 | "Reset" => Color::Reset, 42 | "Black" => Color::Black, 43 | "Red" => Color::Red, 44 | "Green" => Color::Green, 45 | "Yellow" => Color::Yellow, 46 | "Blue" => Color::Blue, 47 | "Magenta" => Color::Magenta, 48 | "Cyan" => Color::Cyan, 49 | "Gray" => Color::Gray, 50 | "DarkGray" => Color::DarkGray, 51 | "LightRed" => Color::LightRed, 52 | "LightGreen" => Color::LightGreen, 53 | "LightYellow" => Color::LightYellow, 54 | "LightBlue" => Color::LightBlue, 55 | "LightMagenta" => Color::LightMagenta, 56 | "LightCyan" => Color::LightCyan, 57 | "White" => Color::White, 58 | _ => { 59 | let colors = theme_item.split(',').collect::>(); 60 | if let (Some(r), Some(g), Some(b)) = (colors.get(0), colors.get(1), colors.get(2)) { 61 | Color::Rgb( 62 | r.trim().parse::()?, 63 | g.trim().parse::()?, 64 | b.trim().parse::()?, 65 | ) 66 | } else { 67 | Color::Black 68 | } 69 | } 70 | }; 71 | 72 | Ok(color) 73 | } 74 | pub fn colorify(list: HashMap) -> HashMap { 75 | let mut result = HashMap::new(); 76 | 77 | for (key, value) in list { 78 | result.insert(key, parse_theme(&value).unwrap_or(Color::Black)); 79 | } 80 | result 81 | } 82 | //TODO: Refactor this 83 | pub fn sort(st: SortType, ct: &mut Vec) { 84 | match st { 85 | SortType::New => { 86 | ct.sort_by(|b, a| { 87 | NaiveDateTime::from_str(&a.comment.comment.published) 88 | .unwrap() 89 | .cmp(&NaiveDateTime::from_str(&b.comment.comment.published).unwrap()) 90 | }); 91 | for c in ct { 92 | sort(SortType::New, &mut c.children); 93 | } 94 | } 95 | SortType::Old => { 96 | ct.sort_by(|a, b| { 97 | NaiveDateTime::from_str(&a.comment.comment.published) 98 | .unwrap() 99 | .cmp(&NaiveDateTime::from_str(&b.comment.comment.published).unwrap()) 100 | }); 101 | for c in ct { 102 | sort(SortType::Old, &mut c.children); 103 | } 104 | } 105 | SortType::Hot => { 106 | ct.sort_by(|b, a| { 107 | let rank = 108 | calculate_hot_rank(a.comment.counts.score, a.comment.comment.published.clone()) 109 | .partial_cmp(&calculate_hot_rank( 110 | b.comment.counts.score, 111 | b.comment.comment.published.clone(), 112 | )); 113 | match rank { 114 | Some(r) => r, 115 | None => std::cmp::Ordering::Equal, 116 | } 117 | }); 118 | for c in ct { 119 | sort(SortType::Hot, &mut c.children); 120 | } 121 | } 122 | } 123 | } 124 | // TODO: Looks correct from some manual tests. but verify properly later 125 | // Code from https://github.com/LemmyNet/lemmy-ui/blob/a11cbb29c73107fcc7a629e7b0babdf939520675/src/shared/utils.ts#L269 126 | pub fn calculate_hot_rank(score: i64, timestr: String) -> f64 { 127 | let elapsed = (chrono::offset::Utc::now().timestamp_millis() 128 | - chrono::NaiveDateTime::from_str(×tr) 129 | .unwrap() 130 | .timestamp_millis()) 131 | / 3600000; 132 | let elapsed_base: f64 = (elapsed + 2) as f64; 133 | let max = std::cmp::max(1, 3 + score) as f64; 134 | (10000 as f64 * max.log10()) / elapsed_base.powf(1.8) 135 | } 136 | --------------------------------------------------------------------------------