diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Cargo.lock | 322 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | config.ini | 3 | ||||
-rw-r--r-- | src/apis/modrinth.rs | 101 | ||||
-rw-r--r-- | src/commands/add.rs | 34 | ||||
-rw-r--r-- | src/commands/mod.rs | 3 | ||||
-rw-r--r-- | src/config.rs | 23 | ||||
-rw-r--r-- | src/db.rs | 18 | ||||
-rw-r--r-- | src/input.rs | 59 | ||||
-rw-r--r-- | src/lib.rs | 11 | ||||
-rw-r--r-- | src/main.rs | 7 | ||||
-rw-r--r-- | src/update.rs | 8 |
13 files changed, 556 insertions, 38 deletions
@@ -1,2 +1,3 @@ | |||
1 | /target | 1 | /target |
2 | /api-tests \ No newline at end of file | 2 | /api-tests |
3 | data.db \ No newline at end of file | ||
@@ -3,6 +3,28 @@ | |||
3 | version = 3 | 3 | version = 3 |
4 | 4 | ||
5 | [[package]] | 5 | [[package]] |
6 | name = "ahash" | ||
7 | version = "0.7.6" | ||
8 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
9 | checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" | ||
10 | dependencies = [ | ||
11 | "getrandom", | ||
12 | "once_cell", | ||
13 | "version_check", | ||
14 | ] | ||
15 | |||
16 | [[package]] | ||
17 | name = "async-trait" | ||
18 | version = "0.1.58" | ||
19 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
20 | checksum = "1e805d94e6b5001b651426cf4cd446b1ab5f319d27bab5c644f61de0a804360c" | ||
21 | dependencies = [ | ||
22 | "proc-macro2", | ||
23 | "quote", | ||
24 | "syn", | ||
25 | ] | ||
26 | |||
27 | [[package]] | ||
6 | name = "autocfg" | 28 | name = "autocfg" |
7 | version = "1.1.0" | 29 | version = "1.1.0" |
8 | source = "registry+https://github.com/rust-lang/crates.io-index" | 30 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -21,6 +43,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
21 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" | 43 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" |
22 | 44 | ||
23 | [[package]] | 45 | [[package]] |
46 | name = "block-buffer" | ||
47 | version = "0.10.3" | ||
48 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
49 | checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" | ||
50 | dependencies = [ | ||
51 | "generic-array", | ||
52 | ] | ||
53 | |||
54 | [[package]] | ||
24 | name = "bumpalo" | 55 | name = "bumpalo" |
25 | version = "3.11.1" | 56 | version = "3.11.1" |
26 | source = "registry+https://github.com/rust-lang/crates.io-index" | 57 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -45,6 +76,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
45 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" | 76 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" |
46 | 77 | ||
47 | [[package]] | 78 | [[package]] |
79 | name = "config" | ||
80 | version = "0.13.2" | ||
81 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
82 | checksum = "11f1667b8320afa80d69d8bbe40830df2c8a06003d86f73d8e003b2c48df416d" | ||
83 | dependencies = [ | ||
84 | "async-trait", | ||
85 | "json5", | ||
86 | "lazy_static", | ||
87 | "nom", | ||
88 | "pathdiff", | ||
89 | "ron", | ||
90 | "rust-ini", | ||
91 | "serde", | ||
92 | "serde_json", | ||
93 | "toml", | ||
94 | "yaml-rust", | ||
95 | ] | ||
96 | |||
97 | [[package]] | ||
48 | name = "core-foundation" | 98 | name = "core-foundation" |
49 | version = "0.9.3" | 99 | version = "0.9.3" |
50 | source = "registry+https://github.com/rust-lang/crates.io-index" | 100 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -61,6 +111,41 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
61 | checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" | 111 | checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" |
62 | 112 | ||
63 | [[package]] | 113 | [[package]] |
114 | name = "cpufeatures" | ||
115 | version = "0.2.5" | ||
116 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
117 | checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" | ||
118 | dependencies = [ | ||
119 | "libc", | ||
120 | ] | ||
121 | |||
122 | [[package]] | ||
123 | name = "crypto-common" | ||
124 | version = "0.1.6" | ||
125 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
126 | checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" | ||
127 | dependencies = [ | ||
128 | "generic-array", | ||
129 | "typenum", | ||
130 | ] | ||
131 | |||
132 | [[package]] | ||
133 | name = "digest" | ||
134 | version = "0.10.5" | ||
135 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
136 | checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c" | ||
137 | dependencies = [ | ||
138 | "block-buffer", | ||
139 | "crypto-common", | ||
140 | ] | ||
141 | |||
142 | [[package]] | ||
143 | name = "dlv-list" | ||
144 | version = "0.3.0" | ||
145 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
146 | checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257" | ||
147 | |||
148 | [[package]] | ||
64 | name = "encoding_rs" | 149 | name = "encoding_rs" |
65 | version = "0.8.31" | 150 | version = "0.8.31" |
66 | source = "registry+https://github.com/rust-lang/crates.io-index" | 151 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -148,6 +233,27 @@ dependencies = [ | |||
148 | ] | 233 | ] |
149 | 234 | ||
150 | [[package]] | 235 | [[package]] |
236 | name = "generic-array" | ||
237 | version = "0.14.6" | ||
238 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
239 | checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" | ||
240 | dependencies = [ | ||
241 | "typenum", | ||
242 | "version_check", | ||
243 | ] | ||
244 | |||
245 | [[package]] | ||
246 | name = "getrandom" | ||
247 | version = "0.2.8" | ||
248 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
249 | checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" | ||
250 | dependencies = [ | ||
251 | "cfg-if", | ||
252 | "libc", | ||
253 | "wasi", | ||
254 | ] | ||
255 | |||
256 | [[package]] | ||
151 | name = "h2" | 257 | name = "h2" |
152 | version = "0.3.15" | 258 | version = "0.3.15" |
153 | source = "registry+https://github.com/rust-lang/crates.io-index" | 259 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -171,6 +277,9 @@ name = "hashbrown" | |||
171 | version = "0.12.3" | 277 | version = "0.12.3" |
172 | source = "registry+https://github.com/rust-lang/crates.io-index" | 278 | source = "registry+https://github.com/rust-lang/crates.io-index" |
173 | checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" | 279 | checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" |
280 | dependencies = [ | ||
281 | "ahash", | ||
282 | ] | ||
174 | 283 | ||
175 | [[package]] | 284 | [[package]] |
176 | name = "hermit-abi" | 285 | name = "hermit-abi" |
@@ -303,6 +412,17 @@ dependencies = [ | |||
303 | ] | 412 | ] |
304 | 413 | ||
305 | [[package]] | 414 | [[package]] |
415 | name = "json5" | ||
416 | version = "0.4.1" | ||
417 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
418 | checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1" | ||
419 | dependencies = [ | ||
420 | "pest", | ||
421 | "pest_derive", | ||
422 | "serde", | ||
423 | ] | ||
424 | |||
425 | [[package]] | ||
306 | name = "lazy_static" | 426 | name = "lazy_static" |
307 | version = "1.4.0" | 427 | version = "1.4.0" |
308 | source = "registry+https://github.com/rust-lang/crates.io-index" | 428 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -315,6 +435,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
315 | checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" | 435 | checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" |
316 | 436 | ||
317 | [[package]] | 437 | [[package]] |
438 | name = "linked-hash-map" | ||
439 | version = "0.5.6" | ||
440 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
441 | checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" | ||
442 | |||
443 | [[package]] | ||
318 | name = "lock_api" | 444 | name = "lock_api" |
319 | version = "0.4.9" | 445 | version = "0.4.9" |
320 | source = "registry+https://github.com/rust-lang/crates.io-index" | 446 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -346,6 +472,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
346 | checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" | 472 | checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" |
347 | 473 | ||
348 | [[package]] | 474 | [[package]] |
475 | name = "minimal-lexical" | ||
476 | version = "0.2.1" | ||
477 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
478 | checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" | ||
479 | |||
480 | [[package]] | ||
349 | name = "mio" | 481 | name = "mio" |
350 | version = "0.8.5" | 482 | version = "0.8.5" |
351 | source = "registry+https://github.com/rust-lang/crates.io-index" | 483 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -361,9 +493,11 @@ dependencies = [ | |||
361 | name = "modlist" | 493 | name = "modlist" |
362 | version = "0.1.0" | 494 | version = "0.1.0" |
363 | dependencies = [ | 495 | dependencies = [ |
496 | "config", | ||
364 | "reqwest", | 497 | "reqwest", |
365 | "serde", | 498 | "serde", |
366 | "serde_json", | 499 | "serde_json", |
500 | "sqlite", | ||
367 | "tokio", | 501 | "tokio", |
368 | ] | 502 | ] |
369 | 503 | ||
@@ -386,6 +520,16 @@ dependencies = [ | |||
386 | ] | 520 | ] |
387 | 521 | ||
388 | [[package]] | 522 | [[package]] |
523 | name = "nom" | ||
524 | version = "7.1.1" | ||
525 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
526 | checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" | ||
527 | dependencies = [ | ||
528 | "memchr", | ||
529 | "minimal-lexical", | ||
530 | ] | ||
531 | |||
532 | [[package]] | ||
389 | name = "num_cpus" | 533 | name = "num_cpus" |
390 | version = "1.13.1" | 534 | version = "1.13.1" |
391 | source = "registry+https://github.com/rust-lang/crates.io-index" | 535 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -447,6 +591,16 @@ dependencies = [ | |||
447 | ] | 591 | ] |
448 | 592 | ||
449 | [[package]] | 593 | [[package]] |
594 | name = "ordered-multimap" | ||
595 | version = "0.4.3" | ||
596 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
597 | checksum = "ccd746e37177e1711c20dd619a1620f34f5c8b569c53590a72dedd5344d8924a" | ||
598 | dependencies = [ | ||
599 | "dlv-list", | ||
600 | "hashbrown", | ||
601 | ] | ||
602 | |||
603 | [[package]] | ||
450 | name = "parking_lot" | 604 | name = "parking_lot" |
451 | version = "0.12.1" | 605 | version = "0.12.1" |
452 | source = "registry+https://github.com/rust-lang/crates.io-index" | 606 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -470,12 +624,62 @@ dependencies = [ | |||
470 | ] | 624 | ] |
471 | 625 | ||
472 | [[package]] | 626 | [[package]] |
627 | name = "pathdiff" | ||
628 | version = "0.2.1" | ||
629 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
630 | checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" | ||
631 | |||
632 | [[package]] | ||
473 | name = "percent-encoding" | 633 | name = "percent-encoding" |
474 | version = "2.2.0" | 634 | version = "2.2.0" |
475 | source = "registry+https://github.com/rust-lang/crates.io-index" | 635 | source = "registry+https://github.com/rust-lang/crates.io-index" |
476 | checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" | 636 | checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" |
477 | 637 | ||
478 | [[package]] | 638 | [[package]] |
639 | name = "pest" | ||
640 | version = "2.4.0" | ||
641 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
642 | checksum = "dbc7bc69c062e492337d74d59b120c274fd3d261b6bf6d3207d499b4b379c41a" | ||
643 | dependencies = [ | ||
644 | "thiserror", | ||
645 | "ucd-trie", | ||
646 | ] | ||
647 | |||
648 | [[package]] | ||
649 | name = "pest_derive" | ||
650 | version = "2.4.0" | ||
651 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
652 | checksum = "60b75706b9642ebcb34dab3bc7750f811609a0eb1dd8b88c2d15bf628c1c65b2" | ||
653 | dependencies = [ | ||
654 | "pest", | ||
655 | "pest_generator", | ||
656 | ] | ||
657 | |||
658 | [[package]] | ||
659 | name = "pest_generator" | ||
660 | version = "2.4.0" | ||
661 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
662 | checksum = "f4f9272122f5979a6511a749af9db9bfc810393f63119970d7085fed1c4ea0db" | ||
663 | dependencies = [ | ||
664 | "pest", | ||
665 | "pest_meta", | ||
666 | "proc-macro2", | ||
667 | "quote", | ||
668 | "syn", | ||
669 | ] | ||
670 | |||
671 | [[package]] | ||
672 | name = "pest_meta" | ||
673 | version = "2.4.0" | ||
674 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
675 | checksum = "4c8717927f9b79515e565a64fe46c38b8cd0427e64c40680b14a7365ab09ac8d" | ||
676 | dependencies = [ | ||
677 | "once_cell", | ||
678 | "pest", | ||
679 | "sha1", | ||
680 | ] | ||
681 | |||
682 | [[package]] | ||
479 | name = "pin-project-lite" | 683 | name = "pin-project-lite" |
480 | version = "0.2.9" | 684 | version = "0.2.9" |
481 | source = "registry+https://github.com/rust-lang/crates.io-index" | 685 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -567,6 +771,27 @@ dependencies = [ | |||
567 | ] | 771 | ] |
568 | 772 | ||
569 | [[package]] | 773 | [[package]] |
774 | name = "ron" | ||
775 | version = "0.7.1" | ||
776 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
777 | checksum = "88073939a61e5b7680558e6be56b419e208420c2adb92be54921fa6b72283f1a" | ||
778 | dependencies = [ | ||
779 | "base64", | ||
780 | "bitflags", | ||
781 | "serde", | ||
782 | ] | ||
783 | |||
784 | [[package]] | ||
785 | name = "rust-ini" | ||
786 | version = "0.18.0" | ||
787 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
788 | checksum = "f6d5f2436026b4f6e79dc829837d467cc7e9a55ee40e750d716713540715a2df" | ||
789 | dependencies = [ | ||
790 | "cfg-if", | ||
791 | "ordered-multimap", | ||
792 | ] | ||
793 | |||
794 | [[package]] | ||
570 | name = "ryu" | 795 | name = "ryu" |
571 | version = "1.0.11" | 796 | version = "1.0.11" |
572 | source = "registry+https://github.com/rust-lang/crates.io-index" | 797 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -655,6 +880,17 @@ dependencies = [ | |||
655 | ] | 880 | ] |
656 | 881 | ||
657 | [[package]] | 882 | [[package]] |
883 | name = "sha1" | ||
884 | version = "0.10.5" | ||
885 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
886 | checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" | ||
887 | dependencies = [ | ||
888 | "cfg-if", | ||
889 | "cpufeatures", | ||
890 | "digest", | ||
891 | ] | ||
892 | |||
893 | [[package]] | ||
658 | name = "signal-hook-registry" | 894 | name = "signal-hook-registry" |
659 | version = "1.4.0" | 895 | version = "1.4.0" |
660 | source = "registry+https://github.com/rust-lang/crates.io-index" | 896 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -689,6 +925,36 @@ dependencies = [ | |||
689 | ] | 925 | ] |
690 | 926 | ||
691 | [[package]] | 927 | [[package]] |
928 | name = "sqlite" | ||
929 | version = "0.27.3" | ||
930 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
931 | checksum = "e66cb949f931ece6201d72bffad3f3601b94998a345793713dd13af70a77c185" | ||
932 | dependencies = [ | ||
933 | "libc", | ||
934 | "sqlite3-sys", | ||
935 | ] | ||
936 | |||
937 | [[package]] | ||
938 | name = "sqlite3-src" | ||
939 | version = "0.4.0" | ||
940 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
941 | checksum = "d1815a7a02c996eb8e5c64f61fcb6fd9b12e593ce265c512c5853b2513635691" | ||
942 | dependencies = [ | ||
943 | "cc", | ||
944 | "pkg-config", | ||
945 | ] | ||
946 | |||
947 | [[package]] | ||
948 | name = "sqlite3-sys" | ||
949 | version = "0.14.0" | ||
950 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
951 | checksum = "d47c99824fc55360ba00caf28de0b8a0458369b832e016a64c13af0ad9fbb9ee" | ||
952 | dependencies = [ | ||
953 | "libc", | ||
954 | "sqlite3-src", | ||
955 | ] | ||
956 | |||
957 | [[package]] | ||
692 | name = "syn" | 958 | name = "syn" |
693 | version = "1.0.103" | 959 | version = "1.0.103" |
694 | source = "registry+https://github.com/rust-lang/crates.io-index" | 960 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -714,6 +980,26 @@ dependencies = [ | |||
714 | ] | 980 | ] |
715 | 981 | ||
716 | [[package]] | 982 | [[package]] |
983 | name = "thiserror" | ||
984 | version = "1.0.37" | ||
985 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
986 | checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" | ||
987 | dependencies = [ | ||
988 | "thiserror-impl", | ||
989 | ] | ||
990 | |||
991 | [[package]] | ||
992 | name = "thiserror-impl" | ||
993 | version = "1.0.37" | ||
994 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
995 | checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" | ||
996 | dependencies = [ | ||
997 | "proc-macro2", | ||
998 | "quote", | ||
999 | "syn", | ||
1000 | ] | ||
1001 | |||
1002 | [[package]] | ||
717 | name = "tinyvec" | 1003 | name = "tinyvec" |
718 | version = "1.6.0" | 1004 | version = "1.6.0" |
719 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1005 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -784,6 +1070,15 @@ dependencies = [ | |||
784 | ] | 1070 | ] |
785 | 1071 | ||
786 | [[package]] | 1072 | [[package]] |
1073 | name = "toml" | ||
1074 | version = "0.5.9" | ||
1075 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1076 | checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" | ||
1077 | dependencies = [ | ||
1078 | "serde", | ||
1079 | ] | ||
1080 | |||
1081 | [[package]] | ||
787 | name = "tower-service" | 1082 | name = "tower-service" |
788 | version = "0.3.2" | 1083 | version = "0.3.2" |
789 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1084 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -816,6 +1111,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
816 | checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" | 1111 | checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" |
817 | 1112 | ||
818 | [[package]] | 1113 | [[package]] |
1114 | name = "typenum" | ||
1115 | version = "1.15.0" | ||
1116 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1117 | checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" | ||
1118 | |||
1119 | [[package]] | ||
1120 | name = "ucd-trie" | ||
1121 | version = "0.1.5" | ||
1122 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1123 | checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" | ||
1124 | |||
1125 | [[package]] | ||
819 | name = "unicode-bidi" | 1126 | name = "unicode-bidi" |
820 | version = "0.3.8" | 1127 | version = "0.3.8" |
821 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1128 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -854,6 +1161,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
854 | checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" | 1161 | checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" |
855 | 1162 | ||
856 | [[package]] | 1163 | [[package]] |
1164 | name = "version_check" | ||
1165 | version = "0.9.4" | ||
1166 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1167 | checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" | ||
1168 | |||
1169 | [[package]] | ||
857 | name = "want" | 1170 | name = "want" |
858 | version = "0.3.0" | 1171 | version = "0.3.0" |
859 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1172 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1075,3 +1388,12 @@ checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" | |||
1075 | dependencies = [ | 1388 | dependencies = [ |
1076 | "winapi", | 1389 | "winapi", |
1077 | ] | 1390 | ] |
1391 | |||
1392 | [[package]] | ||
1393 | name = "yaml-rust" | ||
1394 | version = "0.4.5" | ||
1395 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1396 | checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" | ||
1397 | dependencies = [ | ||
1398 | "linked-hash-map", | ||
1399 | ] | ||
@@ -10,3 +10,5 @@ reqwest = { version = "0.11", features = ["json"] } | |||
10 | tokio = { version = "1", features = ["full"] } | 10 | tokio = { version = "1", features = ["full"] } |
11 | serde = { version = "1.0", features = ["derive"] } | 11 | serde = { version = "1.0", features = ["derive"] } |
12 | serde_json = "1.0.87" | 12 | serde_json = "1.0.87" |
13 | config = "0.13.2" | ||
14 | sqlite = "0.27.3" | ||
diff --git a/config.ini b/config.ini new file mode 100644 index 0000000..0ea32d5 --- /dev/null +++ b/config.ini | |||
@@ -0,0 +1,3 @@ | |||
1 | [apis] | ||
2 | ;modrinth = "http://localhost:8080/" | ||
3 | modrinth = "https://api.modrinth.com/v2/" | ||
diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs index ce9fdd4..3af5bbd 100644 --- a/src/apis/modrinth.rs +++ b/src/apis/modrinth.rs | |||
@@ -1,25 +1,6 @@ | |||
1 | use serde::{Deserialize, Serialize}; | 1 | use serde::Deserialize; |
2 | 2 | ||
3 | async fn get(path: String) -> Result<Vec<u8>, Box<dyn std::error::Error>> { | 3 | use crate::Modloader; |
4 | dbg!(&path); | ||
5 | let api = String::from("https://api.modrinth.com/v2/"); | ||
6 | //let api = String::from("localhost:8080/"); | ||
7 | //let api = String::from("https://www.rust-lang.org/"); | ||
8 | let url = format!(r#"{}{}"#, api, path); | ||
9 | |||
10 | println!("{}", &url); | ||
11 | |||
12 | |||
13 | let data = reqwest::get(r#"https://api.modrinth.com/v2/projects?ids=["kYuIpRLv","89Wsn8GD"]"#) | ||
14 | .await? | ||
15 | .bytes() | ||
16 | .await? | ||
17 | .to_vec(); | ||
18 | |||
19 | //println!("body = {:?}", data); | ||
20 | |||
21 | Ok(data) | ||
22 | } | ||
23 | 4 | ||
24 | #[derive(Debug, Deserialize)] | 5 | #[derive(Debug, Deserialize)] |
25 | pub struct Project { | 6 | pub struct Project { |
@@ -86,19 +67,89 @@ pub enum Status { | |||
86 | processing, | 67 | processing, |
87 | unknown | 68 | unknown |
88 | } | 69 | } |
89 | pub async fn project(name: &str) -> Project { | 70 | |
71 | #[derive(Debug, Deserialize)] | ||
72 | pub struct Version { | ||
73 | pub name: String, | ||
74 | pub version_number: String, | ||
75 | pub changelog: Option<String>, | ||
76 | pub game_versions: Vec<String>, | ||
77 | pub version_type: VersionType, | ||
78 | pub loaders: Vec<String>, | ||
79 | pub featured: bool, | ||
80 | pub id: String, | ||
81 | pub project_id: String, | ||
82 | pub author_id: String, | ||
83 | pub date_published: String, | ||
84 | pub downloads: u32, | ||
85 | pub files: Vec<VersionFile>, | ||
86 | } | ||
87 | |||
88 | #[allow(non_camel_case_types)] | ||
89 | #[derive(Debug, Deserialize)] | ||
90 | pub enum VersionType { | ||
91 | release, | ||
92 | beta, | ||
93 | alpha | ||
94 | } | ||
95 | |||
96 | #[derive(Debug, Deserialize)] | ||
97 | pub struct VersionFile { | ||
98 | pub hashes: Hash, | ||
99 | pub url: String, | ||
100 | pub filename: String, | ||
101 | pub primary: bool, | ||
102 | pub size: u32, | ||
103 | } | ||
104 | |||
105 | #[derive(Debug, Deserialize)] | ||
106 | pub struct Hash { | ||
107 | pub sha512: String, | ||
108 | pub sha1: String, | ||
109 | } | ||
110 | |||
111 | async fn get(api: String, path: String) -> Result<Vec<u8>, Box<dyn std::error::Error>> { | ||
112 | let url = format!(r#"{}{}"#, api, path); | ||
113 | |||
114 | dbg!(&url); | ||
115 | |||
116 | let data = reqwest::get(url) | ||
117 | .await? | ||
118 | .bytes() | ||
119 | .await? | ||
120 | .to_vec(); | ||
121 | |||
122 | Ok(data) | ||
123 | } | ||
124 | |||
125 | |||
126 | pub async fn project(api: String, name: &str) -> Project { | ||
90 | let url = format!("project/{}", name); | 127 | let url = format!("project/{}", name); |
91 | let data = get(url); | 128 | let data = get(api, url); |
92 | 129 | ||
93 | serde_json::from_slice(&data.await.unwrap()).unwrap() | 130 | serde_json::from_slice(&data.await.unwrap()).unwrap() |
94 | } | 131 | } |
95 | 132 | ||
96 | pub async fn projects(ids: Vec<&str>) -> Vec<Project> { | 133 | pub async fn projects(api: String, ids: Vec<&str>) -> Vec<Project> { |
97 | let all = ids.join(r#"",""#); | 134 | let all = ids.join(r#"",""#); |
98 | let url = format!(r#"projects?ids=["{}"]"#, all); | 135 | let url = format!(r#"projects?ids=["{}"]"#, all); |
99 | println!("{}", url); | 136 | println!("{}", url); |
100 | 137 | ||
101 | let data = get(url); | 138 | let data = get(api, url); |
102 | 139 | ||
103 | serde_json::from_slice(&data.await.unwrap()).unwrap() | 140 | serde_json::from_slice(&data.await.unwrap()).unwrap() |
104 | } | 141 | } |
142 | |||
143 | pub async fn versions(api: String, id: String, loader: Modloader, mc_version: String) -> Vec<Version> { | ||
144 | |||
145 | let loaderstr = match loader { | ||
146 | Modloader::Forge => String::from("forge"), | ||
147 | Modloader::Fabric => String::from("fabric"), | ||
148 | }; | ||
149 | |||
150 | let url = format!(r#"project/{}/version?loaders=["{}"]&game_versions=["{}"]"#, id, loaderstr, mc_version); | ||
151 | |||
152 | let data = get(api, url); | ||
153 | |||
154 | serde_json::from_slice(&data.await.unwrap()).unwrap() | ||
155 | } | ||
diff --git a/src/commands/add.rs b/src/commands/add.rs new file mode 100644 index 0000000..67f63de --- /dev/null +++ b/src/commands/add.rs | |||
@@ -0,0 +1,34 @@ | |||
1 | use std::io::{Error, ErrorKind}; | ||
2 | |||
3 | use crate::{modrinth::{project, versions}, config::Cfg, db::insert_mod, Modloader}; | ||
4 | |||
5 | pub async fn add(config: Cfg, mc_mod: String) -> Result<(), Box<dyn std::error::Error>> { | ||
6 | println!("Adding"); | ||
7 | |||
8 | let project = project(String::from(&config.apis.modrinth), &mc_mod).await; | ||
9 | |||
10 | dbg!(&project); | ||
11 | |||
12 | let loader = Modloader::Fabric; | ||
13 | |||
14 | if project.versions.is_empty() { panic!("This should never happen"); }; | ||
15 | |||
16 | let current_version = get_current(config, String::from(&project.id)).await?; | ||
17 | |||
18 | match insert_mod(project.id, project.title, current_version, project.versions, loader, String::from("1.19.2")) { | ||
19 | Err(err) => { Err(Box::new(err)) }, | ||
20 | Ok(()) => Ok(()), | ||
21 | } | ||
22 | |||
23 | } | ||
24 | |||
25 | async fn get_current(config: Cfg, id: String) -> Result<String, Box<dyn std::error::Error>> { | ||
26 | let available_versions = versions(config.apis.modrinth, id, Modloader::Fabric, String::from("1.19.2")).await; | ||
27 | |||
28 | match available_versions.len() { | ||
29 | 0 => Err(Box::new(Error::new(ErrorKind::NotFound, "NO_VERSIONS_AVAILABLE"))), | ||
30 | //TODO compare publish dates | ||
31 | 1.. => Ok(available_versions[0].id.to_string()), | ||
32 | _ => panic!("available_versions should never be negative"), | ||
33 | } | ||
34 | } | ||
diff --git a/src/commands/mod.rs b/src/commands/mod.rs new file mode 100644 index 0000000..0cc183a --- /dev/null +++ b/src/commands/mod.rs | |||
@@ -0,0 +1,3 @@ | |||
1 | pub mod add; | ||
2 | |||
3 | pub use add::*; | ||
diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..a0dfbbe --- /dev/null +++ b/src/config.rs | |||
@@ -0,0 +1,23 @@ | |||
1 | use config::{Config, File, FileFormat}; | ||
2 | use serde::Deserialize; | ||
3 | |||
4 | #[derive(Debug, Deserialize)] | ||
5 | pub struct Cfg { | ||
6 | pub apis: Apis, | ||
7 | } | ||
8 | |||
9 | #[derive(Debug, Deserialize)] | ||
10 | pub struct Apis { | ||
11 | pub modrinth: String, | ||
12 | } | ||
13 | |||
14 | impl Cfg { | ||
15 | pub fn init(path: &str) -> Self { | ||
16 | Config::builder() | ||
17 | .add_source(File::new(path, FileFormat::Ini)) | ||
18 | .build() | ||
19 | .unwrap() | ||
20 | .try_deserialize() | ||
21 | .unwrap() | ||
22 | } | ||
23 | } | ||
@@ -0,0 +1,18 @@ | |||
1 | use crate::Modloader; | ||
2 | |||
3 | pub fn insert_mod(id: String, name: String, current_version: String, old_versions: Vec<String>, mod_loader: Modloader, desired_mc_version: String) -> Result<(), sqlite::Error> { | ||
4 | |||
5 | let connection = sqlite::open("./data.db").unwrap(); | ||
6 | |||
7 | let loader = match mod_loader { | ||
8 | Modloader::Fabric => "fabric", | ||
9 | Modloader::Forge => "forge", | ||
10 | }; | ||
11 | |||
12 | let sql = format!("INSERT INTO mods VALUES ('{}', '{}', '{}', '{}', '{}', '{}')", id, name, current_version, old_versions.join("|"), loader, desired_mc_version); | ||
13 | |||
14 | dbg!(&sql); | ||
15 | |||
16 | connection.execute(sql) | ||
17 | |||
18 | } | ||
diff --git a/src/input.rs b/src/input.rs new file mode 100644 index 0000000..689389e --- /dev/null +++ b/src/input.rs | |||
@@ -0,0 +1,59 @@ | |||
1 | use std::io::{stdin, Error, ErrorKind}; | ||
2 | use crate::{add, config::Cfg}; | ||
3 | |||
4 | pub struct Input { | ||
5 | pub command: String, | ||
6 | pub args: Option<Vec<String>>, | ||
7 | } | ||
8 | |||
9 | impl Input { | ||
10 | pub fn from(string: String) -> Result<Self, Box<dyn std::error::Error>> { | ||
11 | let mut split: Vec<&str> = string.split(' ').collect(); | ||
12 | |||
13 | let command: String; | ||
14 | let mut args: Option<Vec<String>> = None; | ||
15 | |||
16 | if split[0].is_empty() { split.remove(0); }; | ||
17 | |||
18 | dbg!(&split); | ||
19 | |||
20 | match split.len() { | ||
21 | 0 => { Err(Box::new(Error::new(ErrorKind::InvalidInput, "NO_ARGS"))) } | ||
22 | 1 => Ok( Input { command: split[0].to_string(), args }), | ||
23 | 2.. => { | ||
24 | command = split[0].to_string(); | ||
25 | split.remove(0); | ||
26 | let mut str_args: Vec<String> = vec![]; | ||
27 | for e in split { | ||
28 | str_args.push(e.to_string()); | ||
29 | } | ||
30 | args = Some(str_args); | ||
31 | Ok(Input { command, args }) | ||
32 | }, | ||
33 | _ => { panic!("This should never happen") } | ||
34 | } | ||
35 | |||
36 | |||
37 | } | ||
38 | } | ||
39 | |||
40 | pub async fn get_input(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | ||
41 | let mut user_input = String::new(); | ||
42 | stdin() | ||
43 | .read_line(&mut user_input) | ||
44 | .expect("ERROR"); | ||
45 | |||
46 | dbg!(&user_input); | ||
47 | |||
48 | let input = Input::from(user_input.trim().to_string())?; | ||
49 | |||
50 | match input.command.as_str() { | ||
51 | "add" => { | ||
52 | if input.args == None { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))) }; | ||
53 | if input.args.as_ref().unwrap().len() != 1 { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_MANY_ARGUMENTS"))) }; | ||
54 | add(config, input.args.unwrap()[0].to_string()).await?; | ||
55 | Ok(()) | ||
56 | }, | ||
57 | _ => Err(Box::new(Error::new(ErrorKind::InvalidInput, "UNKNOWN_COMMAND"))), | ||
58 | } | ||
59 | } | ||
@@ -1,4 +1,13 @@ | |||
1 | pub mod update; | ||
2 | pub mod apis; | 1 | pub mod apis; |
2 | pub mod config; | ||
3 | pub mod commands; | ||
4 | pub mod input; | ||
5 | pub mod db; | ||
3 | 6 | ||
4 | pub use apis::*; | 7 | pub use apis::*; |
8 | pub use commands::*; | ||
9 | |||
10 | pub enum Modloader { | ||
11 | Fabric, | ||
12 | Forge | ||
13 | } | ||
diff --git a/src/main.rs b/src/main.rs index 8d1a1bd..957e5aa 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,7 +1,8 @@ | |||
1 | use modlist::modrinth::projects; | 1 | use modlist::{config::Cfg, input::get_input}; |
2 | 2 | ||
3 | #[tokio::main] | 3 | #[tokio::main] |
4 | async fn main() { | 4 | async fn main() { |
5 | //projects(vec!["kYuIpRLv", "89Wsn8GD"]); | 5 | let config = Cfg::init("config.ini"); |
6 | println!("{:?}", projects(vec!["kYuIpRLv", "89Wsn8GD"]).await); | 6 | //TODO Error Handling |
7 | get_input(config).await.unwrap(); | ||
7 | } | 8 | } |
diff --git a/src/update.rs b/src/update.rs deleted file mode 100644 index 2e70f43..0000000 --- a/src/update.rs +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | pub fn update_mods() { | ||
2 | |||
3 | } | ||
4 | |||
5 | fn get_version(link: String) { | ||
6 | |||
7 | |||
8 | } | ||