mirror of
https://github.com/C9Glax/tranga.git
synced 2025-07-03 01:14:17 +02:00
Compare commits
1581 Commits
78e44b7704
...
JobQueue-S
Author | SHA1 | Date | |
---|---|---|---|
6f5823596a | |||
8a06ed648c | |||
4dcd6ee035 | |||
e327e93163 | |||
6cd836540a | |||
91c91e4989 | |||
57bb87120a | |||
07880fedb5 | |||
f1d3203ae1 | |||
314700aa8e | |||
b299cc9109 | |||
7e9ba7090a | |||
ea73d03b8f | |||
e9d9bebcd7 | |||
e5937d2654 | |||
7c9e0eddf9 | |||
ae0c6c8240 | |||
e063cf1fd9 | |||
2eb0d941b2 | |||
8170e1d762 | |||
254383b006 | |||
df431e533a | |||
9a4cc0cbaf | |||
861cf7e166 | |||
7e34b3b91e | |||
29d36484f9 | |||
2c6e8e4d16 | |||
fab2886684 | |||
d9ccf71b21 | |||
f36f34f212 | |||
ff10432c79 | |||
776e1e4890 | |||
db0643fa19 | |||
3eeb563ca1 | |||
7a88b1f7ee | |||
b5411e9c6c | |||
07b260dea6 | |||
71ad32de31 | |||
ecd2c2722f | |||
ff1e467ada | |||
24f68b4a8e | |||
e51e90aabc | |||
dc2c27f4bd | |||
406d8eef51 | |||
1fba599c79 | |||
a668a16035 | |||
f89b8e1977 | |||
11290062c0 | |||
f46910fac6 | |||
f974c5ddd1 | |||
a01963a125 | |||
8a877ee465 | |||
c370e656f1 | |||
58ed976737 | |||
1b6af73a0c | |||
70fe23857b | |||
0027af2d36 | |||
1a8f70f501 | |||
aa67c11050 | |||
7b38d0aa2b | |||
64e31fad54 | |||
49a70e2341 | |||
9659f2a68a | |||
d474868116 | |||
b1312c4164 | |||
33856f9927 | |||
02ab3d8cae | |||
7974c58fd5 | |||
503d9dfb5f | |||
62b035f6c5 | |||
40c70fbf19 | |||
49bd66ccab | |||
9b251169a5 | |||
aa29c45094 | |||
bd60fda05a | |||
8ecbdb91b2 | |||
cb1c68f295 | |||
421a25ec31 | |||
2d122a918f | |||
100cb06ba0 | |||
6125b036bf | |||
3fe3fc09b0 | |||
96d5b09391 | |||
84aecda916 | |||
0803a92a66 | |||
7f55aaf85d | |||
3853e2daa2 | |||
852fbf5ae8 | |||
4e7a725fee | |||
698d138642 | |||
8efb60652b | |||
fe60b98cb8 | |||
63442e9af6 | |||
703e32a30e | |||
4ddfe4a54c | |||
fb2b4d6920 | |||
496b49ccb3 | |||
b3efcf19d9 | |||
0903ec606b | |||
6cfa29e3dd | |||
0519ed26de | |||
aacdb72d6a | |||
3283dd7290 | |||
937c5cb7a7 | |||
225b7f02ad | |||
6258e07f20 | |||
622198a09e | |||
49b382fe1f | |||
5a6dc5a5b2 | |||
4bc70eca68 | |||
63fee081e6 | |||
e45b72dcf9 | |||
021ad5e804 | |||
8e0c964883 | |||
d6e945741a | |||
3a3306240f | |||
110dd36166 | |||
065cac62af | |||
563afa1e6f | |||
be2adff57d | |||
adc7ee606e | |||
a764f381c9 | |||
590ccdd09a | |||
0f0a49f74f | |||
a1a5028858 | |||
1792952039 | |||
9e62eb53cb | |||
f3c4b012b0 | |||
7e1c65b470 | |||
4247ae7740 | |||
a5954ed5c8 | |||
d08544b892 | |||
f6f86deb7f | |||
16f5817a31 | |||
d5d9f44a5f | |||
83bc3b418b | |||
205f0a1629 | |||
a1c2942208 | |||
4b4e24c6a0 | |||
475a29b10d | |||
694b88d200 | |||
0f6c060026 | |||
b49b11828c | |||
2d69b30e83 | |||
53d9be5656 | |||
7d4a6be569 | |||
7477f4d04d | |||
30a8162777 | |||
57baad3d2c | |||
3c5f51e495 | |||
397d3c93df | |||
1b49b171f4 | |||
ec5d048df5 | |||
a490e233d7 | |||
f085c5cf8e | |||
31beeeffae | |||
99a3f2614d | |||
15ced9aed8 | |||
64b17aea7a | |||
c696c38983 | |||
dbbac1ad59 | |||
b955d41530 | |||
91e033a2ec | |||
4dd31dfe18 | |||
66fcdca7e7 | |||
9350de0ae9 | |||
c94c55300c | |||
721f932fac | |||
f691529591 | |||
d75262a8f3 | |||
9521f66bac | |||
3981a41303 | |||
f2961711cf | |||
93ad691971 | |||
cef3b24efd | |||
f10c478cab | |||
01ba927491 | |||
90ce1395b8 | |||
892ef6c9d6 | |||
31c039d71e | |||
5b03befbf1 | |||
5012bbb2eb | |||
45a8f7a038 | |||
9b4baa1334 | |||
657ab571f9 | |||
1480aa0a03 | |||
232fe6406a | |||
a2bc14d54a | |||
d278a25f16 | |||
5f42a2d5ae | |||
60d84d1186 | |||
7ee4d32c07 | |||
0e68d64f75 | |||
434e30dc47 | |||
19ff3f578a | |||
cc03b6fa9c | |||
1f59ef66cd | |||
d7f21550cd | |||
d93c8fdb94 | |||
80320fd44d | |||
6449132dbf | |||
0df3381c8c | |||
2ca43e6f5d | |||
3ba1261f31 | |||
be72d4ba97 | |||
f237d82cac | |||
a43901564b | |||
34ec185125 | |||
cd08d9d78b | |||
339f40b61b | |||
8ee8f33f33 | |||
6721bd863f | |||
ee820cfa27 | |||
24361d5a43 | |||
6687ab4b3b | |||
290324f9d9 | |||
89ed500751 | |||
b00b0ee030 | |||
e47c52ad48 | |||
ef87e02d0b | |||
0af83f2fd0 | |||
f3854ab594 | |||
207604a437 | |||
832ddf1442 | |||
313225a1a1 | |||
ffc0e7555a | |||
ecfc8f349b | |||
94678e744f | |||
73eb02e7cb | |||
c3ebd6acac | |||
a694b9f5ab | |||
b24d2e12fc | |||
6909c367e5 | |||
293f0af8e3 | |||
ebfa34e386 | |||
14524407f9 | |||
d56f0b383a | |||
70391c83c1 | |||
dc7696ee26 | |||
49dab9a670 | |||
4cb48dd1b4 | |||
d43ae881b5 | |||
3583e45071 | |||
c4adba6357 | |||
ed74975312 | |||
043f0b9593 | |||
022ebe2bcc | |||
3a8b400851 | |||
6c5bc3685e | |||
c679d7c677 | |||
4075adfe6b | |||
72abc90af3 | |||
894f105786 | |||
d314559361 | |||
5ab0bd0b78 | |||
5c0ace291b | |||
0d931bc835 | |||
e1e5a45960 | |||
3ecbc1a805 | |||
3305519307 | |||
9fca2d81ab | |||
949c0cc16d | |||
5921e524a9 | |||
bf332717a5 | |||
bb31a94eea | |||
c9bc79fbd5 | |||
83ce315f87 | |||
59511056d0 | |||
ed3ca5dba8 | |||
8df05d7e8a | |||
95d1e37b47 | |||
1d2ca4d76a | |||
e2ff2c76ed | |||
8a0829ef69 | |||
d257095885 | |||
68cc23e158 | |||
b6494ab7f9 | |||
1d1d01b6e5 | |||
5bb4977876 | |||
c6bb1c9180 | |||
9a066e7ac7 | |||
4bafffded4 | |||
235183cd7f | |||
942b43da67 | |||
ce5538b352 | |||
0cfdf17bd4 | |||
0c48c1e020 | |||
0638e75ed6 | |||
5a4bc1c6de | |||
71f663ca2f | |||
1b61a16061 | |||
db81fdce39 | |||
fdb5451162 | |||
6b7632b071 | |||
06c080dfce | |||
8130e11a9c | |||
659a42d370 | |||
9cef068785 | |||
4ad3149523 | |||
dccc9fdbef | |||
e6d40a7b36 | |||
a95cb90561 | |||
603e1b41d9 | |||
bb8a514830 | |||
9928abb674 | |||
ebb034e0c7 | |||
edacaaba8a | |||
d97da26994 | |||
8b923d73c4 | |||
1dca7ec569 | |||
7229fad6c5 | |||
814efd3528 | |||
2cd5d8bc4f | |||
5a864ab9b7 | |||
663e2e2ca0 | |||
c700974693 | |||
553b5558d3 | |||
c9bbfee26b | |||
6e869eeb0d | |||
be7da69dbd | |||
7f13d9b1e6 | |||
0c9e3205c2 | |||
6315940cd6 | |||
ef7ebf022d | |||
725813c2f3 | |||
a69e12179b | |||
45ca2695eb | |||
bd9e79d026 | |||
6bbd09072b | |||
d6018b60ae | |||
8c3b70b32e | |||
4f7031ecfc | |||
a713a006dd | |||
ebe7e145aa | |||
f7a285aabd | |||
786482398c | |||
7921dcb1cb | |||
d0c9313279 | |||
58cf4cf4e0 | |||
be6b3da1be | |||
280d715a7c | |||
d0b775444d | |||
b4edcccafe | |||
268441a47d | |||
b818f63f2a | |||
1701881f4b | |||
78a9322036 | |||
e5be5703f8 | |||
cc32b3dfae | |||
110a0bf481 | |||
fdbe585aa0 | |||
ce217aae4f | |||
123a8b06b2 | |||
2350c5a04b | |||
f532e2ff76 | |||
6a8df2f5f8 | |||
3abf7224d0 | |||
b39dbd5671 | |||
375fad0c21 | |||
ee0d17c24f | |||
36ab3c3fdb | |||
c3d60c6586 | |||
524596ad85 | |||
6aa8413c40 | |||
94adefa8e6 | |||
7cf7eb85d2 | |||
55c0e2c4e7 | |||
5494f2b754 | |||
b96ae4a2d2 | |||
80190e1286 | |||
3a25c0b221 | |||
16dd1ffa97 | |||
9cb5f636dd | |||
df319e9afb | |||
84388a469a | |||
d322445550 | |||
81d22bc022 | |||
6b0cefbc7c | |||
519030861d | |||
6940e6c64d | |||
e66ab49e7d | |||
67a15cec7f | |||
ae11c31b9d | |||
60b128fc30 | |||
729f018712 | |||
03e89913e3 | |||
c4fc2f436b | |||
ebc30c85bf | |||
d6b0e3a366 | |||
e1bfdd675b | |||
e6f8853b49 | |||
99ddb06d6d | |||
62876498d0 | |||
1044821147 | |||
7f946da1c3 | |||
79e7941dda | |||
faa235783c | |||
87c5ad001d | |||
3b58e0498b | |||
87274aca19 | |||
77c5903cf1 | |||
0d32f15ee9 | |||
a0774841bc | |||
3ee3a07565 | |||
b9eecd3afd | |||
6534341fd5 | |||
6737be4a20 | |||
84833acdeb | |||
538e6fa60b | |||
8c5bcd2665 | |||
50dfd92c91 | |||
bf9fe517b0 | |||
e1f1a05724 | |||
1008da7ee8 | |||
72d9bda0e8 | |||
a40a9c84df | |||
ec884f888f | |||
57df419d65 | |||
825b945ad1 | |||
b8c624f3ea | |||
93cfdddd19 | |||
4c8d9bfaf2 | |||
dd988658c0 | |||
cf4c84a47f | |||
5d9bfc3adf | |||
5a770c8e9f | |||
395619acd3 | |||
502821c246 | |||
9d6a8ed686 | |||
e3bd7620aa | |||
afcc2cacaf | |||
4040b5845c | |||
428d6e13d1 | |||
1e6a65c0fd | |||
025d43b752 | |||
113c0abba7 | |||
7daebcb1c4 | |||
747df0bde5 | |||
463f360808 | |||
44ff158c66 | |||
85d7c07b13 | |||
b5b45d0801 | |||
553f56ecaf | |||
9cc4f8c090 | |||
29f3f1a16e | |||
204fb7614d | |||
d6e73ffcdf | |||
5a8202f872 | |||
1bd914571c | |||
483dcc41df | |||
55cc2a2e84 | |||
b619109ea1 | |||
72943330c3 | |||
bc44a5333b | |||
38bc1e4d53 | |||
47479f7a0d | |||
b2381be860 | |||
657e1b338b | |||
5018800d09 | |||
ee265a7519 | |||
5b0624654b | |||
a75549c699 | |||
c7dc5e75f2 | |||
3f37eefe72 | |||
b7bc04a045 | |||
f7daacf0d4 | |||
1cb8899195 | |||
f46244cb9c | |||
9db3f1b0da | |||
dc9cd4b1dd | |||
3566ad774d | |||
94b81969c7 | |||
3e581e2ddb | |||
bd8cb86c52 | |||
34c5436b33 | |||
4690394437 | |||
02cf8578c9 | |||
067497ddd0 | |||
4b88cdbd90 | |||
420013f07b | |||
8cee11aa22 | |||
07c6081c03 | |||
585d7e3380 | |||
febce6b92a | |||
fb7ed21d82 | |||
2db85e5070 | |||
198bbdcf94 | |||
c58adf64fa | |||
957debea01 | |||
5186ae66c9 | |||
c35e1ef517 | |||
8f6891142b | |||
b52e6d4908 | |||
96b5921ed6 | |||
9d47445339 | |||
93696fbac1 | |||
582b3af89c | |||
f57667bc8f | |||
f9a30f2587 | |||
240af81fa9 | |||
26b2910000 | |||
a88b85e599 | |||
27f823cfeb | |||
70993a692a | |||
1a631362c9 | |||
00c4f0533f | |||
8670863810 | |||
2c9bd2532e | |||
575fb739cc | |||
d4af068f0e | |||
6a4d454a08 | |||
225db8beda | |||
d80fcd9039 | |||
30c44760e7 | |||
a3ae3c320d | |||
4871bc801d | |||
ea262889e6 | |||
445542b653 | |||
b7718220ef | |||
34c62e8658 | |||
a9fcc93670 | |||
68d7ef258f | |||
fdea4f5ea5 | |||
ac3039e587 | |||
1c5f105a4d | |||
3829a1cf26 | |||
c3daa0b751 | |||
3a072beea3 | |||
8e6f2798a9 | |||
26a07f4a2f | |||
9cbde9a6b4 | |||
0870aa9fdb | |||
172650e644 | |||
48ab44c28d | |||
52ff2e54a8 | |||
61d80a93cf | |||
32ecdcda76 | |||
7be3ee52e9 | |||
981eb0fd9f | |||
a92eba2d14 | |||
47f3044a6d | |||
6d03cc5f8d | |||
290c405f52 | |||
fcdbd32872 | |||
eb6c37cc53 | |||
d922842186 | |||
69323d6d60 | |||
46a0fb8c48 | |||
ec8eb40941 | |||
d2074fae35 | |||
713bbc230f | |||
32ab9a552f | |||
7b6724ad38 | |||
c11c68d6d7 | |||
09fdb6e5f1 | |||
be68ddc9b7 | |||
e86ad03b1e | |||
9dfbe89e87 | |||
96e2845a5b | |||
98e75af486 | |||
e2f5c3badc | |||
cda07bb9aa | |||
7c18466e95 | |||
c36204c7a8 | |||
ce1c4d3f65 | |||
52d0489a1b | |||
18edcef1c3 | |||
73ad881600 | |||
f89aea6ac8 | |||
5f05ba1049 | |||
c6cfd9eb6c | |||
a20ee01cfa | |||
cf5cbba9a8 | |||
600b56033d | |||
fdea3659f1 | |||
7f3754fb64 | |||
2dac5db4da | |||
99df9a9dfd | |||
77bb309dfa | |||
3456fc6564 | |||
35f2625f05 | |||
0b9948e367 | |||
96f3dbce65 | |||
895128a462 | |||
3b9d4a6735 | |||
a94186455b | |||
7d3deee74c | |||
5980b64caa | |||
cbecb257ef | |||
8316ed08a7 | |||
190fa8cba7 | |||
217700d08d | |||
7ff9ac53ee | |||
6faaaf4139 | |||
9b8b80cd24 | |||
15f3e2b8ec | |||
2be29e4019 | |||
e8dbf7a718 | |||
a968f4328d | |||
398b6fff05 | |||
f5da2f8526 | |||
73093ab86c | |||
75eea8c761 | |||
fccaf9fcbe | |||
3122aa32e8 | |||
06cdbbd283 | |||
02fad2dd44 | |||
e0a7d1a187 | |||
054c88712e | |||
d0f9a4102c | |||
9f178821b6 | |||
e95eb0497c | |||
3c3f7bb95a | |||
032ee95716 | |||
682fd0bc2a | |||
dfa8e66f34 | |||
8f51d22303 | |||
d41de84262 | |||
1bd20791b8 | |||
03aeab44cd | |||
6d723b6355 | |||
7b91bb699f | |||
14e33cc496 | |||
6f3bba99b0 | |||
2d848843d0 | |||
63b493fa9c | |||
001a37b8ef | |||
69d6884517 | |||
db73af3bdd | |||
59547efab2 | |||
f4336f9777 | |||
bec3ac52a9 | |||
ea37e81ece | |||
6a20783d48 | |||
21af75f410 | |||
fc884adc9f | |||
960d3f7c62 | |||
6520aebcdf | |||
1ee9b644aa | |||
2f36701fef | |||
b18f8e4059 | |||
8145abb744 | |||
9dd52178b9 | |||
cf242f81e1 | |||
a629792818 | |||
34dd78810d | |||
e1c504226c | |||
200a22228f | |||
bc10136331 | |||
06df6e0767 | |||
ba029b71f5 | |||
082802ddbe | |||
d5f1df0400 | |||
d00881e611 | |||
72bc7ec07b | |||
89b5aa266e | |||
926c0d5833 | |||
80e2568113 | |||
3b6417eff2 | |||
6b9ddca711 | |||
2812a6dff1 | |||
1991862a42 | |||
40e4d5c203 | |||
49e9731184 | |||
a4e85f254f | |||
4f47aeadcf | |||
e0c1356fea | |||
0d9b3d2499 | |||
d73bf70868 | |||
8e5d15ead9 | |||
b8c28e6d21 | |||
9ea5e436fe | |||
b4c310638a | |||
159341ff3c | |||
29338b9b17 | |||
0eda8913b0 | |||
5ca50630e4 | |||
d0bfb262bf | |||
4f14f15ade | |||
d89a24fd11 | |||
a5859e3c82 | |||
dd2fa3fbd7 | |||
33e5d65785 | |||
d60ed77dbe | |||
e15c6816b5 | |||
4a4fe4b40d | |||
d221532e0d | |||
4881789970 | |||
be1e6fe988 | |||
f61e51e506 | |||
eba511749b | |||
5bc2a8909d | |||
de4c57a0cd | |||
e368c3c98a | |||
f3e0959be8 | |||
d17ca1d97a | |||
e9376e3782 | |||
7c217a7e33 | |||
a437fcbca1 | |||
1dcfecd66f | |||
6db4646336 | |||
8a6298e3fd | |||
194705c124 | |||
f4d5969003 | |||
8607bd2c89 | |||
9d92069a4b | |||
5614729eab | |||
fab30dc5a7 | |||
fd20b9febf | |||
ee6de661c8 | |||
d52ec8d36f | |||
790e77b00c | |||
37dfb4df02 | |||
42feea3ad5 | |||
4f14903538 | |||
bbc750d731 | |||
08dd01942f | |||
6ae3918679 | |||
351144e763 | |||
aea4c0c61b | |||
7b9e935db7 | |||
048b165d76 | |||
ebe3012c69 | |||
8ccb6c0cb5 | |||
a5dbed9525 | |||
811ddd903f | |||
beb455308f | |||
f948809bcd | |||
7ceb9cd4cb | |||
57f1e037ef | |||
5c309131ad | |||
6ca8d58e43 | |||
e3211b95e2 | |||
b5e9e03f64 | |||
98bd8a983b | |||
27a559834f | |||
f4996659ef | |||
e05684d5d1 | |||
4a7d23c0d9 | |||
1d44b6d9c6 | |||
2cfc7ac2c5 | |||
811a183af2 | |||
fb0755eb89 | |||
2e8b896f3b | |||
017f31ca83 | |||
4021237888 | |||
7ed3846c5f | |||
4692cc297a | |||
7f95ab9439 | |||
49a9b7ccb0 | |||
0735e2c588 | |||
5b22246c41 | |||
2e1f633f40 | |||
8887cea718 | |||
061da1b4bf | |||
80dc8fbe65 | |||
28a0efe488 | |||
3d08b1f9f2 | |||
3d855020eb | |||
c6d0168d2f | |||
d52213002e | |||
ec9290f41f | |||
6b91796e5a | |||
9f9ea569d5 | |||
4bd1150a0e | |||
8b62e2c467 | |||
7ec262a2e4 | |||
d32d5976ee | |||
58cff6513a | |||
783f229a6a | |||
2651a0c53b | |||
0ced3a7dd9 | |||
a56555eee4 | |||
cee7870aad | |||
aaf06da8e1 | |||
51a26a3cba | |||
bce77180bc | |||
8c66bbc89f | |||
762da4c859 | |||
daba940b45 | |||
79e61a62c7 | |||
06fe98323a | |||
5f820c53f5 | |||
c69f1f6569 | |||
e360037fda | |||
ea866e0136 | |||
c3231327f9 | |||
03e90eccd3 | |||
64482931a3 | |||
cce4901a5d | |||
3adb103fc4 | |||
b6ffb97a04 | |||
5bdbd9e2e4 | |||
49cfff8a2f | |||
6d48a100ca | |||
4104169c19 | |||
4cb7c941a2 | |||
b3fb53f6d8 | |||
f729c44f88 | |||
8b9769b816 | |||
f4966b0348 | |||
9a02859f6b | |||
e96dd07521 | |||
a610eff8f0 | |||
df2fc4a036 | |||
c41f04d92d | |||
5e647099cd | |||
011af9c7a8 | |||
630e507564 | |||
fa2598084f | |||
f79743ee93 | |||
2828fec316 | |||
bd14722791 | |||
d22b49cfa8 | |||
595051b0fe | |||
238395a3da | |||
0313d81204 | |||
f5cecb9e30 | |||
7e5fa6ce41 | |||
0ab2ae03ce | |||
95236daf41 | |||
294ce01bc3 | |||
13565d1c7a | |||
a8aa7d3370 | |||
01bab62190 | |||
2768ab38e6 | |||
54b24ac37f | |||
c67e89f1dd | |||
4ba44d3ac3 | |||
33b8ede492 | |||
dbc1b94124 | |||
8631cf6376 | |||
df4d547e2b | |||
006b71b496 | |||
5f03b0d89c | |||
6dc1ea0030 | |||
ff08754610 | |||
d1a6c0ad3d | |||
0260868968 | |||
b1f72dcb81 | |||
b0f353819b | |||
8f8d019861 | |||
21a7392493 | |||
0d5db15f87 | |||
431fde0d76 | |||
e022bf3081 | |||
c25a4f69ec | |||
82bdb248b9 | |||
b27114eaad | |||
051eb4a417 | |||
482704af2c | |||
af4229920d | |||
6f5fb7e0bb | |||
7628510b87 | |||
dd965d886a | |||
7e54577c54 | |||
537ad3a5f8 | |||
6a8697fc3a | |||
94582496ef | |||
17ef5eae0f | |||
d5b6d4e8ee | |||
05190bc9e2 | |||
d211dd2d01 | |||
590547e407 | |||
2ad04c5c46 | |||
189569ccdf | |||
2872eeea09 | |||
c0cfeaa35d | |||
2fd780996c | |||
b390bb8ea5 | |||
847829e617 | |||
0f29da00de | |||
9b2a6de841 | |||
17a27c9922 | |||
6c9071b22b | |||
abfe42b7c1 | |||
72ae124418 | |||
bee6e7ba37 | |||
8079ffc742 | |||
6d6e33491b | |||
a8697a14a3 | |||
e2adac937a | |||
b4708c5d10 | |||
597abde115 | |||
2a824bbb8d | |||
9691eb0d08 | |||
4888e18fd2 | |||
0aa92a7913 | |||
db53e2156b | |||
1cce0f204e | |||
ce41c49a0e | |||
b8570e5eef | |||
1f24a2349d | |||
ca95460218 | |||
e801cc4cbf | |||
2c4c8de8b5 | |||
0b4461265c | |||
c008d55f26 | |||
9b990aecea | |||
299fa6afda | |||
c03e927565 | |||
bb6c553afa | |||
33d78ed757 | |||
84272ddd1e | |||
2f0fbbd3cb | |||
5bc414fd59 | |||
2eaeadb92c | |||
d8df6eccb1 | |||
db64b717eb | |||
1afe36a525 | |||
aa692f6978 | |||
c706824222 | |||
3ca6245fc2 | |||
2dd82aad13 | |||
3c4867a276 | |||
bae157cdb4 | |||
3b818ff1af | |||
5d12be2983 | |||
31a4e693e0 | |||
e49db9a4cb | |||
54142e61fe | |||
cd5ca0e302 | |||
95da900213 | |||
b5be4e0dd8 | |||
0c135aa89e | |||
e11ee4dafe | |||
05573f65f9 | |||
d986c808e3 | |||
5df63b00c2 | |||
903bb5af5e | |||
cc8453d4a8 | |||
800d4c1ec1 | |||
b4f97eefcf | |||
29f6de2590 | |||
23e5c4a7b1 | |||
e15717cb04 | |||
b995fc568a | |||
442d949371 | |||
263d0e6036 | |||
7c7d43021e | |||
5cdc7d7207 | |||
1bcbd1517f | |||
b72da45ae9 | |||
01041e43ac | |||
4c1a659f16 | |||
2e02f0b237 | |||
77f93d87f9 | |||
45c0f19a9d | |||
7c09deb143 | |||
449d406eab | |||
083ce238d8 | |||
5f9ffb8aad | |||
92bc3d5aa8 | |||
49ab8928b1 | |||
391efcb9bc | |||
963ad375e8 | |||
0a5ded2036 | |||
4843c7f05c | |||
6adbda2359 | |||
425cf7e0d6 | |||
8f5dd5aab5 | |||
733ae285f1 | |||
2e1c8ce34f | |||
c965bc38d1 | |||
37266ea095 | |||
8caac538c9 | |||
7c7f711bb4 | |||
d78897eb74 | |||
438c11af4f | |||
38df54baff | |||
98d187d133 | |||
5352cca058 | |||
3381909afd | |||
7219641859 | |||
f63851d95d | |||
e72301d062 | |||
2302e1009b | |||
40fea6cc7f | |||
5458c43f21 | |||
f78bec43d6 | |||
88876fb8f4 | |||
c71aec8882 | |||
ddfba0d864 | |||
ca9c0b22c1 | |||
6844d0a242 | |||
fd9319de27 | |||
726be70af3 | |||
19c9ecb3e7 | |||
f01a786e59 | |||
59f9bcc7d0 | |||
2796a2adb5 | |||
e07b191293 | |||
9bf650f5fc | |||
334795b263 | |||
51a6f216af | |||
238a2775f4 | |||
fec970d7d6 | |||
e642d50c47 | |||
fafcdac00a | |||
1785aa28ea | |||
f22c332cab | |||
b3bf523e1e | |||
06b2e11164 | |||
7972f07801 | |||
d89af7cc5b | |||
31a0c6ffb2 | |||
668a3b3a96 | |||
3938c61297 | |||
4f3bcd245d | |||
129c95f123 | |||
e2cdf27d40 | |||
4156365b18 | |||
d3ccddd8db | |||
13075a8704 | |||
e7d9f53a93 | |||
dc6dfd4aa1 | |||
0fba09b1e8 | |||
f08b9e85ec | |||
95fcc73c74 | |||
73492d8102 | |||
c69dd22ecf | |||
17b6c523a2 | |||
6c3f7604fe | |||
94f88f08e9 | |||
47327524be | |||
3b96419739 | |||
b7c9b4e9b4 | |||
13adb45444 | |||
b8fbee578e | |||
c1fb42b537 | |||
dcc12ec3ea | |||
8c554076b2 | |||
a10fbdf3a5 | |||
f246209685 | |||
41c561bd1d | |||
fc7d5463c3 | |||
3c2ce266f6 | |||
306cb87d67 | |||
23cda74487 | |||
3ceee63dfc | |||
4e5a6fe97b | |||
b3b1971dad | |||
2699f35b62 | |||
7a14583d6a | |||
660f6a1648 | |||
482fcb7102 | |||
b6cdb07e3f | |||
0875e7ee12 | |||
cb6482ebae | |||
87ea077281 | |||
c1aa4cf6b5 | |||
f5b6b1785f | |||
2553a150d1 | |||
b149d377dc | |||
0209159c5c | |||
e31820eb00 | |||
c4d69c27a4 | |||
3ee53b7436 | |||
64ec0963e1 | |||
27c4ed719c | |||
4f4b0cb3a8 | |||
48d312da0b | |||
1fe4b75ac7 | |||
c580fafc62 | |||
58040ecb10 | |||
2960a9b8f0 | |||
f52bb8eb89 | |||
ae0dc548ae | |||
051b85d08b | |||
d89ca0a2ef | |||
f1f640c1f6 | |||
9319aa7d1f | |||
656e62628e | |||
ba27adf255 | |||
88ca75e883 | |||
67c23b357f | |||
4a5271e2a7 | |||
fec5ad664c | |||
3cea5fb431 | |||
7fa44fba54 | |||
d6b5a29fdc | |||
a4a49d40f0 | |||
28fa85f05c | |||
1066e1ca2e | |||
39307f4313 | |||
a316ee3d48 | |||
569622099d | |||
017701867d | |||
c3d62bd337 | |||
dc9e9e705c | |||
9eee6683fa | |||
1265c7a072 | |||
c601541249 | |||
ae1184320f | |||
384e4c4f43 | |||
76a2b2498a | |||
2ab21b15cf | |||
7acdf7a19b | |||
af8716fcb1 | |||
5f2c66b729 | |||
e030f02431 | |||
bdeb75f4e4 | |||
4ce114986d | |||
8035bf3fcd | |||
85bf3ec7e8 | |||
0f17615b10 | |||
0c8145803e | |||
b2e0c3db97 | |||
ca283fcfff | |||
1d55070daf | |||
32fd75bdae | |||
99ad702163 | |||
6e3a9c2a78 | |||
ad1d4dfe23 | |||
14ba71005f | |||
22c4c0eb2c | |||
44f8d369c3 | |||
c0e6da144e | |||
51a1ae72ca | |||
79bbc92467 | |||
ae5be31c89 | |||
eebe25a378 | |||
0f3da4ec81 | |||
0b77dc1172 | |||
37cf47bc17 | |||
4cce2e04cb | |||
5465ac4e5c | |||
dd4d5a81ee | |||
a05e1914e3 | |||
ed79ee5d0f | |||
28e05e549d | |||
eaab7c5235 | |||
0552b3db82 | |||
c813e1854d | |||
32036df057 | |||
394829ee36 | |||
2a389f1ede | |||
3167f6c3e6 | |||
89c5f4b820 | |||
1c1169e5ce | |||
d5d34c5381 | |||
c0efbb22cc | |||
9f30e52713 | |||
1fd36c91d6 | |||
e663163de8 | |||
4827b90c3d | |||
e274c864f9 | |||
f4bc182954 | |||
3365be219c | |||
10708b3abd | |||
c1e939f1e3 | |||
21d53dabec | |||
a9417dbba6 | |||
4ca7b107eb | |||
61024bcee9 | |||
ea1b8749a6 | |||
2fcab1f1b1 | |||
bbd716383a | |||
6e1a0ab06c | |||
181942153b | |||
fe04af4a2b | |||
4240a1eb6a | |||
32349c1ddf | |||
a94d3d6b40 | |||
f916cda0f1 | |||
a8f0f1af15 | |||
0cf3a95f58 | |||
a89a526fda | |||
4d1e43e7b3 | |||
4f9749d09e | |||
7614f9aad3 | |||
97c0e42512 | |||
565bc0775d | |||
e6a3fa2899 | |||
2d82279d98 | |||
c5559a4ceb | |||
2572a537ab | |||
58db049496 | |||
8f309fcfd7 | |||
11461051f3 | |||
a4aa571870 | |||
e4086a8892 | |||
c45e4ddf90 | |||
675effd317 | |||
a4f67c9ab4 | |||
2538a29788 | |||
81d5802092 | |||
436edfde66 | |||
00c1cd56b8 | |||
a63154b581 | |||
53fe7ee983 | |||
6fb4098c16 | |||
7a024e8733 | |||
835e239be5 | |||
df8538c3b4 | |||
f832fe0de3 | |||
ebdb38bd57 | |||
e3201a9b99 | |||
eb50b84266 | |||
b3d778ff56 | |||
00861c406a | |||
01c8784bab | |||
3aa299e48a | |||
d1ce244135 | |||
c91754614b | |||
70b1ae4812 | |||
336e08aebf | |||
18134cdf01 | |||
5b89cbd042 | |||
74aca86b62 | |||
e5abaa4549 | |||
eb0eb71e86 | |||
4e73b0a4cf | |||
140074208f | |||
fa19d3da14 | |||
3d6657b483 | |||
f9b5e05974 | |||
ad4027779f | |||
98ec0b837f | |||
1afa3df316 | |||
d83aa1ef5b | |||
b610ec734e | |||
abf587377c | |||
437349bd27 | |||
000539d6a6 | |||
b4bef25a22 | |||
579e400a5d | |||
8af2b12fc0 | |||
bad4330330 | |||
42596752d3 | |||
16238c590b | |||
9f38dc3b6a | |||
485637d99a | |||
de14ff0b75 | |||
f947c37bd6 | |||
77eec0f696 | |||
18323f9f51 | |||
2cd2b6842d | |||
09f815903f | |||
c108478039 | |||
74289e43b7 | |||
2779f9ba09 | |||
59a8e556f0 | |||
074b137b5c | |||
3cb2540794 | |||
02c9934896 | |||
b2e1c95bca | |||
8c9e3ea6b6 | |||
db441607ad | |||
91c56783dc | |||
2c288eeeea | |||
57a1ea91fc | |||
06138a3927 | |||
84b053e672 | |||
0fe0cbc4ad | |||
62e6ce8363 | |||
a4f3ec6580 | |||
8b4e996b7e | |||
964540d30f | |||
fa69f4488f | |||
42c2876188 | |||
715244ff1b | |||
2333cd9095 | |||
c8225db4fe | |||
6741ca096b | |||
a897a7b3a2 | |||
0f8932e712 | |||
78023ef0fd | |||
d171f34e4e | |||
aa0dc4fa35 | |||
25f48592c0 | |||
398ac304d2 | |||
58a62f8272 | |||
86752c9a7e | |||
f9a7828d02 | |||
c97ff69148 | |||
1735bbcf8a | |||
9ae8ca65df | |||
00599cd24e | |||
6d5618a1f7 | |||
a1202a875d | |||
98946b4aa3 | |||
41b6bb77b6 | |||
e70a14ca56 | |||
b099da1156 | |||
01d1f922c2 | |||
47a80d67a8 | |||
16e3549455 | |||
be8c6b50ba | |||
a38fcf50ca | |||
82f6c7b3fe | |||
5586d2c104 | |||
62dc9fee2a | |||
ac96fca6dc | |||
25a6ceff10 | |||
b3e1d39d0f | |||
2833b7f22a | |||
cbdd305b69 | |||
b88890817e | |||
f66ab7d40b | |||
4cb3694cd5 | |||
a05d4c8bd9 | |||
22f87a74b2 | |||
ba57282879 | |||
9ccba6fba6 | |||
4f01c1166f | |||
0a51e7ad3d | |||
e541b922dc | |||
604abd5f9a | |||
7b311eae75 | |||
d4eb72cd99 | |||
b515215f4b | |||
a16686dfbf | |||
4275703941 | |||
c3342984ea | |||
ed4bdb5b33 | |||
0f0902c932 | |||
6508055b43 | |||
abc66511d8 | |||
9ed36c47b5 | |||
fd1b2a8470 | |||
8058749ab5 | |||
8737617e5f | |||
7e4f43f1e2 | |||
12b1b2afd6 | |||
0f9ac60fcd | |||
8c87f2948c | |||
e0fb817256 | |||
cdd2d94ba1 | |||
d5b7645cd2 | |||
9af5c1603e | |||
1035939309 | |||
3b542c04f6 | |||
a809b7c285 | |||
e883277400 | |||
23dfdc0933 | |||
edc24fff5b | |||
6cdccdf66b | |||
a4c9168551 | |||
821a1b7c3a | |||
b2b4256972 | |||
d2f46e4637 | |||
303fc293ba | |||
36c145da26 | |||
c822c74f42 | |||
dda4054d34 | |||
5b2546fdbc | |||
c11e3993ea | |||
02a382a99a | |||
c6c8f5cdf6 | |||
84842aed3c | |||
d9ced11cd1 | |||
25c90782dc | |||
e789c429cd | |||
93de471836 | |||
8b58e7dd13 | |||
b571bfa43d | |||
088d1c4647 | |||
f280c01802 | |||
1be10b310d | |||
a0469f3145 | |||
fcd81f03b3 | |||
76604d84d8 | |||
af822febbe | |||
8e207c3119 | |||
b6f8c8aab5 | |||
36f7cbd3e9 | |||
3b2643d949 | |||
9fd8bf1741 | |||
d5c9c5ba96 | |||
c8e27921ab | |||
6eaba07801 | |||
41929e0c72 | |||
4fcaca1a6e | |||
0e3c7f32d7 | |||
1c94625840 | |||
32f89f9dce | |||
234735a562 | |||
8b916eb854 | |||
29e1790c93 | |||
ac4c799a74 | |||
7c62883c37 | |||
02018253bf | |||
2aec884009 | |||
b3321ff030 | |||
16c1094875 | |||
5763d50409 | |||
ad43297358 | |||
b17800e0ef | |||
89c80d2997 | |||
6485b8744f | |||
a3a96b6b55 | |||
5bce3c6fdd | |||
5fa0c98d05 | |||
b166013770 | |||
02fe849046 | |||
d42393c83a | |||
c685bd622f | |||
dc83cc2194 | |||
7784f2024e | |||
4895079887 | |||
ab1ddc6dc8 | |||
87eade10cf | |||
1f3ac41b30 | |||
6a304bb330 | |||
b0642d1251 | |||
63b5139e93 | |||
e938784388 | |||
c436389426 | |||
5099e25f3f | |||
cf6fc3b8f6 | |||
f5141d0f8e | |||
5c753e7a7d | |||
17ce820cf3 | |||
5b4a3b9d7c | |||
f73997e563 | |||
437136804d | |||
e14683d21a | |||
5ae02ee0ed | |||
a2e9a3f34a | |||
bbf05e3dec | |||
d95839e5df | |||
5a303598fe | |||
db2103963e | |||
2c1105527a | |||
ed19dcb5c3 | |||
46f06c2685 | |||
d4f47e057c | |||
61712d0537 | |||
1f8f8c09e3 | |||
0522fa6215 | |||
0383a7d686 | |||
bd189984a9 | |||
58c01b2174 | |||
459558a514 | |||
721b316209 | |||
b1befa2ecc | |||
57a4cc4ab5 | |||
655e8db2b6 | |||
7cdf77cbb9 | |||
5a9aed4969 | |||
5b41f687d0 | |||
d6a62dc315 | |||
6d91788655 | |||
14785e5672 | |||
496d502cd2 | |||
7612411917 | |||
ed1402b5ec | |||
5adaee4821 | |||
2d82fe1489 | |||
783fd8129e | |||
4f29eff48e | |||
e0e7abb62b | |||
ae63a216a5 | |||
5d98295c59 | |||
0c580933f9 | |||
06f735aadd | |||
439d69d8e0 | |||
933df58712 | |||
165bbc412e | |||
6158fa072b | |||
0d3799e00d | |||
e977bed5a5 | |||
cacd5fede2 | |||
1bca99cb6a | |||
15fc367263 | |||
8bb6fb902b | |||
a57903cd5a | |||
1cd819b21d | |||
27afedc1b4 | |||
fac0a3f7eb | |||
03ca480fe8 | |||
c2915468a5 | |||
8805c53cb8 | |||
adbbe3f6cc | |||
14b694d3be | |||
72ce75c6e0 | |||
8381951168 | |||
b24032d124 | |||
8bc23f7c69 | |||
48b7371a18 | |||
61ecefb615 | |||
8ff65bf400 | |||
932057cca0 | |||
67d06cd887 | |||
cbb012a659 | |||
e4f33bcca9 | |||
fbba7c45b9 | |||
d9b6062767 | |||
d477cd1ccd | |||
f892db7dda | |||
16c1b5c506 | |||
d5ecc1c37d | |||
1b9ebd096b | |||
8619630269 | |||
2bc92556e3 | |||
f1ab823e7f | |||
8261d02cc7 | |||
8d3b8be95c | |||
60519910de | |||
0940afe41f | |||
3dc376c19f | |||
3e56ef842b | |||
5a44e3b8b9 | |||
732c2f119c | |||
81638f4b4a | |||
c547aa6422 | |||
d80980512e | |||
f9f802155d | |||
eef0955009 | |||
ec25900ac0 | |||
e5fe14a09e | |||
5dc91095f8 | |||
985ac8fc7a | |||
c9537a9963 | |||
4fd3c03804 | |||
a1e9dd0232 | |||
aa1f9b1b56 | |||
6069578b6e | |||
a84b768e24 | |||
d1a21af15d | |||
7423ae6ace | |||
3aa7ba9d96 | |||
fdbb4570be | |||
b643a0c2a9 | |||
6fa6f897aa | |||
2bfab0298d | |||
147a20385b | |||
afa18d6a2c | |||
66980eef23 | |||
65f468a30a | |||
a91c33ee4f | |||
f39482fe4c | |||
41f47b4d6b | |||
be40091102 | |||
665092be6a | |||
653cb699d0 | |||
8dbc5446ad | |||
750df4ed52 | |||
4772ae0756 | |||
23f703d5a5 | |||
6aa0ea277b | |||
780df1cd6e | |||
0b7da2e9cb | |||
01a059d26b | |||
a8dbece237 | |||
5efa00e059 | |||
02075ed1b1 | |||
fabd16ccea | |||
79928075b0 | |||
9b8eb6a197 | |||
1d263ef45a | |||
e0877add30 | |||
046cad8072 | |||
b2ce55be96 | |||
a6e9013495 | |||
14c69631a6 | |||
ccc4e42a49 | |||
d6e75fda31 | |||
fc89537f63 | |||
fd3423d03c | |||
878f77766f | |||
08001fd684 | |||
e2917d2f2e | |||
32dc58715e | |||
add0583776 | |||
6fed0e5473 | |||
a0636ac7a2 | |||
7aeb78e2f6 | |||
5cf512f2b2 | |||
7d96b0901f | |||
68e80bc066 | |||
ad971fb065 | |||
86052472bc | |||
ec30bb40fa | |||
2fa96e9793 | |||
39fa905733 | |||
a966bd788d | |||
947b521163 | |||
5674adbd5e | |||
0d0b68a8f9 |
@ -1,25 +0,0 @@
|
||||
**/.dockerignore
|
||||
**/.env
|
||||
**/.git
|
||||
**/.gitignore
|
||||
**/.project
|
||||
**/.settings
|
||||
**/.toolstarget
|
||||
**/.vs
|
||||
**/.vscode
|
||||
**/.idea
|
||||
**/*.*proj.user
|
||||
**/*.dbmdl
|
||||
**/*.jfm
|
||||
**/azds.yaml
|
||||
**/bin
|
||||
**/charts
|
||||
**/docker-compose*
|
||||
**/Dockerfile*
|
||||
**/node_modules
|
||||
**/npm-debug.log
|
||||
**/obj
|
||||
**/secrets.dev.yaml
|
||||
**/values.dev.yaml
|
||||
LICENSE
|
||||
README.md
|
21
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
21
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
name: Bug Report
|
||||
description: File a bug report
|
||||
title: "[It broke]: "
|
||||
labels: ["bug"]
|
||||
body:
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: What is broken?
|
||||
description: What happened? How did we get here?
|
||||
placeholder: The place where you tell me what you expected to happen, and what happened instead.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Log-output
|
||||
description: The output of `docker logs tranga-api`
|
||||
render: C#
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Additional stuff
|
||||
description: Screenshots, anything you think might help
|
23
.github/ISSUE_TEMPLATE/new_connector.yml
vendored
Normal file
23
.github/ISSUE_TEMPLATE/new_connector.yml
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
name: New Connector Request
|
||||
description: Request a new site to be added
|
||||
title: "[New Connector]: "
|
||||
labels: ["New Connector"]
|
||||
body:
|
||||
- type: input
|
||||
attributes:
|
||||
label: Website-Link
|
||||
placeholder: https://
|
||||
validations:
|
||||
required: true
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: Is the Website free to access?
|
||||
description: We can't support pay-to-use sites, or captcha-proxied sites as Cloudflare.
|
||||
options:
|
||||
- label: The Website is freely accessible.
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Anything else?
|
||||
validations:
|
||||
required: false
|
7
.github/dependabot.yml
vendored
Normal file
7
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
version: 2
|
||||
updates:
|
||||
# Maintain dependencies for GitHub Actions
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
45
.github/workflows/docker-image-cuttingedge.yml
vendored
Normal file
45
.github/workflows/docker-image-cuttingedge.yml
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
name: Docker Image CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "cuttingedge" ]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# https://github.com/docker/setup-qemu-action#usage
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3.6.0
|
||||
|
||||
# https://github.com/marketplace/actions/docker-setup-buildx
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v3.10.0
|
||||
|
||||
# https://github.com/docker/login-action#docker-hub
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
# https://github.com/docker/build-push-action#multi-platform-image
|
||||
- name: Build and push API
|
||||
uses: docker/build-push-action@v6.15.0
|
||||
with:
|
||||
context: ./
|
||||
file: ./Dockerfile
|
||||
#platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6
|
||||
platforms: linux/amd64,linux/arm64
|
||||
pull: true
|
||||
push: true
|
||||
tags: |
|
||||
glax/tranga-api:cuttingedge
|
45
.github/workflows/docker-image-master.yml
vendored
Normal file
45
.github/workflows/docker-image-master.yml
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
name: Docker Image CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# https://github.com/docker/setup-qemu-action#usage
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3.6.0
|
||||
|
||||
# https://github.com/marketplace/actions/docker-setup-buildx
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v3.10.0
|
||||
|
||||
# https://github.com/docker/login-action#docker-hub
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
# https://github.com/docker/build-push-action#multi-platform-image
|
||||
- name: Build and push API
|
||||
uses: docker/build-push-action@v6.15.0
|
||||
with:
|
||||
context: ./
|
||||
file: ./Dockerfile
|
||||
#platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6
|
||||
platforms: linux/amd64,linux/arm64
|
||||
pull: true
|
||||
push: true
|
||||
tags: |
|
||||
glax/tranga-api:latest
|
45
.github/workflows/docker-image-serverv2.yml
vendored
Normal file
45
.github/workflows/docker-image-serverv2.yml
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
name: Docker Image CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "postgres-Server-V2" ]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# https://github.com/docker/setup-qemu-action#usage
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3.6.0
|
||||
|
||||
# https://github.com/marketplace/actions/docker-setup-buildx
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v3.10.0
|
||||
|
||||
# https://github.com/docker/login-action#docker-hub
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
# https://github.com/docker/build-push-action#multi-platform-image
|
||||
- name: Build and push API
|
||||
uses: docker/build-push-action@v6.15.0
|
||||
with:
|
||||
context: ./
|
||||
file: ./Dockerfile
|
||||
#platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6
|
||||
platforms: linux/amd64,linux/arm64
|
||||
pull: true
|
||||
push: true
|
||||
tags: |
|
||||
glax/tranga-api:Server-V2
|
6
.gitignore
vendored
6
.gitignore
vendored
@ -19,3 +19,9 @@ riderModule.iml
|
||||
/.idea
|
||||
cover.jpg
|
||||
cover.png
|
||||
/.vscode
|
||||
/.vs/
|
||||
Tranga/Properties/launchSettings.json
|
||||
/Manga
|
||||
/settings
|
||||
*.DotSettings.user
|
36
API/API.csproj
Normal file
36
API/API.csproj
Normal file
@ -0,0 +1,36 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<NoWarn>$(NoWarn);1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.12.0" />
|
||||
<PackageReference Include="JikanDotNet" Version="2.9.1" />
|
||||
<PackageReference Include="log4net" Version="3.0.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="9.0.3" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.3" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="9.0.5" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Npgsql" Version="9.0.3" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
|
||||
<PackageReference Include="PuppeteerSharp" Version="20.1.3" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.7" />
|
||||
<PackageReference Include="Soenneker.Utils.String.NeedlemanWunsch" Version="3.0.929" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="8.1.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="9.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
6
API/API.http
Normal file
6
API/API.http
Normal file
@ -0,0 +1,6 @@
|
||||
@API_HostAddress = http://localhost:5105
|
||||
|
||||
GET {{API_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
@ -0,0 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace API.APIEndpointRecords;
|
||||
|
||||
public record DownloadAvailableChaptersJobRecord([Required]string language, [Required]ulong recurrenceTimeMs, [Required]string localLibraryId);
|
16
API/APIEndpointRecords/GotifyRecord.cs
Normal file
16
API/APIEndpointRecords/GotifyRecord.cs
Normal file
@ -0,0 +1,16 @@
|
||||
namespace API.APIEndpointRecords;
|
||||
|
||||
public record GotifyRecord(string Name, string Endpoint, string AppToken, int Priority)
|
||||
{
|
||||
public bool Validate()
|
||||
{
|
||||
if (Endpoint == string.Empty)
|
||||
return false;
|
||||
if (AppToken == string.Empty)
|
||||
return false;
|
||||
if (Priority < 0 || Priority > 10)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
3
API/APIEndpointRecords/ModifyWorkerRecord.cs
Normal file
3
API/APIEndpointRecords/ModifyWorkerRecord.cs
Normal file
@ -0,0 +1,3 @@
|
||||
namespace API.APIEndpointRecords;
|
||||
|
||||
public record ModifyWorkerRecord(ulong? IntervalMs);
|
17
API/APIEndpointRecords/NtfyRecord.cs
Normal file
17
API/APIEndpointRecords/NtfyRecord.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace API.APIEndpointRecords;
|
||||
|
||||
public record NtfyRecord(string Name, string Endpoint, string Username, string Password, string Topic, int Priority)
|
||||
{
|
||||
public bool Validate()
|
||||
{
|
||||
if (Endpoint == string.Empty)
|
||||
return false;
|
||||
if (Username == string.Empty)
|
||||
return false;
|
||||
if (Password == string.Empty)
|
||||
return false;
|
||||
if (Priority < 1 || Priority > 5)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
13
API/APIEndpointRecords/PushoverRecord.cs
Normal file
13
API/APIEndpointRecords/PushoverRecord.cs
Normal file
@ -0,0 +1,13 @@
|
||||
namespace API.APIEndpointRecords;
|
||||
|
||||
public record PushoverRecord(string Name, string AppToken, string User)
|
||||
{
|
||||
public bool Validate()
|
||||
{
|
||||
if (AppToken == string.Empty)
|
||||
return false;
|
||||
if (User == string.Empty)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
141
API/Controllers/FileLibraryController.cs
Normal file
141
API/Controllers/FileLibraryController.cs
Normal file
@ -0,0 +1,141 @@
|
||||
using API.Schema.MangaContext;
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
[ApiVersion(2)]
|
||||
[ApiController]
|
||||
[Route("v{v:apiVersion}/[controller]")]
|
||||
public class FileLibraryController(IServiceScope scope) : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns all <see cref="FileLibrary"/>
|
||||
/// </summary>
|
||||
/// <response code="200"></response>
|
||||
[HttpGet]
|
||||
[ProducesResponseType<FileLibrary[]>(Status200OK, "application/json")]
|
||||
public IActionResult GetFileLibraries()
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
|
||||
return Ok(context.FileLibraries.ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns <see cref="FileLibrary"/> with <paramref name="FileLibraryId"/>
|
||||
/// </summary>
|
||||
/// <param name="FileLibraryId"><see cref="FileLibrary"/>.Key</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="404"><see cref="FileLibrary"/> with <paramref name="FileLibraryId"/> not found.</response>
|
||||
[HttpGet("{FileLibraryId}")]
|
||||
[ProducesResponseType<FileLibrary>(Status200OK, "application/json")]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
public IActionResult GetFileLibrary(string FileLibraryId)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if (context.FileLibraries.Find(FileLibraryId) is not { } library)
|
||||
return NotFound();
|
||||
|
||||
return Ok(library);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the <see cref="FileLibraryId"/>.BasePath with <paramref name="FileLibraryId"/>
|
||||
/// </summary>
|
||||
/// <param name="FileLibraryId"><see cref="FileLibrary"/>.Key</param>
|
||||
/// <param name="newBasePath">New <see cref="FileLibraryId"/>.BasePath</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="404"><see cref="FileLibrary"/> with <paramref name="FileLibraryId"/> not found.</response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpPatch("{FileLibraryId}/ChangeBasePath")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult ChangeLibraryBasePath(string FileLibraryId, [FromBody]string newBasePath)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if (context.FileLibraries.Find(FileLibraryId) is not { } library)
|
||||
return NotFound();
|
||||
|
||||
//TODO Path check
|
||||
library.BasePath = newBasePath;
|
||||
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the <see cref="FileLibraryId"/>.LibraryName with <paramref name="FileLibraryId"/>
|
||||
/// </summary>
|
||||
/// <param name="FileLibraryId"><see cref="FileLibrary"/>.Key</param>
|
||||
/// <param name="newName">New <see cref="FileLibraryId"/>.LibraryName</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="404"><see cref="FileLibrary"/> with <paramref name="FileLibraryId"/> not found.</response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpPatch("{FileLibraryId}/ChangeName")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType(Status400BadRequest)]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult ChangeLibraryName(string FileLibraryId, [FromBody] string newName)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if (context.FileLibraries.Find(FileLibraryId) is not { } library)
|
||||
return NotFound();
|
||||
|
||||
//TODO Name check
|
||||
library.LibraryName = newName;
|
||||
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates new <see cref="FileLibraryId"/>
|
||||
/// </summary>
|
||||
/// <param name="library">New <see cref="FileLibrary"/> to add</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpPut]
|
||||
[ProducesResponseType(Status201Created)]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult CreateNewLibrary([FromBody]FileLibrary library)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
|
||||
//TODO Parameter check
|
||||
context.FileLibraries.Add(library);
|
||||
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Created();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the <see cref="FileLibraryId"/>.LibraryName with <paramref name="FileLibraryId"/>
|
||||
/// </summary>
|
||||
/// <param name="FileLibraryId"><see cref="FileLibrary"/>.Key</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpDelete("{FileLibraryId}")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult DeleteLocalLibrary(string FileLibraryId)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if (context.FileLibraries.Find(FileLibraryId) is not { } library)
|
||||
return NotFound();
|
||||
|
||||
context.FileLibraries.Remove(library);
|
||||
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Ok();
|
||||
}
|
||||
}
|
91
API/Controllers/LibraryConnectorController.cs
Normal file
91
API/Controllers/LibraryConnectorController.cs
Normal file
@ -0,0 +1,91 @@
|
||||
using API.Schema.LibraryContext;
|
||||
using API.Schema.LibraryContext.LibraryConnectors;
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
[ApiVersion(2)]
|
||||
[ApiController]
|
||||
[Route("v{v:apiVersion}/[controller]")]
|
||||
public class LibraryConnectorController(IServiceScope scope) : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets all configured <see cref="LibraryConnector"/>
|
||||
/// </summary>
|
||||
/// <response code="200"></response>
|
||||
[HttpGet]
|
||||
[ProducesResponseType<LibraryConnector[]>(Status200OK, "application/json")]
|
||||
public IActionResult GetAllConnectors()
|
||||
{
|
||||
LibraryContext context = scope.ServiceProvider.GetRequiredService<LibraryContext>();
|
||||
|
||||
LibraryConnector[] connectors = context.LibraryConnectors.ToArray();
|
||||
|
||||
return Ok(connectors);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns <see cref="LibraryConnector"/> with <paramref name="LibraryConnectorId"/>
|
||||
/// </summary>
|
||||
/// <param name="LibraryConnectorId"><see cref="LibraryConnector"/>.Key</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="404"><see cref="LibraryConnector"/> with <paramref name="LibraryConnectorId"/> not found.</response>
|
||||
[HttpGet("{LibraryConnectorId}")]
|
||||
[ProducesResponseType<LibraryConnector>(Status200OK, "application/json")]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
public IActionResult GetConnector(string LibraryConnectorId)
|
||||
{
|
||||
LibraryContext context = scope.ServiceProvider.GetRequiredService<LibraryContext>();
|
||||
if (context.LibraryConnectors.Find(LibraryConnectorId) is not { } connector)
|
||||
return NotFound();
|
||||
|
||||
return Ok(connector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="LibraryConnector"/>
|
||||
/// </summary>
|
||||
/// <param name="libraryConnector"></param>
|
||||
/// <response code="201"></response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpPut]
|
||||
[ProducesResponseType(Status201Created)]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult CreateConnector([FromBody]LibraryConnector libraryConnector)
|
||||
{
|
||||
LibraryContext context = scope.ServiceProvider.GetRequiredService<LibraryContext>();
|
||||
|
||||
context.LibraryConnectors.Add(libraryConnector);
|
||||
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Created();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes <see cref="LibraryConnector"/> with <paramref name="LibraryConnectorId"/>
|
||||
/// </summary>
|
||||
/// <param name="LibraryConnectorId">ToFileLibrary-Connector-ID</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="404"><see cref="LibraryConnector"/> with <<paramref name="LibraryConnectorId"/> not found.</response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpDelete("{LibraryConnectorId}")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult DeleteConnector(string LibraryConnectorId)
|
||||
{
|
||||
LibraryContext context = scope.ServiceProvider.GetRequiredService<LibraryContext>();
|
||||
if (context.LibraryConnectors.Find(LibraryConnectorId) is not { } connector)
|
||||
return NotFound();
|
||||
|
||||
context.LibraryConnectors.Remove(connector);
|
||||
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Ok();
|
||||
}
|
||||
}
|
95
API/Controllers/MangaConnectorController.cs
Normal file
95
API/Controllers/MangaConnectorController.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using API.Schema.MangaContext;
|
||||
using API.Schema.MangaContext.MangaConnectors;
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
[ApiVersion(2)]
|
||||
[ApiController]
|
||||
[Route("v{v:apiVersion}/[controller]")]
|
||||
public class MangaConnectorController(IServiceScope scope) : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Get all <see cref="MangaConnector"/> (Scanlation-Sites)
|
||||
/// </summary>
|
||||
/// <response code="200">Names of <see cref="MangaConnector"/> (Scanlation-Sites)</response>
|
||||
[HttpGet]
|
||||
[ProducesResponseType<MangaConnector[]>(Status200OK, "application/json")]
|
||||
public IActionResult GetConnectors()
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
return Ok(context.MangaConnectors.Select(c => c.Name).ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="MangaConnector"/> (Scanlation-Sites) with the requested Name
|
||||
/// </summary>
|
||||
/// <param name="MangaConnectorName"><see cref="MangaConnector"/>.Name</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="404"><see cref="MangaConnector"/> (Scanlation-Sites) with Name not found.</response>
|
||||
[HttpGet("{MangaConnectorName}")]
|
||||
[ProducesResponseType<MangaConnector>(Status200OK, "application/json")]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
public IActionResult GetConnector(string MangaConnectorName)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if(context.MangaConnectors.Find(MangaConnectorName) is not { } connector)
|
||||
return NotFound();
|
||||
|
||||
return Ok(connector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all enabled <see cref="MangaConnector"/> (Scanlation-Sites)
|
||||
/// </summary>
|
||||
/// <response code="200"></response>
|
||||
[HttpGet("Enabled")]
|
||||
[ProducesResponseType<MangaConnector[]>(Status200OK, "application/json")]
|
||||
public IActionResult GetEnabledConnectors()
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
|
||||
return Ok(context.MangaConnectors.Where(c => c.Enabled).ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all disabled <see cref="MangaConnector"/> (Scanlation-Sites)
|
||||
/// </summary>
|
||||
/// <response code="200"></response>
|
||||
[HttpGet("Disabled")]
|
||||
[ProducesResponseType<MangaConnector[]>(Status200OK, "application/json")]
|
||||
public IActionResult GetDisabledConnectors()
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
|
||||
return Ok(context.MangaConnectors.Where(c => c.Enabled == false).ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enabled or disables <see cref="MangaConnector"/> (Scanlation-Sites) with Name
|
||||
/// </summary>
|
||||
/// <param name="MangaConnectorName"><see cref="MangaConnector"/>.Name</param>
|
||||
/// <param name="Enabled">Set true to enable, false to disable</param>
|
||||
/// <response code="202"></response>
|
||||
/// <response code="404"><see cref="MangaConnector"/> (Scanlation-Sites) with Name not found.</response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpPatch("{MangaConnectorName}/SetEnabled/{Enabled}")]
|
||||
[ProducesResponseType(Status202Accepted)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult SetEnabled(string MangaConnectorName, bool Enabled)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if(context.MangaConnectors.Find(MangaConnectorName) is not { } connector)
|
||||
return NotFound();
|
||||
|
||||
connector.Enabled = Enabled;
|
||||
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Accepted();
|
||||
}
|
||||
}
|
363
API/Controllers/MangaController.cs
Normal file
363
API/Controllers/MangaController.cs
Normal file
@ -0,0 +1,363 @@
|
||||
using API.Schema.MangaContext;
|
||||
using API.Schema.MangaContext.MangaConnectors;
|
||||
using API.Workers;
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Formats.Jpeg;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using SixLabors.ImageSharp.Processing.Processors.Transforms;
|
||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
[ApiVersion(2)]
|
||||
[ApiController]
|
||||
[Route("v{v:apiVersion}/[controller]")]
|
||||
public class MangaController(IServiceScope scope) : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns all cached <see cref="Manga"/>
|
||||
/// </summary>
|
||||
/// <response code="200"></response>
|
||||
[HttpGet]
|
||||
[ProducesResponseType<Manga[]>(Status200OK, "application/json")]
|
||||
public IActionResult GetAllManga()
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
Manga[] ret = context.Mangas.ToArray();
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all cached <see cref="Manga"/> with <paramref name="MangaIds"/>
|
||||
/// </summary>
|
||||
/// <param name="MangaIds">Array of <<see cref="Manga"/>.Key</param>
|
||||
/// <response code="200"></response>
|
||||
[HttpPost("WithIDs")]
|
||||
[ProducesResponseType<Manga[]>(Status200OK, "application/json")]
|
||||
public IActionResult GetManga([FromBody]string[] MangaIds)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
Manga[] ret = context.Mangas.Where(m => MangaIds.Contains(m.Key)).ToArray();
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return <see cref="Manga"/> with <paramref name="MangaId"/>
|
||||
/// </summary>
|
||||
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found</response>
|
||||
[HttpGet("{MangaId}")]
|
||||
[ProducesResponseType<Manga>(Status200OK, "application/json")]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
public IActionResult GetManga(string MangaId)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if (context.Mangas.Find(MangaId) is not { } manga)
|
||||
return NotFound(nameof(MangaId));
|
||||
return Ok(manga);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete <see cref="Manga"/> with <paramref name="MangaId"/>
|
||||
/// </summary>
|
||||
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="404"><<see cref="Manga"/> with <paramref name="MangaId"/> not found</response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpDelete("{MangaId}")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult DeleteManga(string MangaId)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if (context.Mangas.Find(MangaId) is not { } manga)
|
||||
return NotFound(nameof(MangaId));
|
||||
|
||||
context.Mangas.Remove(manga);
|
||||
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Merge two <see cref="Manga"/> into one. THIS IS NOT REVERSIBLE!
|
||||
/// </summary>
|
||||
/// <param name="MangaIdFrom"><see cref="Manga"/>.Key of <see cref="Manga"/> merging data from (getting deleted)</param>
|
||||
/// <param name="MangaIdInto"><see cref="Manga"/>.Key of <see cref="Manga"/> merging data into</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaIdFrom"/> or <paramref name="MangaIdInto"/> not found</response>
|
||||
[HttpPatch("{MangaIdFrom}/MergeInto/{MangaIdInto}")]
|
||||
[ProducesResponseType<byte[]>(Status200OK,"image/jpeg")]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
public IActionResult MergeIntoManga(string MangaIdFrom, string MangaIdInto)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if (context.Mangas.Find(MangaIdFrom) is not { } from)
|
||||
return NotFound(nameof(MangaIdFrom));
|
||||
if (context.Mangas.Find(MangaIdInto) is not { } into)
|
||||
return NotFound(nameof(MangaIdInto));
|
||||
|
||||
BaseWorker[] newJobs = into.MergeFrom(from, context);
|
||||
Tranga.AddWorkers(newJobs);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns Cover of <see cref="Manga"/> with <paramref name="MangaId"/>
|
||||
/// </summary>
|
||||
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||
/// <param name="width">If <paramref name="width"/> is provided, <paramref name="height"/> needs to also be provided</param>
|
||||
/// <param name="height">If <paramref name="height"/> is provided, <paramref name="width"/> needs to also be provided</param>
|
||||
/// <response code="200">JPEG Image</response>
|
||||
/// <response code="204">Cover not loaded</response>
|
||||
/// <response code="400">The formatting-request was invalid</response>
|
||||
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found</response>
|
||||
/// <response code="503">Retry later, downloading cover</response>
|
||||
[HttpGet("{MangaId}/Cover")]
|
||||
[ProducesResponseType<byte[]>(Status200OK,"image/jpeg")]
|
||||
[ProducesResponseType(Status204NoContent)]
|
||||
[ProducesResponseType(Status400BadRequest)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType<int>(Status503ServiceUnavailable, "text/plain")]
|
||||
public IActionResult GetCover(string MangaId, [FromQuery]int? width, [FromQuery]int? height)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if (context.Mangas.Find(MangaId) is not { } manga)
|
||||
return NotFound(nameof(MangaId));
|
||||
|
||||
if (!System.IO.File.Exists(manga.CoverFileNameInCache))
|
||||
{
|
||||
if (Tranga.GetRunningWorkers().Any(worker => worker is DownloadCoverFromMangaconnectorWorker w && w.MangaConnectorId.ObjId == MangaId))
|
||||
{
|
||||
Response.Headers.Append("Retry-After", $"{TrangaSettings.workCycleTimeout * 2 / 1000:D}");
|
||||
return StatusCode(Status503ServiceUnavailable, TrangaSettings.workCycleTimeout * 2 / 1000);
|
||||
}
|
||||
else
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
Image image = Image.Load(manga.CoverFileNameInCache);
|
||||
|
||||
if (width is { } w && height is { } h)
|
||||
{
|
||||
if (width < 10 || height < 10 || width > 65535 || height > 65535)
|
||||
return BadRequest();
|
||||
image.Mutate(i => i.ApplyProcessor(new ResizeProcessor(new ResizeOptions()
|
||||
{
|
||||
Mode = ResizeMode.Max,
|
||||
Size = new Size(w, h)
|
||||
}, image.Size)));
|
||||
}
|
||||
|
||||
using MemoryStream ms = new();
|
||||
image.Save(ms, new JpegEncoder(){Quality = 100});
|
||||
DateTime lastModified = new FileInfo(manga.CoverFileNameInCache).LastWriteTime;
|
||||
HttpContext.Response.Headers.CacheControl = "public";
|
||||
return File(ms.GetBuffer(), "image/jpeg", new DateTimeOffset(lastModified), EntityTagHeaderValue.Parse($"\"{lastModified.Ticks}\""));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all <see cref="Chapter"/> of <see cref="Manga"/> with <paramref name="MangaId"/>
|
||||
/// </summary>
|
||||
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found</response>
|
||||
[HttpGet("{MangaId}/Chapters")]
|
||||
[ProducesResponseType<Chapter[]>(Status200OK, "application/json")]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
public IActionResult GetChapters(string MangaId)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if (context.Mangas.Find(MangaId) is not { } manga)
|
||||
return NotFound(nameof(MangaId));
|
||||
|
||||
Chapter[] chapters = manga.Chapters.ToArray();
|
||||
return Ok(chapters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all downloaded <see cref="Chapter"/> for <see cref="Manga"/> with <paramref name="MangaId"/>
|
||||
/// </summary>
|
||||
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="204">No available chapters</response>
|
||||
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found.</response>
|
||||
[HttpGet("{MangaId}/Chapters/Downloaded")]
|
||||
[ProducesResponseType<Chapter[]>(Status200OK, "application/json")]
|
||||
[ProducesResponseType(Status204NoContent)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
public IActionResult GetChaptersDownloaded(string MangaId)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if (context.Mangas.Find(MangaId) is not { } manga)
|
||||
return NotFound(nameof(MangaId));
|
||||
|
||||
List<Chapter> chapters = manga.Chapters.Where(c => c.Downloaded).ToList();
|
||||
if (chapters.Count == 0)
|
||||
return NoContent();
|
||||
|
||||
return Ok(chapters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all <see cref="Chapter"/> not downloaded for <see cref="Manga"/> with <paramref name="MangaId"/>
|
||||
/// </summary>
|
||||
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="204">No available chapters</response>
|
||||
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found.</response>
|
||||
[HttpGet("{MangaId}/Chapters/NotDownloaded")]
|
||||
[ProducesResponseType<Chapter[]>(Status200OK, "application/json")]
|
||||
[ProducesResponseType(Status204NoContent)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
public IActionResult GetChaptersNotDownloaded(string MangaId)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if (context.Mangas.Find(MangaId) is not { } manga)
|
||||
return NotFound(nameof(MangaId));
|
||||
|
||||
List<Chapter> chapters = manga.Chapters.Where(c => c.Downloaded == false).ToList();
|
||||
if (chapters.Count == 0)
|
||||
return NoContent();
|
||||
|
||||
return Ok(chapters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the latest <see cref="Chapter"/> of requested <see cref="Manga"/> available on <see cref="MangaConnector"/>
|
||||
/// </summary>
|
||||
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="204">No available chapters</response>
|
||||
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found.</response>
|
||||
/// <response code="412">Could not retrieve the maximum chapter-number</response>
|
||||
/// <response code="503">Retry after timeout, updating value</response>
|
||||
[HttpGet("{MangaId}/Chapter/LatestAvailable")]
|
||||
[ProducesResponseType<Chapter>(Status200OK, "application/json")]
|
||||
[ProducesResponseType(Status204NoContent)]
|
||||
[ProducesResponseType<string>(Status404NotFound, "text/plain")]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
[ProducesResponseType<int>(Status503ServiceUnavailable, "text/plain")]
|
||||
public IActionResult GetLatestChapter(string MangaId)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if (context.Mangas.Find(MangaId) is not { } manga)
|
||||
return NotFound(nameof(MangaId));
|
||||
|
||||
List<Chapter> chapters = manga.Chapters.ToList();
|
||||
if (chapters.Count == 0)
|
||||
{
|
||||
if (Tranga.GetRunningWorkers().Any(worker => worker is RetrieveMangaChaptersFromMangaconnectorWorker w && w.MangaConnectorId.ObjId == MangaId && w.State < WorkerExecutionState.Completed))
|
||||
{
|
||||
Response.Headers.Append("Retry-After", $"{TrangaSettings.workCycleTimeout * 2 / 1000:D}");
|
||||
return StatusCode(Status503ServiceUnavailable, TrangaSettings.workCycleTimeout * 2/ 1000);
|
||||
}else
|
||||
return Ok(0);
|
||||
}
|
||||
|
||||
Chapter? max = chapters.Max();
|
||||
if (max is null)
|
||||
return StatusCode(Status500InternalServerError, "Max chapter could not be found");
|
||||
|
||||
return Ok(max);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the latest <see cref="Chapter"/> of requested <see cref="Manga"/> that is downloaded
|
||||
/// </summary>
|
||||
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="204">No available chapters</response>
|
||||
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found.</response>
|
||||
/// <response code="412">Could not retrieve the maximum chapter-number</response>
|
||||
/// <response code="503">Retry after timeout, updating value</response>
|
||||
[HttpGet("{MangaId}/Chapter/LatestDownloaded")]
|
||||
[ProducesResponseType<Chapter>(Status200OK, "application/json")]
|
||||
[ProducesResponseType(Status204NoContent)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType<string>(Status412PreconditionFailed, "text/plain")]
|
||||
[ProducesResponseType<int>(Status503ServiceUnavailable, "text/plain")]
|
||||
public IActionResult GetLatestChapterDownloaded(string MangaId)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if (context.Mangas.Find(MangaId) is not { } manga)
|
||||
return NotFound(nameof(MangaId));
|
||||
|
||||
List<Chapter> chapters = manga.Chapters.ToList();
|
||||
if (chapters.Count == 0)
|
||||
{
|
||||
if (Tranga.GetRunningWorkers().Any(worker => worker is RetrieveMangaChaptersFromMangaconnectorWorker w && w.MangaConnectorId.ObjId == MangaId && w.State < WorkerExecutionState.Completed))
|
||||
{
|
||||
Response.Headers.Append("Retry-After", $"{TrangaSettings.workCycleTimeout * 2 / 1000:D}");
|
||||
return StatusCode(Status503ServiceUnavailable, TrangaSettings.workCycleTimeout * 2/ 1000);
|
||||
}else
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
Chapter? max = chapters.Max();
|
||||
if (max is null)
|
||||
return StatusCode(Status412PreconditionFailed, "Max chapter could not be found");
|
||||
|
||||
return Ok(max);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configure the <see cref="Chapter"/> cut-off for <see cref="Manga"/>
|
||||
/// </summary>
|
||||
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||
/// <param name="chapterThreshold">Threshold (<see cref="Chapter"/> ChapterNumber)</param>
|
||||
/// <response code="202"></response>
|
||||
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found.</response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpPatch("{MangaId}/IgnoreChaptersBefore")]
|
||||
[ProducesResponseType(Status202Accepted)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult IgnoreChaptersBefore(string MangaId, [FromBody]float chapterThreshold)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if (context.Mangas.Find(MangaId) is not { } manga)
|
||||
return NotFound();
|
||||
|
||||
manga.IgnoreChaptersBefore = chapterThreshold;
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
|
||||
return Accepted();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move <see cref="Manga"/> to different <see cref="FileLibrary"/>
|
||||
/// </summary>
|
||||
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||
/// <param name="LibraryId"><see cref="FileLibrary"/>.Key</param>
|
||||
/// <response code="202">Folder is going to be moved</response>
|
||||
/// <response code="404"><paramref name="MangaId"/> or <paramref name="LibraryId"/> not found</response>
|
||||
[HttpPost("{MangaId}/ChangeLibrary/{LibraryId}")]
|
||||
[ProducesResponseType(Status202Accepted)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
public IActionResult MoveFolder(string MangaId, string LibraryId)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if (context.Mangas.Find(MangaId) is not { } manga)
|
||||
return NotFound(nameof(MangaId));
|
||||
if(context.FileLibraries.Find(LibraryId) is not { } library)
|
||||
return NotFound(nameof(LibraryId));
|
||||
|
||||
MoveMangaLibraryWorker moveLibrary = new(manga, library, scope);
|
||||
UpdateChaptersDownloadedWorker updateDownloadedFiles = new(manga, [moveLibrary]);
|
||||
|
||||
Tranga.AddWorkers([moveLibrary, updateDownloadedFiles]);
|
||||
|
||||
return Accepted();
|
||||
}
|
||||
}
|
126
API/Controllers/MetadataFetcherController.cs
Normal file
126
API/Controllers/MetadataFetcherController.cs
Normal file
@ -0,0 +1,126 @@
|
||||
using API.Schema.MangaContext;
|
||||
using API.Schema.MangaContext.MetadataFetchers;
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
[ApiVersion(2)]
|
||||
[ApiController]
|
||||
[Route("v{v:apiVersion}/[controller]")]
|
||||
public class MetadataFetcherController(IServiceScope scope) : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Get all <see cref="MetadataFetcher"/> (Metadata-Sites)
|
||||
/// </summary>
|
||||
/// <response code="200">Names of <see cref="MetadataFetcher"/> (Metadata-Sites)</response>
|
||||
[HttpGet]
|
||||
[ProducesResponseType<string[]>(Status200OK, "application/json")]
|
||||
public IActionResult GetConnectors()
|
||||
{
|
||||
return Ok(Tranga.MetadataFetchers.Select(m => m.Name).ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all <see cref="MetadataEntry"/>
|
||||
/// </summary>
|
||||
/// <response code="200"></response>
|
||||
[HttpGet("Links")]
|
||||
[ProducesResponseType<MetadataEntry[]>(Status200OK, "application/json")]
|
||||
public IActionResult GetLinkedEntries()
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
|
||||
return Ok(context.MetadataEntries.ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searches <see cref="MetadataFetcher"/> (Metadata-Sites) for Manga-Metadata
|
||||
/// </summary>
|
||||
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||
/// <param name="MetadataFetcherName"><see cref="MetadataFetcher"/>.Name</param>
|
||||
/// <param name="searchTerm">Instead of using the <paramref name="MangaId"/> for search on Website, use a specific term</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400"><see cref="MetadataFetcher"/> (Metadata-Sites) with <paramref name="MetadataFetcherName"/> does not exist</response>
|
||||
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found</response>
|
||||
[HttpPost("{MetadataFetcherName}/SearchManga/{MangaId}")]
|
||||
[ProducesResponseType<MetadataSearchResult[]>(Status200OK, "application/json")]
|
||||
[ProducesResponseType(Status400BadRequest)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
public IActionResult SearchMangaMetadata(string MangaId, string MetadataFetcherName, [FromBody(EmptyBodyBehavior = EmptyBodyBehavior.Allow)]string? searchTerm = null)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if(context.Mangas.Find(MangaId) is not { } manga)
|
||||
return NotFound();
|
||||
if(Tranga.MetadataFetchers.FirstOrDefault(f => f.Name == MetadataFetcherName) is not { } fetcher)
|
||||
return BadRequest();
|
||||
|
||||
MetadataSearchResult[] searchResults = searchTerm is null ? fetcher.SearchMetadataEntry(manga) : fetcher.SearchMetadataEntry(searchTerm);
|
||||
return Ok(searchResults);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Links <see cref="MetadataFetcher"/> (Metadata-Sites) using Provider-Specific Identifier to <see cref="Manga"/>
|
||||
/// </summary>
|
||||
/// <param name="MangaId"><see cref="Manga"/>.Key</param>
|
||||
/// <param name="MetadataFetcherName"><see cref="MetadataFetcher"/>.Name</param>
|
||||
/// <param name="Identifier"><see cref="MetadataFetcherName"/>-Specific ID</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400"><see cref="MetadataFetcher"/> (Metadata-Sites) with <paramref name="MetadataFetcherName"/> does not exist</response>
|
||||
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found</response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpPost("{MetadataFetcherName}/Link/{MangaId}")]
|
||||
[ProducesResponseType<MetadataEntry>(Status200OK, "application/json")]
|
||||
[ProducesResponseType(Status400BadRequest)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult LinkMangaMetadata(string MangaId, string MetadataFetcherName, [FromBody]string Identifier)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if(context.Mangas.Find(MangaId) is not { } manga)
|
||||
return NotFound();
|
||||
if(Tranga.MetadataFetchers.FirstOrDefault(f => f.Name == MetadataFetcherName) is not { } fetcher)
|
||||
return BadRequest();
|
||||
|
||||
MetadataEntry entry = fetcher.CreateMetadataEntry(manga, Identifier);
|
||||
context.MetadataEntries.Add(entry);
|
||||
|
||||
if(context.Sync().Result is { } errorMessage)
|
||||
return StatusCode(Status500InternalServerError, errorMessage);
|
||||
return Ok(entry);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Un-Links <see cref="MetadataFetcher"/> (Metadata-Sites) from <see cref="Manga"/>
|
||||
/// </summary>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400"><see cref="MetadataFetcher"/> (Metadata-Sites) with <paramref name="MetadataFetcherName"/> does not exist</response>
|
||||
/// <response code="404"><see cref="Manga"/> with <paramref name="MangaId"/> not found</response>
|
||||
/// <response code="412">No <see cref="MetadataEntry"/> linking <see cref="Manga"/> and <see cref="MetadataFetcher"/> found</response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpPost("{MetadataFetcherName}/Unlink/{MangaId}")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
[ProducesResponseType(Status400BadRequest)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType<string>(Status412PreconditionFailed, "text/plain")]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult UnlinkMangaMetadata(string MangaId, string MetadataFetcherName)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if(context.Mangas.Find(MangaId) is null)
|
||||
return NotFound();
|
||||
if(Tranga.MetadataFetchers.FirstOrDefault(f => f.Name == MetadataFetcherName) is null)
|
||||
return BadRequest();
|
||||
if(context.MetadataEntries.FirstOrDefault(e => e.MangaId == MangaId && e.MetadataFetcherName == MetadataFetcherName) is not { } entry)
|
||||
return StatusCode(Status412PreconditionFailed, "No entry found");
|
||||
|
||||
context.Remove(entry);
|
||||
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Ok();
|
||||
}
|
||||
}
|
163
API/Controllers/NotificationConnectorController.cs
Normal file
163
API/Controllers/NotificationConnectorController.cs
Normal file
@ -0,0 +1,163 @@
|
||||
using System.Text;
|
||||
using API.APIEndpointRecords;
|
||||
using API.Schema.NotificationsContext;
|
||||
using API.Schema.NotificationsContext.NotificationConnectors;
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
[ApiVersion(2)]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Route("v{v:apiVersion}/[controller]")]
|
||||
public class NotificationConnectorController(IServiceScope scope) : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets all configured <see cref="NotificationConnector"/>
|
||||
/// </summary>
|
||||
/// <response code="200"></response>
|
||||
[HttpGet]
|
||||
[ProducesResponseType<NotificationConnector[]>(Status200OK, "application/json")]
|
||||
public IActionResult GetAllConnectors()
|
||||
{
|
||||
NotificationsContext context = scope.ServiceProvider.GetRequiredService<NotificationsContext>();
|
||||
|
||||
return Ok(context.NotificationConnectors.ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns <see cref="NotificationConnector"/> with requested Name
|
||||
/// </summary>
|
||||
/// <param name="Name"><see cref="NotificationConnector"/>.Name</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="404"><see cref="NotificationConnector"/> with <paramref name="Name"/> not found</response>
|
||||
[HttpGet("{Name}")]
|
||||
[ProducesResponseType<NotificationConnector>(Status200OK, "application/json")]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
public IActionResult GetConnector(string Name)
|
||||
{
|
||||
NotificationsContext context = scope.ServiceProvider.GetRequiredService<NotificationsContext>();
|
||||
if(context.NotificationConnectors.Find(Name) is not { } connector)
|
||||
return NotFound();
|
||||
|
||||
return Ok(connector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="NotificationConnector"/>
|
||||
/// </summary>
|
||||
/// <remarks>Formatting placeholders: "%title" and "%text" can be placed in url, header-values and body and will be replaced when notifications are sent</remarks>
|
||||
/// <response code="201"></response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpPut]
|
||||
[ProducesResponseType(Status201Created)]
|
||||
[ProducesResponseType(Status409Conflict)]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult CreateConnector([FromBody]NotificationConnector notificationConnector)
|
||||
{
|
||||
NotificationsContext context = scope.ServiceProvider.GetRequiredService<NotificationsContext>();
|
||||
|
||||
context.NotificationConnectors.Add(notificationConnector);
|
||||
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Created();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Gotify-<see cref="NotificationConnector"/>
|
||||
/// </summary>
|
||||
/// <remarks>Priority needs to be between 0 and 10</remarks>
|
||||
/// <response code="201"></response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpPut("Gotify")]
|
||||
[ProducesResponseType<string>(Status201Created, "application/json")]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult CreateGotifyConnector([FromBody]GotifyRecord gotifyData)
|
||||
{
|
||||
//TODO Validate Data
|
||||
|
||||
NotificationConnector gotifyConnector = new (gotifyData.Name,
|
||||
gotifyData.Endpoint,
|
||||
new Dictionary<string, string>() { { "X-Gotify-IDOnConnector", gotifyData.AppToken } },
|
||||
"POST",
|
||||
$"{{\"message\": \"%text\", \"title\": \"%title\", \"Priority\": {gotifyData.Priority}}}");
|
||||
return CreateConnector(gotifyConnector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Ntfy-<see cref="NotificationConnector"/>
|
||||
/// </summary>
|
||||
/// <remarks>Priority needs to be between 1 and 5</remarks>
|
||||
/// <response code="201"></response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpPut("Ntfy")]
|
||||
[ProducesResponseType<string>(Status201Created, "application/json")]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult CreateNtfyConnector([FromBody]NtfyRecord ntfyRecord)
|
||||
{
|
||||
//TODO Validate Data
|
||||
|
||||
string authHeader = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes($"{ntfyRecord.Username}:{ntfyRecord.Password}"));
|
||||
string auth = Convert.ToBase64String(Encoding.UTF8.GetBytes(authHeader)).Replace("=","");
|
||||
|
||||
NotificationConnector ntfyConnector = new (ntfyRecord.Name,
|
||||
$"{ntfyRecord.Endpoint}/{ntfyRecord.Topic}?auth={auth}",
|
||||
new Dictionary<string, string>()
|
||||
{
|
||||
{"Title", "%title"},
|
||||
{"Priority", ntfyRecord.Priority.ToString()},
|
||||
},
|
||||
"POST",
|
||||
"%text");
|
||||
return CreateConnector(ntfyConnector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Pushover-<see cref="NotificationConnector"/>
|
||||
/// </summary>
|
||||
/// <remarks>https://pushover.net/api</remarks>
|
||||
/// <response code="201">ID of new connector</response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpPut("Pushover")]
|
||||
[ProducesResponseType<string>(Status201Created, "application/json")]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult CreatePushoverConnector([FromBody]PushoverRecord pushoverRecord)
|
||||
{
|
||||
//TODO Validate Data
|
||||
|
||||
NotificationConnector pushoverConnector = new (pushoverRecord.Name,
|
||||
$"https://api.pushover.net/1/messages.json",
|
||||
new Dictionary<string, string>(),
|
||||
"POST",
|
||||
$"{{\"token\": \"{pushoverRecord.AppToken}\", \"user\": \"{pushoverRecord.User}\", \"message:\":\"%text\", \"%title\" }}");
|
||||
return CreateConnector(pushoverConnector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the <see cref="NotificationConnector"/> with the requested Name
|
||||
/// </summary>
|
||||
/// <param name="Name"><see cref="NotificationConnector"/>.Name</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="404"><see cref="NotificationConnector"/> with Name not found</response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpDelete("{Name}")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult DeleteConnector(string Name)
|
||||
{
|
||||
NotificationsContext context = scope.ServiceProvider.GetRequiredService<NotificationsContext>();
|
||||
if(context.NotificationConnectors.Find(Name) is not { } connector)
|
||||
return NotFound();
|
||||
|
||||
context.NotificationConnectors.Remove(connector);
|
||||
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Created();
|
||||
}
|
||||
}
|
82
API/Controllers/QueryController.cs
Normal file
82
API/Controllers/QueryController.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using API.Schema.MangaContext;
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
[ApiVersion(2)]
|
||||
[ApiController]
|
||||
[Route("v{v:apiVersion}/[controller]")]
|
||||
public class QueryController(IServiceScope scope) : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Author"/> with <paramref name="AuthorId"/>
|
||||
/// </summary>
|
||||
/// <param name="AuthorId"><see cref="Author"/>.Key</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="404"><see cref="Author"/> with <paramref name="AuthorId"/> not found</response>
|
||||
[HttpGet("Author/{AuthorId}")]
|
||||
[ProducesResponseType<Author>(Status200OK, "application/json")]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
public IActionResult GetAuthor(string AuthorId)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if (context.Authors.Find(AuthorId) is not { } author)
|
||||
return NotFound();
|
||||
|
||||
return Ok(author);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all <see cref="Manga"/> which where Authored by <see cref="Author"/> with <paramref name="AuthorId"/>
|
||||
/// </summary>
|
||||
/// <param name="AuthorId"><see cref="Author"/>.Key</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="404"><see cref="Author"/> with <paramref name="AuthorId"/></response>
|
||||
[HttpGet("Mangas/WithAuthorId/{AuthorId}")]
|
||||
[ProducesResponseType<Manga[]>(Status200OK, "application/json")]
|
||||
public IActionResult GetMangaWithAuthorIds(string AuthorId)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if (context.Authors.Find(AuthorId) is not { } author)
|
||||
return NotFound();
|
||||
|
||||
return Ok(context.Mangas.Where(m => m.Authors.Contains(author)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all <see cref="Manga"/> with <see cref="Tag"/>
|
||||
/// </summary>
|
||||
/// <param name="Tag"><see cref="Tag"/>.Tag</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="404"><see cref="Tag"/> not found</response>
|
||||
[HttpGet("Mangas/WithTag/{Tag}")]
|
||||
[ProducesResponseType<Manga[]>(Status200OK, "application/json")]
|
||||
public IActionResult GetMangasWithTag(string Tag)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if (context.Tags.Find(Tag) is not { } tag)
|
||||
return NotFound();
|
||||
|
||||
return Ok(context.Mangas.Where(m => m.MangaTags.Contains(tag)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns <see cref="Chapter"/> with <paramref name="ChapterId"/>
|
||||
/// </summary>
|
||||
/// <param name="ChapterId"><see cref="Chapter"/>.Key</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="404"><see cref="Chapter"/> with <paramref name="ChapterId"/> not found</response>
|
||||
[HttpGet("Chapter/{ChapterId}")]
|
||||
[ProducesResponseType<Chapter>(Status200OK, "application/json")]
|
||||
public IActionResult GetChapter(string ChapterId)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if (context.Chapters.Find(ChapterId) is not { } chapter)
|
||||
return NotFound();
|
||||
|
||||
return Ok(chapter);
|
||||
}
|
||||
}
|
103
API/Controllers/SearchController.cs
Normal file
103
API/Controllers/SearchController.cs
Normal file
@ -0,0 +1,103 @@
|
||||
using API.Schema.MangaContext;
|
||||
using API.Schema.MangaContext.MangaConnectors;
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
[ApiVersion(2)]
|
||||
[ApiController]
|
||||
[Route("v{v:apiVersion}/[controller]")]
|
||||
public class SearchController(IServiceScope scope) : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Initiate a search for a <see cref="Manga"/> on <see cref="MangaConnector"/> with searchTerm
|
||||
/// </summary>
|
||||
/// <param name="MangaConnectorName"><see cref="MangaConnector"/>.Name</param>
|
||||
/// <param name="Query">searchTerm</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="404"><see cref="MangaConnector"/> with Name not found</response>
|
||||
/// <response code="412"><see cref="MangaConnector"/> with Name is disabled</response>
|
||||
[HttpGet("{MangaConnectorName}/{Query}")]
|
||||
[ProducesResponseType<Manga[]>(Status200OK, "application/json")]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType(Status406NotAcceptable)]
|
||||
public IActionResult SearchManga(string MangaConnectorName, string Query)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if(context.MangaConnectors.Find(MangaConnectorName) is not { } connector)
|
||||
return NotFound();
|
||||
if (connector.Enabled is false)
|
||||
return StatusCode(Status412PreconditionFailed);
|
||||
|
||||
(Manga, MangaConnectorId<Manga>)[] mangas = connector.SearchManga(Query);
|
||||
List<Manga> retMangas = new();
|
||||
foreach ((Manga manga, MangaConnectorId<Manga> mcId) manga in mangas)
|
||||
{
|
||||
if(AddMangaToContext(manga, context) is { } add)
|
||||
retMangas.Add(add);
|
||||
}
|
||||
|
||||
return Ok(retMangas.ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns <see cref="Manga"/> from the <see cref="MangaConnector"/> associated with <paramref name="url"/>
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="300">Multiple <see cref="MangaConnector"/> found for URL</response>
|
||||
/// <response code="404"><see cref="Manga"/> not found</response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpPost("Url")]
|
||||
[ProducesResponseType<Manga>(Status200OK, "application/json")]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType(Status500InternalServerError)]
|
||||
public IActionResult GetMangaFromUrl([FromBody]string url)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
if (context.MangaConnectors.Find("Global") is not { } connector)
|
||||
return StatusCode(Status500InternalServerError, "Could not find Global Connector.");
|
||||
|
||||
if(connector.GetMangaFromUrl(url) is not { } manga)
|
||||
return NotFound();
|
||||
|
||||
if(AddMangaToContext(manga, context) is not { } add)
|
||||
return StatusCode(Status500InternalServerError);
|
||||
|
||||
return Ok(add);
|
||||
}
|
||||
|
||||
private Manga? AddMangaToContext((Manga, MangaConnectorId<Manga>) manga, MangaContext context) => AddMangaToContext(manga.Item1, manga.Item2, context);
|
||||
|
||||
private static Manga? AddMangaToContext(Manga addManga, MangaConnectorId<Manga> addMcId, MangaContext context)
|
||||
{
|
||||
Manga manga = context.Mangas.Find(addManga.Key) ?? addManga;
|
||||
MangaConnectorId<Manga> mcId = context.MangaConnectorToManga.Find(addMcId.Key) ?? addMcId;
|
||||
mcId.Obj = manga;
|
||||
|
||||
IEnumerable<MangaTag> mergedTags = manga.MangaTags.Select(mt =>
|
||||
{
|
||||
MangaTag? inDb = context.Tags.Find(mt.Tag);
|
||||
return inDb ?? mt;
|
||||
});
|
||||
manga.MangaTags = mergedTags.ToList();
|
||||
|
||||
IEnumerable<Author> mergedAuthors = manga.Authors.Select(ma =>
|
||||
{
|
||||
Author? inDb = context.Authors.Find(ma.Key);
|
||||
return inDb ?? ma;
|
||||
});
|
||||
manga.Authors = mergedAuthors.ToList();
|
||||
|
||||
|
||||
if(context.MangaConnectorToManga.Find(addMcId.Key) is null)
|
||||
context.MangaConnectorToManga.Add(mcId);
|
||||
|
||||
if (context.Sync().Result is { success: false } )
|
||||
return null;
|
||||
return manga;
|
||||
}
|
||||
}
|
301
API/Controllers/SettingsController.cs
Normal file
301
API/Controllers/SettingsController.cs
Normal file
@ -0,0 +1,301 @@
|
||||
using API.MangaDownloadClients;
|
||||
using API.Schema.MangaContext;
|
||||
using API.Workers;
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
[ApiVersion(2)]
|
||||
[ApiController]
|
||||
[Route("v{v:apiVersion}/[controller]")]
|
||||
public class SettingsController(IServiceScope scope) : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Get all Settings
|
||||
/// </summary>
|
||||
/// <response code="200"></response>
|
||||
[HttpGet]
|
||||
[ProducesResponseType<JObject>(Status200OK, "application/json")]
|
||||
public IActionResult GetSettings()
|
||||
{
|
||||
return Ok(JObject.Parse(TrangaSettings.Serialize()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the current UserAgent used by Tranga
|
||||
/// </summary>
|
||||
/// <response code="200"></response>
|
||||
[HttpGet("UserAgent")]
|
||||
[ProducesResponseType<string>(Status200OK, "text/plain")]
|
||||
public IActionResult GetUserAgent()
|
||||
{
|
||||
return Ok(TrangaSettings.userAgent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a new UserAgent
|
||||
/// </summary>
|
||||
/// <response code="200"></response>
|
||||
[HttpPatch("UserAgent")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
public IActionResult SetUserAgent([FromBody]string userAgent)
|
||||
{
|
||||
TrangaSettings.UpdateUserAgent(userAgent);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset the UserAgent to default
|
||||
/// </summary>
|
||||
/// <response code="200"></response>
|
||||
[HttpDelete("UserAgent")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
public IActionResult ResetUserAgent()
|
||||
{
|
||||
TrangaSettings.UpdateUserAgent(TrangaSettings.DefaultUserAgent);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all Request-Limits
|
||||
/// </summary>
|
||||
/// <response code="200"></response>
|
||||
[HttpGet("RequestLimits")]
|
||||
[ProducesResponseType<Dictionary<RequestType,int>>(Status200OK, "application/json")]
|
||||
public IActionResult GetRequestLimits()
|
||||
{
|
||||
return Ok(TrangaSettings.requestLimits);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update all Request-Limits to new values
|
||||
/// </summary>
|
||||
/// <remarks><h1>NOT IMPLEMENTED</h1></remarks>
|
||||
[HttpPatch("RequestLimits")]
|
||||
[ProducesResponseType(Status501NotImplemented)]
|
||||
public IActionResult SetRequestLimits()
|
||||
{
|
||||
return StatusCode(501);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a Request-Limit value
|
||||
/// </summary>
|
||||
/// <param name="RequestType">Type of Request</param>
|
||||
/// <param name="requestLimit">New limit in Requests/Minute</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">Limit needs to be greater than 0</response>
|
||||
[HttpPatch("RequestLimits/{RequestType}")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
[ProducesResponseType(Status400BadRequest)]
|
||||
public IActionResult SetRequestLimit(RequestType RequestType, [FromBody]int requestLimit)
|
||||
{
|
||||
if (requestLimit <= 0)
|
||||
return BadRequest();
|
||||
TrangaSettings.UpdateRequestLimit(RequestType, requestLimit);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset Request-Limit
|
||||
/// </summary>
|
||||
/// <response code="200"></response>
|
||||
[HttpDelete("RequestLimits/{RequestType}")]
|
||||
[ProducesResponseType<string>(Status200OK)]
|
||||
public IActionResult ResetRequestLimits(RequestType RequestType)
|
||||
{
|
||||
TrangaSettings.UpdateRequestLimit(RequestType, TrangaSettings.DefaultRequestLimits[RequestType]);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset Request-Limit
|
||||
/// </summary>
|
||||
/// <response code="200"></response>
|
||||
[HttpDelete("RequestLimits")]
|
||||
[ProducesResponseType<string>(Status200OK)]
|
||||
public IActionResult ResetRequestLimits()
|
||||
{
|
||||
TrangaSettings.ResetRequestLimits();
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns Level of Image-Compression for Images
|
||||
/// </summary>
|
||||
/// <response code="200">JPEG compression-level as Integer</response>
|
||||
[HttpGet("ImageCompression")]
|
||||
[ProducesResponseType<int>(Status200OK, "text/plain")]
|
||||
public IActionResult GetImageCompression()
|
||||
{
|
||||
return Ok(TrangaSettings.compression);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the Image-Compression-Level for Images
|
||||
/// </summary>
|
||||
/// <param name="level">100 to disable, 0-99 for JPEG compression-Level</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">Level outside permitted range</response>
|
||||
[HttpPatch("ImageCompression")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
[ProducesResponseType(Status400BadRequest)]
|
||||
public IActionResult SetImageCompression([FromBody]int level)
|
||||
{
|
||||
if (level < 1 || level > 100)
|
||||
return BadRequest();
|
||||
TrangaSettings.UpdateCompressImages(level);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get state of Black/White-Image setting
|
||||
/// </summary>
|
||||
/// <response code="200">True if enabled</response>
|
||||
[HttpGet("BWImages")]
|
||||
[ProducesResponseType<bool>(Status200OK, "text/plain")]
|
||||
public IActionResult GetBwImagesToggle()
|
||||
{
|
||||
return Ok(TrangaSettings.bwImages);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enable/Disable conversion of Images to Black and White
|
||||
/// </summary>
|
||||
/// <param name="enabled">true to enable</param>
|
||||
/// <response code="200"></response>
|
||||
[HttpPatch("BWImages")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
public IActionResult SetBwImagesToggle([FromBody]bool enabled)
|
||||
{
|
||||
TrangaSettings.UpdateBwImages(enabled);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get state of April Fools Mode
|
||||
/// </summary>
|
||||
/// <remarks>April Fools Mode disables all downloads on April 1st</remarks>
|
||||
/// <response code="200">True if enabled</response>
|
||||
[HttpGet("AprilFoolsMode")]
|
||||
[ProducesResponseType<bool>(Status200OK, "text/plain")]
|
||||
public IActionResult GetAprilFoolsMode()
|
||||
{
|
||||
return Ok(TrangaSettings.aprilFoolsMode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enable/Disable April Fools Mode
|
||||
/// </summary>
|
||||
/// <remarks>April Fools Mode disables all downloads on April 1st</remarks>
|
||||
/// <param name="enabled">true to enable</param>
|
||||
/// <response code="200"></response>
|
||||
[HttpPatch("AprilFoolsMode")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
public IActionResult SetAprilFoolsMode([FromBody]bool enabled)
|
||||
{
|
||||
TrangaSettings.UpdateAprilFoolsMode(enabled);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Chapter Naming Scheme
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Placeholders:
|
||||
/// %M Obj Name
|
||||
/// %V Volume
|
||||
/// %C Chapter
|
||||
/// %T Title
|
||||
/// %A Author (first in list)
|
||||
/// %I Chapter Internal ID
|
||||
/// %i Obj Internal ID
|
||||
/// %Y Year (Obj)
|
||||
///
|
||||
/// ?_(...) replace _ with a value from above:
|
||||
/// Everything inside the braces will only be added if the value of %_ is not null
|
||||
/// </remarks>
|
||||
/// <response code="200"></response>
|
||||
[HttpGet("ChapterNamingScheme")]
|
||||
[ProducesResponseType<string>(Status200OK, "text/plain")]
|
||||
public IActionResult GetCustomNamingScheme()
|
||||
{
|
||||
return Ok(TrangaSettings.chapterNamingScheme);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the Chapter Naming Scheme
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Placeholders:
|
||||
/// %M Obj Name
|
||||
/// %V Volume
|
||||
/// %C Chapter
|
||||
/// %T Title
|
||||
/// %A Author (first in list)
|
||||
/// %Y Year (Obj)
|
||||
///
|
||||
/// ?_(...) replace _ with a value from above:
|
||||
/// Everything inside the braces will only be added if the value of %_ is not null
|
||||
/// </remarks>
|
||||
/// <response code="200"></response>
|
||||
[HttpPatch("ChapterNamingScheme")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
public IActionResult SetCustomNamingScheme([FromBody]string namingScheme)
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
|
||||
Dictionary<Chapter, string> oldPaths = context.Chapters.ToDictionary(c => c, c => c.FullArchiveFilePath);
|
||||
TrangaSettings.UpdateChapterNamingScheme(namingScheme);
|
||||
MoveFileOrFolderWorker[] newJobs = oldPaths
|
||||
.Select(kv => new MoveFileOrFolderWorker(kv.Value, kv.Key.FullArchiveFilePath)).ToArray();
|
||||
Tranga.AddWorkers(newJobs);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the FlareSolverr-URL
|
||||
/// </summary>
|
||||
/// <param name="flareSolverrUrl">URL of FlareSolverr-Instance</param>
|
||||
/// <response code="200"></response>
|
||||
[HttpPost("FlareSolverr/Url")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
public IActionResult SetFlareSolverrUrl([FromBody]string flareSolverrUrl)
|
||||
{
|
||||
TrangaSettings.UpdateFlareSolverrUrl(flareSolverrUrl);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the FlareSolverr-URL (HttpClient does not use FlareSolverr anymore)
|
||||
/// </summary>
|
||||
/// <response code="200"></response>
|
||||
[HttpDelete("FlareSolverr/Url")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
public IActionResult ClearFlareSolverrUrl()
|
||||
{
|
||||
TrangaSettings.UpdateFlareSolverrUrl(string.Empty);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test FlareSolverr
|
||||
/// </summary>
|
||||
/// <response code="200">FlareSolverr is working!</response>
|
||||
/// <response code="500">FlareSolverr is not working</response>
|
||||
[HttpPost("FlareSolverr/Test")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
[ProducesResponseType(Status500InternalServerError)]
|
||||
public IActionResult TestFlareSolverrReachable()
|
||||
{
|
||||
const string knownProtectedUrl = "https://prowlarr.servarr.com/v1/ping";
|
||||
FlareSolverrDownloadClient client = new();
|
||||
RequestResult result = client.MakeRequestInternal(knownProtectedUrl);
|
||||
return (int)result.statusCode >= 200 && (int)result.statusCode < 300 ? Ok() : StatusCode(500, result.statusCode);
|
||||
}
|
||||
}
|
154
API/Controllers/WorkerController.cs
Normal file
154
API/Controllers/WorkerController.cs
Normal file
@ -0,0 +1,154 @@
|
||||
using API.APIEndpointRecords;
|
||||
using API.Workers;
|
||||
using Asp.Versioning;
|
||||
using log4net;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
[ApiVersion(2)]
|
||||
[ApiController]
|
||||
[Route("v{version:apiVersion}/[controller]")]
|
||||
public class WorkerController(ILog Log) : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns all <see cref="BaseWorker"/>
|
||||
/// </summary>
|
||||
/// <response code="200"></response>
|
||||
[HttpGet]
|
||||
[ProducesResponseType<BaseWorker[]>(Status200OK, "application/json")]
|
||||
public IActionResult GetAllWorkers()
|
||||
{
|
||||
return Ok(Tranga.Workers.ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns <see cref="BaseWorker"/> with requested <paramref name="WorkerIds"/>
|
||||
/// </summary>
|
||||
/// <param name="WorkerIds">Array of <see cref="BaseWorker"/>.Key</param>
|
||||
/// <response code="200"></response>
|
||||
[HttpPost("WithIDs")]
|
||||
[ProducesResponseType<BaseWorker[]>(Status200OK, "application/json")]
|
||||
public IActionResult GetJobs([FromBody]string[] WorkerIds)
|
||||
{
|
||||
return Ok(Tranga.Workers.Where(worker => WorkerIds.Contains(worker.Key)).ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all <see cref="BaseWorker"/> in requested <see cref="WorkerExecutionState"/>
|
||||
/// </summary>
|
||||
/// <param name="State">Requested <see cref="WorkerExecutionState"/></param>
|
||||
/// <response code="200"></response>
|
||||
[HttpGet("State/{State}")]
|
||||
[ProducesResponseType<BaseWorker[]>(Status200OK, "application/json")]
|
||||
public IActionResult GetJobsInState(WorkerExecutionState State)
|
||||
{
|
||||
return Ok(Tranga.Workers.Where(worker => worker.State == State).ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return <see cref="BaseWorker"/> with <paramref name="WorkerId"/>
|
||||
/// </summary>
|
||||
/// <param name="WorkerId"><see cref="BaseWorker"/>.Key</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="404"><see cref="BaseWorker"/> with <paramref name="WorkerId"/> could not be found</response>
|
||||
[HttpGet("{WorkerId}")]
|
||||
[ProducesResponseType<BaseWorker>(Status200OK, "application/json")]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
public IActionResult GetJob(string WorkerId)
|
||||
{
|
||||
if(Tranga.Workers.FirstOrDefault(w => w.Key == WorkerId) is not { } worker)
|
||||
return NotFound(nameof(WorkerId));
|
||||
return Ok(worker);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete <see cref="BaseWorker"/> with <paramref name="WorkerId"/> and all child-<see cref="BaseWorker"/>s
|
||||
/// </summary>
|
||||
/// <param name="WorkerId"><see cref="BaseWorker"/>.Key</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="404"><see cref="BaseWorker"/> with <paramref name="WorkerId"/> could not be found</response>
|
||||
[HttpDelete("{WorkerId}")]
|
||||
[ProducesResponseType(Status200OK)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
public IActionResult DeleteJob(string WorkerId)
|
||||
{
|
||||
if(Tranga.Workers.FirstOrDefault(w => w.Key == WorkerId) is not { } worker)
|
||||
return NotFound(nameof(WorkerId));
|
||||
Tranga.RemoveWorker(worker);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modify <see cref="BaseWorker"/> with <paramref name="WorkerId"/>
|
||||
/// </summary>
|
||||
/// <param name="WorkerId"><see cref="BaseWorker"/>.Key</param>
|
||||
/// <param name="modifyWorkerRecord">Fields to modify, set to null to keep previous value</param>
|
||||
/// <response code="202"></response>
|
||||
/// <response code="400"></response>
|
||||
/// <response code="404"><see cref="BaseWorker"/> with <paramref name="WorkerId"/> could not be found</response>
|
||||
/// <response code="409"><see cref="BaseWorker"/> is not <see cref="IPeriodic"/>, can not modify <paramref name="modifyWorkerRecord.IntervalMs"/></response>
|
||||
[HttpPatch("{WorkerId}")]
|
||||
[ProducesResponseType<BaseWorker>(Status202Accepted, "application/json")]
|
||||
[ProducesResponseType(Status400BadRequest)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType<string>(Status409Conflict, "text/plain")]
|
||||
public IActionResult ModifyJob(string WorkerId, [FromBody]ModifyWorkerRecord modifyWorkerRecord)
|
||||
{
|
||||
if(Tranga.Workers.FirstOrDefault(w => w.Key == WorkerId) is not { } worker)
|
||||
return NotFound(nameof(WorkerId));
|
||||
|
||||
if(modifyWorkerRecord.IntervalMs is not null && worker is not IPeriodic)
|
||||
return Conflict("Can not modify Interval of non-Periodic worker");
|
||||
else if(modifyWorkerRecord.IntervalMs is not null && worker is IPeriodic periodic)
|
||||
periodic.Interval = TimeSpan.FromMilliseconds((long)modifyWorkerRecord.IntervalMs);
|
||||
|
||||
return Accepted(worker);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts <see cref="BaseWorker"/> with <paramref name="WorkerId"/>
|
||||
/// </summary>
|
||||
/// <param name="WorkerId"><see cref="BaseWorker"/>.Key</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="404"><see cref="BaseWorker"/> with <paramref name="WorkerId"/> could not be found</response>
|
||||
/// <response code="412"><see cref="BaseWorker"/> was already running</response>
|
||||
[HttpPost("{WorkerId}/Start")]
|
||||
[ProducesResponseType(Status202Accepted)]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType<string>(Status412PreconditionFailed, "text/plain")]
|
||||
public IActionResult StartJob(string WorkerId)
|
||||
{
|
||||
if(Tranga.Workers.FirstOrDefault(w => w.Key == WorkerId) is not { } worker)
|
||||
return NotFound(nameof(WorkerId));
|
||||
|
||||
if (worker.State >= WorkerExecutionState.Waiting)
|
||||
return StatusCode(Status412PreconditionFailed, "Already running");
|
||||
|
||||
Tranga.MarkWorkerForStart(worker);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops <see cref="BaseWorker"/> with <paramref name="WorkerId"/>
|
||||
/// </summary>
|
||||
/// <param name="WorkerId"><see cref="BaseWorker"/>.Key</param>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="404"><see cref="BaseWorker"/> with <paramref name="WorkerId"/> could not be found</response>
|
||||
/// <response code="208"><see cref="BaseWorker"/> was not running</response>
|
||||
[HttpPost("{WorkerId}/Stop")]
|
||||
[ProducesResponseType(Status501NotImplemented)]
|
||||
public IActionResult StopJob(string WorkerId)
|
||||
{
|
||||
if(Tranga.Workers.FirstOrDefault(w => w.Key == WorkerId) is not { } worker)
|
||||
return NotFound(nameof(WorkerId));
|
||||
|
||||
if(worker.State is < WorkerExecutionState.Running or >= WorkerExecutionState.Completed)
|
||||
return StatusCode(Status208AlreadyReported, "Not running");
|
||||
|
||||
Tranga.StopWorker(worker);
|
||||
return Ok();
|
||||
}
|
||||
}
|
35
API/HttpRequestTimeFeature.cs
Normal file
35
API/HttpRequestTimeFeature.cs
Normal file
@ -0,0 +1,35 @@
|
||||
namespace API;
|
||||
|
||||
public interface IHttpRequestTimeFeature
|
||||
{
|
||||
DateTime RequestTime { get; }
|
||||
}
|
||||
|
||||
public class HttpRequestTimeFeature : IHttpRequestTimeFeature
|
||||
{
|
||||
public DateTime RequestTime { get; }
|
||||
|
||||
public HttpRequestTimeFeature()
|
||||
{
|
||||
RequestTime = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
||||
public class RequestTimeMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
|
||||
public RequestTimeMiddleware(RequestDelegate next)
|
||||
{
|
||||
_next = next;
|
||||
}
|
||||
|
||||
public Task InvokeAsync(HttpContext context)
|
||||
{
|
||||
var httpRequestTimeFeature = new HttpRequestTimeFeature();
|
||||
context.Features.Set<IHttpRequestTimeFeature>(httpRequestTimeFeature);
|
||||
|
||||
// Call the next delegate/middleware in the pipeline
|
||||
return this._next(context);
|
||||
}
|
||||
}
|
151
API/MangaDownloadClients/ChromiumDownloadClient.cs
Normal file
151
API/MangaDownloadClients/ChromiumDownloadClient.cs
Normal file
@ -0,0 +1,151 @@
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using HtmlAgilityPack;
|
||||
using log4net;
|
||||
using PuppeteerSharp;
|
||||
|
||||
namespace API.MangaDownloadClients;
|
||||
|
||||
internal class ChromiumDownloadClient : DownloadClient
|
||||
{
|
||||
private static IBrowser? _browser;
|
||||
private readonly HttpDownloadClient _httpDownloadClient;
|
||||
private readonly Thread _closeStalePagesThread;
|
||||
private readonly List<KeyValuePair<IPage, DateTime>> _openPages = new ();
|
||||
|
||||
private static async Task<IBrowser> StartBrowser(ILog log)
|
||||
{
|
||||
return await Puppeteer.LaunchAsync(new LaunchOptions
|
||||
{
|
||||
Headless = true,
|
||||
Args = new [] {
|
||||
"--disable-gpu",
|
||||
"--disable-dev-shm-usage",
|
||||
"--disable-setuid-sandbox",
|
||||
"--no-sandbox"},
|
||||
Timeout = 30000
|
||||
}, new LoggerFactory([new Provider(log)]));
|
||||
}
|
||||
|
||||
public ChromiumDownloadClient()
|
||||
{
|
||||
_httpDownloadClient = new();
|
||||
if(_browser is null)
|
||||
_browser = StartBrowser(Log).Result;
|
||||
_closeStalePagesThread = new Thread(CheckStalePages);
|
||||
_closeStalePagesThread.Start();
|
||||
}
|
||||
|
||||
private void CheckStalePages()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Thread.Sleep(TimeSpan.FromHours(1));
|
||||
Log.Debug("Removing stale pages");
|
||||
foreach ((IPage key, DateTime _) in _openPages.Where(kv => kv.Value.Subtract(DateTime.Now) > TimeSpan.FromHours(1)))
|
||||
{
|
||||
Log.Debug($"Closing {key.Url}");
|
||||
key.CloseAsync().Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Regex _imageUrlRex = new(@"https?:\/\/.*\.(?:p?jpe?g|gif|a?png|bmp|avif|webp)(\?.*)?");
|
||||
internal override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null)
|
||||
{
|
||||
Log.Debug($"Requesting {url}");
|
||||
return _imageUrlRex.IsMatch(url)
|
||||
? _httpDownloadClient.MakeRequestInternal(url, referrer)
|
||||
: MakeRequestBrowser(url, referrer, clickButton);
|
||||
}
|
||||
|
||||
private RequestResult MakeRequestBrowser(string url, string? referrer = null, string? clickButton = null)
|
||||
{
|
||||
if (_browser is null)
|
||||
return new RequestResult(HttpStatusCode.InternalServerError, null, Stream.Null);
|
||||
IPage page = _browser.NewPageAsync().Result;
|
||||
_openPages.Add(new(page, DateTime.Now));
|
||||
page.SetExtraHttpHeadersAsync(new() { { "Referer", referrer } });
|
||||
page.DefaultTimeout = 30000;
|
||||
IResponse response;
|
||||
try
|
||||
{
|
||||
response = page.GoToAsync(url, WaitUntilNavigation.Networkidle0).Result;
|
||||
Log.Debug($"Page loaded. {url}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Info($"Could not load Page {url}\n{e.Message}");
|
||||
page.CloseAsync();
|
||||
_openPages.Remove(_openPages.Find(i => i.Key == page));
|
||||
return new RequestResult(HttpStatusCode.InternalServerError, null, Stream.Null);
|
||||
}
|
||||
|
||||
Stream stream = Stream.Null;
|
||||
HtmlDocument? document = null;
|
||||
|
||||
if (response.Headers.TryGetValue("Content-Type", out string? content))
|
||||
{
|
||||
if (content.Contains("text/html"))
|
||||
{
|
||||
if (clickButton is not null && page.QuerySelectorAsync(clickButton).Result is not null)
|
||||
page.ClickAsync(clickButton).Wait();
|
||||
string htmlString = page.GetContentAsync().Result;
|
||||
stream = new MemoryStream(Encoding.Default.GetBytes(htmlString));
|
||||
document = new ();
|
||||
document.LoadHtml(htmlString);
|
||||
}else if (content.Contains("image"))
|
||||
{
|
||||
stream = new MemoryStream(response.BufferAsync().Result);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
page.CloseAsync().Wait();
|
||||
_openPages.Remove(_openPages.Find(i => i.Key == page));
|
||||
return new RequestResult(HttpStatusCode.InternalServerError, null, Stream.Null);
|
||||
}
|
||||
|
||||
page.CloseAsync().Wait();
|
||||
_openPages.Remove(_openPages.Find(i => i.Key == page));
|
||||
return new RequestResult(response.Status, document, stream, false, "");
|
||||
}
|
||||
|
||||
private class Provider(ILog log) : ILoggerProvider
|
||||
{
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ILogger CreateLogger(string categoryName)
|
||||
{
|
||||
return new ChromiumLogger(log);
|
||||
}
|
||||
}
|
||||
|
||||
private class ChromiumLogger(ILog log) : ILogger
|
||||
{
|
||||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
|
||||
{
|
||||
string message = formatter.Invoke(state, exception);
|
||||
switch(logLevel)
|
||||
{
|
||||
case LogLevel.Critical: log.Fatal(message); break;
|
||||
case LogLevel.Error: log.Error(message); break;
|
||||
case LogLevel.Warning: log.Warn(message); break;
|
||||
case LogLevel.Information: log.Info(message); break;
|
||||
case LogLevel.Debug: log.Debug(message); break;
|
||||
default: log.Info(message); break;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsEnabled(LogLevel logLevel) => true;
|
||||
|
||||
public IDisposable? BeginScope<TState>(TState state) where TState : notnull
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
47
API/MangaDownloadClients/DownloadClient.cs
Normal file
47
API/MangaDownloadClients/DownloadClient.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using System.Net;
|
||||
using log4net;
|
||||
|
||||
namespace API.MangaDownloadClients;
|
||||
|
||||
public abstract class DownloadClient
|
||||
{
|
||||
private static readonly Dictionary<RequestType, DateTime> LastExecutedRateLimit = new();
|
||||
protected ILog Log { get; init; }
|
||||
|
||||
protected DownloadClient()
|
||||
{
|
||||
this.Log = LogManager.GetLogger(GetType());
|
||||
}
|
||||
|
||||
public RequestResult MakeRequest(string url, RequestType requestType, string? referrer = null, string? clickButton = null)
|
||||
{
|
||||
Log.Debug($"Requesting {requestType} {url}");
|
||||
if (!TrangaSettings.requestLimits.ContainsKey(requestType))
|
||||
{
|
||||
return new RequestResult(HttpStatusCode.NotAcceptable, null, Stream.Null);
|
||||
}
|
||||
|
||||
int rateLimit = TrangaSettings.userAgent == TrangaSettings.DefaultUserAgent
|
||||
? TrangaSettings.DefaultRequestLimits[requestType]
|
||||
: TrangaSettings.requestLimits[requestType];
|
||||
|
||||
TimeSpan timeBetweenRequests = TimeSpan.FromMinutes(1).Divide(rateLimit);
|
||||
DateTime now = DateTime.Now;
|
||||
LastExecutedRateLimit.TryAdd(requestType, now.Subtract(timeBetweenRequests));
|
||||
|
||||
TimeSpan rateLimitTimeout = timeBetweenRequests.Subtract(now.Subtract(LastExecutedRateLimit[requestType]));
|
||||
Log.Debug($"Request limit {requestType} {rateLimit}/Minute timeBetweenRequests: {timeBetweenRequests:ss'.'fffff} Timeout: {rateLimitTimeout:ss'.'fffff}");
|
||||
|
||||
if (rateLimitTimeout > TimeSpan.Zero)
|
||||
{
|
||||
Thread.Sleep(rateLimitTimeout);
|
||||
}
|
||||
|
||||
RequestResult result = MakeRequestInternal(url, referrer, clickButton);
|
||||
LastExecutedRateLimit[requestType] = DateTime.UtcNow;
|
||||
Log.Debug($"Result {url}: {result}");
|
||||
return result;
|
||||
}
|
||||
|
||||
internal abstract RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null);
|
||||
}
|
180
API/MangaDownloadClients/FlareSolverrDownloadClient.cs
Normal file
180
API/MangaDownloadClients/FlareSolverrDownloadClient.cs
Normal file
@ -0,0 +1,180 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using HtmlAgilityPack;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace API.MangaDownloadClients;
|
||||
|
||||
public class FlareSolverrDownloadClient : DownloadClient
|
||||
{
|
||||
|
||||
|
||||
internal override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null)
|
||||
{
|
||||
if (clickButton is not null)
|
||||
Log.Warn("Client can not click button");
|
||||
if(referrer is not null)
|
||||
Log.Warn("Client can not set referrer");
|
||||
if (TrangaSettings.flareSolverrUrl == string.Empty)
|
||||
{
|
||||
Log.Error("FlareSolverr URL is empty");
|
||||
return new(HttpStatusCode.InternalServerError, null, Stream.Null);
|
||||
}
|
||||
|
||||
Uri flareSolverrUri = new (TrangaSettings.flareSolverrUrl);
|
||||
if (flareSolverrUri.Segments.Last() != "v1")
|
||||
flareSolverrUri = new UriBuilder(flareSolverrUri)
|
||||
{
|
||||
Path = "v1"
|
||||
}.Uri;
|
||||
|
||||
HttpClient client = new()
|
||||
{
|
||||
Timeout = TimeSpan.FromSeconds(10),
|
||||
DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrHigher,
|
||||
DefaultRequestHeaders = { { "User-Agent", TrangaSettings.userAgent } }
|
||||
};
|
||||
|
||||
JObject requestObj = new()
|
||||
{
|
||||
["cmd"] = "request.get",
|
||||
["url"] = url
|
||||
};
|
||||
|
||||
HttpRequestMessage requestMessage = new(HttpMethod.Post, flareSolverrUri)
|
||||
{
|
||||
Content = new StringContent(JsonConvert.SerializeObject(requestObj)),
|
||||
};
|
||||
requestMessage.Content.Headers.ContentType = new ("application/json");
|
||||
Log.Debug($"Requesting {url}");
|
||||
|
||||
HttpResponseMessage? response;
|
||||
try
|
||||
{
|
||||
response = client.Send(requestMessage);
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
Log.Error(e);
|
||||
return new (HttpStatusCode.Unused, null, Stream.Null);
|
||||
}
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
Log.Debug($"Request returned status code {(int)response.StatusCode} {response.StatusCode}:\n" +
|
||||
$"=====\n" +
|
||||
$"Request:\n" +
|
||||
$"{requestMessage.Method} {requestMessage.RequestUri}\n" +
|
||||
$"{requestMessage.Version} {requestMessage.VersionPolicy}\n" +
|
||||
$"Headers:\n\t{string.Join("\n\t", requestMessage.Headers.Select(h => $"{h.Key}: <{string.Join(">, <", h.Value)}"))}>\n" +
|
||||
$"{requestMessage.Content?.ReadAsStringAsync().Result}" +
|
||||
$"=====\n" +
|
||||
$"Response:\n" +
|
||||
$"{response.Version}\n" +
|
||||
$"Headers:\n\t{string.Join("\n\t", response.Headers.Select(h => $"{h.Key}: <{string.Join(">, <", h.Value)}"))}>\n" +
|
||||
$"{response.Content.ReadAsStringAsync().Result}");
|
||||
return new (response.StatusCode, null, Stream.Null);
|
||||
}
|
||||
|
||||
string responseString = response.Content.ReadAsStringAsync().Result;
|
||||
JObject responseObj = JObject.Parse(responseString);
|
||||
if (!IsInCorrectFormat(responseObj, out string? reason))
|
||||
{
|
||||
Log.Error($"Wrong format: {reason}");
|
||||
return new(HttpStatusCode.Unused, null, Stream.Null);
|
||||
}
|
||||
|
||||
string statusResponse = responseObj["status"]!.Value<string>()!;
|
||||
if (statusResponse != "ok")
|
||||
{
|
||||
Log.Debug($"Status is not ok: {statusResponse}");
|
||||
return new(HttpStatusCode.Unused, null, Stream.Null);
|
||||
}
|
||||
JObject solution = (responseObj["solution"] as JObject)!;
|
||||
|
||||
if (!Enum.TryParse(solution["status"]!.Value<int>().ToString(), out HttpStatusCode statusCode))
|
||||
{
|
||||
Log.Error($"Wrong format: Cant parse status code: {solution["status"]!.Value<int>()}");
|
||||
return new(HttpStatusCode.Unused, null, Stream.Null);
|
||||
}
|
||||
if (statusCode < HttpStatusCode.OK || statusCode >= HttpStatusCode.MultipleChoices)
|
||||
{
|
||||
Log.Debug($"Status is: {statusCode}");
|
||||
return new(statusCode, null, Stream.Null);
|
||||
}
|
||||
|
||||
if (solution["response"]!.Value<string>() is not { } htmlString)
|
||||
{
|
||||
Log.Error("Wrong format: Cant find response in solution");
|
||||
return new(HttpStatusCode.Unused, null, Stream.Null);
|
||||
}
|
||||
|
||||
if (IsJson(htmlString, out HtmlDocument document, out string? json))
|
||||
{
|
||||
MemoryStream ms = new();
|
||||
ms.Write(Encoding.UTF8.GetBytes(json));
|
||||
ms.Position = 0;
|
||||
return new(statusCode, document, ms);
|
||||
}
|
||||
else
|
||||
{
|
||||
MemoryStream ms = new();
|
||||
ms.Write(Encoding.UTF8.GetBytes(htmlString));
|
||||
ms.Position = 0;
|
||||
return new(statusCode, document, ms);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsInCorrectFormat(JObject responseObj, [NotNullWhen(false)]out string? reason)
|
||||
{
|
||||
reason = null;
|
||||
if (!responseObj.ContainsKey("status"))
|
||||
{
|
||||
reason = "Cant find status on response";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (responseObj["solution"] is not JObject solution)
|
||||
{
|
||||
reason = "Cant find solution";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!solution.ContainsKey("status"))
|
||||
{
|
||||
reason = "Wrong format: Cant find status in solution";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!solution.ContainsKey("response"))
|
||||
{
|
||||
|
||||
reason = "Wrong format: Cant find response in solution";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool IsJson(string htmlString, out HtmlDocument document, [NotNullWhen(true)]out string? jsonString)
|
||||
{
|
||||
jsonString = null;
|
||||
document = new();
|
||||
document.LoadHtml(htmlString);
|
||||
|
||||
HtmlNode pre = document.DocumentNode.SelectSingleNode("//pre");
|
||||
try
|
||||
{
|
||||
using JsonDocument _ = JsonDocument.Parse(pre.InnerText);
|
||||
jsonString = pre.InnerText;
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
87
API/MangaDownloadClients/HttpDownloadClient.cs
Normal file
87
API/MangaDownloadClients/HttpDownloadClient.cs
Normal file
@ -0,0 +1,87 @@
|
||||
using System.Net;
|
||||
using HtmlAgilityPack;
|
||||
|
||||
namespace API.MangaDownloadClients;
|
||||
|
||||
internal class HttpDownloadClient : DownloadClient
|
||||
{
|
||||
internal override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null)
|
||||
{
|
||||
if (clickButton is not null)
|
||||
Log.Warn("Client can not click button");
|
||||
HttpClient client = new();
|
||||
client.Timeout = TimeSpan.FromSeconds(10);
|
||||
client.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrHigher;
|
||||
client.DefaultRequestHeaders.Add("User-Agent", TrangaSettings.userAgent);
|
||||
HttpResponseMessage? response;
|
||||
Uri uri = new(url);
|
||||
HttpRequestMessage requestMessage = new(HttpMethod.Get, uri);
|
||||
if (referrer is not null)
|
||||
requestMessage.Headers.Referrer = new (referrer);
|
||||
Log.Debug($"Requesting {url}");
|
||||
try
|
||||
{
|
||||
response = client.Send(requestMessage);
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
Log.Error(e);
|
||||
return new (HttpStatusCode.Unused, null, Stream.Null);
|
||||
}
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
Log.Debug($"Request returned status code {(int)response.StatusCode} {response.StatusCode}");
|
||||
if (response.Headers.Server.Any(s =>
|
||||
(s.Product?.Name ?? "").Contains("cloudflare", StringComparison.InvariantCultureIgnoreCase)))
|
||||
{
|
||||
Log.Debug("Retrying with FlareSolverr!");
|
||||
return new FlareSolverrDownloadClient().MakeRequestInternal(url, referrer, clickButton);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Debug($"Request returned status code {(int)response.StatusCode} {response.StatusCode}:\n" +
|
||||
$"=====\n" +
|
||||
$"Request:\n" +
|
||||
$"{requestMessage.Method} {requestMessage.RequestUri}\n" +
|
||||
$"{requestMessage.Version} {requestMessage.VersionPolicy}\n" +
|
||||
$"Headers:\n\t{string.Join("\n\t", requestMessage.Headers.Select(h => $"{h.Key}: <{string.Join(">, <", h.Value)}"))}>\n" +
|
||||
$"{requestMessage.Content?.ReadAsStringAsync().Result}" +
|
||||
$"=====\n" +
|
||||
$"Response:\n" +
|
||||
$"{response.Version}\n" +
|
||||
$"Headers:\n\t{string.Join("\n\t", response.Headers.Select(h => $"{h.Key}: <{string.Join(">, <", h.Value)}"))}>\n" +
|
||||
$"{response.Content.ReadAsStringAsync().Result}");
|
||||
}
|
||||
}
|
||||
|
||||
Stream stream;
|
||||
try
|
||||
{
|
||||
stream = response.Content.ReadAsStream();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
return new (HttpStatusCode.Unused, null, Stream.Null);
|
||||
}
|
||||
|
||||
HtmlDocument? document = null;
|
||||
|
||||
if (response.Content.Headers.ContentType?.MediaType == "text/html")
|
||||
{
|
||||
StreamReader reader = new (stream);
|
||||
document = new ();
|
||||
document.LoadHtml(reader.ReadToEnd());
|
||||
stream.Position = 0;
|
||||
}
|
||||
|
||||
// Request has been redirected to another page. For example, it redirects directly to the results when there is only 1 result
|
||||
if (response.RequestMessage is not null && response.RequestMessage.RequestUri is not null && response.RequestMessage.RequestUri != uri)
|
||||
{
|
||||
return new (response.StatusCode, document, stream, true, response.RequestMessage.RequestUri.AbsoluteUri);
|
||||
}
|
||||
|
||||
return new (response.StatusCode, document, stream);
|
||||
}
|
||||
}
|
33
API/MangaDownloadClients/RequestResult.cs
Normal file
33
API/MangaDownloadClients/RequestResult.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System.Net;
|
||||
using HtmlAgilityPack;
|
||||
|
||||
namespace API.MangaDownloadClients;
|
||||
|
||||
public struct RequestResult
|
||||
{
|
||||
public HttpStatusCode statusCode { get; }
|
||||
public Stream result { get; }
|
||||
public bool hasBeenRedirected { get; }
|
||||
public string? redirectedToUrl { get; }
|
||||
public HtmlDocument? htmlDocument { get; }
|
||||
|
||||
public RequestResult(HttpStatusCode statusCode, HtmlDocument? htmlDocument, Stream result)
|
||||
{
|
||||
this.statusCode = statusCode;
|
||||
this.htmlDocument = htmlDocument;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public RequestResult(HttpStatusCode statusCode, HtmlDocument? htmlDocument, Stream result, bool hasBeenRedirected, string redirectedTo)
|
||||
: this(statusCode, htmlDocument, result)
|
||||
{
|
||||
this.hasBeenRedirected = hasBeenRedirected;
|
||||
redirectedToUrl = redirectedTo;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return
|
||||
$"{(int)statusCode} {statusCode.ToString()} {(hasBeenRedirected ? "Redirected: " : "")} {redirectedToUrl}";
|
||||
}
|
||||
}
|
11
API/MangaDownloadClients/RequestType.cs
Normal file
11
API/MangaDownloadClients/RequestType.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace API.MangaDownloadClients;
|
||||
|
||||
public enum RequestType : byte
|
||||
{
|
||||
Default = 0,
|
||||
MangaDexFeed = 1,
|
||||
MangaImage = 2,
|
||||
MangaCover = 3,
|
||||
MangaDexImage = 5,
|
||||
MangaInfo = 6
|
||||
}
|
46
API/NamedSwaggerGenOptions.cs
Normal file
46
API/NamedSwaggerGenOptions.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using Asp.Versioning.ApiExplorer;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
namespace API;
|
||||
|
||||
public class NamedSwaggerGenOptions : IConfigureNamedOptions<SwaggerGenOptions>
|
||||
{
|
||||
private readonly IApiVersionDescriptionProvider provider;
|
||||
public NamedSwaggerGenOptions(IApiVersionDescriptionProvider provider)
|
||||
{
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
public void Configure(string? name, SwaggerGenOptions options)
|
||||
{
|
||||
Configure(options);
|
||||
}
|
||||
|
||||
public void Configure(SwaggerGenOptions options)
|
||||
{
|
||||
// add swagger document for every API version discovered
|
||||
foreach (var description in provider.ApiVersionDescriptions)
|
||||
{
|
||||
options.SwaggerDoc(
|
||||
description.GroupName,
|
||||
CreateVersionInfo(description));
|
||||
}
|
||||
}
|
||||
|
||||
private OpenApiInfo CreateVersionInfo(
|
||||
ApiVersionDescription description)
|
||||
{
|
||||
var info = new OpenApiInfo()
|
||||
{
|
||||
Title = "Test API " + description.GroupName,
|
||||
Version = description.ApiVersion.ToString()
|
||||
};
|
||||
if (description.IsDeprecated)
|
||||
{
|
||||
info.Description += " This API version has been deprecated.";
|
||||
}
|
||||
return info;
|
||||
}
|
||||
}
|
153
API/Program.cs
Normal file
153
API/Program.cs
Normal file
@ -0,0 +1,153 @@
|
||||
using System.Reflection;
|
||||
using API;
|
||||
using API.Schema.LibraryContext;
|
||||
using API.Schema.MangaContext;
|
||||
using API.Schema.MangaContext.MangaConnectors;
|
||||
using API.Schema.NotificationsContext;
|
||||
using Asp.Versioning;
|
||||
using Asp.Versioning.Builder;
|
||||
using Asp.Versioning.Conventions;
|
||||
using log4net;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("AllowAll",
|
||||
policy =>
|
||||
{
|
||||
policy
|
||||
.AllowAnyOrigin()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader();
|
||||
});
|
||||
});
|
||||
|
||||
builder.Services.AddApiVersioning(option =>
|
||||
{
|
||||
option.AssumeDefaultVersionWhenUnspecified = true;
|
||||
option.DefaultApiVersion = new ApiVersion(2);
|
||||
option.ReportApiVersions = true;
|
||||
option.ApiVersionReader = ApiVersionReader.Combine(
|
||||
new UrlSegmentApiVersionReader(),
|
||||
new QueryStringApiVersionReader("api-version"),
|
||||
new HeaderApiVersionReader("X-Version"),
|
||||
new MediaTypeApiVersionReader("x-version"));
|
||||
})
|
||||
.AddMvc(options =>
|
||||
{
|
||||
options.Conventions.Add(new VersionByNamespaceConvention());
|
||||
})
|
||||
.AddApiExplorer(options =>
|
||||
{
|
||||
options.GroupNameFormat = "'v'V";
|
||||
options.SubstituteApiVersionInUrl = true;
|
||||
});
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGenNewtonsoftSupport();
|
||||
builder.Services.AddSwaggerGen(opt =>
|
||||
{
|
||||
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
||||
opt.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
|
||||
});
|
||||
builder.Services.ConfigureOptions<NamedSwaggerGenOptions>();
|
||||
|
||||
string connectionString = $"Host={Environment.GetEnvironmentVariable("POSTGRES_HOST") ?? "localhost:5432"}; " +
|
||||
$"Database={Environment.GetEnvironmentVariable("POSTGRES_DB") ?? "postgres"}; " +
|
||||
$"Username={Environment.GetEnvironmentVariable("POSTGRES_USER") ?? "postgres"}; " +
|
||||
$"Password={Environment.GetEnvironmentVariable("POSTGRES_PASSWORD") ?? "postgres"}";
|
||||
|
||||
builder.Services.AddDbContext<MangaContext>(options =>
|
||||
options.UseNpgsql(connectionString));
|
||||
builder.Services.AddDbContext<NotificationsContext>(options =>
|
||||
options.UseNpgsql(connectionString));
|
||||
builder.Services.AddDbContext<LibraryContext>(options =>
|
||||
options.UseNpgsql(connectionString));
|
||||
|
||||
builder.Services.AddControllers(options =>
|
||||
{
|
||||
options.AllowEmptyInputInBodyModelBinding = true;
|
||||
});
|
||||
builder.Services.AddControllers().AddNewtonsoftJson(opts =>
|
||||
{
|
||||
opts.SerializerSettings.Converters.Add(new StringEnumConverter());
|
||||
opts.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
||||
});
|
||||
builder.Services.AddScoped<ILog>(opts => LogManager.GetLogger("API"));
|
||||
|
||||
builder.WebHost.UseUrls("http://*:6531");
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
ApiVersionSet apiVersionSet = app.NewApiVersionSet()
|
||||
.HasApiVersion(new ApiVersion(2))
|
||||
.ReportApiVersions()
|
||||
.Build();
|
||||
|
||||
|
||||
app.UseCors("AllowAll");
|
||||
|
||||
app.MapControllers()
|
||||
.WithApiVersionSet(apiVersionSet)
|
||||
.MapToApiVersion(2);
|
||||
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(options =>
|
||||
{
|
||||
options.SwaggerEndpoint(
|
||||
$"/swagger/v2/swagger.json", "v2");
|
||||
});
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseMiddleware<RequestTimeMiddleware>();
|
||||
|
||||
using (IServiceScope scope = app.Services.CreateScope())
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
context.Database.Migrate();
|
||||
|
||||
MangaConnector[] connectors =
|
||||
[
|
||||
new MangaDex(),
|
||||
new ComickIo(),
|
||||
new Global(scope.ServiceProvider.GetService<MangaContext>()!)
|
||||
];
|
||||
MangaConnector[] newConnectors = connectors.Where(c => !context.MangaConnectors.Contains(c)).ToArray();
|
||||
context.MangaConnectors.AddRange(newConnectors);
|
||||
if (!context.FileLibraries.Any())
|
||||
context.FileLibraries.Add(new FileLibrary(TrangaSettings.downloadLocation, "Default FileLibrary"));
|
||||
|
||||
context.Sync();
|
||||
}
|
||||
|
||||
using (IServiceScope scope = app.Services.CreateScope())
|
||||
{
|
||||
NotificationsContext context = scope.ServiceProvider.GetRequiredService<NotificationsContext>();
|
||||
context.Database.Migrate();
|
||||
|
||||
string[] emojis = { "(•‿•)", "(づ \u25d5‿\u25d5 )づ", "( \u02d8\u25bd\u02d8)っ\u2668", "=\uff3e\u25cf \u22cf \u25cf\uff3e=", "(ΦωΦ)", "(\u272a\u3268\u272a)", "( ノ・o・ )ノ", "(〜^\u2207^ )〜", "~(\u2267ω\u2266)~","૮ \u00b4• ﻌ \u00b4• ა", "(\u02c3ᆺ\u02c2)", "(=\ud83d\udf66 \u0f1d \ud83d\udf66=)"};
|
||||
context.Notifications.Add(new Notification("Tranga Started", emojis[Random.Shared.Next(0, emojis.Length - 1)], NotificationUrgency.High));
|
||||
|
||||
context.Sync();
|
||||
}
|
||||
|
||||
using (IServiceScope scope = app.Services.CreateScope())
|
||||
{
|
||||
LibraryContext context = scope.ServiceProvider.GetRequiredService<LibraryContext>();
|
||||
context.Database.Migrate();
|
||||
|
||||
context.Sync();
|
||||
}
|
||||
|
||||
TrangaSettings.Load();
|
||||
Tranga.StartLogger();
|
||||
|
||||
Tranga.PeriodicWorkerStarterThread.Start(app.Services);
|
||||
|
||||
app.UseCors("AllowAll");
|
||||
|
||||
app.Run();
|
47
API/Properties/launchSettings.json
Normal file
47
API/Properties/launchSettings.json
Normal file
@ -0,0 +1,47 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:5976",
|
||||
"sslPort": 44332,
|
||||
"environmentVariables": {
|
||||
"POSTGRES_Host": "localhost:5432"
|
||||
}
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "http://localhost:5287",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"POSTGRES_Host": "localhost:5432"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7206;http://localhost:5287",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"POSTGRES_Host": "localhost:5432"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"POSTGRES_Host": "localhost:5432"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
21
API/Schema/Identifiable.cs
Normal file
21
API/Schema/Identifiable.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Schema;
|
||||
|
||||
[PrimaryKey("Key")]
|
||||
public abstract class Identifiable
|
||||
{
|
||||
public Identifiable()
|
||||
{
|
||||
this.Key = TokenGen.CreateToken(this.GetType());
|
||||
}
|
||||
|
||||
public Identifiable(string key)
|
||||
{
|
||||
this.Key = key;
|
||||
}
|
||||
|
||||
public string Key { get; init; }
|
||||
|
||||
public override string ToString() => Key;
|
||||
}
|
114
API/Schema/LibraryContext/LibraryConnectors/Kavita.cs
Normal file
114
API/Schema/LibraryContext/LibraryConnectors/Kavita.cs
Normal file
@ -0,0 +1,114 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
namespace API.Schema.LibraryContext.LibraryConnectors;
|
||||
|
||||
public class Kavita : LibraryConnector
|
||||
{
|
||||
|
||||
public Kavita(string baseUrl, string auth) : base(LibraryType.Kavita, baseUrl, auth)
|
||||
{
|
||||
}
|
||||
|
||||
public Kavita(string baseUrl, string username, string password) :
|
||||
this(baseUrl, GetToken(baseUrl, username, password))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
private static string GetToken(string baseUrl, string username, string password)
|
||||
{
|
||||
HttpClient client = new()
|
||||
{
|
||||
DefaultRequestHeaders =
|
||||
{
|
||||
{ "Accept", "application/json" }
|
||||
}
|
||||
};
|
||||
HttpRequestMessage requestMessage = new ()
|
||||
{
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = new Uri($"{baseUrl}/api/Account/login"),
|
||||
Content = new StringContent($"{{\"username\":\"{username}\",\"password\":\"{password}\"}}", System.Text.Encoding.UTF8, "application/json")
|
||||
};
|
||||
try
|
||||
{
|
||||
HttpResponseMessage response = client.Send(requestMessage);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(response.Content.ReadAsStream());
|
||||
if (result is not null)
|
||||
return result["token"]!.GetValue<string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
catch (HttpRequestException)
|
||||
{
|
||||
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
protected override void UpdateLibraryInternal()
|
||||
{
|
||||
foreach (KavitaLibrary lib in GetLibraries())
|
||||
NetClient.MakePost($"{BaseUrl}/api/ToFileLibrary/scan?libraryId={lib.id}", "Bearer", Auth);
|
||||
}
|
||||
|
||||
internal override bool Test()
|
||||
{
|
||||
foreach (KavitaLibrary lib in GetLibraries())
|
||||
if (NetClient.MakePost($"{BaseUrl}/api/ToFileLibrary/scan?libraryId={lib.id}", "Bearer", Auth))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches all libraries available to the user
|
||||
/// </summary>
|
||||
/// <returns>Array of KavitaLibrary</returns>
|
||||
private IEnumerable<KavitaLibrary> GetLibraries()
|
||||
{
|
||||
Stream data = NetClient.MakeRequest($"{BaseUrl}/api/ToFileLibrary/libraries", "Bearer", Auth);
|
||||
if (data == Stream.Null)
|
||||
{
|
||||
Log.Info("No libraries found");
|
||||
return [];
|
||||
}
|
||||
JsonArray? result = JsonSerializer.Deserialize<JsonArray>(data);
|
||||
if (result is null)
|
||||
{
|
||||
Log.Info("No libraries found");
|
||||
return [];
|
||||
}
|
||||
|
||||
List<KavitaLibrary> ret = new();
|
||||
|
||||
foreach (JsonNode? jsonNode in result)
|
||||
{
|
||||
JsonObject? jObject = (JsonObject?)jsonNode;
|
||||
if(jObject is null)
|
||||
continue;
|
||||
int libraryId = jObject["id"]!.GetValue<int>();
|
||||
string libraryName = jObject["name"]!.GetValue<string>();
|
||||
ret.Add(new KavitaLibrary(libraryId, libraryName));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private struct KavitaLibrary
|
||||
{
|
||||
public int id { get; }
|
||||
// ReSharper disable once UnusedAutoPropertyAccessor.Local
|
||||
public string name { get; }
|
||||
|
||||
public KavitaLibrary(int id, string name)
|
||||
{
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
}
|
75
API/Schema/LibraryContext/LibraryConnectors/Komga.cs
Normal file
75
API/Schema/LibraryContext/LibraryConnectors/Komga.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
namespace API.Schema.LibraryContext.LibraryConnectors;
|
||||
|
||||
public class Komga : LibraryConnector
|
||||
{
|
||||
public Komga(string baseUrl, string auth) : base(LibraryType.Komga, baseUrl, auth)
|
||||
{
|
||||
}
|
||||
|
||||
public Komga(string baseUrl, string username, string password)
|
||||
: this(baseUrl, Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{username}:{password}")))
|
||||
{
|
||||
}
|
||||
|
||||
protected override void UpdateLibraryInternal()
|
||||
{
|
||||
foreach (KomgaLibrary lib in GetLibraries())
|
||||
NetClient.MakePost($"{BaseUrl}/api/v1/libraries/{lib.id}/scan", "Basic", Auth);
|
||||
}
|
||||
|
||||
internal override bool Test()
|
||||
{
|
||||
foreach (KomgaLibrary lib in GetLibraries())
|
||||
if (NetClient.MakePost($"{BaseUrl}/api/v1/libraries/{lib.id}/scan", "Basic", Auth))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches all libraries available to the user
|
||||
/// </summary>
|
||||
/// <returns>Array of KomgaLibraries</returns>
|
||||
private IEnumerable<KomgaLibrary> GetLibraries()
|
||||
{
|
||||
Stream data = NetClient.MakeRequest($"{BaseUrl}/api/v1/libraries", "Basic", Auth);
|
||||
if (data == Stream.Null)
|
||||
{
|
||||
Log.Info("No libraries found");
|
||||
return [];
|
||||
}
|
||||
JsonArray? result = JsonSerializer.Deserialize<JsonArray>(data);
|
||||
if (result is null)
|
||||
{
|
||||
Log.Info("No libraries found");
|
||||
return [];
|
||||
}
|
||||
|
||||
HashSet<KomgaLibrary> ret = new();
|
||||
|
||||
foreach (JsonNode? jsonNode in result)
|
||||
{
|
||||
var jObject = (JsonObject?)jsonNode;
|
||||
string libraryId = jObject!["id"]!.GetValue<string>();
|
||||
string libraryName = jObject["name"]!.GetValue<string>();
|
||||
ret.Add(new KomgaLibrary(libraryId, libraryName));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private struct KomgaLibrary
|
||||
{
|
||||
public string id { get; }
|
||||
// ReSharper disable once UnusedAutoPropertyAccessor.Local
|
||||
public string name { get; }
|
||||
|
||||
public KomgaLibrary(string id, string name)
|
||||
{
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using log4net;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace API.Schema.LibraryContext.LibraryConnectors;
|
||||
|
||||
[PrimaryKey("LibraryConnectorId")]
|
||||
public abstract class LibraryConnector : Identifiable
|
||||
{
|
||||
[Required]
|
||||
public LibraryType LibraryType { get; init; }
|
||||
[StringLength(256)]
|
||||
[Required]
|
||||
[Url]
|
||||
public string BaseUrl { get; init; }
|
||||
[StringLength(256)]
|
||||
[Required]
|
||||
public string Auth { get; init; }
|
||||
|
||||
[JsonIgnore]
|
||||
[NotMapped]
|
||||
protected ILog Log { get; init; }
|
||||
|
||||
protected LibraryConnector(LibraryType libraryType, string baseUrl, string auth)
|
||||
: base()
|
||||
{
|
||||
this.LibraryType = libraryType;
|
||||
this.BaseUrl = baseUrl;
|
||||
this.Auth = auth;
|
||||
this.Log = LogManager.GetLogger(GetType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EF CORE ONLY!!!!
|
||||
/// </summary>
|
||||
internal LibraryConnector(string key, LibraryType libraryType, string baseUrl, string auth)
|
||||
: base(key)
|
||||
{
|
||||
this.LibraryType = libraryType;
|
||||
this.BaseUrl = baseUrl;
|
||||
this.Auth = auth;
|
||||
this.Log = LogManager.GetLogger(GetType());
|
||||
}
|
||||
|
||||
public override string ToString() => $"{base.ToString()} {this.LibraryType} {this.BaseUrl}";
|
||||
|
||||
protected abstract void UpdateLibraryInternal();
|
||||
internal abstract bool Test();
|
||||
}
|
||||
|
||||
public enum LibraryType : byte
|
||||
{
|
||||
Komga = 0,
|
||||
Kavita = 1
|
||||
}
|
73
API/Schema/LibraryContext/LibraryConnectors/NetClient.cs
Normal file
73
API/Schema/LibraryContext/LibraryConnectors/NetClient.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using log4net;
|
||||
|
||||
namespace API.Schema.LibraryContext.LibraryConnectors;
|
||||
|
||||
public class NetClient
|
||||
{
|
||||
private static ILog Log = LogManager.GetLogger(typeof(NetClient));
|
||||
|
||||
public static Stream MakeRequest(string url, string authScheme, string auth)
|
||||
{
|
||||
Log.Debug($"Requesting {url}");
|
||||
HttpClient client = new();
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(authScheme, auth);
|
||||
|
||||
HttpRequestMessage requestMessage = new()
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri(url)
|
||||
};
|
||||
try
|
||||
{
|
||||
HttpResponseMessage response = client.Send(requestMessage);
|
||||
|
||||
if (response.StatusCode is HttpStatusCode.Unauthorized &&
|
||||
response.RequestMessage!.RequestUri!.AbsoluteUri != url)
|
||||
return MakeRequest(response.RequestMessage!.RequestUri!.AbsoluteUri, authScheme, auth);
|
||||
else if (response.IsSuccessStatusCode)
|
||||
return response.Content.ReadAsStream();
|
||||
else
|
||||
return Stream.Null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
switch (e)
|
||||
{
|
||||
case HttpRequestException:
|
||||
Log.Debug(e);
|
||||
break;
|
||||
default:
|
||||
throw;
|
||||
}
|
||||
Log.Info("Failed to make request");
|
||||
return Stream.Null;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool MakePost(string url, string authScheme, string auth)
|
||||
{
|
||||
HttpClient client = new()
|
||||
{
|
||||
DefaultRequestHeaders =
|
||||
{
|
||||
{ "Accept", "application/json" },
|
||||
{ "Authorization", new AuthenticationHeaderValue(authScheme, auth).ToString() }
|
||||
}
|
||||
};
|
||||
HttpRequestMessage requestMessage = new ()
|
||||
{
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = new Uri(url)
|
||||
};
|
||||
HttpResponseMessage response = client.Send(requestMessage);
|
||||
|
||||
if(response.StatusCode is HttpStatusCode.Unauthorized && response.RequestMessage!.RequestUri!.AbsoluteUri != url)
|
||||
return MakePost(response.RequestMessage!.RequestUri!.AbsoluteUri, authScheme, auth);
|
||||
else if (response.IsSuccessStatusCode)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
18
API/Schema/LibraryContext/LibraryContext.cs
Normal file
18
API/Schema/LibraryContext/LibraryContext.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using API.Schema.LibraryContext.LibraryConnectors;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Schema.LibraryContext;
|
||||
|
||||
public class LibraryContext(DbContextOptions<LibraryContext> options) : TrangaBaseContext<LibraryContext>(options)
|
||||
{
|
||||
public DbSet<LibraryConnector> LibraryConnectors { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
//LibraryConnector Types
|
||||
modelBuilder.Entity<LibraryConnector>()
|
||||
.HasDiscriminator(l => l.LibraryType)
|
||||
.HasValue<Komga>(LibraryType.Komga)
|
||||
.HasValue<Kavita>(LibraryType.Kavita);
|
||||
}
|
||||
}
|
17
API/Schema/MangaContext/AltTitle.cs
Normal file
17
API/Schema/MangaContext/AltTitle.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Schema.MangaContext;
|
||||
|
||||
[PrimaryKey("Key")]
|
||||
public class AltTitle(string language, string title) : Identifiable(TokenGen.CreateToken("AltTitle"))
|
||||
{
|
||||
[StringLength(8)]
|
||||
[Required]
|
||||
public string Language { get; init; } = language;
|
||||
[StringLength(256)]
|
||||
[Required]
|
||||
public string Title { get; init; } = title;
|
||||
|
||||
public override string ToString() => $"{base.ToString()} {Language} {Title}";
|
||||
}
|
14
API/Schema/MangaContext/Author.cs
Normal file
14
API/Schema/MangaContext/Author.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Schema.MangaContext;
|
||||
|
||||
[PrimaryKey("Key")]
|
||||
public class Author(string authorName) : Identifiable(TokenGen.CreateToken(typeof(Author), authorName))
|
||||
{
|
||||
[StringLength(128)]
|
||||
[Required]
|
||||
public string AuthorName { get; init; } = authorName;
|
||||
|
||||
public override string ToString() => $"{base.ToString()} {AuthorName}";
|
||||
}
|
210
API/Schema/MangaContext/Chapter.cs
Normal file
210
API/Schema/MangaContext/Chapter.cs
Normal file
@ -0,0 +1,210 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace API.Schema.MangaContext;
|
||||
|
||||
[PrimaryKey("Key")]
|
||||
public class Chapter : Identifiable, IComparable<Chapter>
|
||||
{
|
||||
[StringLength(64)] [Required] public string ParentMangaId { get; init; } = null!;
|
||||
private Manga? _parentManga;
|
||||
|
||||
[JsonIgnore]
|
||||
public Manga ParentManga
|
||||
{
|
||||
get => _lazyLoader.Load(this, ref _parentManga) ?? throw new InvalidOperationException();
|
||||
init
|
||||
{
|
||||
ParentMangaId = value.Key;
|
||||
_parentManga = value;
|
||||
}
|
||||
}
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<string, string> IdsOnMangaConnectors =>
|
||||
MangaConnectorIds.ToDictionary(id => id.MangaConnectorName, id => id.IdOnConnectorSite);
|
||||
|
||||
private ICollection<MangaConnectorId<Chapter>>? _mangaConnectorIds;
|
||||
[JsonIgnore]
|
||||
public ICollection<MangaConnectorId<Chapter>> MangaConnectorIds
|
||||
{
|
||||
get => _lazyLoader.Load(this, ref _mangaConnectorIds) ?? throw new InvalidOperationException();
|
||||
init => _mangaConnectorIds = value;
|
||||
}
|
||||
|
||||
public int? VolumeNumber { get; private set; }
|
||||
[StringLength(10)] [Required] public string ChapterNumber { get; private set; }
|
||||
|
||||
[StringLength(256)] public string? Title { get; private set; }
|
||||
|
||||
[StringLength(256)] [Required] public string FileName { get; private set; }
|
||||
|
||||
[Required] public bool Downloaded { get; internal set; }
|
||||
[NotMapped] public string FullArchiveFilePath => Path.Join(ParentManga.FullDirectoryPath, FileName);
|
||||
|
||||
private readonly ILazyLoader _lazyLoader = null!;
|
||||
|
||||
public Chapter(Manga parentManga, string chapterNumber,
|
||||
int? volumeNumber, string? title = null)
|
||||
: base(TokenGen.CreateToken(typeof(Chapter), parentManga.Key, chapterNumber))
|
||||
{
|
||||
this.ParentManga = parentManga;
|
||||
this.MangaConnectorIds = [];
|
||||
this.VolumeNumber = volumeNumber;
|
||||
this.ChapterNumber = chapterNumber;
|
||||
this.Title = title;
|
||||
this.FileName = GetArchiveFilePath();
|
||||
this.Downloaded = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EF ONLY!!!
|
||||
/// </summary>
|
||||
internal Chapter(ILazyLoader lazyLoader, string key, int? volumeNumber, string chapterNumber, string? title, string fileName, bool downloaded)
|
||||
: base(key)
|
||||
{
|
||||
this._lazyLoader = lazyLoader;
|
||||
this.VolumeNumber = volumeNumber;
|
||||
this.ChapterNumber = chapterNumber;
|
||||
this.Title = title;
|
||||
this.FileName = fileName;
|
||||
this.Downloaded = downloaded;
|
||||
}
|
||||
|
||||
public int CompareTo(Chapter? other)
|
||||
{
|
||||
if (other is not { } otherChapter)
|
||||
throw new ArgumentException($"{other} can not be compared to {this}");
|
||||
return VolumeNumber?.CompareTo(otherChapter.VolumeNumber) switch
|
||||
{
|
||||
< 0 => -1,
|
||||
> 0 => 1,
|
||||
_ => CompareChapterNumbers(ChapterNumber, otherChapter.ChapterNumber)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks the filesystem if an archive at the ArchiveFilePath exists
|
||||
/// </summary>
|
||||
/// <returns>True if archive exists on disk</returns>
|
||||
public bool CheckDownloaded() => File.Exists(FullArchiveFilePath);
|
||||
|
||||
/// Placeholders:
|
||||
/// %M Obj Name
|
||||
/// %V Volume
|
||||
/// %C Chapter
|
||||
/// %T Title
|
||||
/// %A Author (first in list)
|
||||
/// %I Chapter Internal ID
|
||||
/// %i Obj Internal ID
|
||||
/// %Y Year (Obj)
|
||||
private static readonly Regex NullableRex = new(@"\?([a-zA-Z])\(([^\)]*)\)|(.+?)");
|
||||
private static readonly Regex ReplaceRexx = new(@"%([a-zA-Z])|(.+?)");
|
||||
private string GetArchiveFilePath()
|
||||
{
|
||||
string archiveNamingScheme = TrangaSettings.chapterNamingScheme;
|
||||
StringBuilder stringBuilder = new();
|
||||
foreach (Match nullable in NullableRex.Matches(archiveNamingScheme))
|
||||
{
|
||||
if (nullable.Groups[3].Success)
|
||||
{
|
||||
stringBuilder.Append(nullable.Groups[3].Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
char placeholder = nullable.Groups[1].Value[0];
|
||||
bool isNull = placeholder switch
|
||||
{
|
||||
'M' => ParentManga?.Name is null,
|
||||
'V' => VolumeNumber is null,
|
||||
'C' => ChapterNumber is null,
|
||||
'T' => Title is null,
|
||||
'A' => ParentManga?.Authors?.FirstOrDefault()?.AuthorName is null,
|
||||
'Y' => ParentManga?.Year is null,
|
||||
_ => true
|
||||
};
|
||||
if(!isNull)
|
||||
stringBuilder.Append(nullable.Groups[2].Value);
|
||||
}
|
||||
|
||||
string checkedString = stringBuilder.ToString();
|
||||
stringBuilder = new();
|
||||
|
||||
foreach (Match replace in ReplaceRexx.Matches(checkedString))
|
||||
{
|
||||
if (replace.Groups[2].Success)
|
||||
{
|
||||
stringBuilder.Append(replace.Groups[2].Value);
|
||||
continue;
|
||||
}
|
||||
|
||||
char placeholder = replace.Groups[1].Value[0];
|
||||
string? value = placeholder switch
|
||||
{
|
||||
'M' => ParentManga?.Name,
|
||||
'V' => VolumeNumber?.ToString(),
|
||||
'C' => ChapterNumber,
|
||||
'T' => Title,
|
||||
'A' => ParentManga?.Authors?.FirstOrDefault()?.AuthorName,
|
||||
'Y' => ParentManga?.Year.ToString(),
|
||||
_ => null
|
||||
};
|
||||
stringBuilder.Append(value);
|
||||
}
|
||||
|
||||
stringBuilder.Append(".cbz");
|
||||
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
private static int CompareChapterNumbers(string ch1, string ch2)
|
||||
{
|
||||
int[] ch1Arr = ch1.Split('.').Select(c => int.TryParse(c, out int result) ? result : -1).ToArray();
|
||||
int[] ch2Arr = ch2.Split('.').Select(c => int.TryParse(c, out int result) ? result : -1).ToArray();
|
||||
|
||||
if (ch1Arr.Contains(-1) || ch2Arr.Contains(-1))
|
||||
throw new ArgumentException("Chapter number is not in correct format");
|
||||
|
||||
int i = 0, j = 0;
|
||||
|
||||
while (i < ch1Arr.Length && j < ch2Arr.Length)
|
||||
{
|
||||
if (ch1Arr[i] < ch2Arr[j])
|
||||
return -1;
|
||||
if (ch1Arr[i] > ch2Arr[j])
|
||||
return 1;
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
internal string GetComicInfoXmlString()
|
||||
{
|
||||
XElement comicInfo = new("ComicInfo",
|
||||
new XElement("Number", ChapterNumber)
|
||||
);
|
||||
if(Title is not null)
|
||||
comicInfo.Add(new XElement("Title", Title));
|
||||
if(ParentManga.MangaTags.Count > 0)
|
||||
comicInfo.Add(new XElement("Tags", string.Join(',', ParentManga.MangaTags.Select(tag => tag.Tag))));
|
||||
if(VolumeNumber is not null)
|
||||
comicInfo.Add(new XElement("Volume", VolumeNumber));
|
||||
if(ParentManga.Authors.Count > 0)
|
||||
comicInfo.Add(new XElement("Writer", string.Join(',', ParentManga.Authors.Select(author => author.AuthorName))));
|
||||
if(ParentManga.OriginalLanguage is not null)
|
||||
comicInfo.Add(new XElement("LanguageISO", ParentManga.OriginalLanguage));
|
||||
if(ParentManga.Description != string.Empty)
|
||||
comicInfo.Add(new XElement("Summary", ParentManga.Description));
|
||||
return comicInfo.ToString();
|
||||
}
|
||||
|
||||
public override string ToString() => $"{base.ToString()} Vol.{VolumeNumber} Ch.{ChapterNumber} - {Title}";
|
||||
}
|
19
API/Schema/MangaContext/FileLibrary.cs
Normal file
19
API/Schema/MangaContext/FileLibrary.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Schema.MangaContext;
|
||||
|
||||
[PrimaryKey("Key")]
|
||||
public class FileLibrary(string basePath, string libraryName)
|
||||
: Identifiable(TokenGen.CreateToken(typeof(FileLibrary), basePath))
|
||||
{
|
||||
[StringLength(256)]
|
||||
[Required]
|
||||
public string BasePath { get; internal set; } = basePath;
|
||||
|
||||
[StringLength(512)]
|
||||
[Required]
|
||||
public string LibraryName { get; internal set; } = libraryName;
|
||||
|
||||
public override string ToString() => $"{base.ToString()} {LibraryName} - {BasePath}";
|
||||
}
|
18
API/Schema/MangaContext/Link.cs
Normal file
18
API/Schema/MangaContext/Link.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Schema.MangaContext;
|
||||
|
||||
[PrimaryKey("Key")]
|
||||
public class Link(string linkProvider, string linkUrl) : Identifiable(TokenGen.CreateToken(typeof(Link), linkProvider, linkUrl))
|
||||
{
|
||||
[StringLength(64)]
|
||||
[Required]
|
||||
public string LinkProvider { get; init; } = linkProvider;
|
||||
[StringLength(2048)]
|
||||
[Required]
|
||||
[Url]
|
||||
public string LinkUrl { get; init; } = linkUrl;
|
||||
|
||||
public override string ToString() => $"{base.ToString()} {LinkProvider} {LinkUrl}";
|
||||
}
|
196
API/Schema/MangaContext/Manga.cs
Normal file
196
API/Schema/MangaContext/Manga.cs
Normal file
@ -0,0 +1,196 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using API.Workers;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Newtonsoft.Json;
|
||||
using static System.IO.UnixFileMode;
|
||||
|
||||
namespace API.Schema.MangaContext;
|
||||
|
||||
[PrimaryKey("Key")]
|
||||
public class Manga : Identifiable
|
||||
{
|
||||
[StringLength(512)] [Required] public string Name { get; internal set; }
|
||||
[Required] public string Description { get; internal set; }
|
||||
[JsonIgnore] [Url] [StringLength(512)] public string CoverUrl { get; internal set; }
|
||||
[Required] public MangaReleaseStatus ReleaseStatus { get; internal set; }
|
||||
[StringLength(64)] public string? LibraryId { get; private set; }
|
||||
private FileLibrary? _library;
|
||||
[JsonIgnore]
|
||||
public FileLibrary? Library
|
||||
{
|
||||
get => _lazyLoader.Load(this, ref _library);
|
||||
set
|
||||
{
|
||||
LibraryId = value?.Key;
|
||||
_library = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ICollection<Author> Authors { get; internal set; }= null!;
|
||||
public ICollection<MangaTag> MangaTags { get; internal set; }= null!;
|
||||
public ICollection<Link> Links { get; internal set; }= null!;
|
||||
public ICollection<AltTitle> AltTitles { get; internal set; } = null!;
|
||||
[Required] public float IgnoreChaptersBefore { get; internal set; }
|
||||
[StringLength(1024)] [Required] public string DirectoryName { get; private set; }
|
||||
[JsonIgnore] [StringLength(512)] public string? CoverFileNameInCache { get; internal set; }
|
||||
public uint? Year { get; internal init; }
|
||||
[StringLength(8)] public string? OriginalLanguage { get; internal init; }
|
||||
|
||||
[JsonIgnore]
|
||||
[NotMapped]
|
||||
public string? FullDirectoryPath => Library is not null ? Path.Join(Library.BasePath, DirectoryName) : null;
|
||||
|
||||
[NotMapped] public ICollection<string> ChapterIds => Chapters.Select(c => c.Key).ToList();
|
||||
private ICollection<Chapter>? _chapters;
|
||||
[JsonIgnore]
|
||||
public ICollection<Chapter> Chapters
|
||||
{
|
||||
get => _lazyLoader.Load(this, ref _chapters) ?? throw new InvalidOperationException();
|
||||
init => _chapters = value;
|
||||
}
|
||||
|
||||
[NotMapped] public Dictionary<string, string> IdsOnMangaConnectors =>
|
||||
MangaConnectorIds.ToDictionary(id => id.MangaConnectorName, id => id.IdOnConnectorSite);
|
||||
private ICollection<MangaConnectorId<Manga>>? _mangaConnectorIds;
|
||||
[JsonIgnore]
|
||||
public ICollection<MangaConnectorId<Manga>> MangaConnectorIds
|
||||
{
|
||||
get => _lazyLoader.Load(this, ref _mangaConnectorIds) ?? throw new InvalidOperationException();
|
||||
private set => _mangaConnectorIds = value;
|
||||
}
|
||||
|
||||
private readonly ILazyLoader _lazyLoader = null!;
|
||||
|
||||
public Manga(string name, string description, string coverUrl, MangaReleaseStatus releaseStatus,
|
||||
ICollection<Author> authors, ICollection<MangaTag> mangaTags, ICollection<Link> links, ICollection<AltTitle> altTitles,
|
||||
FileLibrary? library = null, float ignoreChaptersBefore = 0f, uint? year = null, string? originalLanguage = null)
|
||||
:base(TokenGen.CreateToken(typeof(Manga), name))
|
||||
{
|
||||
this.Name = name;
|
||||
this.Description = description;
|
||||
this.CoverUrl = coverUrl;
|
||||
this.ReleaseStatus = releaseStatus;
|
||||
this.Library = library;
|
||||
this.Authors = authors;
|
||||
this.MangaTags = mangaTags;
|
||||
this.Links = links;
|
||||
this.AltTitles = altTitles;
|
||||
this.IgnoreChaptersBefore = ignoreChaptersBefore;
|
||||
this.DirectoryName = CleanDirectoryName(name);
|
||||
this.Year = year;
|
||||
this.OriginalLanguage = originalLanguage;
|
||||
this.Chapters = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EF ONLY!!!
|
||||
/// </summary>
|
||||
public Manga(ILazyLoader lazyLoader, string key, string name, string description, string coverUrl,
|
||||
MangaReleaseStatus releaseStatus,
|
||||
string directoryName, float ignoreChaptersBefore, string? libraryId, uint? year, string? originalLanguage)
|
||||
: base(key)
|
||||
{
|
||||
this._lazyLoader = lazyLoader;
|
||||
this.Name = name;
|
||||
this.Description = description;
|
||||
this.CoverUrl = coverUrl;
|
||||
this.ReleaseStatus = releaseStatus;
|
||||
this.DirectoryName = directoryName;
|
||||
this.LibraryId = libraryId;
|
||||
this.IgnoreChaptersBefore = ignoreChaptersBefore;
|
||||
this.Year = year;
|
||||
this.OriginalLanguage = originalLanguage;
|
||||
}
|
||||
|
||||
|
||||
public string CreatePublicationFolder()
|
||||
{
|
||||
string? publicationFolder = FullDirectoryPath;
|
||||
if (publicationFolder is null)
|
||||
throw new DirectoryNotFoundException("Publication folder not found");
|
||||
if(!Directory.Exists(publicationFolder))
|
||||
Directory.CreateDirectory(publicationFolder);
|
||||
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
File.SetUnixFileMode(publicationFolder, GroupRead | GroupWrite | GroupExecute | OtherRead | OtherWrite | OtherExecute | UserRead | UserWrite | UserExecute);
|
||||
return publicationFolder;
|
||||
}
|
||||
|
||||
//https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file
|
||||
//less than 32 is control *forbidden*
|
||||
//34 is " *forbidden*
|
||||
//42 is * *forbidden*
|
||||
//47 is / *forbidden*
|
||||
//58 is : *forbidden*
|
||||
//60 is < *forbidden*
|
||||
//62 is > *forbidden*
|
||||
//63 is ? *forbidden*
|
||||
//92 is \ *forbidden*
|
||||
//124 is | *forbidden*
|
||||
//127 is delete *forbidden*
|
||||
//Below 127 all except *******
|
||||
private static readonly int[] ForbiddenCharsBelow127 = [34, 42, 47, 58, 60, 62, 63, 92, 124, 127];
|
||||
//Above 127 none except *******
|
||||
private static readonly int[] IncludeCharsAbove127 = [128, 138, 142];
|
||||
//128 is € include
|
||||
//138 is Š include
|
||||
//142 is Ž include
|
||||
//152 through 255 looks fine except 157, 172, 173, 175 *******
|
||||
private static readonly int[] ForbiddenCharsAbove152 = [157, 172, 173, 175];
|
||||
private static string CleanDirectoryName(string name)
|
||||
{
|
||||
StringBuilder sb = new ();
|
||||
foreach (char c in name)
|
||||
{
|
||||
if (c >= 32 && c < 127 && ForbiddenCharsBelow127.Contains(c) == false)
|
||||
sb.Append(c);
|
||||
else if (c > 127 && c < 152 && IncludeCharsAbove127.Contains(c))
|
||||
sb.Append(c);
|
||||
else if(c >= 152 && c <= 255 && ForbiddenCharsAbove152.Contains(c) == false)
|
||||
sb.Append(c);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Merges another Manga (MangaConnectorIds and Chapters)
|
||||
/// </summary>
|
||||
/// <param name="other">The other <see cref="Manga" /> to merge</param>
|
||||
/// <param name="context"><see cref="MangaContext"/> to use for Database operations</param>
|
||||
/// <returns>An array of <see cref="MoveFileOrFolderWorker"/> for moving <see cref="Chapter"/> to new Directory</returns>
|
||||
public BaseWorker[] MergeFrom(Manga other, MangaContext context)
|
||||
{
|
||||
context.Mangas.Remove(other);
|
||||
List<BaseWorker> newJobs = new();
|
||||
|
||||
this.MangaConnectorIds = this.MangaConnectorIds
|
||||
.UnionBy(other.MangaConnectorIds, id => id.MangaConnectorName)
|
||||
.ToList();
|
||||
|
||||
foreach (Chapter otherChapter in other.Chapters)
|
||||
{
|
||||
string oldPath = otherChapter.FullArchiveFilePath;
|
||||
Chapter newChapter = new(this, otherChapter.ChapterNumber, otherChapter.VolumeNumber,
|
||||
otherChapter.Title);
|
||||
this.Chapters.Add(newChapter);
|
||||
string newPath = newChapter.FullArchiveFilePath;
|
||||
newJobs.Add(new MoveFileOrFolderWorker(newPath, oldPath));
|
||||
}
|
||||
|
||||
return newJobs.ToArray();
|
||||
}
|
||||
|
||||
public override string ToString() => $"{base.ToString()} {Name}";
|
||||
}
|
||||
|
||||
public enum MangaReleaseStatus : byte
|
||||
{
|
||||
Continuing = 0,
|
||||
Completed = 1,
|
||||
OnHiatus = 2,
|
||||
Cancelled = 3,
|
||||
Unreleased = 4
|
||||
}
|
67
API/Schema/MangaContext/MangaConnectorId.cs
Normal file
67
API/Schema/MangaContext/MangaConnectorId.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using API.Schema.MangaContext.MangaConnectors;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace API.Schema.MangaContext;
|
||||
|
||||
[PrimaryKey("Key")]
|
||||
public class MangaConnectorId<T> : Identifiable where T : Identifiable
|
||||
{
|
||||
[StringLength(64)] [Required] public string ObjId { get; private set; } = null!;
|
||||
[JsonIgnore] private T? _obj;
|
||||
|
||||
[JsonIgnore]
|
||||
public T Obj
|
||||
{
|
||||
get => _lazyLoader.Load(this, ref _obj) ?? throw new InvalidOperationException();
|
||||
internal set
|
||||
{
|
||||
ObjId = value.Key;
|
||||
_obj = value;
|
||||
}
|
||||
}
|
||||
|
||||
[StringLength(32)] [Required] public string MangaConnectorName { get; private set; } = null!;
|
||||
[JsonIgnore] private MangaConnector? _mangaConnector;
|
||||
[JsonIgnore]
|
||||
public MangaConnector MangaConnector
|
||||
{
|
||||
get => _lazyLoader.Load(this, ref _mangaConnector) ?? throw new InvalidOperationException();
|
||||
init
|
||||
{
|
||||
MangaConnectorName = value.Name;
|
||||
_mangaConnector = value;
|
||||
}
|
||||
}
|
||||
|
||||
[StringLength(256)] [Required] public string IdOnConnectorSite { get; init; }
|
||||
[Url] [StringLength(512)] public string? WebsiteUrl { get; internal init; }
|
||||
|
||||
private readonly ILazyLoader _lazyLoader = null!;
|
||||
|
||||
public MangaConnectorId(T obj, MangaConnector mangaConnector, string idOnConnectorSite, string? websiteUrl)
|
||||
: base(TokenGen.CreateToken(typeof(MangaConnectorId<T>), mangaConnector.Name, idOnConnectorSite))
|
||||
{
|
||||
this.Obj = obj;
|
||||
this.MangaConnector = mangaConnector;
|
||||
this.IdOnConnectorSite = idOnConnectorSite;
|
||||
this.WebsiteUrl = websiteUrl;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EF CORE ONLY!!!
|
||||
/// </summary>
|
||||
public MangaConnectorId(ILazyLoader lazyLoader, string key, string objId, string mangaConnectorName, string idOnConnectorSite, string? websiteUrl)
|
||||
: base(key)
|
||||
{
|
||||
this._lazyLoader = lazyLoader;
|
||||
this.ObjId = objId;
|
||||
this.MangaConnectorName = mangaConnectorName;
|
||||
this.IdOnConnectorSite = idOnConnectorSite;
|
||||
this.WebsiteUrl = websiteUrl;
|
||||
}
|
||||
|
||||
public override string ToString() => $"{base.ToString()} {_obj}";
|
||||
}
|
258
API/Schema/MangaContext/MangaConnectors/ComickIo.cs
Normal file
258
API/Schema/MangaContext/MangaConnectors/ComickIo.cs
Normal file
@ -0,0 +1,258 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using API.MangaDownloadClients;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace API.Schema.MangaContext.MangaConnectors;
|
||||
|
||||
public class ComickIo : MangaConnector
|
||||
{
|
||||
//https://api.comick.io/docs/
|
||||
//https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes
|
||||
|
||||
public ComickIo() : base("ComickIo",
|
||||
["en","pt","pt-br","it","de","ru","aa","ab","ae","af","ak","am","an","ar-ae","ar-bh","ar-dz","ar-eg","ar-iq","ar-jo","ar-kw","ar-lb","ar-ly","ar-ma","ar-om","ar-qa","ar-sa","ar-sy","ar-tn","ar-ye","ar","as","av","ay","az","ba","be","bg","bh","bi","bm","bn","bo","br","bs","ca","ce","ch","co","cr","cs","cu","cv","cy","da","de-at","de-ch","de-de","de-li","de-lu","div","dv","dz","ee","el","en-au","en-bz","en-ca","en-cb","en-gb","en-ie","en-jm","en-nz","en-ph","en-tt","en-us","en-za","en-zw","eo","es-ar","es-bo","es-cl","es-co","es-cr","es-do","es-ec","es-es","es-gt","es-hn","es-la","es-mx","es-ni","es-pa","es-pe","es-pr","es-py","es-sv","es-us","es-uy","es-ve","es","et","eu","fa","ff","fi","fj","fo","fr-be","fr-ca","fr-ch","fr-fr","fr-lu","fr-mc","fr","fy","ga","gd","gl","gn","gu","gv","ha","he","hi","ho","hr-ba","hr-hr","hr","ht","hu","hy","hz","ia","id","ie","ig","ii","ik","in","io","is","it-ch","it-it","iu","iw","ja","ja-ro","ji","jv","jw","ka","kg","ki","kj","kk","kl","km","kn","ko","ko-ro","kr","ks","ku","kv","kw","ky","kz","la","lb","lg","li","ln","lo","ls","lt","lu","lv","mg","mh","mi","mk","ml","mn","mo","mr","ms-bn","ms-my","ms","mt","my","na","nb","nd","ne","ng","nl-be","nl-nl","nl","nn","no","nr","ns","nv","ny","oc","oj","om","or","os","pa","pi","pl","ps","pt-pt","qu-bo","qu-ec","qu-pe","qu","rm","rn","ro","rw","sa","sb","sc","sd","se-fi","se-no","se-se","se","sg","sh","si","sk","sl","sm","sn","so","sq","sr-ba","sr-sp","sr","ss","st","su","sv-fi","sv-se","sv","sw","sx","syr","ta","te","tg","th","ti","tk","tl","tn","to","tr","ts","tt","tw","ty","ug","uk","ur","us","uz","ve","vi","vo","wa","wo","xh","yi","yo","za","zh-cn","zh-hk","zh-mo","zh-ro","zh-sg","zh-tw","zh","zu"],
|
||||
["comick.io"],
|
||||
"https://comick.io/static/icons/unicorn-64.png")
|
||||
{
|
||||
this.downloadClient = new HttpDownloadClient();
|
||||
}
|
||||
|
||||
public override (Manga, MangaConnectorId<Manga>)[] SearchManga(string mangaSearchName)
|
||||
{
|
||||
Log.Info($"Searching Obj: {mangaSearchName}");
|
||||
|
||||
List<string> slugs = new();
|
||||
int page = 1;
|
||||
while(page < 50)
|
||||
{
|
||||
string requestUrl = $"https://api.comick.fun/v1.0/search/?type=comic&t=false&limit=100&showall=true&" +
|
||||
$"page={page}&q={mangaSearchName}";
|
||||
|
||||
RequestResult result = downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||
if ((int)result.statusCode < 200 || (int)result.statusCode >= 300)
|
||||
{
|
||||
Log.Error("Request failed");
|
||||
return [];
|
||||
}
|
||||
|
||||
using StreamReader sr = new (result.result);
|
||||
JArray data = JArray.Parse(sr.ReadToEnd());
|
||||
|
||||
if (data.Count < 1)
|
||||
break;
|
||||
|
||||
slugs.AddRange(data.Select(token => token.Value<string>("slug")!));
|
||||
page++;
|
||||
}
|
||||
Log.Debug($"Search {mangaSearchName} yielded {slugs.Count} slugs. Requesting mangas now...");
|
||||
|
||||
|
||||
List<(Manga, MangaConnectorId<Manga>)> mangas = new ();
|
||||
foreach (string slug in slugs)
|
||||
{
|
||||
if(GetMangaFromId(slug) is { } entry)
|
||||
mangas.Add(entry);
|
||||
}
|
||||
|
||||
Log.Info($"Search {mangaSearchName} yielded {mangas.Count} results.");
|
||||
return mangas.ToArray();
|
||||
}
|
||||
|
||||
private readonly Regex _getSlugFromTitleRex = new(@"https?:\/\/comick\.io\/comic\/(.+)(?:\/.*)*");
|
||||
public override (Manga, MangaConnectorId<Manga>)? GetMangaFromUrl(string url)
|
||||
{
|
||||
Match m = _getSlugFromTitleRex.Match(url);
|
||||
return m.Groups[1].Success ? GetMangaFromId(m.Groups[1].Value) : null;
|
||||
}
|
||||
|
||||
public override (Manga, MangaConnectorId<Manga>)? GetMangaFromId(string mangaIdOnSite)
|
||||
{
|
||||
string requestUrl = $"https://api.comick.fun/comic/{mangaIdOnSite}";
|
||||
|
||||
RequestResult result = downloadClient.MakeRequest(requestUrl, RequestType.MangaInfo);
|
||||
if ((int)result.statusCode < 200 || (int)result.statusCode >= 300)
|
||||
{
|
||||
Log.Error("Request failed");
|
||||
return null;
|
||||
}
|
||||
using StreamReader sr = new (result.result);
|
||||
JToken data = JToken.Parse(sr.ReadToEnd());
|
||||
|
||||
return ParseMangaFromJToken(data);
|
||||
}
|
||||
|
||||
public override (Chapter, MangaConnectorId<Chapter>)[] GetChapters(MangaConnectorId<Manga> mangaConnectorId,
|
||||
string? language = null)
|
||||
{
|
||||
Log.Info($"Getting Chapters: {mangaConnectorId.IdOnConnectorSite}");
|
||||
List<(Chapter, MangaConnectorId<Chapter>)> chapters = new();
|
||||
int page = 1;
|
||||
while(page < 50)
|
||||
{
|
||||
string requestUrl = $"https://api.comick.fun/comic/{mangaConnectorId.IdOnConnectorSite}/chapters?limit=100&page={page}&lang={language}";
|
||||
|
||||
RequestResult result = downloadClient.MakeRequest(requestUrl, RequestType.MangaInfo);
|
||||
if ((int)result.statusCode < 200 || (int)result.statusCode >= 300)
|
||||
{
|
||||
Log.Error("Request failed");
|
||||
return [];
|
||||
}
|
||||
|
||||
using StreamReader sr = new (result.result);
|
||||
JToken data = JToken.Parse(sr.ReadToEnd());
|
||||
JArray? chaptersArray = data["chapters"] as JArray;
|
||||
|
||||
if (chaptersArray is null || chaptersArray.Count < 1)
|
||||
break;
|
||||
|
||||
chapters.AddRange(ParseChapters(mangaConnectorId, chaptersArray));
|
||||
|
||||
page++;
|
||||
}
|
||||
|
||||
return chapters.ToArray();
|
||||
}
|
||||
|
||||
private readonly Regex _hidFromUrl = new(@"https?:\/\/comick\.io\/comic\/.+\/([^-]+).*");
|
||||
internal override string[] GetChapterImageUrls(MangaConnectorId<Chapter> chapterId)
|
||||
{
|
||||
|
||||
Log.Info($"Getting Chapter Image-Urls: {chapterId.Obj}");
|
||||
if (chapterId.WebsiteUrl is null || !UrlMatchesConnector(chapterId.WebsiteUrl))
|
||||
{
|
||||
Log.Debug($"Url is not for Connector. {chapterId.WebsiteUrl}");
|
||||
return [];
|
||||
}
|
||||
|
||||
Match m = _hidFromUrl.Match(chapterId.WebsiteUrl);
|
||||
if (!m.Groups[1].Success)
|
||||
{
|
||||
Log.Debug($"Could not parse hid from url. {chapterId.WebsiteUrl}");
|
||||
return [];
|
||||
}
|
||||
|
||||
string hid = m.Groups[1].Value;
|
||||
|
||||
string requestUrl = $"https://api.comick.fun/chapter/{hid}/get_images";
|
||||
RequestResult result = downloadClient.MakeRequest(requestUrl, RequestType.MangaInfo);
|
||||
if ((int)result.statusCode < 200 || (int)result.statusCode >= 300)
|
||||
{
|
||||
Log.Error("Request failed");
|
||||
return [];
|
||||
}
|
||||
|
||||
using StreamReader sr = new (result.result);
|
||||
JArray data = JArray.Parse(sr.ReadToEnd());
|
||||
|
||||
return data.Select(token =>
|
||||
{
|
||||
string url = $"https://meo.comick.pictures/{token.Value<string>("b2key")}";
|
||||
return url;
|
||||
}).ToArray();
|
||||
}
|
||||
|
||||
private (Manga manga, MangaConnectorId<Manga> id) ParseMangaFromJToken(JToken json)
|
||||
{
|
||||
string? hid = json["comic"]?.Value<string>("hid");
|
||||
string? slug = json["comic"]?.Value<string>("slug");
|
||||
string? name = json["comic"]?.Value<string>("title");
|
||||
string? description = json["comic"]?.Value<string>("desc");
|
||||
string? originalLanguage = json["comic"]?.Value<string>("country");
|
||||
string url = $"https://comick.io/comic/{slug}";
|
||||
string? coverName = json["comic"]?["md_covers"]?.First?.Value<string>("b2key");
|
||||
string coverUrl = $"https://meo.comick.pictures/{coverName}";
|
||||
int? releaseStatusStr = json["comic"]?.Value<int>("status");
|
||||
MangaReleaseStatus status = releaseStatusStr switch
|
||||
{
|
||||
1 => MangaReleaseStatus.Continuing,
|
||||
2 => MangaReleaseStatus.Completed,
|
||||
3 => MangaReleaseStatus.Cancelled,
|
||||
4 => MangaReleaseStatus.OnHiatus,
|
||||
_ => MangaReleaseStatus.Unreleased
|
||||
};
|
||||
uint? year = json["comic"]?.Value<uint?>("year");
|
||||
JArray? altTitlesArray = json["comic"]?["md_titles"] as JArray;
|
||||
//Cant let language be null, so fill with whatever.
|
||||
byte whatever = 0;
|
||||
List<AltTitle> altTitles = altTitlesArray?
|
||||
.Select(token => new AltTitle(token.Value<string>("lang")??whatever++.ToString(), token.Value<string>("title")!))
|
||||
.ToList()!;
|
||||
|
||||
JArray? authorsArray = json["authors"] as JArray;
|
||||
JArray? artistsArray = json["artists"] as JArray;
|
||||
List<Author> authors = authorsArray?.Concat(artistsArray!)
|
||||
.Select(token => new Author(token.Value<string>("name")!))
|
||||
.DistinctBy(a => a.Key)
|
||||
.ToList()!;
|
||||
|
||||
JArray? genreArray = json["comic"]?["md_comic_md_genres"] as JArray;
|
||||
List<MangaTag> tags = genreArray?
|
||||
.Select(token => new MangaTag(token["md_genres"]?.Value<string>("name")!))
|
||||
.ToList()!;
|
||||
|
||||
JArray? linksArray = json["comic"]?["links"] as JArray;
|
||||
List<Link> links = linksArray?
|
||||
.ToObject<Dictionary<string,string>>()?
|
||||
.Select(kv =>
|
||||
{
|
||||
string fullUrl = kv.Key switch
|
||||
{
|
||||
"al" => $"https://anilist.co/manga/{kv.Value}",
|
||||
"ap" => $"https://www.anime-planet.com/manga/{kv.Value}",
|
||||
"bw" => $"https://bookwalker.jp/{kv.Value}",
|
||||
"mu" => $"https://www.mangaupdates.com/series.html?id={kv.Value}",
|
||||
"nu" => $"https://www.novelupdates.com/series/{kv.Value}",
|
||||
"mal" => $"https://myanimelist.net/manga/{kv.Value}",
|
||||
_ => kv.Value
|
||||
};
|
||||
string key = kv.Key switch
|
||||
{
|
||||
"al" => "AniList",
|
||||
"ap" => "Anime Planet",
|
||||
"bw" => "BookWalker",
|
||||
"mu" => "Obj Updates",
|
||||
"nu" => "Novel Updates",
|
||||
"kt" => "Kitsu.io",
|
||||
"amz" => "Amazon",
|
||||
"ebj" => "eBookJapan",
|
||||
"mal" => "MyAnimeList",
|
||||
"cdj" => "CDJapan",
|
||||
_ => kv.Key
|
||||
};
|
||||
return new Link(key, fullUrl);
|
||||
}).ToList()!;
|
||||
|
||||
if(hid is null)
|
||||
throw new Exception("hid is null");
|
||||
if(slug is null)
|
||||
throw new Exception("slug is null");
|
||||
if(name is null)
|
||||
throw new Exception("name is null");
|
||||
|
||||
Manga manga = new (name, description??"", coverUrl, status, authors, tags, links, altTitles,
|
||||
year: year, originalLanguage: originalLanguage);
|
||||
return (manga, new MangaConnectorId<Manga>(manga, this, hid, url));
|
||||
}
|
||||
|
||||
private List<(Chapter, MangaConnectorId<Chapter>)> ParseChapters(MangaConnectorId<Manga> mcIdManga, JArray chaptersArray)
|
||||
{
|
||||
List<(Chapter, MangaConnectorId<Chapter>)> chapters = new ();
|
||||
foreach (JToken chapter in chaptersArray)
|
||||
{
|
||||
string? chapterNum = chapter.Value<string>("chap");
|
||||
string? volumeNumStr = chapter.Value<string>("vol");
|
||||
int? volumeNum = volumeNumStr is null ? null : int.Parse(volumeNumStr);
|
||||
string? title = chapter.Value<string>("title");
|
||||
string? hid = chapter.Value<string>("hid");
|
||||
string url = $"https://comick.io/comic/{mcIdManga.IdOnConnectorSite}/{hid}";
|
||||
|
||||
if(chapterNum is null || hid is null)
|
||||
continue;
|
||||
|
||||
Chapter ch = new (mcIdManga.Obj, chapterNum, volumeNum, title);
|
||||
|
||||
chapters.Add((ch, new (ch, this, hid, url)));
|
||||
}
|
||||
return chapters;
|
||||
}
|
||||
}
|
54
API/Schema/MangaContext/MangaConnectors/Global.cs
Normal file
54
API/Schema/MangaContext/MangaConnectors/Global.cs
Normal file
@ -0,0 +1,54 @@
|
||||
namespace API.Schema.MangaContext.MangaConnectors;
|
||||
|
||||
public class Global : MangaConnector
|
||||
{
|
||||
private MangaContext context { get; init; }
|
||||
public Global(MangaContext context) : base("Global", ["all"], [""], "")
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public override (Manga, MangaConnectorId<Manga>)[] SearchManga(string mangaSearchName)
|
||||
{
|
||||
//Get all enabled Connectors
|
||||
MangaConnector[] enabledConnectors = context.MangaConnectors.Where(c => c.Enabled && c.Name != "Global").ToArray();
|
||||
|
||||
//Create Task for each MangaConnector to search simultaneously
|
||||
Task<(Manga, MangaConnectorId<Manga>)[]>[] tasks =
|
||||
enabledConnectors.Select(c => new Task<(Manga, MangaConnectorId<Manga>)[]>(() => c.SearchManga(mangaSearchName))).ToArray();
|
||||
foreach (var task in tasks)
|
||||
task.Start();
|
||||
|
||||
//Wait for all tasks to finish
|
||||
do
|
||||
{
|
||||
Thread.Sleep(50);
|
||||
}while(tasks.Any(t => t.Status < TaskStatus.RanToCompletion));
|
||||
|
||||
//Concatenate all results into one
|
||||
(Manga, MangaConnectorId<Manga>)[] ret = tasks.Select(t => t.IsCompletedSuccessfully ? t.Result : []).ToArray().SelectMany(i => i).ToArray();
|
||||
return ret;
|
||||
}
|
||||
|
||||
public override (Manga, MangaConnectorId<Manga>)? GetMangaFromUrl(string url)
|
||||
{
|
||||
MangaConnector? mc = context.MangaConnectors.ToArray().FirstOrDefault(c => c.UrlMatchesConnector(url));
|
||||
return mc?.GetMangaFromUrl(url) ?? null;
|
||||
}
|
||||
|
||||
public override (Manga, MangaConnectorId<Manga>)? GetMangaFromId(string mangaIdOnSite)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public override (Chapter, MangaConnectorId<Chapter>)[] GetChapters(MangaConnectorId<Manga> manga,
|
||||
string? language = null)
|
||||
{
|
||||
return manga.MangaConnector.GetChapters(manga, language);
|
||||
}
|
||||
|
||||
internal override string[] GetChapterImageUrls(MangaConnectorId<Chapter> chapterId)
|
||||
{
|
||||
return chapterId.MangaConnector.GetChapterImageUrls(chapterId);
|
||||
}
|
||||
}
|
75
API/Schema/MangaContext/MangaConnectors/MangaConnector.cs
Normal file
75
API/Schema/MangaContext/MangaConnectors/MangaConnector.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.RegularExpressions;
|
||||
using API.MangaDownloadClients;
|
||||
using log4net;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace API.Schema.MangaContext.MangaConnectors;
|
||||
|
||||
[PrimaryKey("Name")]
|
||||
public abstract class MangaConnector(string name, string[] supportedLanguages, string[] baseUris, string iconUrl)
|
||||
{
|
||||
[JsonIgnore]
|
||||
[NotMapped]
|
||||
internal DownloadClient downloadClient { get; init; } = null!;
|
||||
|
||||
[JsonIgnore]
|
||||
[NotMapped]
|
||||
protected ILog Log { get; init; } = LogManager.GetLogger(name);
|
||||
|
||||
[StringLength(32)]
|
||||
[Required]
|
||||
public string Name { get; init; } = name;
|
||||
[StringLength(8)]
|
||||
[Required]
|
||||
public string[] SupportedLanguages { get; init; } = supportedLanguages;
|
||||
[StringLength(2048)]
|
||||
[Required]
|
||||
public string IconUrl { get; init; } = iconUrl;
|
||||
[StringLength(256)]
|
||||
[Required]
|
||||
public string[] BaseUris { get; init; } = baseUris;
|
||||
[Required]
|
||||
public bool Enabled { get; internal set; } = true;
|
||||
|
||||
public abstract (Manga, MangaConnectorId<Manga>)[] SearchManga(string mangaSearchName);
|
||||
|
||||
public abstract (Manga, MangaConnectorId<Manga>)? GetMangaFromUrl(string url);
|
||||
|
||||
public abstract (Manga, MangaConnectorId<Manga>)? GetMangaFromId(string mangaIdOnSite);
|
||||
|
||||
public abstract (Chapter, MangaConnectorId<Chapter>)[] GetChapters(MangaConnectorId<Manga> mangaId,
|
||||
string? language = null);
|
||||
|
||||
internal abstract string[] GetChapterImageUrls(MangaConnectorId<Chapter> chapterId);
|
||||
|
||||
public bool UrlMatchesConnector(string url) => BaseUris.Any(baseUri => Regex.IsMatch(url, "https?://" + baseUri + "/.*"));
|
||||
|
||||
internal string? SaveCoverImageToCache(MangaConnectorId<Manga> mangaId, int retries = 3)
|
||||
{
|
||||
if(retries < 0)
|
||||
return null;
|
||||
|
||||
Regex urlRex = new (@"https?:\/\/((?:[a-zA-Z0-9-]+\.)+[a-zA-Z0-9]+)\/(?:.+\/)*(.+\.([a-zA-Z]+))");
|
||||
//https?:\/\/[a-zA-Z0-9-]+\.([a-zA-Z0-9-]+\.[a-zA-Z0-9]+)\/(?:.+\/)*(.+\.([a-zA-Z]+)) for only second level domains
|
||||
Match match = urlRex.Match(mangaId.Obj.CoverUrl);
|
||||
string filename = $"{match.Groups[1].Value}-{mangaId.Key}.{match.Groups[3].Value}";
|
||||
string saveImagePath = Path.Join(TrangaSettings.coverImageCache, filename);
|
||||
|
||||
if (File.Exists(saveImagePath))
|
||||
return saveImagePath;
|
||||
|
||||
RequestResult coverResult = downloadClient.MakeRequest(mangaId.Obj.CoverUrl, RequestType.MangaCover, $"https://{match.Groups[1].Value}");
|
||||
if ((int)coverResult.statusCode < 200 || (int)coverResult.statusCode >= 300)
|
||||
return SaveCoverImageToCache(mangaId, --retries);
|
||||
|
||||
using MemoryStream ms = new();
|
||||
coverResult.result.CopyTo(ms);
|
||||
Directory.CreateDirectory(TrangaSettings.coverImageCache);
|
||||
File.WriteAllBytes(saveImagePath, ms.ToArray());
|
||||
|
||||
return saveImagePath;
|
||||
}
|
||||
}
|
338
API/Schema/MangaContext/MangaConnectors/MangaDex.cs
Normal file
338
API/Schema/MangaContext/MangaConnectors/MangaDex.cs
Normal file
@ -0,0 +1,338 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using API.MangaDownloadClients;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace API.Schema.MangaContext.MangaConnectors;
|
||||
|
||||
public class MangaDex : MangaConnector
|
||||
{
|
||||
//https://api.mangadex.org/docs/3-enumerations/#language-codes--localization
|
||||
//https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes
|
||||
//https://gist.github.com/Josantonius/b455e315bc7f790d14b136d61d9ae469
|
||||
public MangaDex() : base("MangaDex",
|
||||
["en","pt","pt-br","it","de","ru","aa","ab","ae","af","ak","am","an","ar-ae","ar-bh","ar-dz","ar-eg","ar-iq","ar-jo","ar-kw","ar-lb","ar-ly","ar-ma","ar-om","ar-qa","ar-sa","ar-sy","ar-tn","ar-ye","ar","as","av","ay","az","ba","be","bg","bh","bi","bm","bn","bo","br","bs","ca","ce","ch","co","cr","cs","cu","cv","cy","da","de-at","de-ch","de-de","de-li","de-lu","div","dv","dz","ee","el","en-au","en-bz","en-ca","en-cb","en-gb","en-ie","en-jm","en-nz","en-ph","en-tt","en-us","en-za","en-zw","eo","es-ar","es-bo","es-cl","es-co","es-cr","es-do","es-ec","es-es","es-gt","es-hn","es-la","es-mx","es-ni","es-pa","es-pe","es-pr","es-py","es-sv","es-us","es-uy","es-ve","es","et","eu","fa","ff","fi","fj","fo","fr-be","fr-ca","fr-ch","fr-fr","fr-lu","fr-mc","fr","fy","ga","gd","gl","gn","gu","gv","ha","he","hi","ho","hr-ba","hr-hr","hr","ht","hu","hy","hz","ia","id","ie","ig","ii","ik","in","io","is","it-ch","it-it","iu","iw","ja","ja-ro","ji","jv","jw","ka","kg","ki","kj","kk","kl","km","kn","ko","ko-ro","kr","ks","ku","kv","kw","ky","kz","la","lb","lg","li","ln","lo","ls","lt","lu","lv","mg","mh","mi","mk","ml","mn","mo","mr","ms-bn","ms-my","ms","mt","my","na","nb","nd","ne","ng","nl-be","nl-nl","nl","nn","no","nr","ns","nv","ny","oc","oj","om","or","os","pa","pi","pl","ps","pt-pt","qu-bo","qu-ec","qu-pe","qu","rm","rn","ro","rw","sa","sb","sc","sd","se-fi","se-no","se-se","se","sg","sh","si","sk","sl","sm","sn","so","sq","sr-ba","sr-sp","sr","ss","st","su","sv-fi","sv-se","sv","sw","sx","syr","ta","te","tg","th","ti","tk","tl","tn","to","tr","ts","tt","tw","ty","ug","uk","ur","us","uz","ve","vi","vo","wa","wo","xh","yi","yo","za","zh-cn","zh-hk","zh-mo","zh-ro","zh-sg","zh-tw","zh","zu"],
|
||||
["mangadex.org"],
|
||||
"https://mangadex.org/favicon.ico")
|
||||
{
|
||||
this.downloadClient = new HttpDownloadClient();
|
||||
}
|
||||
|
||||
private const int Limit = 100;
|
||||
public override (Manga, MangaConnectorId<Manga>)[] SearchManga(string mangaSearchName)
|
||||
{
|
||||
Log.Info($"Searching Obj: {mangaSearchName}");
|
||||
List<(Manga, MangaConnectorId<Manga>)> mangas = new ();
|
||||
|
||||
int offset = 0;
|
||||
int total = int.MaxValue;
|
||||
while(offset < total)
|
||||
{
|
||||
string requestUrl =
|
||||
$"https://api.mangadex.org/manga?limit={Limit}&offset={offset}&title={mangaSearchName}" +
|
||||
$"&contentRating%5B%5D=safe&contentRating%5B%5D=suggestive&contentRating%5B%5D=erotica" +
|
||||
$"&includes%5B%5D=manga&includes%5B%5D=cover_art&includes%5B%5D=author&includes%5B%5D=artist&includes%5B%5D=tag'";
|
||||
offset += Limit;
|
||||
|
||||
RequestResult result = downloadClient.MakeRequest(requestUrl, RequestType.MangaDexFeed);
|
||||
if ((int)result.statusCode < 200 || (int)result.statusCode >= 300)
|
||||
{
|
||||
Log.Error("Request failed");
|
||||
return [];
|
||||
}
|
||||
|
||||
using StreamReader sr = new (result.result);
|
||||
JObject jObject = JObject.Parse(sr.ReadToEnd());
|
||||
|
||||
if (jObject.Value<string>("result") != "ok")
|
||||
{
|
||||
JArray? errors = jObject["errors"] as JArray;
|
||||
Log.Error($"Request failed: {string.Join(',', errors?.Select(e => e.Value<string>("title")) ?? [])}");
|
||||
return [];
|
||||
}
|
||||
|
||||
total = jObject.Value<int>("total");
|
||||
|
||||
JArray? data = jObject.Value<JArray>("data");
|
||||
if (data is null)
|
||||
{
|
||||
Log.Error("Data was null");
|
||||
return [];
|
||||
}
|
||||
|
||||
mangas.AddRange(data.Select(ParseMangaFromJToken));
|
||||
}
|
||||
|
||||
Log.Info($"Search {mangaSearchName} yielded {mangas.Count} results.");
|
||||
return mangas.ToArray();
|
||||
}
|
||||
|
||||
private static readonly Regex GetMangaIdFromUrl = new(@"https?:\/\/mangadex\.org\/title\/([a-z0-9-]+)\/?.*");
|
||||
public override (Manga, MangaConnectorId<Manga>)? GetMangaFromUrl(string url)
|
||||
{
|
||||
Log.Info($"Getting Obj: {url}");
|
||||
if (!UrlMatchesConnector(url))
|
||||
{
|
||||
Log.Debug($"Url is not for Connector. {url}");
|
||||
return null;
|
||||
}
|
||||
|
||||
Match match = GetMangaIdFromUrl.Match(url);
|
||||
if (!match.Success || !match.Groups[1].Success)
|
||||
{
|
||||
Log.Debug($"Url is not for Connector (Could not retrieve id). {url}");
|
||||
return null;
|
||||
}
|
||||
string id = match.Groups[1].Value;
|
||||
|
||||
return GetMangaFromId(id);
|
||||
}
|
||||
|
||||
public override (Manga, MangaConnectorId<Manga>)? GetMangaFromId(string mangaIdOnSite)
|
||||
{
|
||||
Log.Info($"Getting Obj: {mangaIdOnSite}");
|
||||
string requestUrl =
|
||||
$"https://api.mangadex.org/manga/{mangaIdOnSite}" +
|
||||
$"?includes%5B%5D=manga&includes%5B%5D=cover_art&includes%5B%5D=author&includes%5B%5D=artist&includes%5B%5D=tag'";
|
||||
|
||||
RequestResult result = downloadClient.MakeRequest(requestUrl, RequestType.MangaDexFeed);
|
||||
if ((int)result.statusCode < 200 || (int)result.statusCode >= 300)
|
||||
{
|
||||
Log.Error("Request failed");
|
||||
return null;
|
||||
}
|
||||
|
||||
using StreamReader sr = new (result.result);
|
||||
JObject jObject = JObject.Parse(sr.ReadToEnd());
|
||||
|
||||
if (jObject.Value<string>("result") != "ok")
|
||||
{
|
||||
JArray? errors = jObject["errors"] as JArray;
|
||||
Log.Error($"Request failed: {string.Join(',', errors?.Select(e => e.Value<string>("title")) ?? [])}");
|
||||
return null;
|
||||
}
|
||||
|
||||
JObject? data = jObject["data"] as JObject;
|
||||
if (data is null)
|
||||
{
|
||||
Log.Error("Data was null");
|
||||
return null;
|
||||
}
|
||||
|
||||
return ParseMangaFromJToken(data);
|
||||
}
|
||||
|
||||
public override (Chapter, MangaConnectorId<Chapter>)[] GetChapters(MangaConnectorId<Manga> manga, string? language = null)
|
||||
{
|
||||
Log.Info($"Getting Chapters: {manga.IdOnConnectorSite}");
|
||||
List<(Chapter, MangaConnectorId<Chapter>)> chapters = new ();
|
||||
|
||||
int offset = 0;
|
||||
int total = int.MaxValue;
|
||||
while(offset < total)
|
||||
{
|
||||
string requestUrl =
|
||||
$"https://api.mangadex.org/manga/{manga.IdOnConnectorSite}/feed?limit={Limit}&offset={offset}&" +
|
||||
$"translatedLanguage%5B%5D={language}&" +
|
||||
$"contentRating%5B%5D=safe&contentRating%5B%5D=suggestive&contentRating%5B%5D=erotica&includeFutureUpdates=0&includes%5B%5D=";
|
||||
offset += Limit;
|
||||
|
||||
RequestResult result = downloadClient.MakeRequest(requestUrl, RequestType.MangaDexFeed);
|
||||
if ((int)result.statusCode < 200 || (int)result.statusCode >= 300)
|
||||
{
|
||||
Log.Error("Request failed");
|
||||
return [];
|
||||
}
|
||||
|
||||
using StreamReader sr = new (result.result);
|
||||
JObject jObject = JObject.Parse(sr.ReadToEnd());
|
||||
|
||||
if (jObject.Value<string>("result") != "ok")
|
||||
{
|
||||
JArray? errors = jObject["errors"] as JArray;
|
||||
Log.Error($"Request failed: {string.Join(',', errors?.Select(e => e.Value<string>("title")) ?? [])}");
|
||||
return [];
|
||||
}
|
||||
|
||||
total = jObject.Value<int>("total");
|
||||
|
||||
JArray? data = jObject.Value<JArray>("data");
|
||||
if (data is null)
|
||||
{
|
||||
Log.Error("Data was null");
|
||||
return [];
|
||||
}
|
||||
|
||||
chapters.AddRange(data.Select(d => ParseChapterFromJToken(manga, d)));
|
||||
}
|
||||
|
||||
Log.Info($"Request for chapters for {manga.Obj.Name} yielded {chapters.Count} results.");
|
||||
return chapters.ToArray();
|
||||
}
|
||||
|
||||
private static readonly Regex GetChapterIdFromUrl = new(@"https?:\/\/mangadex\.org\/chapter\/([a-z0-9-]+)\/?.*");
|
||||
internal override string[] GetChapterImageUrls(MangaConnectorId<Chapter> chapterId)
|
||||
{
|
||||
Log.Info($"Getting Chapter Image-Urls: {chapterId.Obj}");
|
||||
if (chapterId.WebsiteUrl is null || !UrlMatchesConnector(chapterId.WebsiteUrl))
|
||||
{
|
||||
Log.Debug($"Url is not for Connector. {chapterId.WebsiteUrl}");
|
||||
return [];
|
||||
}
|
||||
|
||||
Match match = GetChapterIdFromUrl.Match(chapterId.WebsiteUrl);
|
||||
if (!match.Success || !match.Groups[1].Success)
|
||||
{
|
||||
Log.Debug($"Url is not for Connector (Could not retrieve id). {chapterId.WebsiteUrl}");
|
||||
return [];
|
||||
}
|
||||
|
||||
string id = match.Groups[1].Value;
|
||||
string requestUrl = $"https://api.mangadex.org/at-home/server/{id}";
|
||||
|
||||
RequestResult result = downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||
if ((int)result.statusCode < 200 || (int)result.statusCode >= 300)
|
||||
{
|
||||
Log.Error("Request failed");
|
||||
return [];
|
||||
}
|
||||
|
||||
using StreamReader sr = new (result.result);
|
||||
JObject jObject = JObject.Parse(sr.ReadToEnd());
|
||||
|
||||
if (jObject.Value<string>("result") != "ok")
|
||||
{
|
||||
JArray? errors = jObject["errors"] as JArray;
|
||||
Log.Error($"Request failed: {string.Join(',', errors?.Select(e => e.Value<string>("title")) ?? [])}");
|
||||
return [];
|
||||
}
|
||||
|
||||
string? baseUrl = jObject.Value<string>("baseUrl");
|
||||
JToken? chapterToken = jObject["chapter"];
|
||||
string? hash = chapterToken?.Value<string>("hash");
|
||||
JArray? data = chapterToken?["data"] as JArray;
|
||||
|
||||
if (baseUrl is null || hash is null || data is null)
|
||||
{
|
||||
Log.Error("Data was null");
|
||||
return [];
|
||||
}
|
||||
|
||||
IEnumerable<string> urls = data.Select(t => $"{baseUrl}/data/{hash}/{t.Value<string>()}");
|
||||
|
||||
return urls.ToArray();
|
||||
}
|
||||
|
||||
private (Manga manga, MangaConnectorId<Manga> id) ParseMangaFromJToken(JToken jToken)
|
||||
{
|
||||
string? id = jToken.Value<string>("id");
|
||||
if(id is null)
|
||||
throw new Exception("jToken was not in expected format");
|
||||
|
||||
JObject? attributes = jToken["attributes"] as JObject;
|
||||
if(attributes is null)
|
||||
throw new Exception("jToken was not in expected format");
|
||||
string? name = attributes["title"]?.Value<string>("en") ?? attributes["title"]?.First?.First?.Value<string>();
|
||||
string description = attributes["description"]?.Value<string>("en")??attributes["description"]?.First?.First?.Value<string>()??"";
|
||||
string? status = attributes["status"]?.Value<string>();
|
||||
uint? year = attributes["year"]?.Value<uint?>();
|
||||
string? originalLanguage = attributes["originalLanguage"]?.Value<string>();
|
||||
JArray? altTitlesJArray = attributes.TryGetValue("altTitles", out JToken? altTitlesArray) ? altTitlesArray as JArray : null;
|
||||
JArray? tagsJArray = attributes.TryGetValue("tags", out JToken? tagsArray) ? tagsArray as JArray : null;
|
||||
JArray? relationships = jToken["relationships"] as JArray;
|
||||
if (name is null || status is null || relationships is null)
|
||||
throw new Exception("jToken was not in expected format");
|
||||
|
||||
string? coverFileName = relationships.FirstOrDefault(r => r["type"]?.Value<string>() == "cover_art")?["attributes"]?.Value<string>("fileName");
|
||||
if(coverFileName is null)
|
||||
throw new Exception("jToken was not in expected format");
|
||||
|
||||
List<Link> links = attributes["links"]?
|
||||
.ToObject<Dictionary<string,string>>()?
|
||||
.Select(kv =>
|
||||
{
|
||||
//https://api.mangadex.org/docs/3-enumerations/#manga-links-data
|
||||
string url = kv.Key switch
|
||||
{
|
||||
"al" => $"https://anilist.co/manga/{kv.Value}",
|
||||
"ap" => $"https://www.anime-planet.com/manga/{kv.Value}",
|
||||
"bw" => $"https://bookwalker.jp/{kv.Value}",
|
||||
"mu" => $"https://www.mangaupdates.com/series.html?id={kv.Value}",
|
||||
"nu" => $"https://www.novelupdates.com/series/{kv.Value}",
|
||||
"mal" => $"https://myanimelist.net/manga/{kv.Value}",
|
||||
_ => kv.Value
|
||||
};
|
||||
string key = kv.Key switch
|
||||
{
|
||||
"al" => "AniList",
|
||||
"ap" => "Anime Planet",
|
||||
"bw" => "BookWalker",
|
||||
"mu" => "Obj Updates",
|
||||
"nu" => "Novel Updates",
|
||||
"kt" => "Kitsu.io",
|
||||
"amz" => "Amazon",
|
||||
"ebj" => "eBookJapan",
|
||||
"mal" => "MyAnimeList",
|
||||
"cdj" => "CDJapan",
|
||||
_ => kv.Key
|
||||
};
|
||||
return new Link(key, url);
|
||||
}).ToList()!;
|
||||
|
||||
List<AltTitle> altTitles = (altTitlesJArray??[])
|
||||
.Select(t =>
|
||||
{
|
||||
JObject? j = t as JObject;
|
||||
JProperty? p = j?.Properties().First();
|
||||
if (p is null)
|
||||
return null;
|
||||
return new AltTitle(p.Name, p.Value.ToString());
|
||||
}).Where(x => x is not null).ToList()!;
|
||||
|
||||
List<MangaTag> tags = (tagsJArray??[])
|
||||
.Where(t => t.Value<string>("type") == "tag")
|
||||
.Select(t => t["attributes"]?["name"]?.Value<string>("en")??t["attributes"]?["name"]?.First?.First?.Value<string>())
|
||||
.Select(str => str is not null ? new MangaTag(str) : null)
|
||||
.Where(x => x is not null).ToList()!;
|
||||
|
||||
List<Author> authors = relationships
|
||||
.Where(r => r["type"]?.Value<string>() == "author")
|
||||
.Select(t => t["attributes"]?.Value<string>("name"))
|
||||
.Select(str => str is not null ? new Author(str) : null)
|
||||
.Where(x => x is not null).ToList()!;
|
||||
|
||||
|
||||
MangaReleaseStatus releaseStatus = status switch
|
||||
{
|
||||
"completed" => MangaReleaseStatus.Completed,
|
||||
"ongoing" => MangaReleaseStatus.Continuing,
|
||||
"cancelled" => MangaReleaseStatus.Cancelled,
|
||||
"hiatus" => MangaReleaseStatus.OnHiatus,
|
||||
_ => MangaReleaseStatus.Unreleased
|
||||
};
|
||||
string websiteUrl = $"https://mangadex.org/title/{id}";
|
||||
string coverUrl = $"https://uploads.mangadex.org/covers/{id}/{coverFileName}";
|
||||
|
||||
Manga manga = new Manga(name, description, coverUrl, releaseStatus, authors, tags, links,altTitles,
|
||||
null, 0f, year, originalLanguage);
|
||||
return (manga, new MangaConnectorId<Manga>(manga, this, id, websiteUrl));
|
||||
}
|
||||
|
||||
private (Chapter chapter, MangaConnectorId<Chapter> id) ParseChapterFromJToken(MangaConnectorId<Manga> mcIdManga, JToken jToken)
|
||||
{
|
||||
string? id = jToken.Value<string>("id");
|
||||
JToken? attributes = jToken["attributes"];
|
||||
string? chapterStr = attributes?.Value<string>("chapter");
|
||||
string? volumeStr = attributes?.Value<string>("volume");
|
||||
int? volumeNumber = null;
|
||||
string? title = attributes?.Value<string>("title");
|
||||
|
||||
if(id is null || chapterStr is null)
|
||||
throw new Exception("jToken was not in expected format");
|
||||
if(volumeStr is not null)
|
||||
volumeNumber = int.Parse(volumeStr);
|
||||
|
||||
string websiteUrl = $"https://mangadex.org/chapter/{id}";
|
||||
Chapter chapter = new (mcIdManga.Obj, chapterStr, volumeNumber, title);
|
||||
return (chapter, new MangaConnectorId<Chapter>(chapter, this, id, websiteUrl));
|
||||
}
|
||||
}
|
134
API/Schema/MangaContext/MangaContext.cs
Normal file
134
API/Schema/MangaContext/MangaContext.cs
Normal file
@ -0,0 +1,134 @@
|
||||
using API.Schema.MangaContext.MangaConnectors;
|
||||
using API.Schema.MangaContext.MetadataFetchers;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Schema.MangaContext;
|
||||
|
||||
public class MangaContext(DbContextOptions<MangaContext> options) : TrangaBaseContext<MangaContext>(options)
|
||||
{
|
||||
public DbSet<MangaConnector> MangaConnectors { get; set; }
|
||||
public DbSet<Manga> Mangas { get; set; }
|
||||
public DbSet<FileLibrary> FileLibraries { get; set; }
|
||||
public DbSet<Chapter> Chapters { get; set; }
|
||||
public DbSet<Author> Authors { get; set; }
|
||||
public DbSet<MangaTag> Tags { get; set; }
|
||||
public DbSet<MangaConnectorId<Manga>> MangaConnectorToManga { get; set; }
|
||||
public DbSet<MangaConnectorId<Chapter>> MangaConnectorToChapter { get; set; }
|
||||
public DbSet<MetadataEntry> MetadataEntries { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
//MangaConnector Types
|
||||
modelBuilder.Entity<MangaConnector>()
|
||||
.HasDiscriminator(c => c.Name)
|
||||
.HasValue<Global>("Global")
|
||||
.HasValue<MangaDex>("MangaDex")
|
||||
.HasValue<ComickIo>("ComickIo");
|
||||
|
||||
//Manga has many Chapters
|
||||
modelBuilder.Entity<Manga>()
|
||||
.HasMany<Chapter>(m => m.Chapters)
|
||||
.WithOne(c => c.ParentManga)
|
||||
.HasForeignKey(c => c.ParentMangaId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
modelBuilder.Entity<Manga>()
|
||||
.Navigation(m => m.Chapters)
|
||||
.EnableLazyLoading();
|
||||
modelBuilder.Entity<Chapter>()
|
||||
.Navigation(c => c.ParentManga)
|
||||
.EnableLazyLoading();
|
||||
//Chapter has MangaConnectorIds
|
||||
modelBuilder.Entity<Chapter>()
|
||||
.HasMany<MangaConnectorId<Chapter>>(c => c.MangaConnectorIds)
|
||||
.WithOne(id => id.Obj)
|
||||
.HasForeignKey(id => id.ObjId)
|
||||
.OnDelete(DeleteBehavior.NoAction);
|
||||
modelBuilder.Entity<MangaConnectorId<Chapter>>()
|
||||
.HasOne<MangaConnector>(id => id.MangaConnector)
|
||||
.WithMany()
|
||||
.HasForeignKey(id => id.MangaConnectorName)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
modelBuilder.Entity<MangaConnectorId<Chapter>>()
|
||||
.Navigation(entry => entry.MangaConnector)
|
||||
.EnableLazyLoading();
|
||||
//Manga owns MangaAltTitles
|
||||
modelBuilder.Entity<Manga>()
|
||||
.OwnsMany<AltTitle>(m => m.AltTitles)
|
||||
.WithOwner();
|
||||
modelBuilder.Entity<Manga>()
|
||||
.Navigation(m => m.AltTitles)
|
||||
.AutoInclude();
|
||||
//Manga owns Links
|
||||
modelBuilder.Entity<Manga>()
|
||||
.OwnsMany<Link>(m => m.Links)
|
||||
.WithOwner();
|
||||
modelBuilder.Entity<Manga>()
|
||||
.Navigation(m => m.Links)
|
||||
.AutoInclude();
|
||||
//Manga has many Tags associated with many Obj
|
||||
modelBuilder.Entity<Manga>()
|
||||
.HasMany<MangaTag>(m => m.MangaTags)
|
||||
.WithMany()
|
||||
.UsingEntity("MangaTagToManga",
|
||||
l=> l.HasOne(typeof(MangaTag)).WithMany().HasForeignKey("MangaTagIds").HasPrincipalKey(nameof(MangaTag.Tag)),
|
||||
r => r.HasOne(typeof(Manga)).WithMany().HasForeignKey("MangaIds").HasPrincipalKey(nameof(Manga.Key)),
|
||||
j => j.HasKey("MangaTagIds", "MangaIds")
|
||||
);
|
||||
modelBuilder.Entity<Manga>()
|
||||
.Navigation(m => m.MangaTags)
|
||||
.AutoInclude();
|
||||
//Manga has many Authors associated with many Obj
|
||||
modelBuilder.Entity<Manga>()
|
||||
.HasMany<Author>(m => m.Authors)
|
||||
.WithMany()
|
||||
.UsingEntity("AuthorToManga",
|
||||
l=> l.HasOne(typeof(Author)).WithMany().HasForeignKey("AuthorIds").HasPrincipalKey(nameof(Author.Key)),
|
||||
r => r.HasOne(typeof(Manga)).WithMany().HasForeignKey("MangaIds").HasPrincipalKey(nameof(Manga.Key)),
|
||||
j => j.HasKey("AuthorIds", "MangaIds")
|
||||
);
|
||||
modelBuilder.Entity<Manga>()
|
||||
.Navigation(m => m.Authors)
|
||||
.AutoInclude();
|
||||
//Manga has many MangaIds
|
||||
modelBuilder.Entity<Manga>()
|
||||
.HasMany<MangaConnectorId<Manga>>(m => m.MangaConnectorIds)
|
||||
.WithOne(id => id.Obj)
|
||||
.HasForeignKey(id => id.ObjId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
modelBuilder.Entity<Manga>()
|
||||
.Navigation(m => m.MangaConnectorIds)
|
||||
.EnableLazyLoading();
|
||||
modelBuilder.Entity<MangaConnectorId<Manga>>()
|
||||
.HasOne<MangaConnector>(id => id.MangaConnector)
|
||||
.WithMany()
|
||||
.HasForeignKey(id => id.MangaConnectorName)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
modelBuilder.Entity<MangaConnectorId<Manga>>()
|
||||
.Navigation(entry => entry.MangaConnector)
|
||||
.EnableLazyLoading();
|
||||
|
||||
|
||||
//FileLibrary has many Mangas
|
||||
modelBuilder.Entity<FileLibrary>()
|
||||
.HasMany<Manga>()
|
||||
.WithOne(m => m.Library)
|
||||
.HasForeignKey(m => m.LibraryId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
modelBuilder.Entity<Manga>()
|
||||
.Navigation(m => m.Library)
|
||||
.EnableLazyLoading();
|
||||
|
||||
modelBuilder.Entity<MetadataFetcher>()
|
||||
.HasDiscriminator<string>(nameof(MetadataEntry))
|
||||
.HasValue<MyAnimeList>(nameof(MyAnimeList));
|
||||
//MetadataEntry
|
||||
modelBuilder.Entity<MetadataEntry>()
|
||||
.HasOne<Manga>(entry => entry.Manga)
|
||||
.WithMany()
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
modelBuilder.Entity<MetadataEntry>()
|
||||
.HasOne<MetadataFetcher>(entry => entry.MetadataFetcher)
|
||||
.WithMany()
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
17
API/Schema/MangaContext/MangaTag.cs
Normal file
17
API/Schema/MangaContext/MangaTag.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Schema.MangaContext;
|
||||
|
||||
[PrimaryKey("Tag")]
|
||||
public class MangaTag(string tag)
|
||||
{
|
||||
[StringLength(64)]
|
||||
[Required]
|
||||
public string Tag { get; init; } = tag;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Tag}";
|
||||
}
|
||||
}
|
35
API/Schema/MangaContext/MetadataFetchers/MetadataEntry.cs
Normal file
35
API/Schema/MangaContext/MetadataFetchers/MetadataEntry.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace API.Schema.MangaContext.MetadataFetchers;
|
||||
|
||||
[PrimaryKey("Name", "Identifier")]
|
||||
public class MetadataEntry
|
||||
{
|
||||
[JsonIgnore]
|
||||
public Manga Manga { get; init; } = null!;
|
||||
public string MangaId { get; init; }
|
||||
[JsonIgnore]
|
||||
public MetadataFetcher MetadataFetcher { get; init; } = null!;
|
||||
public string MetadataFetcherName { get; init; }
|
||||
public string Identifier { get; init; }
|
||||
|
||||
public MetadataEntry(MetadataFetcher fetcher, Manga manga, string identifier)
|
||||
{
|
||||
this.Manga = manga;
|
||||
this.MangaId = manga.Key;
|
||||
this.MetadataFetcher = fetcher;
|
||||
this.MetadataFetcherName = fetcher.Name;
|
||||
this.Identifier = identifier;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EFCORE only!!!!
|
||||
/// </summary>
|
||||
internal MetadataEntry(string mangaId, string identifier, string metadataFetcherName)
|
||||
{
|
||||
this.MangaId = mangaId;
|
||||
this.Identifier = identifier;
|
||||
this.MetadataFetcherName = metadataFetcherName;
|
||||
}
|
||||
}
|
35
API/Schema/MangaContext/MetadataFetchers/MetadataFetcher.cs
Normal file
35
API/Schema/MangaContext/MetadataFetchers/MetadataFetcher.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Schema.MangaContext.MetadataFetchers;
|
||||
|
||||
[PrimaryKey("Name")]
|
||||
public abstract class MetadataFetcher
|
||||
{
|
||||
// ReSharper disable once EntityFramework.ModelValidation.UnlimitedStringLength
|
||||
public string Name { get; init; }
|
||||
|
||||
protected MetadataFetcher()
|
||||
{
|
||||
this.Name = this.GetType().Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EFCORE ONLY!!!
|
||||
/// </summary>
|
||||
internal MetadataFetcher(string name)
|
||||
{
|
||||
this.Name = name;
|
||||
}
|
||||
|
||||
internal MetadataEntry CreateMetadataEntry(Manga manga, string identifier) =>
|
||||
new (this, manga, identifier);
|
||||
|
||||
public abstract MetadataSearchResult[] SearchMetadataEntry(Manga manga);
|
||||
|
||||
public abstract MetadataSearchResult[] SearchMetadataEntry(string searchTerm);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the Manga linked in the MetadataEntry
|
||||
/// </summary>
|
||||
public abstract void UpdateMetadata(MetadataEntry metadataEntry, MangaContext dbContext);
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
namespace API.Schema.MangaContext.MetadataFetchers;
|
||||
|
||||
public record MetadataSearchResult(string Identifier, string Name, string Url, string? Description = null, string? CoverUrl = null);
|
78
API/Schema/MangaContext/MetadataFetchers/MyAnimeList.cs
Normal file
78
API/Schema/MangaContext/MetadataFetchers/MyAnimeList.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using JikanDotNet;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Schema.MangaContext.MetadataFetchers;
|
||||
|
||||
public class MyAnimeList : MetadataFetcher
|
||||
{
|
||||
private static readonly Jikan Jikan = new ();
|
||||
private static readonly Regex GetIdFromUrl = new(@"https?:\/\/myanimelist\.net\/manga\/([0-9]+)\/?.*");
|
||||
|
||||
public override MetadataSearchResult[] SearchMetadataEntry(Manga manga)
|
||||
{
|
||||
if (manga.Links.Any(link => link.LinkProvider.Equals("MyAnimeList", StringComparison.InvariantCultureIgnoreCase)))
|
||||
{
|
||||
string url = manga.Links.First(link => link.LinkProvider.Equals("MyAnimeList", StringComparison.InvariantCultureIgnoreCase)).LinkUrl;
|
||||
Match m = GetIdFromUrl.Match(url);
|
||||
if (m.Success && m.Groups[1].Success)
|
||||
{
|
||||
long id = long.Parse(m.Groups[1].Value);
|
||||
JikanDotNet.Manga data = Jikan.GetMangaAsync(id).Result.Data;
|
||||
return [new MetadataSearchResult(id.ToString(), data.Titles.First().Title, data.Url, data.Synopsis)];
|
||||
}
|
||||
}
|
||||
|
||||
return SearchMetadataEntry(manga.Name);
|
||||
}
|
||||
|
||||
public override MetadataSearchResult[] SearchMetadataEntry(string searchTerm)
|
||||
{
|
||||
|
||||
ICollection<JikanDotNet.Manga> resultData = Jikan.SearchMangaAsync(searchTerm).Result.Data;
|
||||
if (resultData.Count < 1)
|
||||
return [];
|
||||
return resultData.Select(data =>
|
||||
new MetadataSearchResult(data.MalId.ToString(), data.Titles.First().Title, data.Url, data.Synopsis))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the Manga linked in the MetadataEntry
|
||||
/// </summary>
|
||||
/// <param name="metadataEntry"></param>
|
||||
/// <param name="dbContext"></param>
|
||||
/// <exception cref="FormatException"></exception>
|
||||
/// <exception cref="DbUpdateException"></exception>
|
||||
public override void UpdateMetadata(MetadataEntry metadataEntry, MangaContext dbContext)
|
||||
{
|
||||
Manga dbManga = dbContext.Mangas.Find(metadataEntry.MangaId)!;
|
||||
MangaFull resultData;
|
||||
try
|
||||
{
|
||||
long id = long.Parse(metadataEntry.Identifier);
|
||||
resultData = Jikan.GetMangaFullDataAsync(id).Result.Data;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new FormatException("ID was not in correct format");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
dbManga.Name = resultData.Titles.First().Title;
|
||||
dbManga.Description = resultData.Synopsis;
|
||||
dbManga.AltTitles.Clear();
|
||||
dbManga.AltTitles = resultData.Titles.Select(t => new AltTitle(t.Type, t.Title)).ToList();
|
||||
dbManga.Authors.Clear();
|
||||
dbManga.Authors = resultData.Authors.Select(a => new Author(a.Name)).ToList();
|
||||
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
catch (DbUpdateException e)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
52
API/Schema/NotificationsContext/Notification.cs
Normal file
52
API/Schema/NotificationsContext/Notification.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Schema.NotificationsContext;
|
||||
|
||||
[PrimaryKey(nameof(Key))]
|
||||
public class Notification : Identifiable
|
||||
{
|
||||
[Required]
|
||||
public NotificationUrgency Urgency { get; init; }
|
||||
|
||||
[StringLength(128)]
|
||||
[Required]
|
||||
public string Title { get; init; }
|
||||
|
||||
[StringLength(512)]
|
||||
[Required]
|
||||
public string Message { get; init; }
|
||||
|
||||
[Required]
|
||||
public DateTime Date { get; init; }
|
||||
|
||||
public Notification(string title, string message = "", NotificationUrgency urgency = NotificationUrgency.Normal, DateTime? date = null)
|
||||
: base(TokenGen.CreateToken("Notification"))
|
||||
{
|
||||
this.Title = title;
|
||||
this.Message = message;
|
||||
this.Urgency = urgency;
|
||||
this.Date = date ?? DateTime.UtcNow;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EF ONLY!!!
|
||||
/// </summary>
|
||||
public Notification(string key, string title, string message, NotificationUrgency urgency, DateTime date)
|
||||
: base(key)
|
||||
{
|
||||
this.Title = title;
|
||||
this.Message = message;
|
||||
this.Urgency = urgency;
|
||||
this.Date = date;
|
||||
}
|
||||
|
||||
public override string ToString() => $"{base.ToString()} {Urgency} {Title}";
|
||||
}
|
||||
|
||||
public enum NotificationUrgency : byte
|
||||
{
|
||||
Low = 1,
|
||||
Normal = 3,
|
||||
High = 5
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
using log4net;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace API.Schema.NotificationsContext.NotificationConnectors;
|
||||
|
||||
[PrimaryKey("Name")]
|
||||
public class NotificationConnector(string name, string url, Dictionary<string, string> headers, string httpMethod, string body)
|
||||
{
|
||||
[StringLength(64)]
|
||||
[Required]
|
||||
public string Name { get; init; } = name;
|
||||
|
||||
[StringLength(2048)]
|
||||
[Required]
|
||||
[Url]
|
||||
public string Url { get; internal set; } = url;
|
||||
|
||||
[Required]
|
||||
public Dictionary<string, string> Headers { get; internal set; } = headers;
|
||||
|
||||
[StringLength(8)]
|
||||
[Required]
|
||||
public string HttpMethod { get; internal set; } = httpMethod;
|
||||
|
||||
[StringLength(4096)]
|
||||
[Required]
|
||||
public string Body { get; internal set; } = body;
|
||||
|
||||
[JsonIgnore]
|
||||
[NotMapped]
|
||||
private readonly HttpClient Client = new()
|
||||
{
|
||||
DefaultRequestHeaders = { { "User-Agent", TrangaSettings.userAgent } }
|
||||
};
|
||||
|
||||
[JsonIgnore]
|
||||
[NotMapped]
|
||||
protected ILog Log = LogManager.GetLogger(name);
|
||||
|
||||
public void SendNotification(string title, string notificationText)
|
||||
{
|
||||
Log.Info($"Sending notification: {title} - {notificationText}");
|
||||
CustomWebhookFormatProvider formatProvider = new (title, notificationText);
|
||||
string formattedUrl = string.Format(formatProvider, Url);
|
||||
string formattedBody = string.Format(formatProvider, Body, title, notificationText);
|
||||
Dictionary<string, string> formattedHeaders = Headers.ToDictionary(h => h.Key,
|
||||
h => string.Format(formatProvider, h.Value, title, notificationText));
|
||||
|
||||
HttpRequestMessage request = new(System.Net.Http.HttpMethod.Parse(HttpMethod), formattedUrl);
|
||||
foreach (var (key, value) in formattedHeaders)
|
||||
request.Headers.Add(key, value);
|
||||
request.Content = new StringContent(formattedBody);
|
||||
Log.Debug($"Request: {request}");
|
||||
|
||||
HttpResponseMessage response = Client.Send(request);
|
||||
Log.Debug($"Response status code: {response.StatusCode}");
|
||||
}
|
||||
|
||||
private class CustomWebhookFormatProvider(string title, string text) : IFormatProvider
|
||||
{
|
||||
public object? GetFormat(Type? formatType)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public string Format(string fmt, object arg, IFormatProvider provider)
|
||||
{
|
||||
if(arg.GetType() != typeof(string))
|
||||
return arg.ToString() ?? string.Empty;
|
||||
|
||||
StringBuilder sb = new StringBuilder(fmt);
|
||||
sb.Replace("%title", title);
|
||||
sb.Replace("%text", text);
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
10
API/Schema/NotificationsContext/NotificationsContext.cs
Normal file
10
API/Schema/NotificationsContext/NotificationsContext.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using API.Schema.NotificationsContext.NotificationConnectors;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Schema.NotificationsContext;
|
||||
|
||||
public class NotificationsContext(DbContextOptions<NotificationsContext> options) : TrangaBaseContext<NotificationsContext>(options)
|
||||
{
|
||||
public DbSet<NotificationConnector> NotificationConnectors { get; set; }
|
||||
public DbSet<Notification> Notifications { get; set; }
|
||||
}
|
38
API/Schema/TrangaBaseContext.cs
Normal file
38
API/Schema/TrangaBaseContext.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using log4net;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
|
||||
namespace API.Schema;
|
||||
|
||||
public abstract class TrangaBaseContext<T> : DbContext where T : DbContext
|
||||
{
|
||||
private ILog Log { get; init; }
|
||||
|
||||
protected TrangaBaseContext(DbContextOptions<T> options) : base(options)
|
||||
{
|
||||
this.Log = LogManager.GetLogger(GetType());
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
optionsBuilder.LogTo(s =>
|
||||
{
|
||||
Log.Debug(s);
|
||||
}, Array.Empty<string>(), LogLevel.Warning, DbContextLoggerOptions.Level | DbContextLoggerOptions.Category | DbContextLoggerOptions.UtcTime);
|
||||
}
|
||||
|
||||
internal async Task<(bool success, string? exceptionMessage)> Sync()
|
||||
{
|
||||
try
|
||||
{
|
||||
await this.SaveChangesAsync();
|
||||
return (true, null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(null, e);
|
||||
return (false, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
37
API/TokenGen.cs
Normal file
37
API/TokenGen.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace API;
|
||||
|
||||
public static class TokenGen
|
||||
{
|
||||
private const int MinimumLength = 16;
|
||||
private const int MaximumLength = 64;
|
||||
private const string Chars = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
|
||||
public static string CreateToken(Type t, params string[] identifiers) => CreateToken(t.Name, identifiers);
|
||||
|
||||
public static string CreateToken(string prefix, params string[] identifiers)
|
||||
{
|
||||
if (prefix.Length + 1 >= MaximumLength - MinimumLength)
|
||||
throw new ArgumentException("Prefix to long to create Token of meaningful length.");
|
||||
|
||||
int tokenLength = MaximumLength - prefix.Length - 1;
|
||||
|
||||
if (identifiers.Length == 0)
|
||||
{
|
||||
// No identifier, just create a random token
|
||||
byte[] rng = new byte[tokenLength];
|
||||
RandomNumberGenerator.Create().GetBytes(rng);
|
||||
string key = new(rng.Select(b => Chars[b % Chars.Length]).ToArray());
|
||||
key = string.Join('-', prefix, key);
|
||||
return key;
|
||||
}
|
||||
|
||||
// Identifier provided, create a token based on the identifier hashed
|
||||
byte[] hash = MD5.HashData(Encoding.UTF8.GetBytes(string.Join("", identifiers)));
|
||||
string token = Convert.ToHexStringLower(hash);
|
||||
|
||||
return string.Join('-', prefix, token);
|
||||
}
|
||||
}
|
102
API/Tranga.cs
Normal file
102
API/Tranga.cs
Normal file
@ -0,0 +1,102 @@
|
||||
using API.Schema.MangaContext.MetadataFetchers;
|
||||
using API.Workers;
|
||||
using log4net;
|
||||
using log4net.Config;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API;
|
||||
|
||||
public static class Tranga
|
||||
{
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
private const string TRANGA =
|
||||
"\n\n" +
|
||||
" _______ v2\n" +
|
||||
"|_ _|.----..---.-..-----..-----..---.-.\n" +
|
||||
" | | | _|| _ || || _ || _ |\n" +
|
||||
" |___| |__| |___._||__|__||___ ||___._|\n" +
|
||||
" |_____| \n\n";
|
||||
|
||||
public static Thread PeriodicWorkerStarterThread { get; } = new (WorkerStarter);
|
||||
private static readonly ILog Log = LogManager.GetLogger(typeof(Tranga));
|
||||
internal static readonly MetadataFetcher[] MetadataFetchers = [new MyAnimeList()];
|
||||
|
||||
internal static void StartLogger()
|
||||
{
|
||||
BasicConfigurator.Configure();
|
||||
Log.Info("Logger Configured.");
|
||||
Log.Info(TRANGA);
|
||||
}
|
||||
|
||||
internal static HashSet<BaseWorker> Workers { get; private set; } = new ();
|
||||
public static void AddWorker(BaseWorker worker) => Workers.Add(worker);
|
||||
public static void AddWorkers(IEnumerable<BaseWorker> workers)
|
||||
{
|
||||
foreach (BaseWorker baseWorker in workers)
|
||||
{
|
||||
AddWorker(baseWorker);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void StopWorker(BaseWorker worker) => RemoveWorker(worker);
|
||||
|
||||
public static void RemoveWorker(BaseWorker removeWorker)
|
||||
{
|
||||
IEnumerable<BaseWorker> baseWorkers = Workers.Where(w => w.DependenciesAndSelf.Any(worker => worker == removeWorker));
|
||||
|
||||
foreach (BaseWorker worker in baseWorkers)
|
||||
{
|
||||
worker.Cancel();
|
||||
Workers.Remove(worker);
|
||||
if (RunningWorkers.ContainsKey(worker))
|
||||
{
|
||||
worker.Cancel();
|
||||
RunningWorkers.Remove(worker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly Dictionary<BaseWorker, Task<BaseWorker[]>> RunningWorkers = new();
|
||||
public static BaseWorker[] GetRunningWorkers() => RunningWorkers.Keys.ToArray();
|
||||
private static readonly HashSet<BaseWorker> StartWorkers = new();
|
||||
private static void WorkerStarter(object? serviceProviderObj)
|
||||
{
|
||||
Log.Info("WorkerStarter Thread running.");
|
||||
if (serviceProviderObj is null)
|
||||
{
|
||||
Log.Error("serviceProviderObj is null");
|
||||
return;
|
||||
}
|
||||
IServiceProvider serviceProvider = (IServiceProvider)serviceProviderObj;
|
||||
|
||||
while (true)
|
||||
{
|
||||
CheckRunningWorkers();
|
||||
|
||||
foreach (BaseWorker worker in StartWorkers)
|
||||
{
|
||||
if (worker is BaseWorkerWithContext<DbContext> scopedWorker)
|
||||
scopedWorker.SetScope(serviceProvider.CreateScope());
|
||||
RunningWorkers.Add(worker, worker.DoWork());
|
||||
}
|
||||
Thread.Sleep(TrangaSettings.workCycleTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckRunningWorkers()
|
||||
{
|
||||
KeyValuePair<BaseWorker, Task<BaseWorker[]>>[] done = RunningWorkers.Where(kv => kv.Value.IsCompleted).ToArray();
|
||||
Log.Info($"Done: {done.Length}");
|
||||
Log.Debug(string.Join("\n", done.Select(d => d.ToString())));
|
||||
foreach ((BaseWorker worker, Task<BaseWorker[]> task) in done)
|
||||
{
|
||||
RunningWorkers.Remove(worker);
|
||||
foreach (BaseWorker newWorker in task.Result)
|
||||
StartWorkers.Add(newWorker);
|
||||
task.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
internal static void MarkWorkerForStart(BaseWorker worker) => StartWorkers.Add(worker);
|
||||
}
|
188
API/TrangaSettings.cs
Normal file
188
API/TrangaSettings.cs
Normal file
@ -0,0 +1,188 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using API.MangaDownloadClients;
|
||||
using API.Schema.NotificationsContext;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace API;
|
||||
|
||||
public static class TrangaSettings
|
||||
{
|
||||
public static string downloadLocation { get; private set; } = (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/Obj" : Path.Join(Directory.GetCurrentDirectory(), "Downloads"));
|
||||
public static string workingDirectory { get; private set; } = Path.Join(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/usr/share" : Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "tranga-api");
|
||||
[JsonIgnore]
|
||||
internal static readonly string DefaultUserAgent = $"Tranga/2.0 ({Enum.GetName(Environment.OSVersion.Platform)}; {(Environment.Is64BitOperatingSystem ? "x64" : "")})";
|
||||
public static string userAgent { get; private set; } = DefaultUserAgent;
|
||||
public static int compression{ get; private set; } = 40;
|
||||
public static bool bwImages { get; private set; } = false;
|
||||
public static string flareSolverrUrl { get; private set; } = string.Empty;
|
||||
/// <summary>
|
||||
/// Placeholders:
|
||||
/// %M Obj Name
|
||||
/// %V Volume
|
||||
/// %C Chapter
|
||||
/// %T Title
|
||||
/// %A Author (first in list)
|
||||
/// %I Chapter Internal ID
|
||||
/// %i Obj Internal ID
|
||||
/// %Y Year (Obj)
|
||||
///
|
||||
/// ?_(...) replace _ with a value from above:
|
||||
/// Everything inside the braces will only be added if the value of %_ is not null
|
||||
/// </summary>
|
||||
public static string chapterNamingScheme { get; private set; } = "%M - ?V(Vol.%V )Ch.%C?T( - %T)";
|
||||
[JsonIgnore]
|
||||
public static string settingsFilePath => Path.Join(workingDirectory, "settings.json");
|
||||
[JsonIgnore]
|
||||
public static string coverImageCache => Path.Join(workingDirectory, "imageCache");
|
||||
public static bool aprilFoolsMode { get; private set; } = true;
|
||||
public static int workCycleTimeout { get; private set; } = 20000;
|
||||
[JsonIgnore]
|
||||
internal static readonly Dictionary<RequestType, int> DefaultRequestLimits = new ()
|
||||
{
|
||||
{RequestType.MangaInfo, 60},
|
||||
{RequestType.MangaDexFeed, 60},
|
||||
{RequestType.MangaDexImage, 60},
|
||||
{RequestType.MangaImage, 240},
|
||||
{RequestType.MangaCover, 60},
|
||||
{RequestType.Default, 60}
|
||||
};
|
||||
public static Dictionary<RequestType, int> requestLimits { get; private set; } = DefaultRequestLimits;
|
||||
|
||||
public static TimeSpan NotificationUrgencyDelay(NotificationUrgency urgency) => urgency switch
|
||||
{
|
||||
NotificationUrgency.High => TimeSpan.Zero,
|
||||
NotificationUrgency.Normal => TimeSpan.FromMinutes(5),
|
||||
NotificationUrgency.Low => TimeSpan.FromMinutes(10),
|
||||
_ => TimeSpan.FromHours(1)
|
||||
}; //TODO make this a setting?
|
||||
|
||||
public static void Load()
|
||||
{
|
||||
if(File.Exists(settingsFilePath))
|
||||
Deserialize(File.ReadAllText(settingsFilePath));
|
||||
else return;
|
||||
|
||||
Directory.CreateDirectory(downloadLocation);
|
||||
ExportSettings();
|
||||
}
|
||||
|
||||
public static void UpdateAprilFoolsMode(bool enabled)
|
||||
{
|
||||
aprilFoolsMode = enabled;
|
||||
ExportSettings();
|
||||
}
|
||||
|
||||
public static void UpdateCompressImages(int value)
|
||||
{
|
||||
compression = int.Clamp(value, 1, 100);
|
||||
ExportSettings();
|
||||
}
|
||||
|
||||
public static void UpdateBwImages(bool enabled)
|
||||
{
|
||||
bwImages = enabled;
|
||||
ExportSettings();
|
||||
}
|
||||
|
||||
public static void UpdateUserAgent(string? customUserAgent)
|
||||
{
|
||||
userAgent = customUserAgent ?? DefaultUserAgent;
|
||||
ExportSettings();
|
||||
}
|
||||
|
||||
public static void UpdateRequestLimit(RequestType requestType, int newLimit)
|
||||
{
|
||||
requestLimits[requestType] = newLimit;
|
||||
ExportSettings();
|
||||
}
|
||||
|
||||
public static void UpdateChapterNamingScheme(string namingScheme)
|
||||
{
|
||||
chapterNamingScheme = namingScheme;
|
||||
ExportSettings();
|
||||
}
|
||||
|
||||
public static void UpdateFlareSolverrUrl(string url)
|
||||
{
|
||||
flareSolverrUrl = url;
|
||||
ExportSettings();
|
||||
}
|
||||
|
||||
public static void ResetRequestLimits()
|
||||
{
|
||||
requestLimits = DefaultRequestLimits;
|
||||
ExportSettings();
|
||||
}
|
||||
|
||||
public static void ExportSettings()
|
||||
{
|
||||
if (File.Exists(settingsFilePath))
|
||||
{
|
||||
while(IsFileInUse(settingsFilePath))
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
else
|
||||
Directory.CreateDirectory(new FileInfo(settingsFilePath).DirectoryName!);
|
||||
File.WriteAllText(settingsFilePath, Serialize());
|
||||
}
|
||||
|
||||
internal static bool IsFileInUse(string filePath)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
return false;
|
||||
try
|
||||
{
|
||||
using FileStream stream = new (filePath, FileMode.Open, FileAccess.Read, FileShare.None);
|
||||
stream.Close();
|
||||
return false;
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static JObject AsJObject()
|
||||
{
|
||||
JObject jobj = new ();
|
||||
jobj.Add("downloadLocation", JToken.FromObject(downloadLocation));
|
||||
jobj.Add("workingDirectory", JToken.FromObject(workingDirectory));
|
||||
jobj.Add("userAgent", JToken.FromObject(userAgent));
|
||||
jobj.Add("aprilFoolsMode", JToken.FromObject(aprilFoolsMode));
|
||||
jobj.Add("requestLimits", JToken.FromObject(requestLimits));
|
||||
jobj.Add("compression", JToken.FromObject(compression));
|
||||
jobj.Add("bwImages", JToken.FromObject(bwImages));
|
||||
jobj.Add("workCycleTimeout", JToken.FromObject(workCycleTimeout));
|
||||
jobj.Add("chapterNamingScheme", JToken.FromObject(chapterNamingScheme));
|
||||
jobj.Add("flareSolverrUrl", JToken.FromObject(flareSolverrUrl));
|
||||
return jobj;
|
||||
}
|
||||
|
||||
public static string Serialize() => AsJObject().ToString();
|
||||
|
||||
public static void Deserialize(string serialized)
|
||||
{
|
||||
JObject jobj = JObject.Parse(serialized);
|
||||
if (jobj.TryGetValue("downloadLocation", out JToken? dl))
|
||||
downloadLocation = dl.Value<string>()!;
|
||||
if (jobj.TryGetValue("workingDirectory", out JToken? wd))
|
||||
workingDirectory = wd.Value<string>()!;
|
||||
if (jobj.TryGetValue("userAgent", out JToken? ua))
|
||||
userAgent = ua.Value<string>()!;
|
||||
if (jobj.TryGetValue("aprilFoolsMode", out JToken? afm))
|
||||
aprilFoolsMode = afm.Value<bool>()!;
|
||||
if (jobj.TryGetValue("requestLimits", out JToken? rl))
|
||||
requestLimits = rl.ToObject<Dictionary<RequestType, int>>()!;
|
||||
if (jobj.TryGetValue("compression", out JToken? ci))
|
||||
compression = ci.Value<int>()!;
|
||||
if (jobj.TryGetValue("bwImages", out JToken? bwi))
|
||||
bwImages = bwi.Value<bool>()!;
|
||||
if (jobj.TryGetValue("workCycleTimeout", out JToken? snjt))
|
||||
workCycleTimeout = snjt.Value<int>()!;
|
||||
if (jobj.TryGetValue("chapterNamingScheme", out JToken? cns))
|
||||
chapterNamingScheme = cns.Value<string>()!;
|
||||
if (jobj.TryGetValue("flareSolverrUrl", out JToken? fsu))
|
||||
flareSolverrUrl = fsu.Value<string>()!;
|
||||
}
|
||||
}
|
118
API/Workers/BaseWorker.cs
Normal file
118
API/Workers/BaseWorker.cs
Normal file
@ -0,0 +1,118 @@
|
||||
using API.Schema;
|
||||
using log4net;
|
||||
|
||||
namespace API.Workers;
|
||||
|
||||
public abstract class BaseWorker : Identifiable
|
||||
{
|
||||
/// <summary>
|
||||
/// Workers this Worker depends on being completed before running.
|
||||
/// </summary>
|
||||
public BaseWorker[] DependsOn { get; init; }
|
||||
/// <summary>
|
||||
/// Dependencies and dependencies of dependencies. See also <see cref="DependsOn"/>.
|
||||
/// </summary>
|
||||
public IEnumerable<BaseWorker> AllDependencies => DependsOn.Select(d => d.AllDependencies).SelectMany(x => x);
|
||||
/// <summary>
|
||||
/// <see cref="AllDependencies"/> and Self.
|
||||
/// </summary>
|
||||
public IEnumerable<BaseWorker> DependenciesAndSelf => AllDependencies.Append(this);
|
||||
/// <summary>
|
||||
/// <see cref="DependsOn"/> where <see cref="WorkerExecutionState"/> is less than Completed.
|
||||
/// </summary>
|
||||
public IEnumerable<BaseWorker> MissingDependencies => DependsOn.Where(d => d.State < WorkerExecutionState.Completed);
|
||||
public bool AllDependenciesFulfilled => DependsOn.All(d => d.State >= WorkerExecutionState.Completed);
|
||||
internal WorkerExecutionState State { get; private set; }
|
||||
private static readonly CancellationTokenSource CancellationTokenSource = new(TimeSpan.FromMinutes(10));
|
||||
protected ILog Log { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Stops worker, and marks as <see cref="WorkerExecutionState"/>.Cancelled
|
||||
/// </summary>
|
||||
public void Cancel()
|
||||
{
|
||||
Log.Debug($"Cancelled {this}");
|
||||
this.State = WorkerExecutionState.Cancelled;
|
||||
CancellationTokenSource.Cancel();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops worker, and marks as <see cref="WorkerExecutionState"/>.Failed
|
||||
/// </summary>
|
||||
protected void Fail()
|
||||
{
|
||||
Log.Debug($"Failed {this}");
|
||||
this.State = WorkerExecutionState.Failed;
|
||||
CancellationTokenSource.Cancel();
|
||||
}
|
||||
|
||||
public BaseWorker(IEnumerable<BaseWorker>? dependsOn = null)
|
||||
{
|
||||
this.DependsOn = dependsOn?.ToArray() ?? [];
|
||||
this.Log = LogManager.GetLogger(GetType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets States during worker-run.
|
||||
/// States:
|
||||
/// <list type="bullet">
|
||||
/// <item><see cref="WorkerExecutionState"/>.Waiting when waiting for <see cref="MissingDependencies"/></item>
|
||||
/// <item><see cref="WorkerExecutionState"/>.Running when running</item>
|
||||
/// <item><see cref="WorkerExecutionState"/>.Completed after finished</item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <list type="bullet">
|
||||
/// <item>If <see cref="BaseWorker"/> has <see cref="MissingDependencies"/>, missing dependencies.</item>
|
||||
/// <item>If <see cref="MissingDependencies"/> are <see cref="WorkerExecutionState"/>.Running, itself after waiting for dependencies.</item>
|
||||
/// <item>If <see cref="BaseWorker"/> has run, additional <see cref="BaseWorker"/>.</item>
|
||||
/// </list>
|
||||
/// </returns>
|
||||
public Task<BaseWorker[]> DoWork()
|
||||
{
|
||||
Log.Debug($"Checking {this}");
|
||||
this.State = WorkerExecutionState.Waiting;
|
||||
|
||||
BaseWorker[] missingDependenciesThatNeedStarting = MissingDependencies.Where(d => d.State < WorkerExecutionState.Waiting).ToArray();
|
||||
if(missingDependenciesThatNeedStarting.Any())
|
||||
return new Task<BaseWorker[]>(() => missingDependenciesThatNeedStarting);
|
||||
|
||||
if (MissingDependencies.Any())
|
||||
return new Task<BaseWorker[]>(WaitForDependencies);
|
||||
|
||||
Log.Info($"Running {this}");
|
||||
DateTime startTime = DateTime.UtcNow;
|
||||
Task<BaseWorker[]> task = new (DoWorkInternal, CancellationTokenSource.Token);
|
||||
task.GetAwaiter().OnCompleted(() =>
|
||||
{
|
||||
DateTime endTime = DateTime.UtcNow;
|
||||
Log.Info($"Completed {this}\n\t{endTime.Subtract(startTime).TotalMilliseconds} ms");
|
||||
this.State = WorkerExecutionState.Completed;
|
||||
});
|
||||
task.Start();
|
||||
this.State = WorkerExecutionState.Running;
|
||||
return task;
|
||||
}
|
||||
|
||||
protected abstract BaseWorker[] DoWorkInternal();
|
||||
|
||||
private BaseWorker[] WaitForDependencies()
|
||||
{
|
||||
Log.Info($"Waiting for {MissingDependencies.Count()} Dependencies {this}:\n\t{string.Join("\n\t", MissingDependencies.Select(d => d.ToString()))}");
|
||||
while (CancellationTokenSource.IsCancellationRequested == false && MissingDependencies.Any())
|
||||
{
|
||||
Thread.Sleep(TrangaSettings.workCycleTimeout);
|
||||
}
|
||||
return [this];
|
||||
}
|
||||
}
|
||||
|
||||
public enum WorkerExecutionState
|
||||
{
|
||||
Failed = 0,
|
||||
Cancelled = 32,
|
||||
Created = 64,
|
||||
Waiting = 96,
|
||||
Running = 128,
|
||||
Completed = 192
|
||||
}
|
18
API/Workers/BaseWorkerWithContext.cs
Normal file
18
API/Workers/BaseWorkerWithContext.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System.Configuration;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Workers;
|
||||
|
||||
public abstract class BaseWorkerWithContext<T>(IEnumerable<BaseWorker>? dependsOn = null) : BaseWorker(dependsOn) where T : DbContext
|
||||
{
|
||||
protected T DbContext = null!;
|
||||
public void SetScope(IServiceScope scope) => DbContext = scope.ServiceProvider.GetRequiredService<T>();
|
||||
|
||||
/// <exception cref="ConfigurationErrorsException">Scope has not been set. <see cref="SetScope"/></exception>
|
||||
public new Task<BaseWorker[]> DoWork()
|
||||
{
|
||||
if (DbContext is null)
|
||||
throw new ConfigurationErrorsException("Scope has not been set.");
|
||||
return base.DoWork();
|
||||
}
|
||||
}
|
9
API/Workers/IPeriodic.cs
Normal file
9
API/Workers/IPeriodic.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace API.Workers;
|
||||
|
||||
public interface IPeriodic
|
||||
{
|
||||
protected DateTime LastExecution { get; set; }
|
||||
public TimeSpan Interval { get; set; }
|
||||
public DateTime NextExecution => LastExecution.Add(Interval);
|
||||
public bool IsDue => NextExecution <= DateTime.UtcNow;
|
||||
}
|
28
API/Workers/MaintenanceWorkers/CleanupMangaCoversWorker.cs
Normal file
28
API/Workers/MaintenanceWorkers/CleanupMangaCoversWorker.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using API.Schema.MangaContext;
|
||||
|
||||
namespace API.Workers.MaintenanceWorkers;
|
||||
|
||||
public class CleanupMangaCoversWorker(IEnumerable<BaseWorker>? dependsOn = null) : BaseWorkerWithContext<MangaContext>(dependsOn), IPeriodic
|
||||
{
|
||||
public DateTime LastExecution { get; set; } = DateTime.UtcNow;
|
||||
public TimeSpan Interval { get; set; } = TimeSpan.FromMinutes(60);
|
||||
|
||||
protected override BaseWorker[] DoWorkInternal()
|
||||
{
|
||||
Log.Info("Removing stale files...");
|
||||
if (!Directory.Exists(TrangaSettings.coverImageCache))
|
||||
return [];
|
||||
string[] usedFiles = DbContext.Mangas.Select(m => m.CoverFileNameInCache).Where(s => s != null).ToArray()!;
|
||||
string[] extraneousFiles = new DirectoryInfo(TrangaSettings.coverImageCache).GetFiles()
|
||||
.Where(f => usedFiles.Contains(f.FullName) == false)
|
||||
.Select(f => f.FullName)
|
||||
.ToArray();
|
||||
foreach (string path in extraneousFiles)
|
||||
{
|
||||
Log.Info($"Deleting {path}");
|
||||
File.Delete(path);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using API.Schema.MangaContext;
|
||||
namespace API.Workers;
|
||||
|
||||
public class UpdateChaptersDownloadedWorker(Manga manga, IEnumerable<BaseWorker>? dependsOn = null)
|
||||
: BaseWorkerWithContext<MangaContext>(dependsOn), IPeriodic
|
||||
{
|
||||
public DateTime LastExecution { get; set; } = DateTime.UtcNow;
|
||||
public TimeSpan Interval { get; set; } = TimeSpan.FromMinutes(60);
|
||||
protected override BaseWorker[] DoWorkInternal()
|
||||
{
|
||||
foreach (Chapter mangaChapter in manga.Chapters)
|
||||
{
|
||||
mangaChapter.Downloaded = mangaChapter.CheckDownloaded();
|
||||
}
|
||||
|
||||
DbContext.Sync();
|
||||
return [];
|
||||
}
|
||||
}
|
@ -0,0 +1,180 @@
|
||||
using System.IO.Compression;
|
||||
using System.Runtime.InteropServices;
|
||||
using API.MangaDownloadClients;
|
||||
using API.Schema.MangaContext;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Formats.Jpeg;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using SixLabors.ImageSharp.Processing.Processors.Binarization;
|
||||
using static System.IO.UnixFileMode;
|
||||
|
||||
namespace API.Workers;
|
||||
|
||||
public class DownloadChapterFromMangaconnectorWorker(Chapter chapter, IEnumerable<BaseWorker>? dependsOn = null)
|
||||
: BaseWorkerWithContext<MangaContext>(dependsOn)
|
||||
{
|
||||
protected override BaseWorker[] DoWorkInternal()
|
||||
{
|
||||
if (chapter.Downloaded)
|
||||
{
|
||||
Log.Info("Chapter was already downloaded.");
|
||||
return [];
|
||||
}
|
||||
|
||||
//TODO MangaConnector Selection
|
||||
MangaConnectorId<Chapter> mcId = chapter.MangaConnectorIds.First();
|
||||
|
||||
string[] imageUrls = mcId.MangaConnector.GetChapterImageUrls(mcId);
|
||||
if (imageUrls.Length < 1)
|
||||
{
|
||||
Log.Info($"No imageUrls for chapter {chapter}");
|
||||
return [];
|
||||
}
|
||||
string saveArchiveFilePath = chapter.FullArchiveFilePath;
|
||||
Log.Debug($"Chapter path: {saveArchiveFilePath}");
|
||||
|
||||
//Check if Publication Directory already exists
|
||||
string? directoryPath = Path.GetDirectoryName(saveArchiveFilePath);
|
||||
if (directoryPath is null)
|
||||
{
|
||||
Log.Error($"Directory path could not be found: {saveArchiveFilePath}");
|
||||
this.Fail();
|
||||
return [];
|
||||
}
|
||||
if (!Directory.Exists(directoryPath))
|
||||
{
|
||||
Log.Info($"Creating publication Directory: {directoryPath}");
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
Directory.CreateDirectory(directoryPath,
|
||||
UserRead | UserWrite | UserExecute | GroupRead | GroupWrite | GroupExecute );
|
||||
else
|
||||
Directory.CreateDirectory(directoryPath);
|
||||
}
|
||||
|
||||
if (File.Exists(saveArchiveFilePath)) //Don't download twice. Redownload
|
||||
{
|
||||
Log.Info($"Archive {saveArchiveFilePath} already existed, but deleting and re-downloading.");
|
||||
File.Delete(saveArchiveFilePath);
|
||||
}
|
||||
|
||||
//Create a temporary folder to store images
|
||||
string tempFolder = Directory.CreateTempSubdirectory("trangatemp").FullName;
|
||||
Log.Debug($"Created temp folder: {tempFolder}");
|
||||
|
||||
Log.Info($"Downloading images: {chapter}");
|
||||
int chapterNum = 0;
|
||||
//Download all Images to temporary Folder
|
||||
foreach (string imageUrl in imageUrls)
|
||||
{
|
||||
string extension = imageUrl.Split('.')[^1].Split('?')[0];
|
||||
string imagePath = Path.Join(tempFolder, $"{chapterNum++}.{extension}");
|
||||
bool status = DownloadImage(imageUrl, imagePath);
|
||||
if (status is false)
|
||||
{
|
||||
Log.Error($"Failed to download image: {imageUrl}");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
CopyCoverFromCacheToDownloadLocation(chapter.ParentManga);
|
||||
|
||||
Log.Debug($"Creating ComicInfo.xml {chapter}");
|
||||
File.WriteAllText(Path.Join(tempFolder, "ComicInfo.xml"), chapter.GetComicInfoXmlString());
|
||||
|
||||
Log.Debug($"Packaging images to archive {chapter}");
|
||||
//ZIP-it and ship-it
|
||||
ZipFile.CreateFromDirectory(tempFolder, saveArchiveFilePath);
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
File.SetUnixFileMode(saveArchiveFilePath, UserRead | UserWrite | UserExecute | GroupRead | GroupWrite | GroupExecute | OtherRead | OtherExecute);
|
||||
Directory.Delete(tempFolder, true); //Cleanup
|
||||
|
||||
chapter.Downloaded = true;
|
||||
DbContext.Sync();
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
private void ProcessImage(string imagePath)
|
||||
{
|
||||
if (!TrangaSettings.bwImages && TrangaSettings.compression == 100)
|
||||
{
|
||||
Log.Debug("No processing requested for image");
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Debug($"Processing image: {imagePath}");
|
||||
|
||||
try
|
||||
{
|
||||
using Image image = Image.Load(imagePath);
|
||||
if (TrangaSettings.bwImages)
|
||||
image.Mutate(i => i.ApplyProcessor(new AdaptiveThresholdProcessor()));
|
||||
File.Delete(imagePath);
|
||||
image.SaveAsJpeg(imagePath, new JpegEncoder()
|
||||
{
|
||||
Quality = TrangaSettings.compression
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e is UnknownImageFormatException or NotSupportedException)
|
||||
{
|
||||
//If the Image-Format is not processable by ImageSharp, we can't modify it.
|
||||
Log.Debug($"Unable to process {imagePath}: Not supported image format");
|
||||
}else if (e is InvalidImageContentException)
|
||||
{
|
||||
Log.Debug($"Unable to process {imagePath}: Invalid Content");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CopyCoverFromCacheToDownloadLocation(Manga manga)
|
||||
{
|
||||
//Check if Publication already has a Folder and cover
|
||||
string publicationFolder = manga.CreatePublicationFolder();
|
||||
DirectoryInfo dirInfo = new (publicationFolder);
|
||||
if (dirInfo.EnumerateFiles().Any(info => info.Name.Contains("cover", StringComparison.InvariantCultureIgnoreCase)))
|
||||
{
|
||||
Log.Debug($"Cover already exists at {publicationFolder}");
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO MangaConnector Selection
|
||||
MangaConnectorId<Manga> mcId = manga.MangaConnectorIds.First();
|
||||
|
||||
Log.Info($"Copying cover to {publicationFolder}");
|
||||
string? fileInCache = manga.CoverFileNameInCache ?? mcId.MangaConnector.SaveCoverImageToCache(mcId);
|
||||
if (fileInCache is null)
|
||||
{
|
||||
Log.Error($"File {fileInCache} does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
string newFilePath = Path.Join(publicationFolder, $"cover.{Path.GetFileName(fileInCache).Split('.')[^1]}" );
|
||||
File.Copy(fileInCache, newFilePath, true);
|
||||
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
File.SetUnixFileMode(newFilePath, GroupRead | GroupWrite | UserRead | UserWrite | OtherRead | OtherWrite);
|
||||
Log.Debug($"Copied cover from {fileInCache} to {newFilePath}");
|
||||
}
|
||||
|
||||
private bool DownloadImage(string imageUrl, string savePath)
|
||||
{
|
||||
HttpDownloadClient downloadClient = new();
|
||||
RequestResult requestResult = downloadClient.MakeRequest(imageUrl, RequestType.MangaImage);
|
||||
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
return false;
|
||||
if (requestResult.result == Stream.Null)
|
||||
return false;
|
||||
|
||||
FileStream fs = new (savePath, FileMode.Create, FileAccess.Write, FileShare.None);
|
||||
requestResult.result.CopyTo(fs);
|
||||
fs.Close();
|
||||
ProcessImage(savePath);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using API.Schema.MangaContext;
|
||||
using API.Schema.MangaContext.MangaConnectors;
|
||||
|
||||
namespace API.Workers;
|
||||
|
||||
public class DownloadCoverFromMangaconnectorWorker(MangaConnectorId<Manga> mcId, IEnumerable<BaseWorker>? dependsOn = null)
|
||||
: BaseWorkerWithContext<MangaContext>(dependsOn)
|
||||
{
|
||||
public MangaConnectorId<Manga> MangaConnectorId { get; init; } = mcId;
|
||||
protected override BaseWorker[] DoWorkInternal()
|
||||
{
|
||||
MangaConnector mangaConnector = MangaConnectorId.MangaConnector;
|
||||
Manga manga = MangaConnectorId.Obj;
|
||||
|
||||
manga.CoverFileNameInCache = mangaConnector.SaveCoverImageToCache(MangaConnectorId);
|
||||
|
||||
DbContext.Sync();
|
||||
return [];
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using API.Schema.MangaContext;
|
||||
using API.Schema.MangaContext.MangaConnectors;
|
||||
|
||||
namespace API.Workers;
|
||||
|
||||
public class RetrieveMangaChaptersFromMangaconnectorWorker(MangaConnectorId<Manga> mcId, string language, IEnumerable<BaseWorker>? dependsOn = null)
|
||||
: BaseWorkerWithContext<MangaContext>(dependsOn)
|
||||
{
|
||||
public MangaConnectorId<Manga> MangaConnectorId { get; init; } = mcId;
|
||||
protected override BaseWorker[] DoWorkInternal()
|
||||
{
|
||||
MangaConnector mangaConnector = MangaConnectorId.MangaConnector;
|
||||
Manga manga = MangaConnectorId.Obj;
|
||||
// This gets all chapters that are not downloaded
|
||||
(Chapter, MangaConnectorId<Chapter>)[] allChapters =
|
||||
mangaConnector.GetChapters(MangaConnectorId, language).DistinctBy(c => c.Item1.Key).ToArray();
|
||||
(Chapter, MangaConnectorId<Chapter>)[] newChapters = allChapters.Where(chapter =>
|
||||
manga.Chapters.Any(ch => chapter.Item1.Key == ch.Key && ch.Downloaded) == false).ToArray();
|
||||
Log.Info($"{manga.Chapters.Count} existing + {newChapters.Length} new chapters.");
|
||||
|
||||
foreach ((Chapter chapter, MangaConnectorId<Chapter> mcId) newChapter in newChapters)
|
||||
{
|
||||
manga.Chapters.Add(newChapter.chapter);
|
||||
DbContext.MangaConnectorToChapter.Add(newChapter.mcId);
|
||||
}
|
||||
|
||||
DbContext.Sync();
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
47
API/Workers/MoveFileOrFolderWorker.cs
Normal file
47
API/Workers/MoveFileOrFolderWorker.cs
Normal file
@ -0,0 +1,47 @@
|
||||
namespace API.Workers;
|
||||
|
||||
public class MoveFileOrFolderWorker(string toLocation, string fromLocation, IEnumerable<BaseWorker>? dependsOn = null)
|
||||
: BaseWorker(dependsOn)
|
||||
{
|
||||
public readonly string FromLocation = fromLocation;
|
||||
public readonly string ToLocation = toLocation;
|
||||
|
||||
protected override BaseWorker[] DoWorkInternal()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileInfo fi = new (FromLocation);
|
||||
if (!fi.Exists)
|
||||
{
|
||||
Log.Error($"File does not exist at {FromLocation}");
|
||||
return [];
|
||||
}
|
||||
|
||||
if (File.Exists(ToLocation))//Do not override existing
|
||||
{
|
||||
Log.Error($"File already exists at {ToLocation}");
|
||||
return [];
|
||||
}
|
||||
if(fi.Attributes.HasFlag(FileAttributes.Directory))
|
||||
MoveDirectory(fi, ToLocation);
|
||||
else
|
||||
MoveFile(fi, ToLocation);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
private void MoveDirectory(FileInfo from, string toLocation)
|
||||
{
|
||||
Directory.Move(from.FullName, toLocation);
|
||||
}
|
||||
|
||||
private void MoveFile(FileInfo from, string toLocation)
|
||||
{
|
||||
File.Move(from.FullName, toLocation);
|
||||
}
|
||||
}
|
18
API/Workers/MoveMangaLibraryWorker.cs
Normal file
18
API/Workers/MoveMangaLibraryWorker.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using API.Schema.MangaContext;
|
||||
|
||||
namespace API.Workers;
|
||||
|
||||
public class MoveMangaLibraryWorker(Manga manga, FileLibrary toLibrary, IServiceScope scope, IEnumerable<BaseWorker>? dependsOn = null)
|
||||
: BaseWorkerWithContext<MangaContext>(dependsOn)
|
||||
{
|
||||
protected override BaseWorker[] DoWorkInternal()
|
||||
{
|
||||
Dictionary<Chapter, string> oldPath = manga.Chapters.ToDictionary(c => c, c => c.FullArchiveFilePath);
|
||||
manga.Library = toLibrary;
|
||||
|
||||
if (DbContext.Sync().Result is { success: false })
|
||||
return [];
|
||||
|
||||
return manga.Chapters.Select(c => new MoveFileOrFolderWorker(c.FullArchiveFilePath, oldPath[c])).ToArray<BaseWorker>();
|
||||
}
|
||||
}
|
15
API/Workers/SendNotificationsWorker.cs
Normal file
15
API/Workers/SendNotificationsWorker.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using API.Schema.NotificationsContext;
|
||||
|
||||
namespace API.Workers;
|
||||
|
||||
public class SendNotificationsWorker(IEnumerable<BaseWorker>? dependsOn = null)
|
||||
: BaseWorkerWithContext<NotificationsContext>(dependsOn), IPeriodic
|
||||
{
|
||||
public DateTime LastExecution { get; set; } = DateTime.UtcNow;
|
||||
public TimeSpan Interval { get; set; } = TimeSpan.FromMinutes(1);
|
||||
protected override BaseWorker[] DoWorkInternal()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Default": "Error",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Default": "Error",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
BIN
DB-Layout.png
Normal file
BIN
DB-Layout.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
460
DB-Layout.uxf
Normal file
460
DB-Layout.uxf
Normal file
@ -0,0 +1,460 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<diagram program="umlet" version="15.1">
|
||||
<zoom_level>10</zoom_level>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>1160</x>
|
||||
<y>680</y>
|
||||
<w>100</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Manga</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>900</x>
|
||||
<y>680</y>
|
||||
<w>140</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>MangaConnector</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>500</x>
|
||||
<y>800</y>
|
||||
<w>80</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>/Job/</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>680</x>
|
||||
<y>800</y>
|
||||
<w>160</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>/JobWithDownload/</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>680</x>
|
||||
<y>680</y>
|
||||
<w>160</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>RetrieveChaptersJob
|
||||
</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>570</x>
|
||||
<y>810</y>
|
||||
<w>130</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<-</panel_attributes>
|
||||
<additional_attributes>10.0;10.0;110.0;10.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>750</x>
|
||||
<y>710</y>
|
||||
<w>30</w>
|
||||
<h>110</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<-</panel_attributes>
|
||||
<additional_attributes>10.0;90.0;10.0;10.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>1170</x>
|
||||
<y>710</y>
|
||||
<w>30</w>
|
||||
<h>230</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=-</panel_attributes>
|
||||
<additional_attributes>10.0;210.0;10.0;10.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>1030</x>
|
||||
<y>820</y>
|
||||
<w>150</w>
|
||||
<h>140</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=-</panel_attributes>
|
||||
<additional_attributes>130.0;120.0;70.0;120.0;70.0;10.0;10.0;10.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>960</x>
|
||||
<y>710</y>
|
||||
<w>30</w>
|
||||
<h>110</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=-</panel_attributes>
|
||||
<additional_attributes>10.0;90.0;10.0;10.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>830</x>
|
||||
<y>810</y>
|
||||
<w>90</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=-</panel_attributes>
|
||||
<additional_attributes>70.0;10.0;10.0;10.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>1410</x>
|
||||
<y>680</y>
|
||||
<w>100</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>FileLibrary</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>1250</x>
|
||||
<y>690</y>
|
||||
<w>180</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=-</panel_attributes>
|
||||
<additional_attributes>160.0;10.0;10.0;10.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>1410</x>
|
||||
<y>620</y>
|
||||
<w>100</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Link</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>1410</x>
|
||||
<y>560</y>
|
||||
<w>100</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Author</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>1410</x>
|
||||
<y>500</y>
|
||||
<w>100</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>MangaTag</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>1200</x>
|
||||
<y>510</y>
|
||||
<w>230</w>
|
||||
<h>190</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=-</panel_attributes>
|
||||
<additional_attributes>210.0;10.0;10.0;10.0;10.0;170.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>1230</x>
|
||||
<y>570</y>
|
||||
<w>200</w>
|
||||
<h>130</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=-</panel_attributes>
|
||||
<additional_attributes>180.0;10.0;10.0;10.0;10.0;110.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>1250</x>
|
||||
<y>630</y>
|
||||
<w>180</w>
|
||||
<h>70</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=-</panel_attributes>
|
||||
<additional_attributes>160.0;10.0;90.0;10.0;90.0;50.0;10.0;50.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>1410</x>
|
||||
<y>440</y>
|
||||
<w>100</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>AltTitle</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>1170</x>
|
||||
<y>450</y>
|
||||
<w>260</w>
|
||||
<h>250</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=-</panel_attributes>
|
||||
<additional_attributes>240.0;10.0;10.0;10.0;10.0;230.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>1380</x>
|
||||
<y>800</y>
|
||||
<w>160</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>MangaMetadataEntry</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>1230</x>
|
||||
<y>710</y>
|
||||
<w>170</w>
|
||||
<h>130</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=-</panel_attributes>
|
||||
<additional_attributes>150.0;110.0;10.0;110.0;10.0;10.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>1650</x>
|
||||
<y>800</y>
|
||||
<w>140</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>MetadataFetcher</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>1530</x>
|
||||
<y>810</y>
|
||||
<w>140</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=-</panel_attributes>
|
||||
<additional_attributes>120.0;10.0;10.0;10.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLUseCase</id>
|
||||
<coordinates>
|
||||
<x>1660</x>
|
||||
<y>680</y>
|
||||
<w>120</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Path</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>1500</x>
|
||||
<y>690</y>
|
||||
<w>180</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=-</panel_attributes>
|
||||
<additional_attributes>160.0;10.0;10.0;10.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>900</x>
|
||||
<y>800</y>
|
||||
<w>140</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>MangaConnectorID</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>1030</x>
|
||||
<y>690</y>
|
||||
<w>150</w>
|
||||
<h>140</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=-</panel_attributes>
|
||||
<additional_attributes>130.0;10.0;70.0;10.0;70.0;120.0;10.0;120.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>1160</x>
|
||||
<y>920</y>
|
||||
<w>100</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Chapter
|
||||
</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>460</x>
|
||||
<y>680</y>
|
||||
<w>160</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>UpdateChapters
|
||||
DownloadedJob</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>530</x>
|
||||
<y>710</y>
|
||||
<w>30</w>
|
||||
<h>110</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<-</panel_attributes>
|
||||
<additional_attributes>10.0;90.0;10.0;10.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>1970</x>
|
||||
<y>640</y>
|
||||
<w>110</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lw=2
|
||||
Komga</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>1970</x>
|
||||
<y>710</y>
|
||||
<w>110</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lw=2
|
||||
Kavita</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLPackage</id>
|
||||
<coordinates>
|
||||
<x>1930</x>
|
||||
<y>600</y>
|
||||
<w>190</w>
|
||||
<h>170</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Library</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>1770</x>
|
||||
<y>690</y>
|
||||
<w>180</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=-</panel_attributes>
|
||||
<additional_attributes>160.0;10.0;10.0;10.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>710</x>
|
||||
<y>910</y>
|
||||
<w>100</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>/Identifiable/</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>750</x>
|
||||
<y>830</y>
|
||||
<w>30</w>
|
||||
<h>100</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<-</panel_attributes>
|
||||
<additional_attributes>10.0;80.0;10.0;10.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>530</x>
|
||||
<y>830</y>
|
||||
<w>200</w>
|
||||
<h>120</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<-</panel_attributes>
|
||||
<additional_attributes>180.0;100.0;10.0;100.0;10.0;10.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>750</x>
|
||||
<y>930</y>
|
||||
<w>480</w>
|
||||
<h>110</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<-</panel_attributes>
|
||||
<additional_attributes>10.0;10.0;10.0;90.0;460.0;90.0;460.0;30.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>800</x>
|
||||
<y>670</y>
|
||||
<w>380</w>
|
||||
<h>280</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<-</panel_attributes>
|
||||
<additional_attributes>10.0;260.0;260.0;260.0;260.0;10.0;360.0;10.0</additional_attributes>
|
||||
</element>
|
||||
</diagram>
|
42
Dockerfile
Normal file
42
Dockerfile
Normal file
@ -0,0 +1,42 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
ARG DOTNET=9.0
|
||||
|
||||
FROM --platform=$TARGETPLATFORM mcr.microsoft.com/dotnet/aspnet:$DOTNET AS base
|
||||
WORKDIR /publish
|
||||
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
|
||||
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
|
||||
ENV XDG_CONFIG_HOME=/tmp/.chromium
|
||||
ENV XDG_CACHE_HOME=/tmp/.chromium
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y libx11-6 libx11-xcb1 libatk1.0-0 libgtk-3-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxrandr2 libgbm1 libpango-1.0-0 libcairo2 libasound2 libxshmfence1 libnss3 chromium \
|
||||
&& apt-get autopurge -y \
|
||||
&& apt-get autoclean -y
|
||||
|
||||
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:$DOTNET AS build-env
|
||||
WORKDIR /src
|
||||
|
||||
COPY Tranga.sln /src
|
||||
COPY API/API.csproj /src/API/API.csproj
|
||||
RUN dotnet restore /src/Tranga.sln
|
||||
|
||||
COPY . /src/
|
||||
RUN dotnet publish -c Release --property:OutputPath=/publish -maxcpucount:1
|
||||
|
||||
FROM --platform=$TARGETPLATFORM base AS runtime
|
||||
EXPOSE 6531
|
||||
ARG UNAME=tranga
|
||||
ARG UID=1000
|
||||
ARG GID=1000
|
||||
RUN groupadd -g $GID -o $UNAME \
|
||||
&& useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME \
|
||||
&& mkdir /usr/share/tranga-api \
|
||||
&& mkdir /Manga \
|
||||
&& chown 1000:1000 /usr/share/tranga-api \
|
||||
&& chown 1000:1000 /Manga
|
||||
USER $UNAME
|
||||
|
||||
WORKDIR /publish
|
||||
COPY --chown=1000:1000 --from=build-env /publish .
|
||||
USER 0
|
||||
ENTRYPOINT ["dotnet", "/publish/API.dll"]
|
||||
CMD [""]
|
@ -1,32 +0,0 @@
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Logging;
|
||||
|
||||
public class FileLogger : LoggerBase
|
||||
{
|
||||
private string logFilePath { get; }
|
||||
private const int MaxNumberOfLogFiles = 5;
|
||||
|
||||
public FileLogger(string logFilePath, TextWriter? stdOut, Encoding? encoding = null) : base (stdOut, encoding)
|
||||
{
|
||||
this.logFilePath = logFilePath;
|
||||
|
||||
//Remove oldest logfile if more than MaxNumberOfLogFiles
|
||||
string parentFolderPath = Path.GetDirectoryName(logFilePath)!;
|
||||
for (int fileCount = new DirectoryInfo(parentFolderPath).EnumerateFiles().Count(); fileCount > MaxNumberOfLogFiles - 1; fileCount--) //-1 because we create own logfile later
|
||||
File.Delete(new DirectoryInfo(parentFolderPath).EnumerateFiles().MinBy(file => file.LastWriteTime)!.FullName);
|
||||
}
|
||||
|
||||
protected override void Write(LogMessage logMessage)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.AppendAllText(logFilePath, logMessage.ToString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
stdOut?.WriteLine(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Logging;
|
||||
|
||||
public class FormattedConsoleLogger : LoggerBase
|
||||
{
|
||||
|
||||
public FormattedConsoleLogger(TextWriter? stdOut, Encoding? encoding = null) : base(stdOut, encoding)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Write(LogMessage message)
|
||||
{
|
||||
//Nothing to do yet
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
using System.Net.Mime;
|
||||
using System.Text;
|
||||
|
||||
namespace Logging;
|
||||
|
||||
public class Logger : TextWriter
|
||||
{
|
||||
public override Encoding Encoding { get; }
|
||||
public enum LoggerType
|
||||
{
|
||||
FileLogger,
|
||||
ConsoleLogger
|
||||
}
|
||||
|
||||
private FileLogger? _fileLogger;
|
||||
private FormattedConsoleLogger? _formattedConsoleLogger;
|
||||
private MemoryLogger _memoryLogger;
|
||||
private TextWriter? stdOut;
|
||||
|
||||
public Logger(LoggerType[] enabledLoggers, TextWriter? stdOut, Encoding? encoding, string? logFilePath)
|
||||
{
|
||||
this.Encoding = encoding ?? Encoding.ASCII;
|
||||
this.stdOut = stdOut ?? null;
|
||||
if (enabledLoggers.Contains(LoggerType.FileLogger) && logFilePath is not null)
|
||||
_fileLogger = new FileLogger(logFilePath, null, encoding);
|
||||
else
|
||||
{
|
||||
_fileLogger = null;
|
||||
throw new ArgumentException($"logFilePath can not be null for LoggerType {LoggerType.FileLogger}");
|
||||
}
|
||||
_formattedConsoleLogger = enabledLoggers.Contains(LoggerType.ConsoleLogger) ? new FormattedConsoleLogger(null, encoding) : null;
|
||||
_memoryLogger = new MemoryLogger(null, encoding);
|
||||
}
|
||||
|
||||
public void WriteLine(string caller, string? value)
|
||||
{
|
||||
value = value is null ? Environment.NewLine : string.Concat(value, Environment.NewLine);
|
||||
|
||||
Write(caller, value);
|
||||
}
|
||||
|
||||
public void Write(string caller, string? value)
|
||||
{
|
||||
if (value is null)
|
||||
return;
|
||||
|
||||
_fileLogger?.Write(caller, value);
|
||||
_formattedConsoleLogger?.Write(caller, value);
|
||||
|
||||
_memoryLogger.Write(caller, value);
|
||||
stdOut?.Write(value);
|
||||
}
|
||||
|
||||
public string[] Tail(uint? lines)
|
||||
{
|
||||
return _memoryLogger.Tail(lines);
|
||||
}
|
||||
|
||||
public string[] GetNewLines()
|
||||
{
|
||||
return _memoryLogger.GetNewLines();
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Logging;
|
||||
|
||||
public abstract class LoggerBase : TextWriter
|
||||
{
|
||||
public override Encoding Encoding { get; }
|
||||
protected TextWriter? stdOut { get; }
|
||||
|
||||
public LoggerBase(TextWriter? stdOut, Encoding? encoding = null)
|
||||
{
|
||||
this.Encoding = encoding ?? Encoding.ASCII;
|
||||
this.stdOut = stdOut;
|
||||
}
|
||||
|
||||
public void WriteLine(string caller, string? value)
|
||||
{
|
||||
value = value is null ? Environment.NewLine : string.Join(value, Environment.NewLine);
|
||||
|
||||
LogMessage message = new LogMessage(DateTime.Now, caller, value);
|
||||
|
||||
Write(message);
|
||||
}
|
||||
|
||||
public void Write(string caller, string? value)
|
||||
{
|
||||
if (value is null)
|
||||
return;
|
||||
|
||||
LogMessage message = new LogMessage(DateTime.Now, caller, value);
|
||||
|
||||
stdOut?.Write(message.ToString());
|
||||
|
||||
Write(message);
|
||||
}
|
||||
|
||||
protected abstract void Write(LogMessage message);
|
||||
|
||||
public class LogMessage
|
||||
{
|
||||
public DateTime logTime { get; }
|
||||
public string caller { get; }
|
||||
public string value { get; }
|
||||
|
||||
public LogMessage(DateTime now, string caller, string value)
|
||||
{
|
||||
this.logTime = now;
|
||||
this.caller = caller;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string dateTimeString = $"{logTime.ToShortDateString()} {logTime.ToLongTimeString()}";
|
||||
return $"[{dateTimeString}] {caller.Split(new char[]{'.','+'}).Last(),15} | {value}";
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
@ -1,57 +0,0 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Logging;
|
||||
|
||||
public class MemoryLogger : LoggerBase
|
||||
{
|
||||
private readonly SortedList<DateTime, LogMessage> _logMessages = new();
|
||||
private int _lastLogMessageIndex = 0;
|
||||
|
||||
public MemoryLogger(TextWriter? stdOut, Encoding? encoding = null) : base(stdOut, encoding)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Write(LogMessage value)
|
||||
{
|
||||
_logMessages.Add(value.logTime, value);
|
||||
}
|
||||
|
||||
public string[] GetLogMessage()
|
||||
{
|
||||
return Tail(Convert.ToUInt32(_logMessages.Count));
|
||||
}
|
||||
|
||||
public string[] Tail(uint? length)
|
||||
{
|
||||
int retLength;
|
||||
if (length is null || length > _logMessages.Count)
|
||||
retLength = _logMessages.Count;
|
||||
else
|
||||
retLength = (int)length;
|
||||
|
||||
string[] ret = new string[retLength];
|
||||
|
||||
for (int retIndex = 0; retIndex < ret.Length; retIndex++)
|
||||
{
|
||||
ret[retIndex] = _logMessages.GetValueAtIndex(_logMessages.Count - retLength + retIndex).ToString();
|
||||
}
|
||||
|
||||
_lastLogMessageIndex = _logMessages.Count - 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public string[] GetNewLines()
|
||||
{
|
||||
int logMessageCount = _logMessages.Count;
|
||||
string[] ret = new string[logMessageCount - _lastLogMessageIndex];
|
||||
|
||||
for (int retIndex = 0; retIndex < ret.Length; retIndex++)
|
||||
{
|
||||
ret[retIndex] = _logMessages.GetValueAtIndex(_lastLogMessageIndex + retIndex).ToString();
|
||||
}
|
||||
|
||||
_lastLogMessageIndex = logMessageCount;
|
||||
return ret;
|
||||
}
|
||||
}
|
208
README.md
208
README.md
@ -1,140 +1,196 @@
|
||||
<!-- PROJECT SHIELDS -->
|
||||
<!--
|
||||
*** I'm using markdown "reference style" links for readability.
|
||||
*** Reference links are enclosed in brackets [ ] instead of parentheses ( ).
|
||||
*** See the bottom of this document for the declaration of the reference variables
|
||||
*** for contributors-url, forks-url, etc. This is an optional, concise syntax you may use.
|
||||
*** https://www.markdownguide.org/basic-syntax/#reference-style-links
|
||||
-->
|
||||
|
||||
<!-- PROJECT LOGO -->
|
||||
<br />
|
||||
<span id="readme-top"></span>
|
||||
<div align="center">
|
||||
|
||||
<h3 align="center">Tranga</h3>
|
||||
|
||||
<h1 align="center">Tranga v2</h1>
|
||||
<p align="center">
|
||||
Automatic Manga and Metadata downloader
|
||||
</p>
|
||||
|
||||

|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th><img alt="GitHub branch check runs" src="https://img.shields.io/github/check-runs/c9glax/tranga/master?label=master"></th>
|
||||
<td><img alt="Last Run" src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapi.github.com%2Frepos%2Fc9glax%2Ftranga%2Factions%2Fworkflows%2Fdocker-image-master.yml%2Fruns%3Fper_page%3D1&query=workflow_runs%5B0%5D.created_at&label=Last%20Run"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><img alt="GitHub branch check runs" src="https://img.shields.io/github/check-runs/c9glax/tranga/cuttingedge?label=cuttingedge"></th>
|
||||
<td><img alt="Last Run" src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapi.github.com%2Frepos%2Fc9glax%2Ftranga%2Factions%2Fworkflows%2Fdocker-image-cuttingedge.yml%2Fruns%3Fper_page%3D1&query=workflow_runs%5B0%5D.created_at&label=Last%20Run"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><img alt="GitHub branch check runs" src="https://img.shields.io/github/check-runs/c9glax/tranga/postgres-Server-V2?label=postgres-Server-V2"></th>
|
||||
<td><img alt="Last Run" src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapi.github.com%2Frepos%2Fc9glax%2Ftranga%2Factions%2Fworkflows%2Fdocker-image-serverv2.yml%2Fruns%3Fper_page%3D1&query=workflow_runs%5B0%5D.created_at&label=Last%20Run"></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- TABLE OF CONTENTS -->
|
||||
<details>
|
||||
<summary>Table of Contents</summary>
|
||||
<ol>
|
||||
<li>
|
||||
<a href="#about-the-project">About The Project</a>
|
||||
<ul>
|
||||
<li><a href="#built-with">Built With</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#getting-started">Getting Started</a>
|
||||
<ul>
|
||||
<li><a href="#prerequisites">Prerequisites</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#roadmap">Roadmap</a></li>
|
||||
<li><a href="#contributing">Contributing</a></li>
|
||||
<li><a href="#license">License</a></li>
|
||||
<li><a href="#acknowledgments">Acknowledgments</a></li>
|
||||
</ol>
|
||||
</details>
|
||||
|
||||
|
||||
|
||||
<!-- ABOUT THE PROJECT -->
|
||||
## About The Project
|
||||
|
||||
Tranga can download Chapters and Metadata from Scanlation sites such as
|
||||
Tranga can download Chapters and Metadata from "Scanlation" sites such as
|
||||
|
||||
- [MangaDex.org](https://mangadex.org/)
|
||||
- [MangaDex.org](https://mangadex.org/) (Multilingual)
|
||||
- [Comick.io](https://comick.io/)
|
||||
- ❓ Open an [issue](https://github.com/C9Glax/tranga/issues/new?assignees=&labels=New+Connector&projects=&template=new_connector.yml&title=%5BNew+Connector%5D%3A+)
|
||||
|
||||
and automatically start updates in [Komga](https://komga.org/) to import them.
|
||||
and trigger a library-scan with [Komga](https://komga.org/) and [Kavita](https://www.kavitareader.com/).
|
||||
Notifications can be sent to your devices using [Gotify](https://gotify.net/), [LunaSea](https://www.lunasea.app/) or [Ntfy](https://ntfy.sh/
|
||||
), or any other service that can use REST Webhooks.
|
||||
|
||||
### Inspiration:
|
||||
## What this program does and does *not* do
|
||||
|
||||
DOES: Download Images from a Website.<br />
|
||||
DOES: Create Archives.<br />
|
||||
|
||||
### how:
|
||||
|
||||
Tranga (this repository) is a REST-API and worker in one. Tranga provides REST-Endpoints to configure workers (Jobs).
|
||||
Requests include searches for Manga, creating and starting Jobs such as downloading available chapters.
|
||||
For available endpoints check `<hostedInstance>/swagger`
|
||||
|
||||
This repository *does not* include a frontend. A frontend can take many forms, such as a website:
|
||||
|
||||
[tranga-website](https://github.com/C9Glax/tranga-website)
|
||||
|
||||
When downloading a chapter (meaning the images that make-up the manga) from a Website, Tranga will
|
||||
additionally try and scrape Metadata from the same website ~~or enhance it from third-party sources~~
|
||||
([tbd issue](https://github.com/C9Glax/tranga/issues/280)).
|
||||
Downloaded images can be jpeg-compressed and/or made black and white to save on diskspace
|
||||
(measured at least a 50% reduction in size, without a significant loss of quality).
|
||||
|
||||
Tranga will then package the contents of each chapter in a `.cbz`-archive and place it in a common folder per Manga.
|
||||
If specified, Tranga will then notify library-Managers such as [Komga](https://komga.org/) and [Kavita](https://www.kavitareader.com/) to trigger a scan for new
|
||||
chapters. Tranga can also send notifications to your devices via third-party services such as [Gotify](https://gotify.net/), [Ntfy](https://ntfy.sh/),
|
||||
or any other REST Webhook.
|
||||
|
||||
## Screenshots
|
||||
|
||||
This repository has no frontend, however checkout [tranga-website](https://github.com/C9Glax/tranga-website) for a default!
|
||||
|
||||
## Inspiration:
|
||||
|
||||
Because [Kaizoku](https://github.com/oae/kaizoku) was relying on [mangal](https://github.com/metafates/mangal) and mangal
|
||||
hasn't received bugfixes for it's issues with Titles not showing up, or throwing errors because of illegal characters,
|
||||
there were no alternatives for automatic downloads. However [Kaizoku](https://github.com/oae/kaizoku) certainly had a great Web-UI.
|
||||
hasn't received bugfixes for its issues with Titles not showing up, or throwing errors because of illegal characters,
|
||||
there were no alternatives for automatic downloads. However, [Kaizoku](https://github.com/oae/kaizoku) certainly had a great Web-UI.
|
||||
|
||||
That is why I wanted to create my own project, in a language I understand, and that I am able to maintain myself.
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
||||
## Endpoint Documentation
|
||||
|
||||
Endpoints are documented in Swagger. Just spin up an instance, and go to `http://<url>/swagger`.
|
||||
|
||||
### Built With
|
||||
## Built With
|
||||
|
||||
- .NET-Core
|
||||
- Newtonsoft.JSON
|
||||
- Love <3
|
||||
- ASP.NET
|
||||
- Entity Framework Core
|
||||
- [PostgreSQL](https://www.postgresql.org/about/licence/)
|
||||
- [Ngpsql](https://github.com/npgsql/npgsql/blob/main/LICENSE)
|
||||
- [Swagger](https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/master/LICENSE)
|
||||
- [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json/blob/master/LICENSE.md)
|
||||
- [Sixlabors.ImageSharp](https://docs-v2.sixlabors.com/articles/imagesharp/index.html#license)
|
||||
- [PuppeteerSharp](https://github.com/hardkoded/puppeteer-sharp/blob/master/LICENSE)
|
||||
- [Html Agility Pack (HAP)](https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE)
|
||||
- [Soenneker.Utils.String.NeedlemanWunsch](https://github.com/soenneker/soenneker.utils.string.needlemanwunsch/blob/main/LICENSE)
|
||||
- [Jikan](https://jikan.moe/)
|
||||
- [Jikan.Net](https://github.com/Ervie/jikan.net)
|
||||
- 💙 Blåhaj 🦈
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
||||
## Star History
|
||||
|
||||
<a href="https://star-history.com/#c9glax/tranga&Date">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=c9glax/tranga&type=Date&theme=dark" />
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=c9glax/tranga&type=Date" />
|
||||
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=c9glax/tranga&type=Date" />
|
||||
</picture>
|
||||
</a>
|
||||
|
||||
<!-- GETTING STARTED -->
|
||||
## Getting Started
|
||||
|
||||
To use head over to [releases](https://git.bernloehr.eu/glax/Tranga/releases) and download a release.
|
||||
### Docker
|
||||
|
||||
A CLI will guide you through setup.
|
||||
Built for AMD64 (and ARM64, maybe, if it feels like it).
|
||||
|
||||
### Prerequisites
|
||||
An example `docker-compose.yaml` is provided. Mount `/Manga` to wherever you want your chapters (`.cbz`-Archives)
|
||||
downloaded (where Komga/Kavita can access them for example).
|
||||
The file also includes [tranga-website](https://github.com/C9Glax/tranga-website) as frontend. For its configuration refer to the
|
||||
[Tranga-Website Repository](https://github.com/C9Glax/tranga-website) README.
|
||||
|
||||
[.NET-Core 7.0](https://dotnet.microsoft.com/en-us/download/dotnet/7.0)
|
||||
For compatibility do not execute the compose as root (which you should not do anyways...) but as user that can
|
||||
access the folder. Permission conflicts with Komga and Kavita should thus be limited.
|
||||
|
||||
<!-- ROADMAP -->
|
||||
## Roadmap
|
||||
### Bare-Metal
|
||||
|
||||
- [ ] Web-UI #1
|
||||
- [ ] More Connectors
|
||||
- [ ] Manganato #2
|
||||
- [ ] ?
|
||||
While not supported/currently built, Tranga should also run Bare-Metal without issue.
|
||||
|
||||
See the [open issues](https://git.bernloehr.eu/glax/Tranga/issues) for a full list of proposed features (and known issues).
|
||||
Configuration-Files will be stored per OS:
|
||||
- Linux `/usr/share/tranga-api`
|
||||
- Windows `%appdata%/tranga-api`
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
Downloads (default) are stored in - but this can be configured in `settings.json` (which will be generated on first after first launch):
|
||||
- Linux `/Manga`
|
||||
- Windows `%currentDirectory%/Downloads`
|
||||
|
||||
#### Prerequisits
|
||||
|
||||
[.NET-Core 9.0](https://dotnet.microsoft.com/en-us/download/dotnet/9.0)
|
||||
|
||||
<!-- CONTRIBUTING -->
|
||||
## Contributing
|
||||
|
||||
The following is copy & pasted:
|
||||
If you want to contribute, please feel free to fork and create a Pull-Request!
|
||||
|
||||
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
|
||||
General rules:
|
||||
- Strongly-type your variables. This improves readability.
|
||||
```csharp
|
||||
var xyz = Object.GetSomething(); //Do not do this. What type is xyz (without looking at Method returns etc.)?
|
||||
Manga[] zyx = Object.GetAnotherThing(); //I can now easily see that zyx is an Array.
|
||||
```
|
||||
Tranga is using a code-first Entity-Framework Core approach. If you modify the db-table structure you need to create a migration.
|
||||
|
||||
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
|
||||
Don't forget to give the project a star! Thanks again!
|
||||
**A broad overview of where is what:**<br />
|
||||
|
||||
1. Fork the Project
|
||||
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
|
||||
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
|
||||
4. Push to the Branch (`git push origin feature/AmazingFeature`)
|
||||
5. Open a Pull Request
|
||||

|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
- `Program.cs` Configuration for ASP.NET, Swagger (also in `NamedSwaggerGenOptions.cs`)
|
||||
- `Tranga.cs` Worker-Logic
|
||||
- `Schema/` Entity-Framework
|
||||
- `Schema/Jobs/` + Logic for Jobs
|
||||
- `Schema/**/` + Logic for **
|
||||
- `Schema/Contexts/` EF configuration
|
||||
- `MangaDownloadClients/` Networking-Clients for Scraping
|
||||
- `Controllers/` ASP.NET Controllers (Endpoints)
|
||||
- `APIEndpointRecords/` Records for API-Requests with specific Request-Types (Body)
|
||||
|
||||
If you want to add a new Website-Connector: <br />
|
||||
1. Copy one of the existing connectors, or start from scratch and inherit from `API.Schema.MangaConnectors.MangaConnector`.
|
||||
2. Add the new Connector as Object-Instance in `Program.cs` to the MangaConnector-Array `connectors`.
|
||||
3. In `PgsqlContext.cs` add the Discriminator for the Connector (the value is the name of the connector, as defined
|
||||
in the constructor).
|
||||
4. In `Program.cs` add a new Object to the Array.
|
||||
|
||||
### How to test locally
|
||||
|
||||
In the Project root a `docker-compose.local.yaml` file will compile the code and create the container(s).
|
||||
|
||||
<!-- LICENSE -->
|
||||
## License
|
||||
|
||||
Distributed under the GNU GPLv3 License. See `LICENSE.txt` for more information.
|
||||
Distributed under the GNU GPLv3 License. See [LICENSE.txt](https://github.com/C9Glax/tranga/blob/master/LICENSE.txt) for more information.
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
||||
|
||||
|
||||
<!-- ACKNOWLEDGMENTS -->
|
||||
## Acknowledgments
|
||||
|
||||
* [Choose an Open Source License](https://choosealicense.com)
|
||||
* [Font Awesome](https://fontawesome.com)
|
||||
* [Best-README-Template](https://github.com/othneildrew/Best-README-Template/tree/master)
|
||||
* [Shields.io](https://shields.io/)
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
@ -1,20 +0,0 @@
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
EXPOSE 443
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
|
||||
WORKDIR /src
|
||||
COPY ["Tranga-API/Tranga-API.csproj", "Tranga-API/"]
|
||||
RUN dotnet restore "Tranga-API/Tranga-API.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/Tranga-API"
|
||||
RUN dotnet build "Tranga-API.csproj" -c Release -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "Tranga-API.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "Tranga-API.dll"]
|
@ -1,110 +0,0 @@
|
||||
using Logging;
|
||||
using Tranga;
|
||||
|
||||
string applicationFolderPath =
|
||||
Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Tranga-API");
|
||||
string logsFolderPath = Path.Join(applicationFolderPath, "logs");
|
||||
string logFilePath = Path.Join(logsFolderPath, $"log-{DateTime.Now:dd-M-yyyy-HH-mm-ss}.txt");
|
||||
string settingsFilePath = Path.Join(applicationFolderPath, "settings.json");
|
||||
|
||||
Directory.CreateDirectory(applicationFolderPath);
|
||||
Directory.CreateDirectory(logsFolderPath);
|
||||
|
||||
Console.WriteLine($"Logfile-Path: {logFilePath}");
|
||||
Console.WriteLine($"Settings-File-Path: {settingsFilePath}");
|
||||
|
||||
Logger logger = new(new[] { Logger.LoggerType.FileLogger }, null, null, logFilePath);
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Loading Taskmanager.");
|
||||
TrangaSettings settings;
|
||||
if (File.Exists(settingsFilePath))
|
||||
settings = TrangaSettings.LoadSettings(settingsFilePath);
|
||||
else
|
||||
settings = new TrangaSettings(Directory.GetCurrentDirectory(), applicationFolderPath, null);
|
||||
|
||||
TaskManager taskManager = new (settings, logger);
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.Services.AddControllers().AddNewtonsoftJson();
|
||||
var app = builder.Build();
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
|
||||
app.MapGet("/GetAvailableControllers", () => taskManager.GetAvailableConnectors());
|
||||
|
||||
app.MapGet("/GetKnownPublications", () => taskManager.GetAllPublications());
|
||||
|
||||
app.MapGet("/GetPublicationsFromConnector", (string connectorName, string title) =>
|
||||
{
|
||||
Connector? connector = taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName).Value;
|
||||
if (connector is null)
|
||||
return Array.Empty<Publication>();
|
||||
if(title.Length < 4)
|
||||
return Array.Empty<Publication>();
|
||||
return taskManager.GetPublicationsFromConnector(connector, title);
|
||||
});
|
||||
|
||||
app.MapGet("/Tasks/GetTaskTypes", () => Enum.GetNames(typeof(TrangaTask.Task)));
|
||||
|
||||
|
||||
app.MapPost("/Tasks/Create", (string taskType, string? connectorName, string? publicationId, string reoccurrenceTime, string? language) =>
|
||||
{
|
||||
Publication? publication = taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == publicationId);
|
||||
TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType);
|
||||
taskManager.AddTask(task, connectorName, publication, TimeSpan.Parse(reoccurrenceTime), language??"");
|
||||
});
|
||||
|
||||
app.MapDelete("/Tasks/Delete", (string taskType, string? connectorName, string? publicationId) =>
|
||||
{
|
||||
Publication? publication = taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == publicationId);
|
||||
TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType);
|
||||
taskManager.DeleteTask(task, connectorName, publication);
|
||||
});
|
||||
|
||||
app.MapGet("/Tasks/GetList", () => taskManager.GetAllTasks());
|
||||
|
||||
app.MapPost("/Tasks/Start", (string taskType, string? connectorName, string? publicationId) =>
|
||||
{
|
||||
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
|
||||
TrangaTask? task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
|
||||
tTask.task == pTask && tTask.publication?.internalId == publicationId && tTask.connectorName == connectorName);
|
||||
if (task is null)
|
||||
return;
|
||||
taskManager.ExecuteTaskNow(task);
|
||||
});
|
||||
|
||||
app.MapGet("/Tasks/GetRunningTasks",
|
||||
() => taskManager.GetAllTasks().Where(task => task.state is TrangaTask.ExecutionState.Running));
|
||||
|
||||
app.MapGet("/Queue/GetList",
|
||||
() => taskManager.GetAllTasks().Where(task => task.state is TrangaTask.ExecutionState.Enqueued));
|
||||
|
||||
app.MapPost("/Queue/Enqueue", (string taskType, string? connectorName, string? publicationId) =>
|
||||
{
|
||||
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
|
||||
TrangaTask? task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
|
||||
tTask.task == pTask && tTask.publication?.internalId == publicationId && tTask.connectorName == connectorName);
|
||||
if (task is null)
|
||||
return;
|
||||
taskManager.AddTaskToQueue(task);
|
||||
});
|
||||
|
||||
app.MapDelete("/Queue/Dequeue", (string taskType, string? connectorName, string? publicationId) =>
|
||||
{
|
||||
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
|
||||
TrangaTask? task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
|
||||
tTask.task == pTask && tTask.publication?.internalId == publicationId && tTask.connectorName == connectorName);
|
||||
if (task is null)
|
||||
return;
|
||||
taskManager.RemoveTaskFromQueue(task);
|
||||
});
|
||||
|
||||
app.MapGet("/Settings/Get", () => taskManager.settings);
|
||||
|
||||
app.MapPost("/Settings/Update", (string? downloadLocation, string? komgaUrl, string? komgaAuth) => taskManager.UpdateSettings(downloadLocation, komgaUrl, komgaAuth) );
|
||||
|
||||
app.Run();
|
@ -1,37 +0,0 @@
|
||||
{
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:1716",
|
||||
"sslPort": 44391
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5177",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7036;http://localhost:5177",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>Tranga_API</RootNamespace>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\.dockerignore">
|
||||
<Link>.dockerignore</Link>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Logging\Logging.csproj" />
|
||||
<ProjectReference Include="..\Tranga\Tranga.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.5" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.6" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,18 +0,0 @@
|
||||
FROM mcr.microsoft.com/dotnet/runtime:7.0 AS base
|
||||
WORKDIR /app
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
|
||||
WORKDIR /src
|
||||
COPY ["Tranga-CLI/Tranga-CLI.csproj", "Tranga-CLI/"]
|
||||
RUN dotnet restore "Tranga-CLI/Tranga-CLI.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/Tranga-CLI"
|
||||
RUN dotnet build "Tranga-CLI.csproj" -c Release -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "Tranga-CLI.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "Tranga-CLI.dll"]
|
@ -1,22 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<RootNamespace>Tranga_CLI</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\.dockerignore">
|
||||
<Link>.dockerignore</Link>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Tranga\Tranga.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,536 +0,0 @@
|
||||
using System.Globalization;
|
||||
using Logging;
|
||||
using Tranga;
|
||||
|
||||
namespace Tranga_CLI;
|
||||
|
||||
/*
|
||||
* This is written with pure hatred for readability.
|
||||
* At some point do this properly.
|
||||
* Read at own risk.
|
||||
*/
|
||||
|
||||
public static class Tranga_Cli
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
string applicationFolderPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Tranga");
|
||||
string logsFolderPath = Path.Join(applicationFolderPath, "logs");
|
||||
string logFilePath = Path.Join(logsFolderPath, $"log-{DateTime.Now:dd-M-yyyy-HH-mm-ss}.txt");
|
||||
string settingsFilePath = Path.Join(applicationFolderPath, "settings.json");
|
||||
|
||||
Directory.CreateDirectory(applicationFolderPath);
|
||||
Directory.CreateDirectory(logsFolderPath);
|
||||
|
||||
Console.WriteLine($"Logfile-Path: {logFilePath}");
|
||||
Console.WriteLine($"Settings-File-Path: {settingsFilePath}");
|
||||
|
||||
Logger logger = new(new[] { Logger.LoggerType.FileLogger }, null, null, logFilePath);
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Loading Taskmanager.");
|
||||
TrangaSettings settings;
|
||||
if (File.Exists(settingsFilePath))
|
||||
settings = TrangaSettings.LoadSettings(settingsFilePath);
|
||||
else
|
||||
settings = new TrangaSettings(Directory.GetCurrentDirectory(), applicationFolderPath, null);
|
||||
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "User Input");
|
||||
Console.WriteLine($"Output folder path [{settings.downloadLocation}]:");
|
||||
string? tmpPath = Console.ReadLine();
|
||||
while(tmpPath is null)
|
||||
tmpPath = Console.ReadLine();
|
||||
if (tmpPath.Length > 0)
|
||||
settings.downloadLocation = tmpPath;
|
||||
|
||||
Console.WriteLine($"Komga BaseURL [{settings.komga?.baseUrl}]:");
|
||||
string? tmpUrl = Console.ReadLine();
|
||||
while (tmpUrl is null)
|
||||
tmpUrl = Console.ReadLine();
|
||||
if (tmpUrl.Length > 0)
|
||||
{
|
||||
Console.WriteLine("Username:");
|
||||
string? tmpUser = Console.ReadLine();
|
||||
while (tmpUser is null || tmpUser.Length < 1)
|
||||
tmpUser = Console.ReadLine();
|
||||
|
||||
Console.WriteLine("Password:");
|
||||
string tmpPass = string.Empty;
|
||||
ConsoleKey key;
|
||||
do
|
||||
{
|
||||
var keyInfo = Console.ReadKey(intercept: true);
|
||||
key = keyInfo.Key;
|
||||
|
||||
if (key == ConsoleKey.Backspace && tmpPass.Length > 0)
|
||||
{
|
||||
Console.Write("\b \b");
|
||||
tmpPass = tmpPass[0..^1];
|
||||
}
|
||||
else if (!char.IsControl(keyInfo.KeyChar))
|
||||
{
|
||||
Console.Write("*");
|
||||
tmpPass += keyInfo.KeyChar;
|
||||
}
|
||||
} while (key != ConsoleKey.Enter);
|
||||
|
||||
settings.komga = new Komga(tmpUrl, tmpUser, tmpPass, logger);
|
||||
}
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Loaded.");
|
||||
TaskMode(settings, logger);
|
||||
}
|
||||
|
||||
private static void TaskMode(TrangaSettings settings, Logger logger)
|
||||
{
|
||||
TaskManager taskManager = new (settings, logger);
|
||||
ConsoleKey selection = ConsoleKey.EraseEndOfFile;
|
||||
PrintMenu(taskManager, taskManager.settings.downloadLocation, logger);
|
||||
while (selection != ConsoleKey.Q)
|
||||
{
|
||||
int taskCount = taskManager.GetAllTasks().Length;
|
||||
int taskRunningCount = taskManager.GetAllTasks().Count(task => task.state == TrangaTask.ExecutionState.Running);
|
||||
int taskEnqueuedCount =
|
||||
taskManager.GetAllTasks().Count(task => task.state == TrangaTask.ExecutionState.Enqueued);
|
||||
Console.SetCursorPosition(0,1);
|
||||
Console.WriteLine($"Tasks (Running/Queue/Total)): {taskRunningCount}/{taskEnqueuedCount}/{taskCount}");
|
||||
|
||||
if (Console.KeyAvailable)
|
||||
{
|
||||
selection = Console.ReadKey().Key;
|
||||
switch (selection)
|
||||
{
|
||||
case ConsoleKey.L:
|
||||
PrintTasks(taskManager.GetAllTasks(), logger);
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
break;
|
||||
case ConsoleKey.C:
|
||||
CreateTask(taskManager, taskManager.settings, logger);
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
break;
|
||||
case ConsoleKey.D:
|
||||
DeleteTask(taskManager, logger);
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
break;
|
||||
case ConsoleKey.E:
|
||||
ExecuteTaskNow(taskManager, logger);
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
break;
|
||||
case ConsoleKey.S:
|
||||
SearchTasks(taskManager, logger);
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
break;
|
||||
case ConsoleKey.R:
|
||||
PrintTasks(
|
||||
taskManager.GetAllTasks().Where(eTask => eTask.state == TrangaTask.ExecutionState.Running)
|
||||
.ToArray(), logger);
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
break;
|
||||
case ConsoleKey.K:
|
||||
PrintTasks(
|
||||
taskManager.GetAllTasks().Where(qTask => qTask.state is TrangaTask.ExecutionState.Enqueued)
|
||||
.ToArray(), logger);
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
break;
|
||||
case ConsoleKey.F:
|
||||
TailLog(logger);
|
||||
Console.ReadKey();
|
||||
break;
|
||||
case ConsoleKey.G:
|
||||
RemoveTaskFromQueue(taskManager, logger);
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
break;
|
||||
case ConsoleKey.B:
|
||||
AddTaskToQueue(taskManager, logger);
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
break;
|
||||
case ConsoleKey.M:
|
||||
AddMangaTaskToQueue(taskManager, logger);
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
break;
|
||||
}
|
||||
PrintMenu(taskManager, taskManager.settings.downloadLocation, logger);
|
||||
}
|
||||
Thread.Sleep(200);
|
||||
}
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Exiting.");
|
||||
Console.Clear();
|
||||
Console.WriteLine("Exiting.");
|
||||
if (taskManager.GetAllTasks().Any(task => task.state == TrangaTask.ExecutionState.Running))
|
||||
{
|
||||
Console.WriteLine("Force quit (Even with running tasks?) y/N");
|
||||
selection = Console.ReadKey().Key;
|
||||
while(selection != ConsoleKey.Y && selection != ConsoleKey.N)
|
||||
selection = Console.ReadKey().Key;
|
||||
taskManager.Shutdown(selection == ConsoleKey.Y);
|
||||
}else
|
||||
// ReSharper disable once RedundantArgumentDefaultValue Better readability
|
||||
taskManager.Shutdown(false);
|
||||
}
|
||||
|
||||
private static void PrintMenu(TaskManager taskManager, string folderPath, Logger logger)
|
||||
{
|
||||
int taskCount = taskManager.GetAllTasks().Length;
|
||||
int taskRunningCount = taskManager.GetAllTasks().Count(task => task.state == TrangaTask.ExecutionState.Running);
|
||||
int taskEnqueuedCount =
|
||||
taskManager.GetAllTasks().Count(task => task.state == TrangaTask.ExecutionState.Enqueued);
|
||||
Console.Clear();
|
||||
Console.WriteLine($"Download Folder: {folderPath}");
|
||||
Console.WriteLine($"Tasks (Running/Queue/Total)): {taskRunningCount}/{taskEnqueuedCount}/{taskCount}");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"{"C: Create Task",-30}{"L: List tasks",-30}{"B: Enqueue Task", -30}");
|
||||
Console.WriteLine($"{"D: Delete Task",-30}{"S: Search Tasks", -30}{"K: List Task Queue", -30}");
|
||||
Console.WriteLine($"{"E: Execute Task now",-30}{"R: List Running Tasks", -30}{"G: Remove Task from Queue", -30}");
|
||||
Console.WriteLine($"{"M: New Download Manga Task",-30}{"", -30}{"", -30}");
|
||||
Console.WriteLine($"{"",-30}{"F: Show Log",-30}{"Q: Exit",-30}");
|
||||
}
|
||||
|
||||
private static void PrintTasks(TrangaTask[] tasks, Logger logger)
|
||||
{
|
||||
logger.WriteLine("Tranga_CLI", "Printing Tasks");
|
||||
int taskCount = tasks.Length;
|
||||
int taskRunningCount = tasks.Count(task => task.state == TrangaTask.ExecutionState.Running);
|
||||
int taskEnqueuedCount = tasks.Count(task => task.state == TrangaTask.ExecutionState.Enqueued);
|
||||
Console.Clear();
|
||||
int tIndex = 0;
|
||||
Console.WriteLine($"Tasks (Running/Queue/Total): {taskRunningCount}/{taskEnqueuedCount}/{taskCount}");
|
||||
string header =
|
||||
$"{"",-5}{"Task",-20} | {"Last Executed",-20} | {"Reoccurrence",-12} | {"State",-10} | {"Connector",-15} | Publication/Manga";
|
||||
Console.WriteLine(header);
|
||||
Console.WriteLine(new string('-', header.Length));
|
||||
foreach (TrangaTask trangaTask in tasks)
|
||||
{
|
||||
string[] taskSplit = trangaTask.ToString().Split(", ");
|
||||
Console.WriteLine($"{tIndex++:000}: {taskSplit[0],-20} | {taskSplit[1],-20} | {taskSplit[2],-12} | {taskSplit[3],-10} | {(taskSplit.Length > 4 ? taskSplit[4] : ""),-15} | {(taskSplit.Length > 5 ? taskSplit[5] : "")}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static TrangaTask? SelectTask(TrangaTask[] tasks, Logger logger)
|
||||
{
|
||||
logger.WriteLine("Tranga_CLI", "Menu: Select task");
|
||||
if (tasks.Length < 1)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("There are no available Tasks.");
|
||||
logger.WriteLine("Tranga_CLI", "No available Tasks.");
|
||||
return null;
|
||||
}
|
||||
PrintTasks(tasks, logger);
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Selecting Task to Remove (from queue)");
|
||||
Console.WriteLine("Enter q to abort");
|
||||
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
|
||||
|
||||
string? selectedTask = Console.ReadLine();
|
||||
while(selectedTask is null || selectedTask.Length < 1)
|
||||
selectedTask = Console.ReadLine();
|
||||
|
||||
if (selectedTask.Length == 1 && selectedTask.ToLower() == "q")
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("aborted.");
|
||||
logger.WriteLine("Tranga_CLI", "aborted");
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
||||
return tasks[selectedTaskIndex];
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"Exception: {e.Message}");
|
||||
logger.WriteLine("Tranga_CLI", e.Message);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void AddMangaTaskToQueue(TaskManager taskManager, Logger logger)
|
||||
{
|
||||
Console.Clear();
|
||||
logger.WriteLine("Tranga_CLI", "Menu: Add Manga Download to queue");
|
||||
|
||||
Connector? connector = SelectConnector(taskManager.settings.downloadLocation, taskManager.GetAvailableConnectors().Values.ToArray(), logger);
|
||||
if (connector is null)
|
||||
return;
|
||||
|
||||
Publication? publication = SelectPublication(taskManager, connector!, logger);
|
||||
if (publication is null)
|
||||
return;
|
||||
|
||||
TimeSpan reoccurrence = SelectReoccurrence(logger);
|
||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
||||
TrangaTask newTask = taskManager.AddTask(TrangaTask.Task.DownloadNewChapters, connector?.name, publication, reoccurrence, "en");
|
||||
Console.WriteLine(newTask);
|
||||
}
|
||||
|
||||
private static void AddTaskToQueue(TaskManager taskManager, Logger logger)
|
||||
{
|
||||
Console.Clear();
|
||||
logger.WriteLine("Tranga_CLI", "Menu: Add Task to queue");
|
||||
|
||||
TrangaTask[] tasks = taskManager.GetAllTasks().Where(rTask =>
|
||||
rTask.state is not TrangaTask.ExecutionState.Enqueued and not TrangaTask.ExecutionState.Running).ToArray();
|
||||
|
||||
TrangaTask? selectedTask = SelectTask(tasks, logger);
|
||||
if (selectedTask is null)
|
||||
return;
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
||||
taskManager.AddTaskToQueue(selectedTask);
|
||||
}
|
||||
|
||||
private static void RemoveTaskFromQueue(TaskManager taskManager, Logger logger)
|
||||
{
|
||||
Console.Clear();
|
||||
logger.WriteLine("Tranga_CLI", "Menu: Remove Task from queue");
|
||||
|
||||
TrangaTask[] tasks = taskManager.GetAllTasks().Where(rTask => rTask.state is TrangaTask.ExecutionState.Enqueued).ToArray();
|
||||
|
||||
TrangaTask? selectedTask = SelectTask(tasks, logger);
|
||||
if (selectedTask is null)
|
||||
return;
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
||||
taskManager.RemoveTaskFromQueue(selectedTask);
|
||||
}
|
||||
|
||||
private static void TailLog(Logger logger)
|
||||
{
|
||||
logger.WriteLine("Tranga_CLI", "Menu: Show Log-lines");
|
||||
Console.Clear();
|
||||
|
||||
string[] lines = logger.Tail(20);
|
||||
foreach (string message in lines)
|
||||
Console.Write(message);
|
||||
|
||||
while (!Console.KeyAvailable)
|
||||
{
|
||||
string[] newLines = logger.GetNewLines();
|
||||
foreach(string message in newLines)
|
||||
Console.Write(message);
|
||||
Thread.Sleep(40);
|
||||
}
|
||||
}
|
||||
|
||||
private static void CreateTask(TaskManager taskManager, TrangaSettings settings, Logger logger)
|
||||
{
|
||||
logger.WriteLine("Tranga_CLI", "Menu: Creating Task");
|
||||
TrangaTask.Task? tmpTask = SelectTaskType(logger);
|
||||
if (tmpTask is null)
|
||||
return;
|
||||
TrangaTask.Task task = (TrangaTask.Task)tmpTask!;
|
||||
|
||||
Connector? connector = null;
|
||||
if (task != TrangaTask.Task.UpdateKomgaLibrary)
|
||||
{
|
||||
connector = SelectConnector(settings.downloadLocation, taskManager.GetAvailableConnectors().Values.ToArray(), logger);
|
||||
if (connector is null)
|
||||
return;
|
||||
}
|
||||
|
||||
Publication? publication = null;
|
||||
if (task != TrangaTask.Task.UpdatePublications && task != TrangaTask.Task.UpdateKomgaLibrary)
|
||||
{
|
||||
publication = SelectPublication(taskManager, connector!, logger);
|
||||
if (publication is null)
|
||||
return;
|
||||
}
|
||||
|
||||
TimeSpan reoccurrence = SelectReoccurrence(logger);
|
||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
||||
TrangaTask newTask = taskManager.AddTask(task, connector?.name, publication, reoccurrence, "en");
|
||||
Console.WriteLine(newTask);
|
||||
}
|
||||
|
||||
private static void ExecuteTaskNow(TaskManager taskManager, Logger logger)
|
||||
{
|
||||
logger.WriteLine("Tranga_CLI", "Menu: Executing Task");
|
||||
TrangaTask[] tasks = taskManager.GetAllTasks().Where(nTask => nTask.state is not TrangaTask.ExecutionState.Running).ToArray();
|
||||
|
||||
TrangaTask? selectedTask = SelectTask(tasks, logger);
|
||||
if (selectedTask is null)
|
||||
return;
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
||||
taskManager.ExecuteTaskNow(selectedTask);
|
||||
}
|
||||
|
||||
private static void DeleteTask(TaskManager taskManager, Logger logger)
|
||||
{
|
||||
logger.WriteLine("Tranga_CLI", "Menu: Delete Task");
|
||||
TrangaTask[] tasks = taskManager.GetAllTasks();
|
||||
|
||||
TrangaTask? selectedTask = SelectTask(tasks, logger);
|
||||
if (selectedTask is null)
|
||||
return;
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
||||
taskManager.DeleteTask(selectedTask.task, selectedTask.connectorName, selectedTask.publication);
|
||||
}
|
||||
|
||||
private static TrangaTask.Task? SelectTaskType(Logger logger)
|
||||
{
|
||||
logger.WriteLine("Tranga_CLI", "Menu: Select TaskType");
|
||||
Console.Clear();
|
||||
string[] taskNames = Enum.GetNames<TrangaTask.Task>();
|
||||
|
||||
int tIndex = 0;
|
||||
Console.WriteLine("Available Tasks:");
|
||||
foreach (string taskName in taskNames)
|
||||
Console.WriteLine($"{tIndex++}: {taskName}");
|
||||
|
||||
Console.WriteLine("Enter q to abort");
|
||||
Console.WriteLine($"Select Task (0-{taskNames.Length - 1}):");
|
||||
|
||||
string? selectedTask = Console.ReadLine();
|
||||
while(selectedTask is null || selectedTask.Length < 1)
|
||||
selectedTask = Console.ReadLine();
|
||||
|
||||
if (selectedTask.Length == 1 && selectedTask.ToLower() == "q")
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("aborted.");
|
||||
logger.WriteLine("Tranga_CLI", "aborted.");
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
||||
string selectedTaskName = taskNames[selectedTaskIndex];
|
||||
return Enum.Parse<TrangaTask.Task>(selectedTaskName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"Exception: {e.Message}");
|
||||
logger.WriteLine("Tranga_CLI", e.Message);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static TimeSpan SelectReoccurrence(Logger logger)
|
||||
{
|
||||
logger.WriteLine("Tranga_CLI", "Menu: Select Reoccurrence");
|
||||
Console.WriteLine("Select reoccurrence Timer (Format hh:mm:ss):");
|
||||
return TimeSpan.Parse(Console.ReadLine()!, new CultureInfo("en-US"));
|
||||
}
|
||||
|
||||
private static Connector? SelectConnector(string folderPath, Connector[] connectors, Logger logger)
|
||||
{
|
||||
logger.WriteLine("Tranga_CLI", "Menu: Select Connector");
|
||||
Console.Clear();
|
||||
|
||||
int cIndex = 0;
|
||||
Console.WriteLine("Connectors:");
|
||||
foreach (Connector connector in connectors)
|
||||
Console.WriteLine($"{cIndex++}: {connector.name}");
|
||||
|
||||
Console.WriteLine("Enter q to abort");
|
||||
Console.WriteLine($"Select Connector (0-{connectors.Length - 1}):");
|
||||
|
||||
string? selectedConnector = Console.ReadLine();
|
||||
while(selectedConnector is null || selectedConnector.Length < 1)
|
||||
selectedConnector = Console.ReadLine();
|
||||
|
||||
if (selectedConnector.Length == 1 && selectedConnector.ToLower() == "q")
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("aborted.");
|
||||
logger.WriteLine("Tranga_CLI", "aborted.");
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
int selectedConnectorIndex = Convert.ToInt32(selectedConnector);
|
||||
return connectors[selectedConnectorIndex];
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"Exception: {e.Message}");
|
||||
logger.WriteLine("Tranga_CLI", e.Message);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Publication? SelectPublication(TaskManager taskManager, Connector connector, Logger logger)
|
||||
{
|
||||
logger.WriteLine("Tranga_CLI", "Menu: Select Publication");
|
||||
|
||||
Console.Clear();
|
||||
Console.WriteLine($"Connector: {connector.name}");
|
||||
Console.WriteLine("Publication search query (leave empty for all):");
|
||||
string? query = Console.ReadLine();
|
||||
|
||||
Publication[] publications = taskManager.GetPublicationsFromConnector(connector, query ?? "");
|
||||
|
||||
if (publications.Length < 1)
|
||||
{
|
||||
logger.WriteLine("Tranga_CLI", "No publications returned");
|
||||
Console.WriteLine($"No publications for query '{query}' returned;");
|
||||
return null;
|
||||
}
|
||||
|
||||
int pIndex = 0;
|
||||
Console.WriteLine("Publications:");
|
||||
foreach(Publication publication in publications)
|
||||
Console.WriteLine($"{pIndex++}: {publication.sortName}");
|
||||
|
||||
Console.WriteLine("Enter q to abort");
|
||||
Console.WriteLine($"Select publication to Download (0-{publications.Length - 1}):");
|
||||
|
||||
string? selectedPublication = Console.ReadLine();
|
||||
while(selectedPublication is null || selectedPublication.Length < 1)
|
||||
selectedPublication = Console.ReadLine();
|
||||
|
||||
if (selectedPublication.Length == 1 && selectedPublication.ToLower() == "q")
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("aborted.");
|
||||
logger.WriteLine("Tranga_CLI", "aborted.");
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
int selectedPublicationIndex = Convert.ToInt32(selectedPublication);
|
||||
return publications[selectedPublicationIndex];
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"Exception: {e.Message}");
|
||||
logger.WriteLine("Tranga_CLI", e.Message);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void SearchTasks(TaskManager taskManager, Logger logger)
|
||||
{
|
||||
logger.WriteLine("Tranga_CLI", "Menu: Search task");
|
||||
Console.Clear();
|
||||
Console.WriteLine("Enter search query:");
|
||||
string? query = Console.ReadLine();
|
||||
while (query is null || query.Length < 4)
|
||||
query = Console.ReadLine();
|
||||
PrintTasks(taskManager.GetAllTasks().Where(qTask =>
|
||||
qTask.ToString().ToLower().Contains(query, StringComparison.OrdinalIgnoreCase)).ToArray(), logger);
|
||||
}
|
||||
}
|
28
Tranga.sln
28
Tranga.sln
@ -1,12 +1,6 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga", ".\Tranga\Tranga.csproj", "{545E81B9-D96B-4C8F-A97F-2C02414DE566}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-CLI", "Tranga-CLI\Tranga-CLI.csproj", "{4899E3B2-B259-479A-B43E-042D043E9501}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logging", "Logging\Logging.csproj", "{415BE889-BB7D-426F-976F-8D977876A462}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-API", "Tranga-API\Tranga-API.csproj", "{48F4E495-75BC-4402-8E03-DEC5B79D7E83}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "API\API.csproj", "{EDB07E7B-351F-4FCC-9AEF-777838E5551E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -14,21 +8,9 @@ Global
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{545E81B9-D96B-4C8F-A97F-2C02414DE566}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{545E81B9-D96B-4C8F-A97F-2C02414DE566}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{545E81B9-D96B-4C8F-A97F-2C02414DE566}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{545E81B9-D96B-4C8F-A97F-2C02414DE566}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4899E3B2-B259-479A-B43E-042D043E9501}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4899E3B2-B259-479A-B43E-042D043E9501}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4899E3B2-B259-479A-B43E-042D043E9501}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4899E3B2-B259-479A-B43E-042D043E9501}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{415BE889-BB7D-426F-976F-8D977876A462}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{415BE889-BB7D-426F-976F-8D977876A462}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{415BE889-BB7D-426F-976F-8D977876A462}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{415BE889-BB7D-426F-976F-8D977876A462}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{48F4E495-75BC-4402-8E03-DEC5B79D7E83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{48F4E495-75BC-4402-8E03-DEC5B79D7E83}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{48F4E495-75BC-4402-8E03-DEC5B79D7E83}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{48F4E495-75BC-4402-8E03-DEC5B79D7E83}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{EDB07E7B-351F-4FCC-9AEF-777838E5551E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{EDB07E7B-351F-4FCC-9AEF-777838E5551E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EDB07E7B-351F-4FCC-9AEF-777838E5551E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EDB07E7B-351F-4FCC-9AEF-777838E5551E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
@ -1,3 +1,18 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=altnames/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=authorsartists/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=comick/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Gotify/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=jikan/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=jjob/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=kitsu/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Komga/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=lunasea/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=mangakatana/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Manganato/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mangasee/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mangaworld/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Ntfy/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=solverr/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Taskmanager/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tranga/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
@ -1,33 +0,0 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace Tranga;
|
||||
|
||||
/// <summary>
|
||||
/// Has to be Part of a publication
|
||||
/// Includes the Chapter-Name, -VolumeNumber, -ChapterNumber, the location of the chapter on the internet and the saveName of the local file.
|
||||
/// </summary>
|
||||
public struct Chapter
|
||||
{
|
||||
public string? name { get; }
|
||||
public string? volumeNumber { get; }
|
||||
public string? chapterNumber { get; }
|
||||
public string url { get; }
|
||||
public string fileName { get; }
|
||||
public string sortNumber { get; }
|
||||
|
||||
public Chapter(string? name, string? volumeNumber, string? chapterNumber, string url)
|
||||
{
|
||||
this.name = name;
|
||||
this.volumeNumber = volumeNumber is { Length: > 0 } ? volumeNumber : "1";
|
||||
this.chapterNumber = chapterNumber;
|
||||
this.url = url;
|
||||
string chapterName = string.Concat((name ?? "").Split(Path.GetInvalidFileNameChars()));
|
||||
NumberFormatInfo nfi = new NumberFormatInfo()
|
||||
{
|
||||
NumberDecimalSeparator = "."
|
||||
};
|
||||
sortNumber = decimal.Round(Convert.ToDecimal(this.volumeNumber) * Convert.ToDecimal(this.chapterNumber, nfi), 1)
|
||||
.ToString(nfi);
|
||||
this.fileName = $"{chapterName} - V{volumeNumber}C{chapterNumber} - {sortNumber}";
|
||||
}
|
||||
}
|
@ -1,248 +0,0 @@
|
||||
using System.IO.Compression;
|
||||
using System.Net;
|
||||
using System.Xml.Linq;
|
||||
using Logging;
|
||||
|
||||
namespace Tranga;
|
||||
|
||||
/// <summary>
|
||||
/// Base-Class for all Connectors
|
||||
/// Provides some methods to be used by all Connectors, as well as a DownloadClient
|
||||
/// </summary>
|
||||
public abstract class Connector
|
||||
{
|
||||
internal string downloadLocation { get; } //Location of local files
|
||||
protected DownloadClient downloadClient { get; init; }
|
||||
|
||||
protected Logger? logger;
|
||||
|
||||
protected Connector(string downloadLocation, Logger? logger)
|
||||
{
|
||||
this.downloadLocation = downloadLocation;
|
||||
this.logger = logger;
|
||||
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
||||
{
|
||||
//RequestTypes for RateLimits
|
||||
}, logger);
|
||||
}
|
||||
|
||||
public abstract string name { get; } //Name of the Connector (e.g. Website)
|
||||
|
||||
/// <summary>
|
||||
/// Returns all Publications with the given string.
|
||||
/// If the string is empty or null, returns all Publication of the Connector
|
||||
/// </summary>
|
||||
/// <param name="publicationTitle">Search-Query</param>
|
||||
/// <returns>Publications matching the query</returns>
|
||||
public abstract Publication[] GetPublications(string publicationTitle = "");
|
||||
|
||||
/// <summary>
|
||||
/// Returns all Chapters of the publication in the provided language.
|
||||
/// If the language is empty or null, returns all Chapters in all Languages.
|
||||
/// </summary>
|
||||
/// <param name="publication">Publication to get Chapters for</param>
|
||||
/// <param name="language">Language of the Chapters</param>
|
||||
/// <returns>Array of Chapters matching Publication and Language</returns>
|
||||
public abstract Chapter[] GetChapters(Publication publication, string language = "");
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the Chapter (+Images) from the website.
|
||||
/// Should later call DownloadChapterImages to retrieve the individual Images of the Chapter.
|
||||
/// </summary>
|
||||
/// <param name="publication">Publication that contains Chapter</param>
|
||||
/// <param name="chapter">Chapter with Images to retrieve</param>
|
||||
public abstract void DownloadChapter(Publication publication, Chapter chapter);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the Cover from the Website
|
||||
/// </summary>
|
||||
/// <param name="publication">Publication to retrieve Cover for</param>
|
||||
public abstract void DownloadCover(Publication publication);
|
||||
|
||||
/// <summary>
|
||||
/// Saves the series-info to series.json in the Publication Folder
|
||||
/// </summary>
|
||||
/// <param name="publication">Publication to save series.json for</param>
|
||||
public void SaveSeriesInfo(Publication publication)
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Saving series.json for {publication.sortName}");
|
||||
//Check if Publication already has a Folder and a series.json
|
||||
string publicationFolder = Path.Join(downloadLocation, publication.folderName);
|
||||
if(!Directory.Exists(publicationFolder))
|
||||
Directory.CreateDirectory(publicationFolder);
|
||||
|
||||
string seriesInfoPath = Path.Join(publicationFolder, "series.json");
|
||||
if(!File.Exists(seriesInfoPath))
|
||||
File.WriteAllText(seriesInfoPath,publication.GetSeriesInfoJson());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a string containing XML of publication and chapter.
|
||||
/// See ComicInfo.xml
|
||||
/// </summary>
|
||||
/// <returns>XML-string</returns>
|
||||
protected static string CreateComicInfo(Publication publication, Chapter chapter, Logger? logger)
|
||||
{
|
||||
logger?.WriteLine("Connector", $"Creating ComicInfo.Xml for {publication.sortName} Chapter {chapter.volumeNumber} {chapter.chapterNumber}");
|
||||
XElement comicInfo = new XElement("ComicInfo",
|
||||
new XElement("Tags", string.Join(',',publication.tags)),
|
||||
new XElement("LanguageISO", publication.originalLanguage),
|
||||
new XElement("Title", chapter.name),
|
||||
new XElement("Writer", publication.author),
|
||||
new XElement("Volume", chapter.volumeNumber),
|
||||
new XElement("Number", chapter.chapterNumber) //TODO check if this is correct at some point
|
||||
);
|
||||
return comicInfo.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a chapter-archive is already present
|
||||
/// </summary>
|
||||
/// <returns>true if chapter is present</returns>
|
||||
public bool ChapterIsDownloaded(Publication publication, Chapter chapter)
|
||||
{
|
||||
return File.Exists(CreateFullFilepath(publication, chapter));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates full file path of chapter-archive
|
||||
/// </summary>
|
||||
/// <returns>Filepath</returns>
|
||||
protected string CreateFullFilepath(Publication publication, Chapter chapter)
|
||||
{
|
||||
return Path.Join(downloadLocation, publication.folderName, $"{chapter.fileName}.cbz");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Downloads Image from URL and saves it to the given path(incl. fileName)
|
||||
/// </summary>
|
||||
/// <param name="imageUrl"></param>
|
||||
/// <param name="fullPath"></param>
|
||||
/// <param name="downloadClient">DownloadClient of the connector</param>
|
||||
/// <param name="requestType">Requesttype for ratelimit</param>
|
||||
protected static void DownloadImage(string imageUrl, string fullPath, DownloadClient downloadClient, byte requestType)
|
||||
{
|
||||
DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(imageUrl, requestType);
|
||||
byte[] buffer = new byte[requestResult.result.Length];
|
||||
requestResult.result.ReadExactly(buffer, 0, buffer.Length);
|
||||
File.WriteAllBytes(fullPath, buffer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Downloads all Images from URLs, Compresses to zip(cbz) and saves.
|
||||
/// </summary>
|
||||
/// <param name="imageUrls">List of URLs to download Images from</param>
|
||||
/// <param name="saveArchiveFilePath">Full path to save archive to (without file ending .cbz)</param>
|
||||
/// <param name="downloadClient">DownloadClient of the connector</param>
|
||||
/// <param name="comicInfoPath">Path of the generate Chapter ComicInfo.xml, if it was generated</param>
|
||||
/// <param name="requestType">RequestType for RateLimits</param>
|
||||
protected static void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient, byte requestType, Logger? logger, string? comicInfoPath = null)
|
||||
{
|
||||
logger?.WriteLine("Connector", "Downloading Images");
|
||||
//Check if Publication Directory already exists
|
||||
string directoryPath = Path.GetDirectoryName(saveArchiveFilePath)!;
|
||||
if (!Directory.Exists(directoryPath))
|
||||
Directory.CreateDirectory(directoryPath);
|
||||
|
||||
if (File.Exists(saveArchiveFilePath)) //Don't download twice.
|
||||
return;
|
||||
|
||||
//Create a temporary folder to store images
|
||||
string tempFolder = Directory.CreateTempSubdirectory().FullName;
|
||||
|
||||
int chapter = 0;
|
||||
//Download all Images to temporary Folder
|
||||
foreach (string imageUrl in imageUrls)
|
||||
{
|
||||
string[] split = imageUrl.Split('.');
|
||||
string extension = split[^1];
|
||||
DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), downloadClient, requestType);
|
||||
}
|
||||
|
||||
if(comicInfoPath is not null)
|
||||
File.Copy(comicInfoPath, Path.Join(tempFolder, "ComicInfo.xml"));
|
||||
|
||||
logger?.WriteLine("Connector", "Creating archive");
|
||||
//ZIP-it and ship-it
|
||||
ZipFile.CreateFromDirectory(tempFolder, saveArchiveFilePath);
|
||||
Directory.Delete(tempFolder, true); //Cleanup
|
||||
}
|
||||
|
||||
protected class DownloadClient
|
||||
{
|
||||
private static readonly HttpClient Client = new();
|
||||
|
||||
private readonly Dictionary<byte, DateTime> _lastExecutedRateLimit;
|
||||
private readonly Dictionary<byte, TimeSpan> _rateLimit;
|
||||
private Logger? logger;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a httpClient
|
||||
/// </summary>
|
||||
/// <param name="delay">minimum delay between requests (to avoid spam)</param>
|
||||
/// <param name="rateLimitRequestsPerMinute">Rate limits for requests. byte is RequestType, int maximum requests per minute for RequestType</param>
|
||||
public DownloadClient(Dictionary<byte, int> rateLimitRequestsPerMinute, Logger? logger)
|
||||
{
|
||||
this.logger = logger;
|
||||
_lastExecutedRateLimit = new();
|
||||
_rateLimit = new();
|
||||
foreach(KeyValuePair<byte, int> limit in rateLimitRequestsPerMinute)
|
||||
_rateLimit.Add(limit.Key, TimeSpan.FromMinutes(1).Divide(limit.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request Webpage
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="requestType">For RateLimits: Same Endpoints use same type</param>
|
||||
/// <returns>RequestResult with StatusCode and Stream of received data</returns>
|
||||
public RequestResult MakeRequest(string url, byte requestType)
|
||||
{
|
||||
if (_rateLimit.TryGetValue(requestType, out TimeSpan value))
|
||||
_lastExecutedRateLimit.TryAdd(requestType, DateTime.Now.Subtract(value));
|
||||
else
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), "RequestType not configured for rate-limit.");
|
||||
return new RequestResult(HttpStatusCode.NotAcceptable, Stream.Null);
|
||||
}
|
||||
|
||||
TimeSpan rateLimitTimeout = _rateLimit[requestType]
|
||||
.Subtract(DateTime.Now.Subtract(_lastExecutedRateLimit[requestType]));
|
||||
|
||||
if(rateLimitTimeout > TimeSpan.Zero)
|
||||
Thread.Sleep(rateLimitTimeout);
|
||||
|
||||
HttpResponseMessage? response = null;
|
||||
while (response is null)
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpRequestMessage requestMessage = new(HttpMethod.Get, url);
|
||||
_lastExecutedRateLimit[requestType] = DateTime.Now;
|
||||
response = Client.Send(requestMessage);
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), e.Message);
|
||||
Thread.Sleep(_rateLimit[requestType] * 2);
|
||||
}
|
||||
}
|
||||
Stream resultString = response.IsSuccessStatusCode ? response.Content.ReadAsStream() : Stream.Null;
|
||||
if (!response.IsSuccessStatusCode)
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Request-Error {response.StatusCode}: {response.ReasonPhrase}");
|
||||
return new RequestResult(response.StatusCode, resultString);
|
||||
}
|
||||
|
||||
public struct RequestResult
|
||||
{
|
||||
public HttpStatusCode statusCode { get; }
|
||||
public Stream result { get; }
|
||||
|
||||
public RequestResult(HttpStatusCode statusCode, Stream result)
|
||||
{
|
||||
this.statusCode = statusCode;
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,295 +0,0 @@
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Logging;
|
||||
|
||||
namespace Tranga.Connectors;
|
||||
public class MangaDex : Connector
|
||||
{
|
||||
public override string name { get; }
|
||||
|
||||
private enum RequestType : byte
|
||||
{
|
||||
Manga,
|
||||
Feed,
|
||||
AtHomeServer,
|
||||
Cover,
|
||||
Author
|
||||
}
|
||||
|
||||
public MangaDex(string downloadLocation, Logger? logger) : base(downloadLocation, logger)
|
||||
{
|
||||
name = "MangaDex";
|
||||
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
||||
{
|
||||
{(byte)RequestType.Manga, 250},
|
||||
{(byte)RequestType.Feed, 250},
|
||||
{(byte)RequestType.AtHomeServer, 40},
|
||||
{(byte)RequestType.Cover, 250},
|
||||
{(byte)RequestType.Author, 250}
|
||||
}, logger);
|
||||
}
|
||||
|
||||
public override Publication[] GetPublications(string publicationTitle = "")
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})");
|
||||
const int limit = 100; //How many values we want returned at once
|
||||
int offset = 0; //"Page"
|
||||
int total = int.MaxValue; //How many total results are there, is updated on first request
|
||||
HashSet<Publication> publications = new();
|
||||
while (offset < total) //As long as we haven't requested all "Pages"
|
||||
{
|
||||
//Request next Page
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest(
|
||||
$"https://api.mangadex.org/manga?limit={limit}&title={publicationTitle}&offset={offset}", (byte)RequestType.Manga);
|
||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
||||
break;
|
||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||
|
||||
offset += limit;
|
||||
if (result is null)
|
||||
break;
|
||||
|
||||
total = result["total"]!.GetValue<int>(); //Update the total number of Publications
|
||||
|
||||
JsonArray mangaInResult = result["data"]!.AsArray(); //Manga-data-Array
|
||||
//Loop each Manga and extract information from JSON
|
||||
foreach (JsonNode? mangeNode in mangaInResult)
|
||||
{
|
||||
JsonObject manga = (JsonObject)mangeNode!;
|
||||
JsonObject attributes = manga["attributes"]!.AsObject();
|
||||
|
||||
string publicationId = manga["id"]!.GetValue<string>();
|
||||
|
||||
string title = attributes["title"]!.AsObject().ContainsKey("en") && attributes["title"]!["en"] is not null
|
||||
? attributes["title"]!["en"]!.GetValue<string>()
|
||||
: attributes["title"]![((IDictionary<string, JsonNode?>)attributes["title"]!.AsObject()).Keys.First()]!.GetValue<string>();
|
||||
|
||||
string? description = attributes["description"]!.AsObject().ContainsKey("en") && attributes["description"]!["en"] is not null
|
||||
? attributes["description"]!["en"]!.GetValue<string?>()
|
||||
: null;
|
||||
|
||||
JsonArray altTitlesObject = attributes["altTitles"]!.AsArray();
|
||||
Dictionary<string, string> altTitlesDict = new();
|
||||
foreach (JsonNode? altTitleNode in altTitlesObject)
|
||||
{
|
||||
JsonObject altTitleObject = (JsonObject)altTitleNode!;
|
||||
string key = ((IDictionary<string, JsonNode?>)altTitleObject).Keys.ToArray()[0];
|
||||
altTitlesDict.TryAdd(key, altTitleObject[key]!.GetValue<string>());
|
||||
}
|
||||
|
||||
JsonArray tagsObject = attributes["tags"]!.AsArray();
|
||||
HashSet<string> tags = new();
|
||||
foreach (JsonNode? tagNode in tagsObject)
|
||||
{
|
||||
JsonObject tagObject = (JsonObject)tagNode!;
|
||||
if(tagObject["attributes"]!["name"]!.AsObject().ContainsKey("en"))
|
||||
tags.Add(tagObject["attributes"]!["name"]!["en"]!.GetValue<string>());
|
||||
}
|
||||
|
||||
string? posterId = null;
|
||||
string? authorId = null;
|
||||
if (manga.ContainsKey("relationships") && manga["relationships"] is not null)
|
||||
{
|
||||
JsonArray relationships = manga["relationships"]!.AsArray();
|
||||
posterId = relationships.FirstOrDefault(relationship => relationship!["type"]!.GetValue<string>() == "cover_art")!["id"]!.GetValue<string>();
|
||||
authorId = relationships.FirstOrDefault(relationship => relationship!["type"]!.GetValue<string>() == "author")!["id"]!.GetValue<string>();
|
||||
}
|
||||
string? coverUrl = GetCoverUrl(publicationId, posterId);
|
||||
string? author = GetAuthor(authorId);
|
||||
|
||||
Dictionary<string, string> linksDict = new();
|
||||
if (attributes.ContainsKey("links") && attributes["links"] is not null)
|
||||
{
|
||||
JsonObject linksObject = attributes["links"]!.AsObject();
|
||||
foreach (string key in ((IDictionary<string, JsonNode?>)linksObject).Keys)
|
||||
{
|
||||
linksDict.Add(key, linksObject[key]!.GetValue<string>());
|
||||
}
|
||||
}
|
||||
|
||||
int? year = attributes.ContainsKey("year") && attributes["year"] is not null
|
||||
? attributes["year"]!.GetValue<int?>()
|
||||
: null;
|
||||
|
||||
string? originalLanguage = attributes.ContainsKey("originalLanguage") && attributes["originalLanguage"] is not null
|
||||
? attributes["originalLanguage"]!.GetValue<string?>()
|
||||
: null;
|
||||
|
||||
string status = attributes["status"]!.GetValue<string>();
|
||||
|
||||
Publication pub = new (
|
||||
title,
|
||||
author,
|
||||
description,
|
||||
altTitlesDict,
|
||||
tags.ToArray(),
|
||||
coverUrl,
|
||||
linksDict,
|
||||
year,
|
||||
originalLanguage,
|
||||
status,
|
||||
publicationId
|
||||
);
|
||||
publications.Add(pub); //Add Publication (Manga) to result
|
||||
}
|
||||
}
|
||||
|
||||
return publications.ToArray();
|
||||
}
|
||||
|
||||
public override Chapter[] GetChapters(Publication publication, string language = "")
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters {publication.sortName} (language={language})");
|
||||
const int limit = 100; //How many values we want returned at once
|
||||
int offset = 0; //"Page"
|
||||
int total = int.MaxValue; //How many total results are there, is updated on first request
|
||||
List<Chapter> chapters = new();
|
||||
//As long as we haven't requested all "Pages"
|
||||
while (offset < total)
|
||||
{
|
||||
//Request next "Page"
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest(
|
||||
$"https://api.mangadex.org/manga/{publication.publicationId}/feed?limit={limit}&offset={offset}&translatedLanguage%5B%5D={language}", (byte)RequestType.Feed);
|
||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
||||
break;
|
||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||
|
||||
offset += limit;
|
||||
if (result is null)
|
||||
break;
|
||||
|
||||
total = result["total"]!.GetValue<int>();
|
||||
JsonArray chaptersInResult = result["data"]!.AsArray();
|
||||
//Loop through all Chapters in result and extract information from JSON
|
||||
foreach (JsonNode? jsonNode in chaptersInResult)
|
||||
{
|
||||
JsonObject chapter = (JsonObject)jsonNode!;
|
||||
JsonObject attributes = chapter["attributes"]!.AsObject();
|
||||
string chapterId = chapter["id"]!.GetValue<string>();
|
||||
|
||||
string? title = attributes.ContainsKey("title") && attributes["title"] is not null
|
||||
? attributes["title"]!.GetValue<string>()
|
||||
: null;
|
||||
|
||||
string? volume = attributes.ContainsKey("volume") && attributes["volume"] is not null
|
||||
? attributes["volume"]!.GetValue<string>()
|
||||
: null;
|
||||
|
||||
string? chapterNum = attributes.ContainsKey("chapter") && attributes["chapter"] is not null
|
||||
? attributes["chapter"]!.GetValue<string>()
|
||||
: null;
|
||||
|
||||
chapters.Add(new Chapter(title, volume, chapterNum, chapterId));
|
||||
}
|
||||
}
|
||||
|
||||
//Return Chapters ordered by Chapter-Number
|
||||
NumberFormatInfo chapterNumberFormatInfo = new()
|
||||
{
|
||||
NumberDecimalSeparator = "."
|
||||
};
|
||||
return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray();
|
||||
}
|
||||
|
||||
public override void DownloadChapter(Publication publication, Chapter chapter)
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Download Chapter {publication.sortName} {chapter.volumeNumber}-{chapter.chapterNumber}");
|
||||
//Request URLs for Chapter-Images
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest($"https://api.mangadex.org/at-home/server/{chapter.url}?forcePort443=false'", (byte)RequestType.AtHomeServer);
|
||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
||||
return;
|
||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||
if (result is null)
|
||||
return;
|
||||
|
||||
string baseUrl = result["baseUrl"]!.GetValue<string>();
|
||||
string hash = result["chapter"]!["hash"]!.GetValue<string>();
|
||||
JsonArray imageFileNames = result["chapter"]!["data"]!.AsArray();
|
||||
//Loop through all imageNames and construct urls (imageUrl)
|
||||
HashSet<string> imageUrls = new();
|
||||
foreach (JsonNode? image in imageFileNames)
|
||||
imageUrls.Add($"{baseUrl}/data/{hash}/{image!.GetValue<string>()}");
|
||||
|
||||
string comicInfoPath = Path.GetTempFileName();
|
||||
File.WriteAllText(comicInfoPath, CreateComicInfo(publication, chapter, logger));
|
||||
|
||||
//Download Chapter-Images
|
||||
DownloadChapterImages(imageUrls.ToArray(), CreateFullFilepath(publication, chapter), downloadClient, (byte)RequestType.AtHomeServer, logger, comicInfoPath);
|
||||
}
|
||||
|
||||
private string? GetCoverUrl(string publicationId, string? posterId)
|
||||
{
|
||||
if (posterId is null)
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"No posterId");
|
||||
return null;
|
||||
}
|
||||
|
||||
//Request information where to download Cover
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest($"https://api.mangadex.org/cover/{posterId}", (byte)RequestType.Cover);
|
||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
||||
return null;
|
||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||
if (result is null)
|
||||
return null;
|
||||
|
||||
string fileName = result["data"]!["attributes"]!["fileName"]!.GetValue<string>();
|
||||
|
||||
string coverUrl = $"https://uploads.mangadex.org/covers/{publicationId}/{fileName}";
|
||||
return coverUrl;
|
||||
}
|
||||
|
||||
private string? GetAuthor(string? authorId)
|
||||
{
|
||||
if (authorId is null)
|
||||
return null;
|
||||
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest($"https://api.mangadex.org/author/{authorId}", (byte)RequestType.Author);
|
||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
||||
return null;
|
||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||
if (result is null)
|
||||
return null;
|
||||
|
||||
string author = result["data"]!["attributes"]!["name"]!.GetValue<string>();
|
||||
return author;
|
||||
}
|
||||
|
||||
public override void DownloadCover(Publication publication)
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Download cover {publication.sortName}");
|
||||
//Check if Publication already has a Folder and cover
|
||||
string publicationFolder = Path.Join(downloadLocation, publication.folderName);
|
||||
if(!Directory.Exists(publicationFolder))
|
||||
Directory.CreateDirectory(publicationFolder);
|
||||
DirectoryInfo dirInfo = new (publicationFolder);
|
||||
if (dirInfo.EnumerateFiles().Any(info => info.Name.Contains("cover.")))
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Cover exists {publication.sortName}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (publication.posterUrl is null || publication.posterUrl!.Contains("http"))
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"No Poster-URL in publication");
|
||||
return;
|
||||
}
|
||||
|
||||
//Get file-extension (jpg, png)
|
||||
string[] split = publication.posterUrl.Split('.');
|
||||
string extension = split[^1];
|
||||
|
||||
string outFolderPath = Path.Join(downloadLocation, publication.folderName);
|
||||
Directory.CreateDirectory(outFolderPath);
|
||||
|
||||
//Download cover-Image
|
||||
DownloadImage(publication.posterUrl, Path.Join(downloadLocation, publication.folderName, $"cover.{extension}"), this.downloadClient, (byte)RequestType.AtHomeServer);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user