Compare commits
616 Commits
v1b18
...
v2_ChangeA
| Author | SHA1 | Date | |
|---|---|---|---|
| 0cc35300f1 | |||
| 2f21806bea | |||
| c5d75a8710 | |||
| f3dd37f649 | |||
| b035dd6b76 | |||
| 34c4bb8cb7 | |||
| de5c9f4ea1 | |||
| 9ab69ffef5 | |||
| d2ef59d171 | |||
| 8e2b333f47 | |||
| 594fb3073f | |||
| 3e87d5c140 | |||
| 86bec7f2ee | |||
| 8e242dc8da | |||
| efca9cf5d8 | |||
| 8573fffaa2 | |||
| 51aeb67ad6 | |||
| 5e371edf2b | |||
| d46ad72cb6 | |||
| a6ae2aacfb | |||
| dc862e4b3c | |||
| e56c5edfb4 | |||
| 70b310adef | |||
| 6748288f3c | |||
| 2c5d45e9c2 | |||
| c02c13bf90 | |||
| 902ca114c1 | |||
| 17cd039c9b | |||
| 26f955fce2 | |||
| 3cc48fb8f7 | |||
| 60178dc54b | |||
| 8a63a3448a | |||
| f5336f63ce | |||
| 97583349df | |||
| 9bec336323 | |||
| 123b64a666 | |||
| 5a215231fa | |||
| 6a29b5386c | |||
| 7cd138b09f | |||
| 504837fe77 | |||
| 7dde1d86f8 | |||
| a480ae9c50 | |||
| 2c9a87bf3e | |||
| 03ea94b858 | |||
| 9e42985ec8 | |||
| dbf17aee3b | |||
| 2b91d9a798 | |||
| 74d18419a6 | |||
| e3f007b568 | |||
| 6690f09a32 | |||
| 7c496b4c7f | |||
| 77abdd807d | |||
| 7599a7d60a | |||
| 14993b9fe7 | |||
| acba3a9f53 | |||
| 2b62fc141d | |||
| 4baa0bbe77 | |||
| d88376f2fb | |||
| eaece9e334 | |||
| 7e158d48c6 | |||
| 4ed153ac5b | |||
| 6b17296139 | |||
| bb5dffe395 | |||
| 0fa844f856 | |||
| 4fea77c837 | |||
| f76c797a7f | |||
| ad81fd9199 | |||
| f732c80230 | |||
| eb97d15f03 | |||
| be590d8e2b | |||
| a41845e45c | |||
| a1cb4f243a | |||
| 110e055e24 | |||
| f3a35bd62a | |||
| 565d9a5a4d | |||
| dbc29046f5 | |||
| 0152502c1b | |||
| 0520e3d7e5 | |||
| dc49e168ab | |||
| da55f2b19e | |||
| 424f2a8779 | |||
| 255bfba9e3 | |||
| 593a79c506 | |||
| d4a7600c14 | |||
|
|
7ead76fbcc | ||
|
|
f87e4a0800 | ||
|
|
eab03d7f5a | ||
| 9dc77e6dde | |||
| 3a804c99ce | |||
|
|
c49b000521 | ||
|
|
ebc1b9441e | ||
| 0e5402c347 | |||
| 6922242b4f | |||
| 73ca5e57e8 | |||
| a579dd4759 | |||
|
|
609a0297d5 | ||
|
|
0743bad93c | ||
|
|
49848db96f | ||
|
|
ba736d2b19 | ||
|
|
753cb04dfe | ||
|
|
bc25210fe4 | ||
|
|
a4e0175173 | ||
|
|
bd8ea67017 | ||
| 8126250d1a | |||
|
|
8ac2d20d8a | ||
| 1b4d32eed3 | |||
| 1a67fcffb4 | |||
| bbc6c0fbd3 | |||
| 6657bae0cd | |||
| 65ea5985d3 | |||
| 7defc9a6a9 | |||
| 504cb8e950 | |||
| f81b84e4b3 | |||
| c12e1e38b8 | |||
| db7ac8d174 | |||
| 0b0c9304b1 | |||
| f56f592c4c | |||
| b0fe27c643 | |||
| 55bc825cb7 | |||
| 7fa46ef245 | |||
| e1c0722fce | |||
| 3f511cefa8 | |||
| f1adba4fa6 | |||
| a9d3a30782 | |||
| 55a8cfad46 | |||
| 420ff46ceb | |||
| 75f037da02 | |||
| 1238095f09 | |||
| 3084bb268b | |||
| f1c0d3b896 | |||
| 340cf738dc | |||
| f23320eb1c | |||
| 9fb1667bf0 | |||
| 1f95577eb7 | |||
| 45ccb6fc4c | |||
| b1092985ff | |||
| 6c5e4c2a1e | |||
| caa8d47af2 | |||
| cdc4744f28 | |||
| f4a0aabb61 | |||
| 64f4a3a58c | |||
| a23c3b0fdd | |||
| 3dd5d2958a | |||
| 69df761bf4 | |||
| 4a571e1944 | |||
| fa86b26f46 | |||
| 480d118014 | |||
| 2e5d0dcd73 | |||
| b6b488edf6 | |||
| bf5a744499 | |||
| 1a4864ba00 | |||
| e299cde6da | |||
| 8372cfad1b | |||
| d477e803ab | |||
| bf89ef16f7 | |||
| 744d977454 | |||
| b95f89687f | |||
| 143ba3c138 | |||
| 094af845a0 | |||
| 5efeb5fba6 | |||
| 42ab052699 | |||
| e6c9feed6b | |||
| e63a3db8b9 | |||
| 75cefea4fa | |||
| 150a18cc0b | |||
| 64b20e26ac | |||
| f08c8f013d | |||
| 721570927f | |||
| 62fe6089f7 | |||
| 0a76e64d2f | |||
| 2e98d166ec | |||
|
|
bc737c830f | ||
|
|
23a74bdfc6 | ||
|
|
f702167d6e | ||
|
|
fe31c01a06 | ||
|
|
2d0a0e53c0 | ||
|
|
072adb5bb1 | ||
|
|
e5555c815b | ||
|
|
a074f0c4f0 | ||
|
|
d92f996169 | ||
|
|
96bb3a5c0f | ||
|
|
18810766ed | ||
|
|
764ebe3586 | ||
|
|
add4c3e99f | ||
|
|
f9c4ec1d31 | ||
|
|
f2d653563c | ||
|
|
288b0c8d97 | ||
|
|
69e5e1c75b | ||
|
|
399fbbaab5 | ||
|
|
06f7731011 | ||
|
|
81d8bc45ee | ||
|
|
17a4e7ec14 | ||
|
|
b73c3ebfb3 | ||
|
|
b0a044db97 | ||
|
|
fce44f49b6 | ||
|
|
6d0c75ceff | ||
|
|
324bf6891a | ||
|
|
e5f29e4725 | ||
|
|
54e0675ba9 | ||
|
|
e02af774a9 | ||
|
|
f6ed12fc7a | ||
|
|
c15f18108d | ||
|
|
7239182e83 | ||
|
|
eba6e00251 | ||
|
|
6f3341e6ad | ||
|
|
910f190c86 | ||
|
|
c4c3d1bd60 | ||
|
|
f166de1a43 | ||
|
|
71dc81c4dc | ||
|
|
8883b521e9 | ||
|
|
6be3b8338d | ||
|
|
9d1351527d | ||
|
|
13daa3cbac | ||
|
|
19afc5d055 | ||
|
|
bb29177e41 | ||
|
|
f48e5d4b19 | ||
|
|
cf25e4e1e6 | ||
|
|
966e67afee | ||
|
|
a0432eec68 | ||
|
|
522d0c1471 | ||
|
|
ca1b7a84c9 | ||
|
|
e32e35d3af | ||
|
|
ef2e6c9a20 | ||
|
|
fa748494f6 | ||
|
|
73bf27d222 | ||
|
|
c05ea18513 | ||
|
|
23dc3495f1 | ||
|
|
bdcacdf6b7 | ||
|
|
c0ff47e478 | ||
|
|
6d0a59f5b9 | ||
|
|
a56adfed8a | ||
|
|
a2a520e9fd | ||
|
|
bd189caf80 | ||
|
|
333346889d | ||
|
|
26ba7e0ef6 | ||
|
|
5e61526218 | ||
|
|
ae2634f57e | ||
|
|
583aeb9225 | ||
|
|
dcef6e4500 | ||
|
|
e53a1bad0e | ||
|
|
3f0ade7fb2 | ||
|
|
e778b3ebae | ||
|
|
f54e5d8716 | ||
|
|
90b8b00ef6 | ||
|
|
9602a201ce | ||
|
|
ba907d5499 | ||
|
|
1eb63d7a8c | ||
|
|
1cca9457ee | ||
|
|
20b67eafe1 | ||
|
|
4e1f1629a1 | ||
|
|
2eac1b3c78 | ||
|
|
a895372e13 | ||
|
|
52b3616de4 | ||
|
|
caa7bb2af6 | ||
|
|
a8bb2aa000 | ||
|
|
c6d88fe7bf | ||
|
|
48e84e815b | ||
|
|
d821ce43b5 | ||
|
|
83c40ec417 | ||
|
|
fcfbf5a01d | ||
|
|
f924bcfcc6 | ||
|
|
9d9717df61 | ||
|
|
1b6bc61263 | ||
|
|
650b993325 | ||
|
|
1525215757 | ||
|
|
9eb9e047e1 | ||
|
|
326bd09662 | ||
|
|
53509ecf63 | ||
|
|
95a5eafec2 | ||
|
|
2838a91e3c | ||
|
|
7fcd674b7f | ||
|
|
d9d17c8342 | ||
|
|
42e9f18fb6 | ||
|
|
7c2db9bb00 | ||
|
|
2060b9140f | ||
|
|
ed33678f50 | ||
|
|
63cf9c758d | ||
|
|
efe37d2dd7 | ||
|
|
a12e2be0e7 | ||
|
|
7870baed08 | ||
|
|
4e6b75d167 | ||
|
|
38b93cd500 | ||
|
|
04422b94d0 | ||
|
|
be3a5fb6c3 | ||
|
|
8b5270d2ed | ||
|
|
173361bc2b | ||
|
|
09d6da4ad3 | ||
|
|
862b43ae6d | ||
|
|
b1854c1a30 | ||
|
|
a0f256946e | ||
|
|
8b489da287 | ||
|
|
87f93b3cab | ||
|
|
0fd60b5ccb | ||
|
|
ebe1c0b2df | ||
|
|
addb71c558 | ||
|
|
b7a21ceb94 | ||
|
|
67b201e7c5 | ||
|
|
1254925c4a | ||
|
|
1cc32fa5c4 | ||
|
|
77d24ed90f | ||
|
|
d2d2463164 | ||
|
|
2bb3b0fd48 | ||
|
|
e43d6bff06 | ||
|
|
4401a91d35 | ||
|
|
fc863cc422 | ||
|
|
dd3724b4de | ||
|
|
dc1b35fbe0 | ||
|
|
d62af84dfd | ||
|
|
b5119b6be1 | ||
|
|
ac5890f115 | ||
|
|
96a906b717 | ||
|
|
02da555028 | ||
|
|
4d4eb6e640 | ||
|
|
0dd24f1e7f | ||
|
|
20d0e1c8eb | ||
|
|
dfb633f6a7 | ||
|
|
0ff0ce1252 | ||
|
|
09dffe020d | ||
|
|
f3a5a8de25 | ||
|
|
d107164d7d | ||
|
|
fd76a085dc | ||
|
|
7a9708137c | ||
|
|
13a49d3306 | ||
|
|
6fa91d8890 | ||
|
|
a580e4335b | ||
|
|
a4080cc1b1 | ||
|
|
4f5a4913d7 | ||
|
|
83f453da3f | ||
|
|
c340e48f02 | ||
|
|
61492bc669 | ||
|
|
6264a15b1d | ||
|
|
257af8106d | ||
|
|
6eedc8aba9 | ||
|
|
cba98bdf6f | ||
|
|
d2da868b71 | ||
|
|
685221b454 | ||
|
|
f12e5f10d5 | ||
|
|
cc7b4d7daa | ||
|
|
769c876dc5 | ||
|
|
ccec79cca7 | ||
|
|
e79f2199c3 | ||
|
|
c53d315bd8 | ||
|
|
0ae9c27d93 | ||
|
|
2950034a30 | ||
|
|
158115bb3b | ||
|
|
56184a8254 | ||
|
|
c27b1689f3 | ||
|
|
3c3dd2af92 | ||
|
|
125260e7ef | ||
|
|
b608a0779c | ||
|
|
7225db0bf1 | ||
|
|
3f0cdff262 | ||
|
|
3270039a6a | ||
|
|
fda972a90e | ||
|
|
45e81c98bf | ||
|
|
d9dd9bbf4d | ||
|
|
160de6443b | ||
|
|
923a3c18b8 | ||
|
|
8dc37525ce | ||
|
|
7bd34842fa | ||
|
|
da8b01bb98 | ||
|
|
c9fe469f5b | ||
|
|
406f7cad65 | ||
|
|
558e237608 | ||
|
|
b4251a0f1f | ||
|
|
0234a8e179 | ||
|
|
efacaa9b86 | ||
|
|
7c40d999ff | ||
|
|
99c14693d5 | ||
|
|
2cf03d4b68 | ||
|
|
52bab229ea | ||
|
|
8b15383b45 | ||
|
|
eaddefdc8e | ||
|
|
95cfa815fb | ||
|
|
870b2516a1 | ||
|
|
ef982a52ed | ||
|
|
6ae2390b46 | ||
|
|
e1fbf601f3 | ||
|
|
2364a53dd1 | ||
|
|
be7cecc721 | ||
|
|
f2aad2ccdf | ||
|
|
8e76a68b62 | ||
|
|
6c722a9ac3 | ||
|
|
52515e7df1 | ||
|
|
722c56271f | ||
|
|
9e85c35f59 | ||
|
|
538a15b609 | ||
|
|
bb0ab9dc67 | ||
|
|
87b9b5e1c2 | ||
|
|
ba0b46db90 | ||
|
|
ddcbf56abe | ||
|
|
c553f6f5da | ||
|
|
5b25774851 | ||
|
|
01729b982d | ||
|
|
fd01787dfb | ||
|
|
90eed5c74c | ||
|
|
dcfb836b39 | ||
|
|
610501ef19 | ||
|
|
48e2e1eb98 | ||
|
|
f3ad71e33f | ||
|
|
eaacdb3446 | ||
|
|
be173e1d48 | ||
|
|
e3f040c978 | ||
|
|
e25b005643 | ||
|
|
4631e66dca | ||
|
|
73b93f8262 | ||
|
|
5a1ecebbe9 | ||
|
|
8dbf458ea3 | ||
|
|
c5fef04d06 | ||
|
|
5fb507febc | ||
|
|
50d6954829 | ||
|
|
e5f4fd9d62 | ||
|
|
7da87fb065 | ||
|
|
b81646c1d4 | ||
|
|
752f84127c | ||
|
|
bf1b9533c8 | ||
|
|
feddea1a69 | ||
|
|
20fcd5015e | ||
|
|
9abf32b288 | ||
|
|
5d9c32a196 | ||
|
|
cdc2954d0b | ||
|
|
b2929fe211 | ||
|
|
3a74f3abcd | ||
|
|
49077e7023 | ||
|
|
44b2d07fdb | ||
|
|
0ee4f3fe04 | ||
|
|
456d87f262 | ||
|
|
e47a4c29f7 | ||
|
|
f172d765e3 | ||
|
|
9bf129f1ad | ||
|
|
1cb603a3f3 | ||
|
|
0a807605ad | ||
|
|
e20415a5bd | ||
|
|
15a3789174 | ||
|
|
823970f617 | ||
|
|
5a025eb75b | ||
|
|
bf6641c151 | ||
|
|
f18877f9b1 | ||
|
|
c3679afed7 | ||
|
|
a0ca9af5c9 | ||
|
|
d1f73e6d78 | ||
|
|
368886c95c | ||
|
|
86f3957028 | ||
|
|
6ec86fdc25 | ||
|
|
068858f3a1 | ||
|
|
8d11d2360e | ||
|
|
970bca7121 | ||
|
|
07c09e48e3 | ||
|
|
b2c816cafb | ||
|
|
960a0bceff | ||
|
|
aaf4c05630 | ||
|
|
fada1a11b0 | ||
|
|
dfa34a6808 | ||
|
|
1b427607d1 | ||
|
|
70445069fd | ||
|
|
423616b9f3 | ||
|
|
26ed50c94b | ||
|
|
caa34dd79d | ||
|
|
0eabe27196 | ||
|
|
dfc2b5af17 | ||
|
|
955946d0a6 | ||
|
|
9e515d9ed7 | ||
|
|
95507fd41f | ||
|
|
8d75b30ae4 | ||
|
|
64bcfe74e7 | ||
|
|
2729564495 | ||
|
|
0ec6949095 | ||
|
|
681403ec6e | ||
|
|
aaee81e9c4 | ||
|
|
4e5124cc1b | ||
|
|
99a7d7bd73 | ||
|
|
6fd1336f1c | ||
|
|
33c1ffa0ba | ||
|
|
19001e5836 | ||
|
|
12bc66a95b | ||
|
|
63b2b40227 | ||
|
|
bb53f1c40a | ||
|
|
46f08059d7 | ||
|
|
a9af1ec15e | ||
|
|
9179d6825c | ||
|
|
4816befa71 | ||
|
|
67c846ddc8 | ||
|
|
79d860351c | ||
|
|
c1216ea708 | ||
|
|
a11569a737 | ||
|
|
cd4feec58f | ||
|
|
518ec7055a | ||
|
|
2552b92e5d | ||
|
|
e9d3ab5307 | ||
|
|
becc67c46b | ||
|
|
c3a0833410 | ||
|
|
da53a0eef7 | ||
|
|
289f8921ff | ||
|
|
e1a0cfeebb | ||
|
|
55a7d71c7f | ||
|
|
8d1cb47a8a | ||
|
|
2510d6748c | ||
|
|
f17ff9246d | ||
|
|
a2a9a6e21d | ||
|
|
0e1ddfbccb | ||
|
|
2edf8b4a9f | ||
|
|
e47cac71fc | ||
|
|
0aa28d9764 | ||
|
|
8b032462c0 | ||
|
|
3ae694a3da | ||
|
|
741d13b18a | ||
|
|
0d8cc5bd5d | ||
|
|
04ef9dc827 | ||
|
|
c11ff632d2 | ||
|
|
c5a3c0550c | ||
|
|
a67829035e | ||
|
|
f57aac4f6c | ||
|
|
3a53fa0a3c | ||
|
|
7145890801 | ||
|
|
6d5a5fd16c | ||
|
|
3092daaad4 | ||
|
|
0f989a38c3 | ||
|
|
e8706cad1c | ||
|
|
d55490dd51 | ||
|
|
a1cd6b5cd9 | ||
|
|
0e43278bdd | ||
|
|
d8bb2b7356 | ||
|
|
f779e5e920 | ||
|
|
c57ad9cce7 | ||
|
|
b492d65efb | ||
|
|
332937f964 | ||
|
|
f5501f77fe | ||
|
|
30bfae96fd | ||
|
|
d95d613a57 | ||
|
|
1c96f9d13c | ||
|
|
9e182768f6 | ||
|
|
11dace2617 | ||
|
|
93cfe7cd1a | ||
|
|
b580781618 | ||
|
|
ee9190447f | ||
|
|
aa501244e1 | ||
|
|
52d39151da | ||
|
|
0241be13cf | ||
|
|
c3acb4898e | ||
|
|
559a00c181 | ||
|
|
122a205f92 | ||
|
|
c4e7e10f5e | ||
|
|
6d83c31f42 | ||
|
|
d98e8ef0f8 | ||
|
|
a29dc8257e | ||
|
|
801c78bb84 | ||
|
|
a671e601c0 | ||
|
|
4de6804f13 | ||
|
|
7a3d61c659 | ||
|
|
b0d9837256 | ||
|
|
f07e3c5a5a | ||
|
|
19b5c7816a | ||
|
|
dae09668b2 | ||
|
|
aa150a7a69 | ||
|
|
d0f03a19a2 | ||
|
|
863a002370 | ||
|
|
ff9bcc6433 | ||
|
|
e062df4eb6 | ||
|
|
2dd1d1f69c | ||
|
|
3d4f22f6f6 | ||
|
|
48c95d4ec6 | ||
|
|
b19208b3b0 | ||
|
|
6410846afc | ||
|
|
f7a16fd287 | ||
|
|
4159170244 | ||
|
|
8c82631569 | ||
|
|
96bd131807 | ||
|
|
0cde0fe302 | ||
|
|
49c893f515 | ||
|
|
3bb4e7daab | ||
|
|
afb3a7f3a3 | ||
|
|
69b50275cd | ||
|
|
76866fe14f | ||
|
|
3308def6c5 | ||
|
|
39b632d483 | ||
|
|
84d39c1c75 | ||
|
|
9abd9d86b2 | ||
|
|
73a07761f8 | ||
|
|
ebe2d9d7ef | ||
|
|
48b12fde90 | ||
|
|
8ac4fae9c1 | ||
|
|
d224f1e1bb | ||
|
|
13131e6fca | ||
|
|
26fdfe112b | ||
|
|
ecf0d372e5 | ||
|
|
e281cfadbd | ||
|
|
ae2228e08a | ||
|
|
3f5a7504fa | ||
|
|
f8af48aeab | ||
|
|
9b9656892d | ||
|
|
db2c6ec30d | ||
|
|
e46122b030 | ||
|
|
1a9836a884 | ||
|
|
ef930400c8 | ||
|
|
450a954b9d | ||
|
|
31ba5f04cc | ||
|
|
6ca024d6cb | ||
|
|
cef5cb11cb | ||
|
|
e91a9b2239 | ||
|
|
d7ca9d1fe6 | ||
|
|
564745b4a2 | ||
|
|
74361b7a4a | ||
|
|
7a992d71fb | ||
|
|
b8d30f0380 | ||
|
|
07d7df8188 | ||
|
|
2ddb8723af | ||
|
|
caf990dd4e | ||
|
|
d0401a1709 | ||
|
|
67974123db | ||
|
|
05817a8866 | ||
|
|
707776f1ed | ||
|
|
4ba7634b94 | ||
|
|
732abe53e0 | ||
|
|
37b1288ae6 | ||
|
|
dda302ebf1 | ||
|
|
f1aace98c3 |
@@ -1,25 +0,0 @@
|
|||||||
**/.classpath
|
|
||||||
**/.dockerignore
|
|
||||||
**/.env
|
|
||||||
**/.git
|
|
||||||
**/.gitignore
|
|
||||||
**/.project
|
|
||||||
**/.settings
|
|
||||||
**/.toolstarget
|
|
||||||
**/.vs
|
|
||||||
**/.vscode
|
|
||||||
**/*.*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
|
|
||||||
8
.gitattributes
vendored
8
.gitattributes
vendored
@@ -1,10 +1,2 @@
|
|||||||
# Auto detect text files and perform LF normalization
|
# Auto detect text files and perform LF normalization
|
||||||
* text=auto
|
* text=auto
|
||||||
Moonlight/wwwroot/** linguist-vendored
|
|
||||||
Moonlight/wwwroot/assets/js/scripts.bundle.js linguist-vendored
|
|
||||||
Moonlight/wwwroot/assets/js/widgets.bundle.js linguist-vendored
|
|
||||||
Moonlight/wwwroot/assets/js/theme.js linguist-vendored
|
|
||||||
Moonlight/wwwroot/assets/css/boxicons.min.css linguist-vendored
|
|
||||||
Moonlight/wwwroot/assets/css/style.bundle.css linguist-vendored
|
|
||||||
Moonlight/wwwroot/assets/plugins/** linguist-vendored
|
|
||||||
Moonlight/wwwroot/assets/fonts/** linguist-vendored
|
|
||||||
|
|||||||
2
.github/FUNDING.yml
vendored
Normal file
2
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
ko_fi: masuowo
|
||||||
87
.github/ISSUE_TEMPLATE/bug-report.yml
vendored
Normal file
87
.github/ISSUE_TEMPLATE/bug-report.yml
vendored
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
name: Bug Report
|
||||||
|
description: Something isn't working quite right in the software.
|
||||||
|
labels: [not confirmed]
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Bug reports should only be used for reporting issues with how the software works. For assistance installing this software, as well as debugging issues with dependencies, please use our [Discord server](https://discord.gg/TJaspT7A8p).
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Current Behavior
|
||||||
|
description: Please provide a clear & concise description of the issue.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Expected Behavior
|
||||||
|
description: Please describe what you expected to happen.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Steps to Reproduce
|
||||||
|
description: Please be as detailed as possible when providing steps to reproduce, failure to provide steps will result in this issue being closed.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
id: panel-version
|
||||||
|
attributes:
|
||||||
|
label: Panel Version
|
||||||
|
description: Version number of your Panel (latest is not a version)
|
||||||
|
placeholder: v2 EA
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
id: daemon-version
|
||||||
|
attributes:
|
||||||
|
label: Daemon Version
|
||||||
|
description: Version number of your Daemon (latest is not a version)
|
||||||
|
placeholder: v2 EA
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
id: image-details
|
||||||
|
attributes:
|
||||||
|
label: Games and/or Images Affected
|
||||||
|
description: Please include the specific game(s) or Image(s) you are running into this bug with.
|
||||||
|
placeholder: Minecraft (Paper), Minecraft (Forge)
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
id: docker-image
|
||||||
|
attributes:
|
||||||
|
label: Docker Image
|
||||||
|
description: The specific Docker image you are using for the game(s) above.
|
||||||
|
placeholder: ghcr.io/xxx/yolks:java_17
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: panel-logs
|
||||||
|
attributes:
|
||||||
|
label: Error Logs
|
||||||
|
description: |
|
||||||
|
Run the following command to collect logs on your system.
|
||||||
|
|
||||||
|
Panel: `docker logs moonlight`
|
||||||
|
Wings: `sudo wings diagnostics`
|
||||||
|
placeholder: logs here
|
||||||
|
render: bash
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
|
||||||
|
- type: checkboxes
|
||||||
|
attributes:
|
||||||
|
label: Is there an existing issue for this?
|
||||||
|
description: Please [search here](https://github.com/Moonlight-Panel/Moonlight/issues) to see if an issue already exists for your problem.
|
||||||
|
options:
|
||||||
|
- label: I have searched the existing issues before opening this issue.
|
||||||
|
required: true
|
||||||
|
- label: I have provided all relevant details, including the specific game and Docker images I am using if this issue is related to running a server.
|
||||||
|
required: true
|
||||||
|
- label: I have checked in the Discord server and believe this is a bug with the software, and not a configuration issue with my specific system.
|
||||||
|
required: true
|
||||||
8
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
8
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
blank_issues_enabled: true
|
||||||
|
contact_links:
|
||||||
|
- name: Installation Help
|
||||||
|
url: https://discord.gg/TJaspT7A8p
|
||||||
|
about: Please visit our Discord for help with your installation.
|
||||||
|
- name: General Question
|
||||||
|
url: https://discord.gg/TJaspT7A8p
|
||||||
|
about: Please visit our Discord for general questions about Moonlight Panel.
|
||||||
32
.github/ISSUE_TEMPLATE/feature-request.yml
vendored
Normal file
32
.github/ISSUE_TEMPLATE/feature-request.yml
vendored
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
name: Feature Request
|
||||||
|
description: Suggest a new feature or improvement for the software.
|
||||||
|
labels: [feature request]
|
||||||
|
body:
|
||||||
|
- type: checkboxes
|
||||||
|
attributes:
|
||||||
|
label: Is there an existing feature request for this?
|
||||||
|
description: Please [search here](https://github.com/Moonlight-Panel/Moonlight/issues?q=is%3Aissue) to see if someone else has already suggested this.
|
||||||
|
options:
|
||||||
|
- label: I have searched the existing issues before opening this feature request.
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Describe the feature you would like to see.
|
||||||
|
description: "A clear & concise description of the feature you'd like to have added, and what issues it would solve."
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Describe the solution you'd like.
|
||||||
|
description: "You must explain how you'd like to see this feature implemented. Technical implementation details are not necessary, rather an idea of how you'd like to see this feature used."
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Additional context to this request.
|
||||||
|
description: "Add any other context or screenshots about the feature request."
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
42
.github/workflows/publish-dev-packages.yml
vendored
Normal file
42
.github/workflows/publish-dev-packages.yml
vendored
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
name: Build and Publish NuGet Package
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ v2_ChangeArchitecture,v2.1 ]
|
||||||
|
paths:
|
||||||
|
- '**.csproj'
|
||||||
|
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
publish:
|
||||||
|
runs-on: debian-12
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
project:
|
||||||
|
- Moonlight.Client
|
||||||
|
- Moonlight.ApiServer
|
||||||
|
- Moonlight.Shared
|
||||||
|
|
||||||
|
steps:
|
||||||
|
# Step 1: Clean environment
|
||||||
|
- name: Clean up Environment
|
||||||
|
run: |
|
||||||
|
rm -rf ./*
|
||||||
|
rm -rf ./.??*
|
||||||
|
|
||||||
|
# Step 2: Checkout the code
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
# Step 3: Build project
|
||||||
|
- name: "Build project"
|
||||||
|
run: dotnet build --configuration Debug ${{ matrix.project }}/${{ matrix.project }}.csproj
|
||||||
|
|
||||||
|
# Step 4: Pack project
|
||||||
|
- name: "Pack project"
|
||||||
|
run: dotnet pack --configuration Debug --no-build --output . ${{ matrix.project }}/${{ matrix.project }}.csproj
|
||||||
|
|
||||||
|
# Step 5: Publish on package registry
|
||||||
|
- name: Publish on package registry"
|
||||||
|
run: dotnet nuget push "*.nupkg" --skip-duplicate --api-key ${{secrets.GH_PACKAGES_READWRITE}} --source https://nuget.pkg.github.com/Moonlight-Panel/index.json
|
||||||
18
.github/workflows/test-docker-build.yml
vendored
18
.github/workflows/test-docker-build.yml
vendored
@@ -1,18 +0,0 @@
|
|||||||
name: Test Build
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ "main" ]
|
|
||||||
pull_request:
|
|
||||||
types:
|
|
||||||
- closed
|
|
||||||
branches: [ "main" ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
- name: Build Docker image
|
|
||||||
run: docker build -t moonlightpanel/moonlight:${{ github.sha }} -f Moonlight/Dockerfile .
|
|
||||||
461
.gitignore
vendored
461
.gitignore
vendored
@@ -1,45 +1,434 @@
|
|||||||
Common IntelliJ Platform excludes
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
## files generated by popular Visual Studio add-ons.
|
||||||
# User specific
|
##
|
||||||
**/.idea/**/workspace.xml
|
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
|
||||||
**/.idea/**/tasks.xml
|
|
||||||
**/.idea/shelf/*
|
|
||||||
**/.idea/dictionaries
|
|
||||||
**/.idea/httpRequests/
|
|
||||||
|
|
||||||
# Sensitive or high-churn files
|
|
||||||
**/.idea/**/dataSources/
|
|
||||||
**/.idea/**/dataSources.ids
|
|
||||||
**/.idea/**/dataSources.xml
|
|
||||||
**/.idea/**/dataSources.local.xml
|
|
||||||
**/.idea/**/sqlDataSources.xml
|
|
||||||
**/.idea/**/dynamic.xml
|
|
||||||
|
|
||||||
# Rider
|
|
||||||
# Rider auto-generates .iml files, and contentModel.xml
|
|
||||||
**/.idea/**/*.iml
|
|
||||||
**/.idea/**/contentModel.xml
|
|
||||||
**/.idea/**/modules.xml
|
|
||||||
|
|
||||||
|
|
||||||
Moonlight/[Bb]in/
|
|
||||||
Moonlight/[Oo]bj/
|
|
||||||
Moonlight/_UpgradeReport_Files/
|
|
||||||
Moonlight/[Pp]ackages/
|
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.rsuser
|
||||||
*.suo
|
*.suo
|
||||||
*.user
|
*.user
|
||||||
.vs/
|
*.userosscache
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||||
|
*.userprefs
|
||||||
|
|
||||||
|
# Mono auto generated files
|
||||||
|
mono_crash.*
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Dd]ebugPublic/
|
||||||
|
[Rr]elease/
|
||||||
|
[Rr]eleases/
|
||||||
|
x64/
|
||||||
|
x86/
|
||||||
|
[Ww][Ii][Nn]32/
|
||||||
|
[Aa][Rr][Mm]/
|
||||||
|
[Aa][Rr][Mm]64/
|
||||||
|
bld/
|
||||||
[Bb]in/
|
[Bb]in/
|
||||||
[Oo]bj/
|
[Oo]bj/
|
||||||
|
[Ll]og/
|
||||||
|
[Ll]ogs/
|
||||||
|
|
||||||
|
# Visual Studio 2015/2017 cache/options directory
|
||||||
|
.vs/
|
||||||
|
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||||
|
#wwwroot/
|
||||||
|
|
||||||
|
# Visual Studio 2017 auto generated files
|
||||||
|
Generated\ Files/
|
||||||
|
|
||||||
|
# MSTest test Results
|
||||||
|
[Tt]est[Rr]esult*/
|
||||||
|
[Bb]uild[Ll]og.*
|
||||||
|
|
||||||
|
# NUnit
|
||||||
|
*.VisualState.xml
|
||||||
|
TestResult.xml
|
||||||
|
nunit-*.xml
|
||||||
|
|
||||||
|
# Build Results of an ATL Project
|
||||||
|
[Dd]ebugPS/
|
||||||
|
[Rr]eleasePS/
|
||||||
|
dlldata.c
|
||||||
|
|
||||||
|
# Benchmark Results
|
||||||
|
BenchmarkDotNet.Artifacts/
|
||||||
|
|
||||||
|
# .NET Core
|
||||||
|
project.lock.json
|
||||||
|
project.fragment.lock.json
|
||||||
|
artifacts/
|
||||||
|
|
||||||
|
# ASP.NET Scaffolding
|
||||||
|
ScaffoldingReadMe.txt
|
||||||
|
|
||||||
|
# StyleCop
|
||||||
|
StyleCopReport.xml
|
||||||
|
|
||||||
|
# Files built by Visual Studio
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*_h.h
|
||||||
|
*.ilk
|
||||||
|
*.meta
|
||||||
|
*.obj
|
||||||
|
*.iobj
|
||||||
|
*.pch
|
||||||
|
*.pdb
|
||||||
|
*.ipdb
|
||||||
|
*.pgc
|
||||||
|
*.pgd
|
||||||
|
*.rsp
|
||||||
|
*.sbr
|
||||||
|
*.tlb
|
||||||
|
*.tli
|
||||||
|
*.tlh
|
||||||
|
*.tmp
|
||||||
|
*.tmp_proj
|
||||||
|
*_wpftmp.csproj
|
||||||
|
*.log
|
||||||
|
*.tlog
|
||||||
|
*.vspscc
|
||||||
|
*.vssscc
|
||||||
|
.builds
|
||||||
|
*.pidb
|
||||||
|
*.svclog
|
||||||
|
*.scc
|
||||||
|
|
||||||
|
# Chutzpah Test files
|
||||||
|
_Chutzpah*
|
||||||
|
|
||||||
|
# Visual C++ cache files
|
||||||
|
ipch/
|
||||||
|
*.aps
|
||||||
|
*.ncb
|
||||||
|
*.opendb
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
*.cachefile
|
||||||
|
*.VC.db
|
||||||
|
*.VC.VC.opendb
|
||||||
|
|
||||||
|
# Visual Studio profiler
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
*.vspx
|
||||||
|
*.sap
|
||||||
|
|
||||||
|
# Visual Studio Trace Files
|
||||||
|
*.e2e
|
||||||
|
|
||||||
|
# TFS 2012 Local Workspace
|
||||||
|
$tf/
|
||||||
|
|
||||||
|
# Guidance Automation Toolkit
|
||||||
|
*.gpState
|
||||||
|
|
||||||
|
# ReSharper is a .NET coding add-in
|
||||||
|
_ReSharper*/
|
||||||
|
*.[Rr]e[Ss]harper
|
||||||
|
*.DotSettings.user
|
||||||
|
|
||||||
|
# TeamCity is a build add-in
|
||||||
|
_TeamCity*
|
||||||
|
|
||||||
|
# DotCover is a Code Coverage Tool
|
||||||
|
*.dotCover
|
||||||
|
|
||||||
|
# AxoCover is a Code Coverage Tool
|
||||||
|
.axoCover/*
|
||||||
|
!.axoCover/settings.json
|
||||||
|
|
||||||
|
# Coverlet is a free, cross platform Code Coverage Tool
|
||||||
|
coverage*.json
|
||||||
|
coverage*.xml
|
||||||
|
coverage*.info
|
||||||
|
|
||||||
|
# Visual Studio code coverage results
|
||||||
|
*.coverage
|
||||||
|
*.coveragexml
|
||||||
|
|
||||||
|
# NCrunch
|
||||||
|
_NCrunch_*
|
||||||
|
.*crunch*.local.xml
|
||||||
|
nCrunchTemp_*
|
||||||
|
|
||||||
|
# MightyMoose
|
||||||
|
*.mm.*
|
||||||
|
AutoTest.Net/
|
||||||
|
|
||||||
|
# Web workbench (sass)
|
||||||
|
.sass-cache/
|
||||||
|
|
||||||
|
# Installshield output folder
|
||||||
|
[Ee]xpress/
|
||||||
|
|
||||||
|
# DocProject is a documentation generator add-in
|
||||||
|
DocProject/buildhelp/
|
||||||
|
DocProject/Help/*.HxT
|
||||||
|
DocProject/Help/*.HxC
|
||||||
|
DocProject/Help/*.hhc
|
||||||
|
DocProject/Help/*.hhk
|
||||||
|
DocProject/Help/*.hhp
|
||||||
|
DocProject/Help/Html2
|
||||||
|
DocProject/Help/html
|
||||||
|
|
||||||
|
# Click-Once directory
|
||||||
|
publish/
|
||||||
|
|
||||||
|
# Publish Web Output
|
||||||
|
*.[Pp]ublish.xml
|
||||||
|
*.azurePubxml
|
||||||
|
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||||
|
# but database connection strings (with potential passwords) will be unencrypted
|
||||||
|
*.pubxml
|
||||||
|
*.publishproj
|
||||||
|
|
||||||
|
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||||
|
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||||
|
# in these scripts will be unencrypted
|
||||||
|
PublishScripts/
|
||||||
|
|
||||||
|
# NuGet Packages
|
||||||
|
*.nupkg
|
||||||
|
# NuGet Symbol Packages
|
||||||
|
*.snupkg
|
||||||
|
# The packages folder can be ignored because of Package Restore
|
||||||
|
**/[Pp]ackages/*
|
||||||
|
# except build/, which is used as an MSBuild target.
|
||||||
|
!**/[Pp]ackages/build/
|
||||||
|
# Uncomment if necessary however generally it will be regenerated when needed
|
||||||
|
#!**/[Pp]ackages/repositories.config
|
||||||
|
# NuGet v3's project.json files produces more ignorable files
|
||||||
|
*.nuget.props
|
||||||
|
*.nuget.targets
|
||||||
|
|
||||||
|
# Microsoft Azure Build Output
|
||||||
|
csx/
|
||||||
|
*.build.csdef
|
||||||
|
|
||||||
|
# Microsoft Azure Emulator
|
||||||
|
ecf/
|
||||||
|
rcf/
|
||||||
|
|
||||||
|
# Windows Store app package directories and files
|
||||||
|
AppPackages/
|
||||||
|
BundleArtifacts/
|
||||||
|
Package.StoreAssociation.xml
|
||||||
|
_pkginfo.txt
|
||||||
|
*.appx
|
||||||
|
*.appxbundle
|
||||||
|
*.appxupload
|
||||||
|
|
||||||
|
# Visual Studio cache files
|
||||||
|
# files ending in .cache can be ignored
|
||||||
|
*.[Cc]ache
|
||||||
|
# but keep track of directories ending in .cache
|
||||||
|
!?*.[Cc]ache/
|
||||||
|
|
||||||
|
# Others
|
||||||
|
ClientBin/
|
||||||
|
~$*
|
||||||
|
*~
|
||||||
|
*.dbmdl
|
||||||
|
*.dbproj.schemaview
|
||||||
|
*.jfm
|
||||||
|
*.pfx
|
||||||
|
*.publishsettings
|
||||||
|
orleans.codegen.cs
|
||||||
|
|
||||||
|
# Including strong name files can present a security risk
|
||||||
|
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||||
|
#*.snk
|
||||||
|
|
||||||
|
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||||
|
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||||
|
#bower_components/
|
||||||
|
|
||||||
|
# RIA/Silverlight projects
|
||||||
|
Generated_Code/
|
||||||
|
|
||||||
|
# Backup & report files from converting an old project file
|
||||||
|
# to a newer Visual Studio version. Backup files are not needed,
|
||||||
|
# because we have git ;-)
|
||||||
_UpgradeReport_Files/
|
_UpgradeReport_Files/
|
||||||
[Pp]ackages/
|
Backup*/
|
||||||
|
UpgradeLog*.XML
|
||||||
|
UpgradeLog*.htm
|
||||||
|
ServiceFabricBackup/
|
||||||
|
*.rptproj.bak
|
||||||
|
|
||||||
Thumbs.db
|
# SQL Server files
|
||||||
Desktop.ini
|
*.mdf
|
||||||
.DS_Store
|
*.ldf
|
||||||
.idea/.idea.Moonlight/.idea/discord.xml
|
*.ndf
|
||||||
|
|
||||||
|
# Business Intelligence projects
|
||||||
|
*.rdl.data
|
||||||
|
*.bim.layout
|
||||||
|
*.bim_*.settings
|
||||||
|
*.rptproj.rsuser
|
||||||
|
*- [Bb]ackup.rdl
|
||||||
|
*- [Bb]ackup ([0-9]).rdl
|
||||||
|
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||||
|
|
||||||
|
# Microsoft Fakes
|
||||||
|
FakesAssemblies/
|
||||||
|
|
||||||
|
# GhostDoc plugin setting file
|
||||||
|
*.GhostDoc.xml
|
||||||
|
|
||||||
|
# Node.js Tools for Visual Studio
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Visual Studio 6 build log
|
||||||
|
*.plg
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace options file
|
||||||
|
*.opt
|
||||||
|
|
||||||
|
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||||
|
*.vbw
|
||||||
|
|
||||||
|
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
|
||||||
|
*.vbp
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
|
||||||
|
*.dsw
|
||||||
|
*.dsp
|
||||||
|
|
||||||
|
# Visual Studio 6 technical files
|
||||||
|
*.ncb
|
||||||
|
*.aps
|
||||||
|
|
||||||
|
# Visual Studio LightSwitch build output
|
||||||
|
**/*.HTMLClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/ModelManifest.xml
|
||||||
|
**/*.Server/GeneratedArtifacts
|
||||||
|
**/*.Server/ModelManifest.xml
|
||||||
|
_Pvt_Extensions
|
||||||
|
|
||||||
|
# Paket dependency manager
|
||||||
|
.paket/paket.exe
|
||||||
|
paket-files/
|
||||||
|
|
||||||
|
# FAKE - F# Make
|
||||||
|
.fake/
|
||||||
|
|
||||||
|
# CodeRush personal settings
|
||||||
|
.cr/personal
|
||||||
|
|
||||||
|
# Python Tools for Visual Studio (PTVS)
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Cake - Uncomment if you are using it
|
||||||
|
# tools/**
|
||||||
|
# !tools/packages.config
|
||||||
|
|
||||||
|
# Tabs Studio
|
||||||
|
*.tss
|
||||||
|
|
||||||
|
# Telerik's JustMock configuration file
|
||||||
|
*.jmconfig
|
||||||
|
|
||||||
|
# BizTalk build output
|
||||||
|
*.btp.cs
|
||||||
|
*.btm.cs
|
||||||
|
*.odx.cs
|
||||||
|
*.xsd.cs
|
||||||
|
|
||||||
|
# OpenCover UI analysis results
|
||||||
|
OpenCover/
|
||||||
|
|
||||||
|
# Azure Stream Analytics local run output
|
||||||
|
ASALocalRun/
|
||||||
|
|
||||||
|
# MSBuild Binary and Structured Log
|
||||||
|
*.binlog
|
||||||
|
|
||||||
|
# NVidia Nsight GPU debugger configuration file
|
||||||
|
*.nvuser
|
||||||
|
|
||||||
|
# MFractors (Xamarin productivity tool) working folder
|
||||||
|
.mfractor/
|
||||||
|
|
||||||
|
# Local History for Visual Studio
|
||||||
|
.localhistory/
|
||||||
|
|
||||||
|
# Visual Studio History (VSHistory) files
|
||||||
|
.vshistory/
|
||||||
|
|
||||||
|
# BeatPulse healthcheck temp database
|
||||||
|
healthchecksdb
|
||||||
|
|
||||||
|
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||||
|
MigrationBackup/
|
||||||
|
|
||||||
|
# Ionide (cross platform F# VS Code tools) working folder
|
||||||
|
.ionide/
|
||||||
|
|
||||||
|
# Fody - auto-generated XML schema
|
||||||
|
FodyWeavers.xsd
|
||||||
|
|
||||||
|
# VS Code files for those working on multiple tools
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
*.code-workspace
|
||||||
|
|
||||||
|
# Local History for Visual Studio Code
|
||||||
|
.history/
|
||||||
|
|
||||||
|
# Windows Installer files from build outputs
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# JetBrains Rider
|
||||||
|
*.sln.iml
|
||||||
|
|
||||||
|
# User-specific stuff
|
||||||
|
.idea/**/workspace.xml
|
||||||
|
.idea/**/tasks.xml
|
||||||
|
.idea/**/usage.statistics.xml
|
||||||
|
.idea/**/dictionaries
|
||||||
|
.idea/**/shelf
|
||||||
|
|
||||||
|
# Generated files
|
||||||
|
.idea/**/contentModel.xml
|
||||||
|
|
||||||
|
# Sensitive or high-churn files
|
||||||
|
.idea/**/dataSources/
|
||||||
|
.idea/**/dataSources.ids
|
||||||
|
.idea/**/dataSources.local.xml
|
||||||
|
.idea/**/sqlDataSources.xml
|
||||||
|
.idea/**/dynamic.xml
|
||||||
|
.idea/**/uiDesigner.xml
|
||||||
|
.idea/**/dbnavigator.xml
|
||||||
|
|
||||||
|
# Gradle
|
||||||
|
.idea/**/gradle.xml
|
||||||
|
.idea/**/libraries
|
||||||
|
|
||||||
|
# Moonlight
|
||||||
storage/
|
storage/
|
||||||
Moonlight/publish.ps1
|
**/.idea/**
|
||||||
Moonlight/version
|
style.min.css
|
||||||
|
|
||||||
|
# Build script for nuget packages
|
||||||
|
finalPackages/
|
||||||
|
nupkgs/
|
||||||
|
|
||||||
|
# Scripts
|
||||||
|
**/bin/**
|
||||||
|
**/obj/**
|
||||||
13
.idea/.idea.Moonlight/.idea/.gitignore
generated
vendored
13
.idea/.idea.Moonlight/.idea/.gitignore
generated
vendored
@@ -1,13 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Rider ignored files
|
|
||||||
/contentModel.xml
|
|
||||||
/projectSettingsUpdater.xml
|
|
||||||
/modules.xml
|
|
||||||
/.idea.Moonlight.iml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
||||||
# Datasource local storage ignored files
|
|
||||||
/dataSources/
|
|
||||||
/dataSources.local.xml
|
|
||||||
21
.idea/.idea.Moonlight/.idea/efCoreCommonOptions.xml
generated
21
.idea/.idea.Moonlight/.idea/efCoreCommonOptions.xml
generated
@@ -1,21 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="EfCoreCommonOptions">
|
|
||||||
<option name="migrationsToStartupProjects">
|
|
||||||
<map>
|
|
||||||
<entry key="16141d00-a997-4ba6-b0dc-af6f4712613a" value="16141d00-a997-4ba6-b0dc-af6f4712613a" />
|
|
||||||
</map>
|
|
||||||
</option>
|
|
||||||
<option name="solutionLevelOptions">
|
|
||||||
<map>
|
|
||||||
<entry key="migrationsProject" value="16141d00-a997-4ba6-b0dc-af6f4712613a" />
|
|
||||||
<entry key="startupProject" value="16141d00-a997-4ba6-b0dc-af6f4712613a" />
|
|
||||||
</map>
|
|
||||||
</option>
|
|
||||||
<option name="startupToMigrationsProjects">
|
|
||||||
<map>
|
|
||||||
<entry key="16141d00-a997-4ba6-b0dc-af6f4712613a" value="16141d00-a997-4ba6-b0dc-af6f4712613a" />
|
|
||||||
</map>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
14
.idea/.idea.Moonlight/.idea/efCoreDialogsState.xml
generated
14
.idea/.idea.Moonlight/.idea/efCoreDialogsState.xml
generated
@@ -1,14 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="EfCoreDialogsState">
|
|
||||||
<option name="keyValueStorage">
|
|
||||||
<map>
|
|
||||||
<entry key="Common:16141d00-a997-4ba6-b0dc-af6f4712613a:dbContext" value="Moonlight.App.Database.DataContext" />
|
|
||||||
<entry key="Common:buildConfiguration" value="Debug" />
|
|
||||||
<entry key="Common:noBuild" value="false" />
|
|
||||||
<entry key="Common:outputFolder" value="App/Database/Migrations" />
|
|
||||||
<entry key="Common:useDefaultConnection" value="true" />
|
|
||||||
</map>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
4
.idea/.idea.Moonlight/.idea/encodings.xml
generated
4
.idea/.idea.Moonlight/.idea/encodings.xml
generated
@@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
|
||||||
</project>
|
|
||||||
8
.idea/.idea.Moonlight/.idea/indexLayout.xml
generated
8
.idea/.idea.Moonlight/.idea/indexLayout.xml
generated
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="UserContentModel">
|
|
||||||
<attachedFolders />
|
|
||||||
<explicitIncludes />
|
|
||||||
<explicitExcludes />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
6
.idea/.idea.Moonlight/.idea/vcs.xml
generated
6
.idea/.idea.Moonlight/.idea/vcs.xml
generated
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
6
.idea/vcs.xml
generated
6
.idea/vcs.xml
generated
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
121
LICENSE
Normal file
121
LICENSE
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
Creative Commons Legal Code
|
||||||
|
|
||||||
|
CC0 1.0 Universal
|
||||||
|
|
||||||
|
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
||||||
|
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
||||||
|
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
||||||
|
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
||||||
|
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
||||||
|
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
||||||
|
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
||||||
|
HEREUNDER.
|
||||||
|
|
||||||
|
Statement of Purpose
|
||||||
|
|
||||||
|
The laws of most jurisdictions throughout the world automatically confer
|
||||||
|
exclusive Copyright and Related Rights (defined below) upon the creator
|
||||||
|
and subsequent owner(s) (each and all, an "owner") of an original work of
|
||||||
|
authorship and/or a database (each, a "Work").
|
||||||
|
|
||||||
|
Certain owners wish to permanently relinquish those rights to a Work for
|
||||||
|
the purpose of contributing to a commons of creative, cultural and
|
||||||
|
scientific works ("Commons") that the public can reliably and without fear
|
||||||
|
of later claims of infringement build upon, modify, incorporate in other
|
||||||
|
works, reuse and redistribute as freely as possible in any form whatsoever
|
||||||
|
and for any purposes, including without limitation commercial purposes.
|
||||||
|
These owners may contribute to the Commons to promote the ideal of a free
|
||||||
|
culture and the further production of creative, cultural and scientific
|
||||||
|
works, or to gain reputation or greater distribution for their Work in
|
||||||
|
part through the use and efforts of others.
|
||||||
|
|
||||||
|
For these and/or other purposes and motivations, and without any
|
||||||
|
expectation of additional consideration or compensation, the person
|
||||||
|
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
||||||
|
is an owner of Copyright and Related Rights in the Work, voluntarily
|
||||||
|
elects to apply CC0 to the Work and publicly distribute the Work under its
|
||||||
|
terms, with knowledge of his or her Copyright and Related Rights in the
|
||||||
|
Work and the meaning and intended legal effect of CC0 on those rights.
|
||||||
|
|
||||||
|
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||||
|
protected by copyright and related or neighboring rights ("Copyright and
|
||||||
|
Related Rights"). Copyright and Related Rights include, but are not
|
||||||
|
limited to, the following:
|
||||||
|
|
||||||
|
i. the right to reproduce, adapt, distribute, perform, display,
|
||||||
|
communicate, and translate a Work;
|
||||||
|
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||||
|
iii. publicity and privacy rights pertaining to a person's image or
|
||||||
|
likeness depicted in a Work;
|
||||||
|
iv. rights protecting against unfair competition in regards to a Work,
|
||||||
|
subject to the limitations in paragraph 4(a), below;
|
||||||
|
v. rights protecting the extraction, dissemination, use and reuse of data
|
||||||
|
in a Work;
|
||||||
|
vi. database rights (such as those arising under Directive 96/9/EC of the
|
||||||
|
European Parliament and of the Council of 11 March 1996 on the legal
|
||||||
|
protection of databases, and under any national implementation
|
||||||
|
thereof, including any amended or successor version of such
|
||||||
|
directive); and
|
||||||
|
vii. other similar, equivalent or corresponding rights throughout the
|
||||||
|
world based on applicable law or treaty, and any national
|
||||||
|
implementations thereof.
|
||||||
|
|
||||||
|
2. Waiver. To the greatest extent permitted by, but not in contravention
|
||||||
|
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
||||||
|
irrevocably and unconditionally waives, abandons, and surrenders all of
|
||||||
|
Affirmer's Copyright and Related Rights and associated claims and causes
|
||||||
|
of action, whether now known or unknown (including existing as well as
|
||||||
|
future claims and causes of action), in the Work (i) in all territories
|
||||||
|
worldwide, (ii) for the maximum duration provided by applicable law or
|
||||||
|
treaty (including future time extensions), (iii) in any current or future
|
||||||
|
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
||||||
|
including without limitation commercial, advertising or promotional
|
||||||
|
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
||||||
|
member of the public at large and to the detriment of Affirmer's heirs and
|
||||||
|
successors, fully intending that such Waiver shall not be subject to
|
||||||
|
revocation, rescission, cancellation, termination, or any other legal or
|
||||||
|
equitable action to disrupt the quiet enjoyment of the Work by the public
|
||||||
|
as contemplated by Affirmer's express Statement of Purpose.
|
||||||
|
|
||||||
|
3. Public License Fallback. Should any part of the Waiver for any reason
|
||||||
|
be judged legally invalid or ineffective under applicable law, then the
|
||||||
|
Waiver shall be preserved to the maximum extent permitted taking into
|
||||||
|
account Affirmer's express Statement of Purpose. In addition, to the
|
||||||
|
extent the Waiver is so judged Affirmer hereby grants to each affected
|
||||||
|
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
||||||
|
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
||||||
|
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
||||||
|
maximum duration provided by applicable law or treaty (including future
|
||||||
|
time extensions), (iii) in any current or future medium and for any number
|
||||||
|
of copies, and (iv) for any purpose whatsoever, including without
|
||||||
|
limitation commercial, advertising or promotional purposes (the
|
||||||
|
"License"). The License shall be deemed effective as of the date CC0 was
|
||||||
|
applied by Affirmer to the Work. Should any part of the License for any
|
||||||
|
reason be judged legally invalid or ineffective under applicable law, such
|
||||||
|
partial invalidity or ineffectiveness shall not invalidate the remainder
|
||||||
|
of the License, and in such case Affirmer hereby affirms that he or she
|
||||||
|
will not (i) exercise any of his or her remaining Copyright and Related
|
||||||
|
Rights in the Work or (ii) assert any associated claims and causes of
|
||||||
|
action with respect to the Work, in either case contrary to Affirmer's
|
||||||
|
express Statement of Purpose.
|
||||||
|
|
||||||
|
4. Limitations and Disclaimers.
|
||||||
|
|
||||||
|
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||||
|
surrendered, licensed or otherwise affected by this document.
|
||||||
|
b. Affirmer offers the Work as-is and makes no representations or
|
||||||
|
warranties of any kind concerning the Work, express, implied,
|
||||||
|
statutory or otherwise, including without limitation warranties of
|
||||||
|
title, merchantability, fitness for a particular purpose, non
|
||||||
|
infringement, or the absence of latent or other defects, accuracy, or
|
||||||
|
the present or absence of errors, whether or not discoverable, all to
|
||||||
|
the greatest extent permissible under applicable law.
|
||||||
|
c. Affirmer disclaims responsibility for clearing rights of other persons
|
||||||
|
that may apply to the Work or any use thereof, including without
|
||||||
|
limitation any person's Copyright and Related Rights in the Work.
|
||||||
|
Further, Affirmer disclaims responsibility for obtaining any necessary
|
||||||
|
consents, permissions or other rights required for any use of the
|
||||||
|
Work.
|
||||||
|
d. Affirmer understands and acknowledges that Creative Commons is not a
|
||||||
|
party to this document and has no duty or obligation with respect to
|
||||||
|
this CC0 or use of the Work.
|
||||||
128
LICENSE.md
128
LICENSE.md
@@ -1,128 +0,0 @@
|
|||||||
<h3>Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License (modified)</h3>
|
|
||||||
<p>By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions.</p>
|
|
||||||
<p id="s1"><strong>Section 1 – Definitions.</strong></p>
|
|
||||||
<ol type="a">
|
|
||||||
<li id="s1a"><strong>Adapted Material</strong> means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image.</li>
|
|
||||||
<li id="s1b"><strong>Adapter's License</strong> means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License.</li>
|
|
||||||
<li id="s1c"><strong>BY-NC-SA Compatible License</strong> means a license listed at <a href="//creativecommons.org/compatiblelicenses"> creativecommons.org/compatiblelicenses</a>, approved by Creative Commons as essentially the equivalent of this Public License.</li>
|
|
||||||
<li id="s1d"><strong>Copyright and Similar Rights</strong> means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section <a href="#s2b">2(b)(1)-(2)</a> are not Copyright and Similar Rights.</li>
|
|
||||||
<li id="s1e"><strong>Effective Technological Measures</strong> means those measures that, in the absence of proper authority, may not
|
|
||||||
be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar
|
|
||||||
international agreements.</li>
|
|
||||||
<li id="s1f"><strong>Exceptions and Limitations</strong> means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material.</li>
|
|
||||||
<li id="s1g"><strong>License Elements</strong> means the license attributes listed in the name of a Creative Commons Public License. The License Elements of this Public License are Attribution, NonCommercial, and ShareAlike.</li>
|
|
||||||
<li id="s1h"><strong>Licensed Material</strong> means the artistic or literary work, database, or other material to which the Licensor applied this Public License.</li>
|
|
||||||
<li id="s1i"><strong>Licensed Rights</strong> means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license.</li>
|
|
||||||
<li id="s1j"><strong>Licensor</strong> means the individual(s) or entity(ies) granting rights under this Public License.</li>
|
|
||||||
<li id="s1k"><strong>NonCommercial</strong> means not primarily intended for or directed towards commercial advantage or monetary compensation. This also includes free hosting services or simmular which have no direct permission from the moonlight panel team to use this software. For purposes of this Public License, the exchange of the Licensed Material for other material subject to Copyright and Similar Rights by digital file-sharing or similar means is NonCommercial provided there is no payment of monetary compensation in connection with the exchange.</li>
|
|
||||||
<li id="s1l"><strong>Share</strong> means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them.</li>
|
|
||||||
<li id="s1m"><strong>Sui Generis Database Rights</strong> means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world.</li>
|
|
||||||
<li id="s1n"><strong>You</strong> means the individual or entity exercising the Licensed Rights under this Public License. <strong>Your</strong> has a corresponding meaning.</li>
|
|
||||||
</ol>
|
|
||||||
<p id="s2"><strong>Section 2 – Scope.</strong></p>
|
|
||||||
<ol type="a">
|
|
||||||
<li id="s2a"><strong>License grant</strong>.
|
|
||||||
<ol>
|
|
||||||
<li id="s2a1">Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to:
|
|
||||||
<ol type="A">
|
|
||||||
<li id="s2a1A">reproduce and Share the Licensed Material, in whole or in part, for NonCommercial purposes only; and</li>
|
|
||||||
<li id="s2a1B">produce, reproduce, and Share Adapted Material for NonCommercial purposes only.</li>
|
|
||||||
</ol>
|
|
||||||
</li><li id="s2a2"><span style="text-decoration: underline;">Exceptions and Limitations</span>. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions.</li>
|
|
||||||
<li id="s2a3"><span style="text-decoration: underline;">Term</span>. The term of this Public License is specified in Section <a href="#s6a">6(a)</a>.</li>
|
|
||||||
<li id="s2a4"><span style="text-decoration: underline;">Media and formats; technical modifications allowed</span>. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section <a href="#s2a4">2(a)(4)</a> never produces Adapted Material.</li>
|
|
||||||
<li id="s2a5"><span style="text-decoration: underline;">Downstream recipients</span>.
|
|
||||||
<div class="para">
|
|
||||||
<ol type="A">
|
|
||||||
<li id="s2a5A"><span style="text-decoration: underline;">Offer from the Licensor – Licensed Material</span>. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License.</li>
|
|
||||||
<li id="s2a5B"><span style="text-decoration: underline;">Additional offer from the Licensor – Adapted Material</span>. Every recipient of Adapted Material from You automatically receives an offer from the Licensor to exercise the Licensed Rights in the Adapted Material under the conditions of the Adapter’s License You apply.</li>
|
|
||||||
<li id="s2a5C"><span style="text-decoration: underline;">No downstream restrictions</span>. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material.</li>
|
|
||||||
</ol>
|
|
||||||
</div>
|
|
||||||
</li><li id="s2a6"><span style="text-decoration: underline;">No endorsement</span>. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section <a href="#s3a1Ai">3(a)(1)(A)(i)</a>.</li>
|
|
||||||
</ol>
|
|
||||||
</li><li id="s2b"><p><strong>Other rights</strong>.</p>
|
|
||||||
<ol>
|
|
||||||
<li id="s2b1">Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise.</li>
|
|
||||||
<li id="s2b2">Patent and trademark rights are not licensed under this Public License.</li>
|
|
||||||
<li id="s2b3">To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties, including when the Licensed Material is used other than for NonCommercial purposes.</li>
|
|
||||||
</ol>
|
|
||||||
</li>
|
|
||||||
</ol>
|
|
||||||
<p id="s3"><strong>Section 3 – License Conditions.</strong></p>
|
|
||||||
<p>Your exercise of the Licensed Rights is expressly made subject to the following conditions.</p>
|
|
||||||
<ol type="a">
|
|
||||||
<li id="s3a"><p><strong>Attribution</strong>.</p>
|
|
||||||
<ol>
|
|
||||||
<li id="s3a1"><p>If You Share the Licensed Material (including in modified form), You must:</p>
|
|
||||||
<ol type="A">
|
|
||||||
<li id="s3a1A">retain the following if it is supplied by the Licensor with the Licensed Material:
|
|
||||||
<ol type="i">
|
|
||||||
<li id="s3a1Ai">identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated);</li>
|
|
||||||
<li id="s3a1Aii">a copyright notice;</li>
|
|
||||||
<li id="s3a1Aiii">a notice that refers to this Public License; </li>
|
|
||||||
<li id="s3a1Aiv">a notice that refers to the disclaimer of warranties;</li>
|
|
||||||
<li id="s3a1Av">a URI or hyperlink to the Licensed Material to the extent reasonably practicable;</li>
|
|
||||||
</ol>
|
|
||||||
</li><li id="s3a1B">indicate if You modified the Licensed Material and retain an indication of any previous modifications; and</li>
|
|
||||||
<li id="s3a1C">indicate the Licensed Material is licensed under this Public License,
|
|
||||||
and include the text of, or the URI or hyperlink to, this Public
|
|
||||||
License.</li>
|
|
||||||
</ol>
|
|
||||||
</li>
|
|
||||||
<li id="s3a2">You may satisfy the conditions in Section <a href="#s3a1">3(a)(1)</a> in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information.</li>
|
|
||||||
<li id="s3a3">If requested by the Licensor, You must remove any of the information required by Section <a href="#s3a1A">3(a)(1)(A)</a> to the extent reasonably practicable.</li>
|
|
||||||
</ol>
|
|
||||||
</li>
|
|
||||||
<li id="s3b"><strong>ShareAlike</strong>.
|
|
||||||
<p>In addition to the conditions in Section <a href="#s3a">3(a)</a>, if You Share Adapted Material You produce, the following conditions also apply.</p>
|
|
||||||
<ol>
|
|
||||||
<li id="s3b1">The Adapter’s License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-NC-SA Compatible License.</li>
|
|
||||||
<li id="s3b2">You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material.</li>
|
|
||||||
<li id="s3b3">You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply.</li>
|
|
||||||
</ol>
|
|
||||||
</li>
|
|
||||||
</ol>
|
|
||||||
<p id="s4"><strong>Section 4 – Sui Generis Database Rights.</strong></p>
|
|
||||||
<p>Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material:</p>
|
|
||||||
<ol type="a">
|
|
||||||
<li id="s4a">for the avoidance of doubt, Section <a href="#s2a1">2(a)(1)</a> grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database for NonCommercial purposes only;</li>
|
|
||||||
<li id="s4b">if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material, including for purposes of Section <a href="#s3b">3(b)</a>; and</li>
|
|
||||||
<li id="s4c">You must comply with the conditions in Section <a href="#s3a">3(a)</a> if You Share all or a substantial portion of the contents of the database.</li>
|
|
||||||
</ol>
|
|
||||||
For the avoidance of doubt, this Section <a href="#s4">4</a> supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights.
|
|
||||||
<p id="s5"><strong>Section 5 – Disclaimer of Warranties and Limitation of Liability.</strong></p>
|
|
||||||
<ol style="font-weight: bold;" type="a">
|
|
||||||
<li id="s5a"><strong>Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.</strong></li>
|
|
||||||
<li id="s5b"><strong>To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.</strong></li>
|
|
||||||
</ol>
|
|
||||||
<ol start="3" type="a">
|
|
||||||
<li id="s5c">The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability.</li>
|
|
||||||
</ol>
|
|
||||||
<p id="s6"><strong>Section 6 – Term and Termination.</strong></p>
|
|
||||||
<ol type="a">
|
|
||||||
<li id="s6a">This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically.</li>
|
|
||||||
<li id="s6b">
|
|
||||||
<p>Where Your right to use the Licensed Material has terminated under Section <a href="#s6a">6(a)</a>, it reinstates:</p>
|
|
||||||
<ol>
|
|
||||||
<li id="s6b1">automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or</li>
|
|
||||||
<li id="s6b2">upon express reinstatement by the Licensor.</li>
|
|
||||||
</ol>
|
|
||||||
For the avoidance of doubt, this Section <a href="#s6b">6(b)</a> does not affect any right the Licensor may have to seek remedies for Your violations of this Public License.</li>
|
|
||||||
<li id="s6c">For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License.</li>
|
|
||||||
<li id="s6d">Sections <a href="#s1">1</a>, <a href="#s5">5</a>, <a href="#s6">6</a>, <a href="#s7">7</a>, and <a href="#s8">8</a> survive termination of this Public License.</li>
|
|
||||||
</ol>
|
|
||||||
<p id="s7"><strong>Section 7 – Other Terms and Conditions.</strong></p>
|
|
||||||
<ol type="a">
|
|
||||||
<li id="s7a">The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed.</li>
|
|
||||||
<li id="s7b">Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License.</li>
|
|
||||||
</ol>
|
|
||||||
<p id="s8"><strong>Section 8 – Interpretation.</strong></p>
|
|
||||||
<ol type="a">
|
|
||||||
<li id="s8a">For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License.</li>
|
|
||||||
<li id="s8b">To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions.</li>
|
|
||||||
<li id="s8c">No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor.</li>
|
|
||||||
<li id="s8d">Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority.</li>
|
|
||||||
</ol>
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<NoDefaultLaunchSettingsFile>True</NoDefaultLaunchSettingsFile>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Moonlight.ApiServer\Moonlight.ApiServer.csproj" />
|
||||||
|
<ProjectReference Include="..\Moonlight.Client.Runtime\Moonlight.Client.Runtime.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="9.0.8" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.8">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="MoonCore.PluginFramework" Version="1.0.9" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Import Project="Plugins.props" />
|
||||||
|
|
||||||
|
</Project>
|
||||||
10
Moonlight.ApiServer.Runtime/PluginLoader.cs
Normal file
10
Moonlight.ApiServer.Runtime/PluginLoader.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using MoonCore.PluginFramework;
|
||||||
|
using Moonlight.ApiServer.Plugins;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Runtime;
|
||||||
|
|
||||||
|
[PluginLoader]
|
||||||
|
public partial class PluginLoader : IPluginStartup
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
4
Moonlight.ApiServer.Runtime/Plugins.props
Normal file
4
Moonlight.ApiServer.Runtime/Plugins.props
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<Project>
|
||||||
|
<ItemGroup>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
34
Moonlight.ApiServer.Runtime/Program.cs
Normal file
34
Moonlight.ApiServer.Runtime/Program.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using Moonlight.ApiServer.Configuration;
|
||||||
|
using Moonlight.ApiServer.Runtime;
|
||||||
|
using Moonlight.ApiServer.Startup;
|
||||||
|
|
||||||
|
var pluginLoader = new PluginLoader();
|
||||||
|
pluginLoader.Initialize();
|
||||||
|
|
||||||
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
builder.AddMoonlight(pluginLoader.Instances);
|
||||||
|
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
|
app.UseMoonlight(pluginLoader.Instances);
|
||||||
|
|
||||||
|
// Add frontend
|
||||||
|
var configuration = AppConfiguration.CreateEmpty();
|
||||||
|
builder.Configuration.Bind(configuration);
|
||||||
|
|
||||||
|
// Handle setup of wasm app hosting in the runtime
|
||||||
|
// so the Moonlight.ApiServer doesn't need the wasm package
|
||||||
|
if (configuration.Frontend.EnableHosting)
|
||||||
|
{
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
|
app.UseWebAssemblyDebugging();
|
||||||
|
|
||||||
|
app.UseBlazorFrameworkFiles();
|
||||||
|
app.UseStaticFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
app.MapMoonlight(pluginLoader.Instances);
|
||||||
|
|
||||||
|
|
||||||
|
await app.RunAsync();
|
||||||
29
Moonlight.ApiServer.Runtime/Properties/launchSettings.json
Normal file
29
Moonlight.ApiServer.Runtime/Properties/launchSettings.json
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"profiles": {
|
||||||
|
"http": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": false,
|
||||||
|
"applicationUrl": "http://localhost:5165",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||||
|
"HTTP_PROXY": "",
|
||||||
|
"HTTPS_PROXY": ""
|
||||||
|
},
|
||||||
|
"hotReloadEnabled": true
|
||||||
|
},
|
||||||
|
"WASM Debug": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": false,
|
||||||
|
"applicationUrl": "http://localhost:5165",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||||
|
"HTTP_PROXY": "",
|
||||||
|
"HTTPS_PROXY": ""
|
||||||
|
},
|
||||||
|
"hotReloadEnabled": true,
|
||||||
|
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
154
Moonlight.ApiServer/Configuration/AppConfiguration.cs
Normal file
154
Moonlight.ApiServer/Configuration/AppConfiguration.cs
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
using MoonCore.Helpers;
|
||||||
|
using Moonlight.ApiServer.Implementations.LocalAuth;
|
||||||
|
using YamlDotNet.Serialization;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Configuration;
|
||||||
|
|
||||||
|
public record AppConfiguration
|
||||||
|
{
|
||||||
|
[YamlMember(Description = "Moonlight configuration\n\n\nThe public url your instance should be accessible through")]
|
||||||
|
public string PublicUrl { get; set; } = "http://localhost:5165";
|
||||||
|
|
||||||
|
[YamlMember(Description = "\nThe credentials of the postgres which moonlight should use")]
|
||||||
|
public DatabaseConfig Database { get; set; } = new();
|
||||||
|
|
||||||
|
[YamlMember(Description = "\nSettings regarding authentication")]
|
||||||
|
public AuthenticationConfig Authentication { get; set; } = new();
|
||||||
|
|
||||||
|
[YamlMember(Description = "\nThese options are only meant for development purposes")]
|
||||||
|
public DevelopmentConfig Development { get; set; } = new();
|
||||||
|
|
||||||
|
[YamlMember(Description = "\nSettings for hosting the frontend")]
|
||||||
|
public FrontendData Frontend { get; set; } = new();
|
||||||
|
|
||||||
|
[YamlMember(Description = "\nSettings for the internal web server moonlight is running in")]
|
||||||
|
public KestrelConfig Kestrel { get; set; } = new();
|
||||||
|
|
||||||
|
[YamlMember(Description = "\nSettings for the internal file manager for moonlights storage access")]
|
||||||
|
public FilesData Files { get; set; } = new();
|
||||||
|
|
||||||
|
[YamlMember(Description = "\nSettings for open telemetry")]
|
||||||
|
public OpenTelemetryData OpenTelemetry { get; set; } = new();
|
||||||
|
|
||||||
|
[YamlMember(Description = "\nConfiguration for the realtime communication solution SignalR")]
|
||||||
|
public SignalRData SignalR { get; set; } = new();
|
||||||
|
|
||||||
|
public static AppConfiguration CreateEmpty()
|
||||||
|
{
|
||||||
|
return new AppConfiguration()
|
||||||
|
{
|
||||||
|
// Set arrays as empty here
|
||||||
|
|
||||||
|
Kestrel = new()
|
||||||
|
{
|
||||||
|
AllowedOrigins = []
|
||||||
|
},
|
||||||
|
Authentication = new()
|
||||||
|
{
|
||||||
|
EnabledSchemes = []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public record SignalRData
|
||||||
|
{
|
||||||
|
[YamlMember(Description =
|
||||||
|
"\nWhether to use redis (or any other redis compatible solution) to scale out SignalR hubs. This is required when using multiple api server replicas")]
|
||||||
|
public bool UseRedis { get; set; } = false;
|
||||||
|
|
||||||
|
public string RedisConnectionString { get; set; } = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public record FilesData
|
||||||
|
{
|
||||||
|
[YamlMember(Description = "The maximum file size limit a combine operation is allowed to process")]
|
||||||
|
public double CombineLimit { get; set; } = ByteConverter.FromGigaBytes(5).MegaBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public record FrontendData
|
||||||
|
{
|
||||||
|
[YamlMember(Description = "Enable the hosting of the frontend. Disable this if you only want to run the api server")]
|
||||||
|
public bool EnableHosting { get; set; } = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public record DatabaseConfig
|
||||||
|
{
|
||||||
|
public string Host { get; set; } = "your-database-host.name";
|
||||||
|
public int Port { get; set; } = 5432;
|
||||||
|
|
||||||
|
public string Username { get; set; } = "db_user";
|
||||||
|
public string Password { get; set; } = "db_password";
|
||||||
|
|
||||||
|
public string Database { get; set; } = "db_name";
|
||||||
|
}
|
||||||
|
|
||||||
|
public record AuthenticationConfig
|
||||||
|
{
|
||||||
|
[YamlMember(Description = "The secret token to use for creating jwts and encrypting things. This needs to be at least 32 characters long")]
|
||||||
|
public string Secret { get; set; } = Formatter.GenerateString(32);
|
||||||
|
|
||||||
|
[YamlMember(Description = "Settings for the user sessions")]
|
||||||
|
public SessionsConfig Sessions { get; set; } = new();
|
||||||
|
|
||||||
|
[YamlMember(Description = "This specifies if the first registered/synced user will become an admin automatically")]
|
||||||
|
public bool FirstUserAdmin { get; set; } = true;
|
||||||
|
|
||||||
|
[YamlMember(Description = "This specifies the authentication schemes the frontend should be able to challenge")]
|
||||||
|
public string[] EnabledSchemes { get; set; } = [LocalAuthConstants.AuthenticationScheme];
|
||||||
|
}
|
||||||
|
|
||||||
|
public record SessionsConfig
|
||||||
|
{
|
||||||
|
public string CookieName { get; set; } = "session";
|
||||||
|
public int ExpiresIn { get; set; } = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
public record DevelopmentConfig
|
||||||
|
{
|
||||||
|
[YamlMember(Description = "This toggles the availability of the api docs via /api/swagger")]
|
||||||
|
public bool EnableApiDocs { get; set; } = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public record KestrelConfig
|
||||||
|
{
|
||||||
|
[YamlMember(Description = "The upload limit in megabytes for the api server")]
|
||||||
|
public int UploadLimit { get; set; } = 100;
|
||||||
|
|
||||||
|
[YamlMember(Description = "The allowed origins for the api server. Use * to allow all origins (which is not advised)")]
|
||||||
|
public string[] AllowedOrigins { get; set; } = ["*"];
|
||||||
|
}
|
||||||
|
|
||||||
|
public record OpenTelemetryData
|
||||||
|
{
|
||||||
|
[YamlMember(Description = "This enables open telemetry for moonlight")]
|
||||||
|
public bool Enable { get; set; } = false;
|
||||||
|
|
||||||
|
public OpenTelemetryMetricsData Metrics { get; set; } = new();
|
||||||
|
public OpenTelemetryTracesData Traces { get; set; } = new();
|
||||||
|
public OpenTelemetryLogsData Logs { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public record OpenTelemetryMetricsData
|
||||||
|
{
|
||||||
|
[YamlMember(Description = "This enables the exporting of metrics")]
|
||||||
|
public bool Enable { get; set; } = true;
|
||||||
|
|
||||||
|
[YamlMember(Description = "Enables the /metrics exporter for prometheus")]
|
||||||
|
public bool EnablePrometheus { get; set; } = false;
|
||||||
|
|
||||||
|
[YamlMember(Description = "The interval in which metrics are created, specified in seconds")]
|
||||||
|
public int Interval { get; set; } = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
public record OpenTelemetryTracesData
|
||||||
|
{
|
||||||
|
[YamlMember(Description = "This enables the exporting of traces")]
|
||||||
|
public bool Enable { get; set; } = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public record OpenTelemetryLogsData
|
||||||
|
{
|
||||||
|
[YamlMember(Description = "This enables the exporting of logs")]
|
||||||
|
public bool Enable { get; set; } = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
55
Moonlight.ApiServer/Database/CoreDataContext.cs
Normal file
55
Moonlight.ApiServer/Database/CoreDataContext.cs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
using Hangfire.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Moonlight.ApiServer.Configuration;
|
||||||
|
using Moonlight.ApiServer.Database.Entities;
|
||||||
|
using Moonlight.ApiServer.Models;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Database;
|
||||||
|
|
||||||
|
public class CoreDataContext : DbContext
|
||||||
|
{
|
||||||
|
private readonly AppConfiguration Configuration;
|
||||||
|
|
||||||
|
public DbSet<User> Users { get; set; }
|
||||||
|
public DbSet<ApiKey> ApiKeys { get; set; }
|
||||||
|
public DbSet<Theme> Themes { get; set; }
|
||||||
|
|
||||||
|
public CoreDataContext(AppConfiguration configuration)
|
||||||
|
{
|
||||||
|
Configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
if(optionsBuilder.IsConfigured)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var database = Configuration.Database;
|
||||||
|
|
||||||
|
var connectionString = $"Host={database.Host};" +
|
||||||
|
$"Port={database.Port};" +
|
||||||
|
$"Database={database.Database};" +
|
||||||
|
$"Username={database.Username};" +
|
||||||
|
$"Password={database.Password}";
|
||||||
|
|
||||||
|
optionsBuilder.UseNpgsql(connectionString, builder =>
|
||||||
|
{
|
||||||
|
builder.MigrationsHistoryTable("MigrationsHistory", "core");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.Model.SetDefaultSchema("core");
|
||||||
|
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
modelBuilder.OnHangfireModelCreating();
|
||||||
|
|
||||||
|
modelBuilder.Ignore<ApplicationTheme>();
|
||||||
|
modelBuilder.Entity<Theme>()
|
||||||
|
.OwnsOne(x => x.Content, builder =>
|
||||||
|
{
|
||||||
|
builder.ToJson();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
14
Moonlight.ApiServer/Database/Entities/ApiKey.cs
Normal file
14
Moonlight.ApiServer/Database/Entities/ApiKey.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
namespace Moonlight.ApiServer.Database.Entities;
|
||||||
|
|
||||||
|
public class ApiKey
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Description { get; set; }
|
||||||
|
|
||||||
|
public string[] Permissions { get; set; } = [];
|
||||||
|
|
||||||
|
public DateTimeOffset ExpiresAt { get; set; }
|
||||||
|
|
||||||
|
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
|
||||||
|
}
|
||||||
19
Moonlight.ApiServer/Database/Entities/Theme.cs
Normal file
19
Moonlight.ApiServer/Database/Entities/Theme.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using Moonlight.ApiServer.Models;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Database.Entities;
|
||||||
|
|
||||||
|
public class Theme
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public bool IsEnabled { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Author { get; set; }
|
||||||
|
public string Version { get; set; }
|
||||||
|
|
||||||
|
public string? UpdateUrl { get; set; }
|
||||||
|
public string? DonateUrl { get; set; }
|
||||||
|
|
||||||
|
public ApplicationTheme Content { get; set; }
|
||||||
|
}
|
||||||
12
Moonlight.ApiServer/Database/Entities/User.cs
Normal file
12
Moonlight.ApiServer/Database/Entities/User.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
namespace Moonlight.ApiServer.Database.Entities;
|
||||||
|
|
||||||
|
public class User
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Username { get; set; }
|
||||||
|
public string Email { get; set; }
|
||||||
|
public string Password { get; set; }
|
||||||
|
public DateTimeOffset TokenValidTimestamp { get; set; } = DateTimeOffset.MinValue;
|
||||||
|
public string[] Permissions { get; set; } = [];
|
||||||
|
}
|
||||||
565
Moonlight.ApiServer/Database/Migrations/20250919201409_RecreatedMigrationsForChangeOfSchema.Designer.cs
generated
Normal file
565
Moonlight.ApiServer/Database/Migrations/20250919201409_RecreatedMigrationsForChangeOfSchema.Designer.cs
generated
Normal file
@@ -0,0 +1,565 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Moonlight.ApiServer.Database;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Database.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(CoreDataContext))]
|
||||||
|
[Migration("20250919201409_RecreatedMigrationsForChangeOfSchema")]
|
||||||
|
partial class RecreatedMigrationsForChangeOfSchema
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasDefaultSchema("core")
|
||||||
|
.HasAnnotation("ProductVersion", "9.0.8")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireCounter", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateTime?>("ExpireAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<long>("Value")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ExpireAt");
|
||||||
|
|
||||||
|
b.HasIndex("Key", "Value");
|
||||||
|
|
||||||
|
b.ToTable("HangfireCounter", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireHash", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("Field")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("ExpireAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Value")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Key", "Field");
|
||||||
|
|
||||||
|
b.HasIndex("ExpireAt");
|
||||||
|
|
||||||
|
b.ToTable("HangfireHash", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireJob", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("ExpireAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("InvocationData")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<long?>("StateId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<string>("StateName")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ExpireAt");
|
||||||
|
|
||||||
|
b.HasIndex("StateId");
|
||||||
|
|
||||||
|
b.HasIndex("StateName");
|
||||||
|
|
||||||
|
b.ToTable("HangfireJob", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireJobParameter", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("JobId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("Value")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("JobId", "Name");
|
||||||
|
|
||||||
|
b.ToTable("HangfireJobParameter", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireList", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<int>("Position")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("ExpireAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Value")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Key", "Position");
|
||||||
|
|
||||||
|
b.HasIndex("ExpireAt");
|
||||||
|
|
||||||
|
b.ToTable("HangfireList", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireLock", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Id")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("AcquiredAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("HangfireLock", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireQueuedJob", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateTime?>("FetchedAt")
|
||||||
|
.IsConcurrencyToken()
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<long>("JobId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<string>("Queue")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("JobId");
|
||||||
|
|
||||||
|
b.HasIndex("Queue", "FetchedAt");
|
||||||
|
|
||||||
|
b.ToTable("HangfireQueuedJob", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireServer", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Id")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Heartbeat")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Queues")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("StartedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<int>("WorkerCount")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("Heartbeat");
|
||||||
|
|
||||||
|
b.ToTable("HangfireServer", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireSet", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.HasColumnType("character varying(100)");
|
||||||
|
|
||||||
|
b.Property<string>("Value")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("ExpireAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<double>("Score")
|
||||||
|
.HasColumnType("double precision");
|
||||||
|
|
||||||
|
b.HasKey("Key", "Value");
|
||||||
|
|
||||||
|
b.HasIndex("ExpireAt");
|
||||||
|
|
||||||
|
b.HasIndex("Key", "Score");
|
||||||
|
|
||||||
|
b.ToTable("HangfireSet", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireState", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Data")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<long>("JobId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("Reason")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("JobId");
|
||||||
|
|
||||||
|
b.ToTable("HangfireState", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.ApiKey", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("CreatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("ExpiresAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("Permissions")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("ApiKeys", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.Theme", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Author")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("DonateUrl")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<bool>("IsEnabled")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("UpdateUrl")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Version")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Themes", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("Permissions")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("TokenValidTimestamp")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireJob", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Hangfire.EntityFrameworkCore.HangfireState", "State")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("StateId");
|
||||||
|
|
||||||
|
b.Navigation("State");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireJobParameter", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Hangfire.EntityFrameworkCore.HangfireJob", "Job")
|
||||||
|
.WithMany("Parameters")
|
||||||
|
.HasForeignKey("JobId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Job");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireQueuedJob", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Hangfire.EntityFrameworkCore.HangfireJob", "Job")
|
||||||
|
.WithMany("QueuedJobs")
|
||||||
|
.HasForeignKey("JobId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Job");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireState", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Hangfire.EntityFrameworkCore.HangfireJob", "Job")
|
||||||
|
.WithMany("States")
|
||||||
|
.HasForeignKey("JobId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Job");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.Theme", b =>
|
||||||
|
{
|
||||||
|
b.OwnsOne("Moonlight.ApiServer.Models.ApplicationTheme", "Content", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<int>("ThemeId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b1.Property<float>("Border")
|
||||||
|
.HasColumnType("real");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorAccent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorAccentContent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorBackground")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorBase100")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorBase150")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorBase200")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorBase250")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorBase300")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorBaseContent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorError")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorErrorContent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorInfo")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorInfoContent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorNeutral")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorNeutralContent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorPrimary")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorPrimaryContent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorSecondary")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorSecondaryContent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorSuccess")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorSuccessContent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorWarning")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorWarningContent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<int>("Depth")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b1.Property<int>("Noise")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b1.Property<float>("RadiusBox")
|
||||||
|
.HasColumnType("real");
|
||||||
|
|
||||||
|
b1.Property<float>("RadiusField")
|
||||||
|
.HasColumnType("real");
|
||||||
|
|
||||||
|
b1.Property<float>("RadiusSelector")
|
||||||
|
.HasColumnType("real");
|
||||||
|
|
||||||
|
b1.Property<float>("SizeField")
|
||||||
|
.HasColumnType("real");
|
||||||
|
|
||||||
|
b1.Property<float>("SizeSelector")
|
||||||
|
.HasColumnType("real");
|
||||||
|
|
||||||
|
b1.HasKey("ThemeId");
|
||||||
|
|
||||||
|
b1.ToTable("Themes", "core");
|
||||||
|
|
||||||
|
b1.ToJson("Content");
|
||||||
|
|
||||||
|
b1.WithOwner()
|
||||||
|
.HasForeignKey("ThemeId");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.Navigation("Content")
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireJob", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Parameters");
|
||||||
|
|
||||||
|
b.Navigation("QueuedJobs");
|
||||||
|
|
||||||
|
b.Navigation("States");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,399 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Database.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class RecreatedMigrationsForChangeOfSchema : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.EnsureSchema(
|
||||||
|
name: "core");
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "ApiKeys",
|
||||||
|
schema: "core",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
Description = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Permissions = table.Column<string[]>(type: "text[]", nullable: false),
|
||||||
|
ExpiresAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||||
|
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_ApiKeys", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "HangfireCounter",
|
||||||
|
schema: "core",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
Key = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
||||||
|
Value = table.Column<long>(type: "bigint", nullable: false),
|
||||||
|
ExpireAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_HangfireCounter", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "HangfireHash",
|
||||||
|
schema: "core",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Key = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
||||||
|
Field = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
||||||
|
Value = table.Column<string>(type: "text", nullable: true),
|
||||||
|
ExpireAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_HangfireHash", x => new { x.Key, x.Field });
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "HangfireList",
|
||||||
|
schema: "core",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Key = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
||||||
|
Position = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
Value = table.Column<string>(type: "text", nullable: true),
|
||||||
|
ExpireAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_HangfireList", x => new { x.Key, x.Position });
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "HangfireLock",
|
||||||
|
schema: "core",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
||||||
|
AcquiredAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_HangfireLock", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "HangfireServer",
|
||||||
|
schema: "core",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
||||||
|
StartedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
Heartbeat = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
WorkerCount = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
Queues = table.Column<string>(type: "text", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_HangfireServer", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "HangfireSet",
|
||||||
|
schema: "core",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Key = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
||||||
|
Value = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
||||||
|
Score = table.Column<double>(type: "double precision", nullable: false),
|
||||||
|
ExpireAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_HangfireSet", x => new { x.Key, x.Value });
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Themes",
|
||||||
|
schema: "core",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
IsEnabled = table.Column<bool>(type: "boolean", nullable: false),
|
||||||
|
Name = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Author = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Version = table.Column<string>(type: "text", nullable: false),
|
||||||
|
UpdateUrl = table.Column<string>(type: "text", nullable: true),
|
||||||
|
DonateUrl = table.Column<string>(type: "text", nullable: true),
|
||||||
|
Content = table.Column<string>(type: "jsonb", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Themes", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Users",
|
||||||
|
schema: "core",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
Username = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Email = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Password = table.Column<string>(type: "text", nullable: false),
|
||||||
|
TokenValidTimestamp = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||||
|
Permissions = table.Column<string[]>(type: "text[]", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Users", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "HangfireJob",
|
||||||
|
schema: "core",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
StateId = table.Column<long>(type: "bigint", nullable: true),
|
||||||
|
StateName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
|
||||||
|
ExpireAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||||
|
InvocationData = table.Column<string>(type: "text", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_HangfireJob", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "HangfireJobParameter",
|
||||||
|
schema: "core",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
JobId = table.Column<long>(type: "bigint", nullable: false),
|
||||||
|
Name = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
||||||
|
Value = table.Column<string>(type: "text", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_HangfireJobParameter", x => new { x.JobId, x.Name });
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_HangfireJobParameter_HangfireJob_JobId",
|
||||||
|
column: x => x.JobId,
|
||||||
|
principalSchema: "core",
|
||||||
|
principalTable: "HangfireJob",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "HangfireQueuedJob",
|
||||||
|
schema: "core",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
JobId = table.Column<long>(type: "bigint", nullable: false),
|
||||||
|
Queue = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
||||||
|
FetchedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_HangfireQueuedJob", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_HangfireQueuedJob_HangfireJob_JobId",
|
||||||
|
column: x => x.JobId,
|
||||||
|
principalSchema: "core",
|
||||||
|
principalTable: "HangfireJob",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "HangfireState",
|
||||||
|
schema: "core",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
JobId = table.Column<long>(type: "bigint", nullable: false),
|
||||||
|
Name = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
||||||
|
Reason = table.Column<string>(type: "text", nullable: true),
|
||||||
|
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
Data = table.Column<string>(type: "text", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_HangfireState", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_HangfireState_HangfireJob_JobId",
|
||||||
|
column: x => x.JobId,
|
||||||
|
principalSchema: "core",
|
||||||
|
principalTable: "HangfireJob",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_HangfireCounter_ExpireAt",
|
||||||
|
schema: "core",
|
||||||
|
table: "HangfireCounter",
|
||||||
|
column: "ExpireAt");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_HangfireCounter_Key_Value",
|
||||||
|
schema: "core",
|
||||||
|
table: "HangfireCounter",
|
||||||
|
columns: new[] { "Key", "Value" });
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_HangfireHash_ExpireAt",
|
||||||
|
schema: "core",
|
||||||
|
table: "HangfireHash",
|
||||||
|
column: "ExpireAt");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_HangfireJob_ExpireAt",
|
||||||
|
schema: "core",
|
||||||
|
table: "HangfireJob",
|
||||||
|
column: "ExpireAt");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_HangfireJob_StateId",
|
||||||
|
schema: "core",
|
||||||
|
table: "HangfireJob",
|
||||||
|
column: "StateId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_HangfireJob_StateName",
|
||||||
|
schema: "core",
|
||||||
|
table: "HangfireJob",
|
||||||
|
column: "StateName");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_HangfireList_ExpireAt",
|
||||||
|
schema: "core",
|
||||||
|
table: "HangfireList",
|
||||||
|
column: "ExpireAt");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_HangfireQueuedJob_JobId",
|
||||||
|
schema: "core",
|
||||||
|
table: "HangfireQueuedJob",
|
||||||
|
column: "JobId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_HangfireQueuedJob_Queue_FetchedAt",
|
||||||
|
schema: "core",
|
||||||
|
table: "HangfireQueuedJob",
|
||||||
|
columns: new[] { "Queue", "FetchedAt" });
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_HangfireServer_Heartbeat",
|
||||||
|
schema: "core",
|
||||||
|
table: "HangfireServer",
|
||||||
|
column: "Heartbeat");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_HangfireSet_ExpireAt",
|
||||||
|
schema: "core",
|
||||||
|
table: "HangfireSet",
|
||||||
|
column: "ExpireAt");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_HangfireSet_Key_Score",
|
||||||
|
schema: "core",
|
||||||
|
table: "HangfireSet",
|
||||||
|
columns: new[] { "Key", "Score" });
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_HangfireState_JobId",
|
||||||
|
schema: "core",
|
||||||
|
table: "HangfireState",
|
||||||
|
column: "JobId");
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_HangfireJob_HangfireState_StateId",
|
||||||
|
schema: "core",
|
||||||
|
table: "HangfireJob",
|
||||||
|
column: "StateId",
|
||||||
|
principalSchema: "core",
|
||||||
|
principalTable: "HangfireState",
|
||||||
|
principalColumn: "Id");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_HangfireJob_HangfireState_StateId",
|
||||||
|
schema: "core",
|
||||||
|
table: "HangfireJob");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "ApiKeys",
|
||||||
|
schema: "core");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "HangfireCounter",
|
||||||
|
schema: "core");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "HangfireHash",
|
||||||
|
schema: "core");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "HangfireJobParameter",
|
||||||
|
schema: "core");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "HangfireList",
|
||||||
|
schema: "core");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "HangfireLock",
|
||||||
|
schema: "core");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "HangfireQueuedJob",
|
||||||
|
schema: "core");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "HangfireServer",
|
||||||
|
schema: "core");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "HangfireSet",
|
||||||
|
schema: "core");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Themes",
|
||||||
|
schema: "core");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Users",
|
||||||
|
schema: "core");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "HangfireState",
|
||||||
|
schema: "core");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "HangfireJob",
|
||||||
|
schema: "core");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,562 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Moonlight.ApiServer.Database;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Database.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(CoreDataContext))]
|
||||||
|
partial class CoreDataContextModelSnapshot : ModelSnapshot
|
||||||
|
{
|
||||||
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasDefaultSchema("core")
|
||||||
|
.HasAnnotation("ProductVersion", "9.0.8")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireCounter", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateTime?>("ExpireAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<long>("Value")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ExpireAt");
|
||||||
|
|
||||||
|
b.HasIndex("Key", "Value");
|
||||||
|
|
||||||
|
b.ToTable("HangfireCounter", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireHash", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("Field")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("ExpireAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Value")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Key", "Field");
|
||||||
|
|
||||||
|
b.HasIndex("ExpireAt");
|
||||||
|
|
||||||
|
b.ToTable("HangfireHash", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireJob", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("ExpireAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("InvocationData")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<long?>("StateId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<string>("StateName")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ExpireAt");
|
||||||
|
|
||||||
|
b.HasIndex("StateId");
|
||||||
|
|
||||||
|
b.HasIndex("StateName");
|
||||||
|
|
||||||
|
b.ToTable("HangfireJob", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireJobParameter", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("JobId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("Value")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("JobId", "Name");
|
||||||
|
|
||||||
|
b.ToTable("HangfireJobParameter", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireList", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<int>("Position")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("ExpireAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Value")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Key", "Position");
|
||||||
|
|
||||||
|
b.HasIndex("ExpireAt");
|
||||||
|
|
||||||
|
b.ToTable("HangfireList", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireLock", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Id")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("AcquiredAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("HangfireLock", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireQueuedJob", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateTime?>("FetchedAt")
|
||||||
|
.IsConcurrencyToken()
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<long>("JobId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<string>("Queue")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("JobId");
|
||||||
|
|
||||||
|
b.HasIndex("Queue", "FetchedAt");
|
||||||
|
|
||||||
|
b.ToTable("HangfireQueuedJob", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireServer", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Id")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Heartbeat")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Queues")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("StartedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<int>("WorkerCount")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("Heartbeat");
|
||||||
|
|
||||||
|
b.ToTable("HangfireServer", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireSet", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.HasColumnType("character varying(100)");
|
||||||
|
|
||||||
|
b.Property<string>("Value")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("ExpireAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<double>("Score")
|
||||||
|
.HasColumnType("double precision");
|
||||||
|
|
||||||
|
b.HasKey("Key", "Value");
|
||||||
|
|
||||||
|
b.HasIndex("ExpireAt");
|
||||||
|
|
||||||
|
b.HasIndex("Key", "Score");
|
||||||
|
|
||||||
|
b.ToTable("HangfireSet", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireState", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Data")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<long>("JobId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("Reason")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("JobId");
|
||||||
|
|
||||||
|
b.ToTable("HangfireState", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.ApiKey", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("CreatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("ExpiresAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("Permissions")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("ApiKeys", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.Theme", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Author")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("DonateUrl")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<bool>("IsEnabled")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("UpdateUrl")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Version")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Themes", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("Permissions")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("TokenValidTimestamp")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireJob", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Hangfire.EntityFrameworkCore.HangfireState", "State")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("StateId");
|
||||||
|
|
||||||
|
b.Navigation("State");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireJobParameter", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Hangfire.EntityFrameworkCore.HangfireJob", "Job")
|
||||||
|
.WithMany("Parameters")
|
||||||
|
.HasForeignKey("JobId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Job");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireQueuedJob", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Hangfire.EntityFrameworkCore.HangfireJob", "Job")
|
||||||
|
.WithMany("QueuedJobs")
|
||||||
|
.HasForeignKey("JobId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Job");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireState", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Hangfire.EntityFrameworkCore.HangfireJob", "Job")
|
||||||
|
.WithMany("States")
|
||||||
|
.HasForeignKey("JobId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Job");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.Theme", b =>
|
||||||
|
{
|
||||||
|
b.OwnsOne("Moonlight.ApiServer.Models.ApplicationTheme", "Content", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<int>("ThemeId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b1.Property<float>("Border")
|
||||||
|
.HasColumnType("real");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorAccent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorAccentContent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorBackground")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorBase100")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorBase150")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorBase200")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorBase250")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorBase300")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorBaseContent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorError")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorErrorContent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorInfo")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorInfoContent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorNeutral")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorNeutralContent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorPrimary")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorPrimaryContent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorSecondary")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorSecondaryContent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorSuccess")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorSuccessContent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorWarning")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("ColorWarningContent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<int>("Depth")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b1.Property<int>("Noise")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b1.Property<float>("RadiusBox")
|
||||||
|
.HasColumnType("real");
|
||||||
|
|
||||||
|
b1.Property<float>("RadiusField")
|
||||||
|
.HasColumnType("real");
|
||||||
|
|
||||||
|
b1.Property<float>("RadiusSelector")
|
||||||
|
.HasColumnType("real");
|
||||||
|
|
||||||
|
b1.Property<float>("SizeField")
|
||||||
|
.HasColumnType("real");
|
||||||
|
|
||||||
|
b1.Property<float>("SizeSelector")
|
||||||
|
.HasColumnType("real");
|
||||||
|
|
||||||
|
b1.HasKey("ThemeId");
|
||||||
|
|
||||||
|
b1.ToTable("Themes", "core");
|
||||||
|
|
||||||
|
b1.ToJson("Content");
|
||||||
|
|
||||||
|
b1.WithOwner()
|
||||||
|
.HasForeignKey("ThemeId");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.Navigation("Content")
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Hangfire.EntityFrameworkCore.HangfireJob", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Parameters");
|
||||||
|
|
||||||
|
b.Navigation("QueuedJobs");
|
||||||
|
|
||||||
|
b.Navigation("States");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
33
Moonlight.ApiServer/Extensions/ZipArchiveExtensions.cs
Normal file
33
Moonlight.ApiServer/Extensions/ZipArchiveExtensions.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using System.IO.Compression;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Extensions;
|
||||||
|
|
||||||
|
public static class ZipArchiveExtensions
|
||||||
|
{
|
||||||
|
public static async Task AddBinaryAsync(this ZipArchive archive, string name, byte[] bytes)
|
||||||
|
{
|
||||||
|
var entry = archive.CreateEntry(name);
|
||||||
|
await using var dataStream = entry.Open();
|
||||||
|
|
||||||
|
await dataStream.WriteAsync(bytes);
|
||||||
|
await dataStream.FlushAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task AddTextAsync(this ZipArchive archive, string name, string content)
|
||||||
|
{
|
||||||
|
var data = Encoding.UTF8.GetBytes(content);
|
||||||
|
await archive.AddBinaryAsync(name, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task AddFileAsync(this ZipArchive archive, string name, string path)
|
||||||
|
{
|
||||||
|
var fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
|
|
||||||
|
var entry = archive.CreateEntry(name);
|
||||||
|
await using var dataStream = entry.Open();
|
||||||
|
|
||||||
|
await fs.CopyToAsync(dataStream);
|
||||||
|
await dataStream.FlushAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
25
Moonlight.ApiServer/Helpers/FilePathHelper.cs
Normal file
25
Moonlight.ApiServer/Helpers/FilePathHelper.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
namespace Moonlight.ApiServer.Helpers;
|
||||||
|
|
||||||
|
public class FilePathHelper
|
||||||
|
{
|
||||||
|
public static string SanitizePath(string path)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(path))
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
|
// Normalize separators
|
||||||
|
path = path.Replace('\\', '/');
|
||||||
|
|
||||||
|
// Remove ".." and "."
|
||||||
|
var parts = path.Split('/', StringSplitOptions.RemoveEmptyEntries)
|
||||||
|
.Where(part => part != ".." && part != ".");
|
||||||
|
|
||||||
|
var sanitized = string.Join("/", parts);
|
||||||
|
|
||||||
|
// Ensure it does not start with a slash
|
||||||
|
if (sanitized.StartsWith('/'))
|
||||||
|
sanitized = sanitized.TrimStart('/');
|
||||||
|
|
||||||
|
return sanitized;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,150 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using MoonCore.Common;
|
||||||
|
using MoonCore.Extended.Abstractions;
|
||||||
|
using Moonlight.ApiServer.Database.Entities;
|
||||||
|
using Moonlight.ApiServer.Mappers;
|
||||||
|
using Moonlight.ApiServer.Services;
|
||||||
|
using Moonlight.Shared.Http.Requests.Admin.ApiKeys;
|
||||||
|
using Moonlight.Shared.Http.Responses.Admin.ApiKeys;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Http.Controllers.Admin.ApiKeys;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/apikeys")]
|
||||||
|
public class ApiKeysController : Controller
|
||||||
|
{
|
||||||
|
private readonly DatabaseRepository<ApiKey> ApiKeyRepository;
|
||||||
|
private readonly ApiKeyService ApiKeyService;
|
||||||
|
|
||||||
|
public ApiKeysController(DatabaseRepository<ApiKey> apiKeyRepository, ApiKeyService apiKeyService)
|
||||||
|
{
|
||||||
|
ApiKeyRepository = apiKeyRepository;
|
||||||
|
ApiKeyService = apiKeyService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Authorize(Policy = "permissions:admin.apikeys.get")]
|
||||||
|
public async Task<ActionResult<CountedData<ApiKeyResponse>>> GetAsync(
|
||||||
|
[FromQuery] int startIndex,
|
||||||
|
[FromQuery] int count,
|
||||||
|
[FromQuery] string? orderBy,
|
||||||
|
[FromQuery] string? filter,
|
||||||
|
[FromQuery] string orderByDir = "asc"
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (count > 100)
|
||||||
|
return Problem("You cannot fetch more items than 100 at a time", statusCode: 400);
|
||||||
|
|
||||||
|
IQueryable<ApiKey> query = ApiKeyRepository.Get();
|
||||||
|
|
||||||
|
query = orderBy switch
|
||||||
|
{
|
||||||
|
nameof(ApiKey.Id) => orderByDir == "desc"
|
||||||
|
? query.OrderByDescending(x => x.Id)
|
||||||
|
: query.OrderBy(x => x.Id),
|
||||||
|
|
||||||
|
nameof(ApiKey.ExpiresAt) => orderByDir == "desc"
|
||||||
|
? query.OrderByDescending(x => x.ExpiresAt)
|
||||||
|
: query.OrderBy(x => x.ExpiresAt),
|
||||||
|
|
||||||
|
nameof(ApiKey.CreatedAt) => orderByDir == "desc"
|
||||||
|
? query.OrderByDescending(x => x.CreatedAt)
|
||||||
|
: query.OrderBy(x => x.CreatedAt),
|
||||||
|
|
||||||
|
_ => query.OrderBy(x => x.Id)
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(filter))
|
||||||
|
{
|
||||||
|
query = query.Where(x =>
|
||||||
|
EF.Functions.ILike(x.Description, $"%{filter}%")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
var totalCount = await query.CountAsync();
|
||||||
|
|
||||||
|
var items = await query
|
||||||
|
.Skip(startIndex)
|
||||||
|
.Take(count)
|
||||||
|
.AsNoTracking()
|
||||||
|
.ProjectToResponse()
|
||||||
|
.ToArrayAsync();
|
||||||
|
|
||||||
|
return new CountedData<ApiKeyResponse>()
|
||||||
|
{
|
||||||
|
Items = items,
|
||||||
|
TotalCount = totalCount
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id:int}")]
|
||||||
|
[Authorize(Policy = "permissions:admin.apikeys.get")]
|
||||||
|
public async Task<ActionResult<ApiKeyResponse>> GetSingleAsync(int id)
|
||||||
|
{
|
||||||
|
var apiKey = await ApiKeyRepository
|
||||||
|
.Get()
|
||||||
|
.AsNoTracking()
|
||||||
|
.ProjectToResponse()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
|
||||||
|
if (apiKey == null)
|
||||||
|
return Problem("No api key with that id found", statusCode: 404);
|
||||||
|
|
||||||
|
return apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[Authorize(Policy = "permissions:admin.apikeys.create")]
|
||||||
|
public async Task<CreateApiKeyResponse> CreateAsync([FromBody] CreateApiKeyRequest request)
|
||||||
|
{
|
||||||
|
var apiKey = ApiKeyMapper.ToApiKey(request);
|
||||||
|
|
||||||
|
var finalApiKey = await ApiKeyRepository.AddAsync(apiKey);
|
||||||
|
|
||||||
|
var response = new CreateApiKeyResponse
|
||||||
|
{
|
||||||
|
Id = finalApiKey.Id,
|
||||||
|
Permissions = finalApiKey.Permissions,
|
||||||
|
Description = finalApiKey.Description,
|
||||||
|
ExpiresAt = finalApiKey.ExpiresAt,
|
||||||
|
Secret = ApiKeyService.GenerateJwt(finalApiKey)
|
||||||
|
};
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPatch("{id:int}")]
|
||||||
|
[Authorize(Policy = "permissions:admin.apikeys.update")]
|
||||||
|
public async Task<ActionResult<ApiKeyResponse>> UpdateAsync([FromRoute] int id, [FromBody] UpdateApiKeyRequest request)
|
||||||
|
{
|
||||||
|
var apiKey = await ApiKeyRepository
|
||||||
|
.Get()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
|
||||||
|
if (apiKey == null)
|
||||||
|
return Problem("No api key with that id found", statusCode: 404);
|
||||||
|
|
||||||
|
ApiKeyMapper.Merge(apiKey, request);
|
||||||
|
|
||||||
|
await ApiKeyRepository.UpdateAsync(apiKey);
|
||||||
|
|
||||||
|
return ApiKeyMapper.ToResponse(apiKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("{id:int}")]
|
||||||
|
[Authorize(Policy = "permissions:admin.apikeys.delete")]
|
||||||
|
public async Task<ActionResult> DeleteAsync([FromRoute] int id)
|
||||||
|
{
|
||||||
|
var apiKey = await ApiKeyRepository
|
||||||
|
.Get()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
|
||||||
|
if (apiKey == null)
|
||||||
|
return Problem("No api key with that id found", statusCode: 404);
|
||||||
|
|
||||||
|
await ApiKeyRepository.RemoveAsync(apiKey);
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Moonlight.ApiServer.Services;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Http.Controllers.Admin.Sys;
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/system/advanced")]
|
||||||
|
public class AdvancedController : Controller
|
||||||
|
{
|
||||||
|
private readonly FrontendService FrontendService;
|
||||||
|
|
||||||
|
public AdvancedController(FrontendService frontendService)
|
||||||
|
{
|
||||||
|
FrontendService = frontendService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("frontend")]
|
||||||
|
[Authorize(Policy = "permissions:admin.system.advanced.frontend")]
|
||||||
|
public async Task FrontendAsync()
|
||||||
|
{
|
||||||
|
var stream = await FrontendService.GenerateZipAsync();
|
||||||
|
await Results.File(stream, fileDownloadName: "frontend.zip").ExecuteAsync(HttpContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using MoonCore.Common;
|
||||||
|
using MoonCore.Extended.Abstractions;
|
||||||
|
using Moonlight.ApiServer.Database.Entities;
|
||||||
|
using Moonlight.ApiServer.Mappers;
|
||||||
|
using Moonlight.Shared.Http.Requests.Admin.Sys.Theme;
|
||||||
|
using Moonlight.Shared.Http.Responses.Admin;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Http.Controllers.Admin.Sys.Customisation;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/system/customisation/themes")]
|
||||||
|
public class ThemesController : Controller
|
||||||
|
{
|
||||||
|
private readonly DatabaseRepository<Theme> ThemeRepository;
|
||||||
|
|
||||||
|
public ThemesController(DatabaseRepository<Theme> themeRepository)
|
||||||
|
{
|
||||||
|
ThemeRepository = themeRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Authorize(Policy = "permissions:admin.system.customisation.themes.read")]
|
||||||
|
public async Task<ActionResult<CountedData<ThemeResponse>>> GetAsync(
|
||||||
|
[FromQuery] int startIndex,
|
||||||
|
[FromQuery] int count,
|
||||||
|
[FromQuery] string? orderBy,
|
||||||
|
[FromQuery] string? filter,
|
||||||
|
[FromQuery] string orderByDir = "asc"
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (count > 100)
|
||||||
|
return Problem("You cannot fetch more items than 100 at a time", statusCode: 400);
|
||||||
|
|
||||||
|
IQueryable<Theme> query = ThemeRepository.Get();
|
||||||
|
|
||||||
|
query = orderBy switch
|
||||||
|
{
|
||||||
|
nameof(Theme.Id) => orderByDir == "desc"
|
||||||
|
? query.OrderByDescending(x => x.Id)
|
||||||
|
: query.OrderBy(x => x.Id),
|
||||||
|
|
||||||
|
nameof(Theme.Name) => orderByDir == "desc"
|
||||||
|
? query.OrderByDescending(x => x.Name)
|
||||||
|
: query.OrderBy(x => x.Name),
|
||||||
|
|
||||||
|
nameof(Theme.Version) => orderByDir == "desc"
|
||||||
|
? query.OrderByDescending(x => x.Version)
|
||||||
|
: query.OrderBy(x => x.Version),
|
||||||
|
|
||||||
|
_ => query.OrderBy(x => x.Id)
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(filter))
|
||||||
|
{
|
||||||
|
query = query.Where(x =>
|
||||||
|
EF.Functions.ILike(x.Name, $"%{filter}%")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
var totalCount = await query.CountAsync();
|
||||||
|
|
||||||
|
var items = await query
|
||||||
|
.Skip(startIndex)
|
||||||
|
.Take(count)
|
||||||
|
.AsNoTracking()
|
||||||
|
.ProjectToResponse()
|
||||||
|
.ToArrayAsync();
|
||||||
|
|
||||||
|
return new CountedData<ThemeResponse>()
|
||||||
|
{
|
||||||
|
Items = items,
|
||||||
|
TotalCount = totalCount
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id:int}")]
|
||||||
|
[Authorize(Policy = "permissions:admin.system.customisation.themes.read")]
|
||||||
|
public async Task<ActionResult<ThemeResponse>> GetSingleAsync([FromRoute] int id)
|
||||||
|
{
|
||||||
|
var theme = await ThemeRepository
|
||||||
|
.Get()
|
||||||
|
.AsNoTracking()
|
||||||
|
.ProjectToResponse()
|
||||||
|
.FirstOrDefaultAsync(t => t.Id == id);
|
||||||
|
|
||||||
|
if (theme == null)
|
||||||
|
return Problem("Theme with this id not found", statusCode: 404);
|
||||||
|
|
||||||
|
return theme;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[Authorize(Policy = "permissions:admin.system.customisation.themes.write")]
|
||||||
|
public async Task<ActionResult<ThemeResponse>> CreateAsync([FromBody] CreateThemeRequest request)
|
||||||
|
{
|
||||||
|
var theme = ThemeMapper.ToTheme(request);
|
||||||
|
|
||||||
|
var finalTheme = await ThemeRepository.AddAsync(theme);
|
||||||
|
|
||||||
|
return ThemeMapper.ToResponse(finalTheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPatch("{id:int}")]
|
||||||
|
[Authorize(Policy = "permissions:admin.system.customisation.themes.write")]
|
||||||
|
public async Task<ActionResult<ThemeResponse>> UpdateAsync([FromRoute] int id, [FromBody] UpdateThemeRequest request)
|
||||||
|
{
|
||||||
|
var theme = await ThemeRepository
|
||||||
|
.Get()
|
||||||
|
.FirstOrDefaultAsync(t => t.Id == id);
|
||||||
|
|
||||||
|
if (theme == null)
|
||||||
|
return Problem("Theme with this id not found", statusCode: 404);
|
||||||
|
|
||||||
|
// Disable all other enabled themes if we are enabling the current theme.
|
||||||
|
// This ensures only one theme is enabled at the time
|
||||||
|
if (request.IsEnabled)
|
||||||
|
{
|
||||||
|
var otherThemes = await ThemeRepository
|
||||||
|
.Get()
|
||||||
|
.Where(x => x.IsEnabled && x.Id != id)
|
||||||
|
.ToArrayAsync();
|
||||||
|
|
||||||
|
foreach (var otherTheme in otherThemes)
|
||||||
|
otherTheme.IsEnabled = false;
|
||||||
|
|
||||||
|
await ThemeRepository.RunTransactionAsync(set => { set.UpdateRange(otherThemes); });
|
||||||
|
}
|
||||||
|
|
||||||
|
ThemeMapper.Merge(theme, request);
|
||||||
|
|
||||||
|
await ThemeRepository.UpdateAsync(theme);
|
||||||
|
|
||||||
|
return ThemeMapper.ToResponse(theme);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("{id:int}")]
|
||||||
|
[Authorize(Policy = "permissions:admin.system.customisation.themes.write")]
|
||||||
|
public async Task<ActionResult> DeleteAsync([FromRoute] int id)
|
||||||
|
{
|
||||||
|
var theme = await ThemeRepository
|
||||||
|
.Get()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
|
||||||
|
if (theme == null)
|
||||||
|
return Problem("Theme with this id not found", statusCode: 404);
|
||||||
|
|
||||||
|
await ThemeRepository.RemoveAsync(theme);
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Moonlight.ApiServer.Services;
|
||||||
|
using Moonlight.Shared.Http.Requests.Admin.Sys;
|
||||||
|
using Moonlight.Shared.Http.Responses.Admin.Sys;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Http.Controllers.Admin.Sys;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/system/diagnose")]
|
||||||
|
[Authorize(Policy = "permissions:admin.system.diagnose")]
|
||||||
|
public class DiagnoseController : Controller
|
||||||
|
{
|
||||||
|
private readonly DiagnoseService DiagnoseService;
|
||||||
|
|
||||||
|
public DiagnoseController(DiagnoseService diagnoseService)
|
||||||
|
{
|
||||||
|
DiagnoseService = diagnoseService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<ActionResult> DiagnoseAsync([FromBody] GenerateDiagnoseRequest request)
|
||||||
|
{
|
||||||
|
var stream = await DiagnoseService.GenerateDiagnoseAsync(request.Providers);
|
||||||
|
|
||||||
|
return File(stream, "application/zip", "diagnose.zip");
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("providers")]
|
||||||
|
public async Task<ActionResult<DiagnoseProvideResponse[]>> GetProvidersAsync()
|
||||||
|
{
|
||||||
|
return await DiagnoseService.GetProvidersAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using MoonCore.Helpers;
|
||||||
|
using Moonlight.ApiServer.Configuration;
|
||||||
|
using Moonlight.ApiServer.Helpers;
|
||||||
|
using Moonlight.Shared.Http.Requests.Admin.Sys.Files;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Http.Controllers.Admin.Sys.Files;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/system/files")]
|
||||||
|
[Authorize(Policy = "permissions:admin.system.files")]
|
||||||
|
public class CombineController : Controller
|
||||||
|
{
|
||||||
|
private readonly AppConfiguration Configuration;
|
||||||
|
|
||||||
|
private const string BaseDirectory = "storage";
|
||||||
|
|
||||||
|
public CombineController(AppConfiguration configuration)
|
||||||
|
{
|
||||||
|
Configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("combine")]
|
||||||
|
public async Task<IResult> CombineAsync([FromBody] CombineRequest request)
|
||||||
|
{
|
||||||
|
// Validate file lenght
|
||||||
|
if (request.Files.Length < 2)
|
||||||
|
return Results.Problem("At least two files are required", statusCode: 400);
|
||||||
|
|
||||||
|
// Resolve the physical paths
|
||||||
|
var destination = Path.Combine(BaseDirectory, FilePathHelper.SanitizePath(request.Destination));
|
||||||
|
|
||||||
|
var files = request.Files
|
||||||
|
.Select(path => Path.Combine(BaseDirectory, FilePathHelper.SanitizePath(path)))
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
// Validate max file size
|
||||||
|
long combinedSize = 0;
|
||||||
|
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
var fi = new FileInfo(file);
|
||||||
|
combinedSize += fi.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ByteConverter.FromBytes(combinedSize).MegaBytes > Configuration.Files.CombineLimit)
|
||||||
|
{
|
||||||
|
return Results.Problem("The combine operation exceeds the maximum file size", statusCode: 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Combine files
|
||||||
|
|
||||||
|
await using var destinationFs = System.IO.File.Open(
|
||||||
|
destination,
|
||||||
|
FileMode.Create,
|
||||||
|
FileAccess.ReadWrite,
|
||||||
|
FileShare.Read
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
await using var fs = System.IO.File.Open(
|
||||||
|
file,
|
||||||
|
FileMode.Open,
|
||||||
|
FileAccess.ReadWrite
|
||||||
|
);
|
||||||
|
|
||||||
|
await fs.CopyToAsync(destinationFs);
|
||||||
|
await destinationFs.FlushAsync();
|
||||||
|
|
||||||
|
fs.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
await destinationFs.FlushAsync();
|
||||||
|
destinationFs.Close();
|
||||||
|
|
||||||
|
return Results.Ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,183 @@
|
|||||||
|
using System.Text;
|
||||||
|
using ICSharpCode.SharpZipLib.GZip;
|
||||||
|
using ICSharpCode.SharpZipLib.Tar;
|
||||||
|
using ICSharpCode.SharpZipLib.Zip;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using MoonCore.Helpers;
|
||||||
|
using Moonlight.ApiServer.Helpers;
|
||||||
|
using Moonlight.Shared.Http.Requests.Admin.Sys.Files;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Http.Controllers.Admin.Sys.Files;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/system/files")]
|
||||||
|
[Authorize(Policy = "permissions:admin.system.files")]
|
||||||
|
public class CompressController : Controller
|
||||||
|
{
|
||||||
|
private const string BaseDirectory = "storage";
|
||||||
|
|
||||||
|
[HttpPost("compress")]
|
||||||
|
public async Task<IResult> CompressAsync([FromBody] CompressRequest request)
|
||||||
|
{
|
||||||
|
// Validate item length
|
||||||
|
if (request.Items.Length == 0)
|
||||||
|
{
|
||||||
|
return Results.Problem(
|
||||||
|
"At least one item is required",
|
||||||
|
statusCode: 400
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build paths
|
||||||
|
var destinationPath = Path.Combine(BaseDirectory, FilePathHelper.SanitizePath(request.Destination));
|
||||||
|
var rootPath = Path.Combine(BaseDirectory, FilePathHelper.SanitizePath(request.Root));
|
||||||
|
|
||||||
|
// Resolve the relative to the root item paths to absolute paths
|
||||||
|
var itemsPaths = request.Items.Select(item =>
|
||||||
|
Path.Combine(
|
||||||
|
BaseDirectory,
|
||||||
|
FilePathHelper.SanitizePath(
|
||||||
|
UnixPath.Combine(request.Root, item)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Execute request
|
||||||
|
switch (request.Format)
|
||||||
|
{
|
||||||
|
case "tar.gz":
|
||||||
|
await CompressTarGzAsync(destinationPath, itemsPaths, rootPath);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "zip":
|
||||||
|
await CompressZipAsync(destinationPath, itemsPaths, rootPath);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return Results.Problem("Unsupported archive format specified", statusCode: 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Results.Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#region Tar Gz
|
||||||
|
|
||||||
|
private async Task CompressTarGzAsync(string destination, IEnumerable<string> items, string root)
|
||||||
|
{
|
||||||
|
await using var outStream = System.IO.File.Create(destination);
|
||||||
|
await using var gzoStream = new GZipOutputStream(outStream);
|
||||||
|
await using var tarStream = new TarOutputStream(gzoStream, Encoding.UTF8);
|
||||||
|
|
||||||
|
foreach (var item in items)
|
||||||
|
await CompressItemToTarGzAsync(tarStream, item, root);
|
||||||
|
|
||||||
|
await tarStream.FlushAsync();
|
||||||
|
await gzoStream.FlushAsync();
|
||||||
|
await outStream.FlushAsync();
|
||||||
|
|
||||||
|
tarStream.Close();
|
||||||
|
gzoStream.Close();
|
||||||
|
outStream.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task CompressItemToTarGzAsync(TarOutputStream tarOutputStream, string item, string root)
|
||||||
|
{
|
||||||
|
if (System.IO.File.Exists(item))
|
||||||
|
{
|
||||||
|
// Open file stream
|
||||||
|
var fs = System.IO.File.Open(item, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
|
|
||||||
|
// Meta
|
||||||
|
var entry = TarEntry.CreateTarEntry(
|
||||||
|
Formatter
|
||||||
|
.ReplaceStart(item, root, "")
|
||||||
|
.TrimStart('/')
|
||||||
|
);
|
||||||
|
|
||||||
|
// Set size
|
||||||
|
entry.Size = fs.Length;
|
||||||
|
|
||||||
|
// Write entry
|
||||||
|
await tarOutputStream.PutNextEntryAsync(entry, CancellationToken.None);
|
||||||
|
|
||||||
|
// Copy file content to tar stream
|
||||||
|
await fs.CopyToAsync(tarOutputStream);
|
||||||
|
fs.Close();
|
||||||
|
|
||||||
|
// Close the entry
|
||||||
|
tarOutputStream.CloseEntry();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Directory.Exists(item))
|
||||||
|
{
|
||||||
|
foreach (var fsEntry in Directory.EnumerateFileSystemEntries(item))
|
||||||
|
await CompressItemToTarGzAsync(tarOutputStream, fsEntry, root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ZIP
|
||||||
|
|
||||||
|
private async Task CompressZipAsync(string destination, IEnumerable<string> items, string root)
|
||||||
|
{
|
||||||
|
await using var outStream = System.IO.File.Create(destination);
|
||||||
|
await using var zipOutputStream = new ZipOutputStream(outStream);
|
||||||
|
|
||||||
|
foreach (var item in items)
|
||||||
|
await AddItemToZipAsync(zipOutputStream, item, root);
|
||||||
|
|
||||||
|
await zipOutputStream.FlushAsync();
|
||||||
|
await outStream.FlushAsync();
|
||||||
|
|
||||||
|
zipOutputStream.Close();
|
||||||
|
outStream.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task AddItemToZipAsync(ZipOutputStream outputStream, string item, string root)
|
||||||
|
{
|
||||||
|
if (System.IO.File.Exists(item))
|
||||||
|
{
|
||||||
|
// Open file stream
|
||||||
|
var fs = System.IO.File.Open(item, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
|
|
||||||
|
// Meta
|
||||||
|
var entry = new ZipEntry(
|
||||||
|
Formatter
|
||||||
|
.ReplaceStart(item, root, "")
|
||||||
|
.TrimStart('/')
|
||||||
|
);
|
||||||
|
|
||||||
|
entry.Size = fs.Length;
|
||||||
|
|
||||||
|
// Write entry
|
||||||
|
await outputStream.PutNextEntryAsync(entry, CancellationToken.None);
|
||||||
|
|
||||||
|
// Copy file content to tar stream
|
||||||
|
await fs.CopyToAsync(outputStream);
|
||||||
|
fs.Close();
|
||||||
|
|
||||||
|
// Close the entry
|
||||||
|
outputStream.CloseEntry();
|
||||||
|
|
||||||
|
// Flush caches
|
||||||
|
await outputStream.FlushAsync();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Directory.Exists(item))
|
||||||
|
{
|
||||||
|
foreach (var subItem in Directory.EnumerateFileSystemEntries(item))
|
||||||
|
await AddItemToZipAsync(outputStream, subItem, root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
using System.Text;
|
||||||
|
using ICSharpCode.SharpZipLib.GZip;
|
||||||
|
using ICSharpCode.SharpZipLib.Tar;
|
||||||
|
using ICSharpCode.SharpZipLib.Zip;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Moonlight.ApiServer.Helpers;
|
||||||
|
using Moonlight.Shared.Http.Requests.Admin.Sys.Files;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Http.Controllers.Admin.Sys.Files;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/system/files")]
|
||||||
|
[Authorize(Policy = "permissions:admin.system.files")]
|
||||||
|
public class DecompressController : Controller
|
||||||
|
{
|
||||||
|
private const string BaseDirectory = "storage";
|
||||||
|
|
||||||
|
[HttpPost("decompress")]
|
||||||
|
public async Task DecompressAsync([FromBody] DecompressRequest request)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(BaseDirectory, FilePathHelper.SanitizePath(request.Path));
|
||||||
|
var destination = Path.Combine(BaseDirectory, FilePathHelper.SanitizePath(request.Destination));
|
||||||
|
|
||||||
|
switch (request.Format)
|
||||||
|
{
|
||||||
|
case "tar.gz":
|
||||||
|
await DecompressTarGzAsync(path, destination);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "zip":
|
||||||
|
await DecompressZipAsync(path, destination);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Tar Gz
|
||||||
|
|
||||||
|
private async Task DecompressTarGzAsync(string path, string destination)
|
||||||
|
{
|
||||||
|
await using var fs = System.IO.File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
|
await using var gzipInputStream = new GZipInputStream(fs);
|
||||||
|
await using var tarInputStream = new TarInputStream(gzipInputStream, Encoding.UTF8);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
var entry = await tarInputStream.GetNextEntryAsync(CancellationToken.None);
|
||||||
|
|
||||||
|
if (entry == null)
|
||||||
|
break;
|
||||||
|
|
||||||
|
var safeFilePath = FilePathHelper.SanitizePath(entry.Name);
|
||||||
|
var fileDestination = Path.Combine(destination, safeFilePath);
|
||||||
|
var parentFolder = Path.GetDirectoryName(fileDestination);
|
||||||
|
|
||||||
|
// Ensure parent directory exists, if it's not the base directory
|
||||||
|
if (parentFolder != null && parentFolder != BaseDirectory)
|
||||||
|
Directory.CreateDirectory(parentFolder);
|
||||||
|
|
||||||
|
await using var fileDestinationFs =
|
||||||
|
System.IO.File.Open(fileDestination, FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
|
||||||
|
await tarInputStream.CopyToAsync(fileDestinationFs, CancellationToken.None);
|
||||||
|
|
||||||
|
await fileDestinationFs.FlushAsync();
|
||||||
|
fileDestinationFs.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
tarInputStream.Close();
|
||||||
|
gzipInputStream.Close();
|
||||||
|
fs.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Zip
|
||||||
|
|
||||||
|
private async Task DecompressZipAsync(string path, string destination)
|
||||||
|
{
|
||||||
|
await using var fs = System.IO.File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
|
await using var zipInputStream = new ZipInputStream(fs);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
var entry = zipInputStream.GetNextEntry();
|
||||||
|
|
||||||
|
if (entry == null)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (entry.IsDirectory)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var safeFilePath = FilePathHelper.SanitizePath(entry.Name);
|
||||||
|
var fileDestination = Path.Combine(destination, safeFilePath);
|
||||||
|
var parentFolder = Path.GetDirectoryName(fileDestination);
|
||||||
|
|
||||||
|
// Ensure parent directory exists, if it's not the base directory
|
||||||
|
if (parentFolder != null && parentFolder != BaseDirectory)
|
||||||
|
Directory.CreateDirectory(parentFolder);
|
||||||
|
|
||||||
|
await using var fileDestinationFs =
|
||||||
|
System.IO.File.Open(fileDestination, FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
|
||||||
|
await zipInputStream.CopyToAsync(fileDestinationFs, CancellationToken.None);
|
||||||
|
|
||||||
|
await fileDestinationFs.FlushAsync();
|
||||||
|
fileDestinationFs.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
zipInputStream.Close();
|
||||||
|
fs.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
using ICSharpCode.SharpZipLib.Zip;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using MoonCore.Exceptions;
|
||||||
|
using MoonCore.Helpers;
|
||||||
|
using Moonlight.ApiServer.Configuration;
|
||||||
|
using Moonlight.ApiServer.Helpers;
|
||||||
|
using Moonlight.Shared.Http.Responses.Admin.Sys;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Http.Controllers.Admin.Sys.Files;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/system/files/downloadUrl")]
|
||||||
|
[Authorize(Policy = "permissions:admin.system.files")]
|
||||||
|
public class DownloadUrlController : Controller
|
||||||
|
{
|
||||||
|
private readonly AppConfiguration Configuration;
|
||||||
|
|
||||||
|
private const string BaseDirectory = "storage";
|
||||||
|
|
||||||
|
public DownloadUrlController(AppConfiguration configuration)
|
||||||
|
{
|
||||||
|
Configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task GetAsync([FromQuery] string path)
|
||||||
|
{
|
||||||
|
var physicalPath = Path.Combine(BaseDirectory, FilePathHelper.SanitizePath(path));
|
||||||
|
var name = Path.GetFileName(physicalPath);
|
||||||
|
|
||||||
|
if (System.IO.File.Exists(physicalPath))
|
||||||
|
{
|
||||||
|
await using var fs = System.IO.File.Open(physicalPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
|
|
||||||
|
await Results.File(fs, fileDownloadName: name).ExecuteAsync(HttpContext);
|
||||||
|
}
|
||||||
|
else if(Directory.Exists(physicalPath))
|
||||||
|
{
|
||||||
|
// Without the base directory we would have the full path to the target folder
|
||||||
|
// inside the zip
|
||||||
|
|
||||||
|
var baseDirectory = Path.Combine(
|
||||||
|
BaseDirectory,
|
||||||
|
FilePathHelper.SanitizePath(Path.GetDirectoryName(path) ?? "")
|
||||||
|
);
|
||||||
|
|
||||||
|
Response.StatusCode = 200;
|
||||||
|
Response.ContentType = "application/zip";
|
||||||
|
Response.Headers["Content-Disposition"] = $"attachment; filename=\"{name}.zip\"";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await using var zipStream = new ZipOutputStream(Response.Body);
|
||||||
|
zipStream.IsStreamOwner = false;
|
||||||
|
|
||||||
|
await StreamFolderAsZipAsync(zipStream, physicalPath, baseDirectory, HttpContext.RequestAborted);
|
||||||
|
}
|
||||||
|
catch (ZipException)
|
||||||
|
{
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
|
catch (TaskCanceledException)
|
||||||
|
{
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task StreamFolderAsZipAsync(
|
||||||
|
ZipOutputStream zipStream,
|
||||||
|
string path, string rootPath,
|
||||||
|
CancellationToken cancellationToken
|
||||||
|
)
|
||||||
|
{
|
||||||
|
foreach (var file in Directory.EnumerateFiles(path))
|
||||||
|
{
|
||||||
|
if (HttpContext.RequestAborted.IsCancellationRequested)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var fi = new FileInfo(file);
|
||||||
|
|
||||||
|
var filePath = Formatter.ReplaceStart(file, rootPath, "");
|
||||||
|
|
||||||
|
await zipStream.PutNextEntryAsync(new ZipEntry(filePath)
|
||||||
|
{
|
||||||
|
Size = fi.Length,
|
||||||
|
}, cancellationToken);
|
||||||
|
|
||||||
|
await using var fs = System.IO.File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
|
await fs.CopyToAsync(zipStream, cancellationToken);
|
||||||
|
await fs.FlushAsync(cancellationToken);
|
||||||
|
|
||||||
|
fs.Close();
|
||||||
|
|
||||||
|
await zipStream.FlushAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var directory in Directory.EnumerateDirectories(path))
|
||||||
|
{
|
||||||
|
if (HttpContext.RequestAborted.IsCancellationRequested)
|
||||||
|
return;
|
||||||
|
|
||||||
|
await StreamFolderAsZipAsync(zipStream, directory, rootPath, cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Yes I know we can just create that url on the client as the exist validation is done on both endpoints,
|
||||||
|
// but we leave it here for future modifications. E.g. using a distributed file provider or smth like that
|
||||||
|
[HttpPost]
|
||||||
|
public Task<DownloadUrlResponse> PostAsync([FromQuery] string path)
|
||||||
|
{
|
||||||
|
var safePath = FilePathHelper.SanitizePath(path);
|
||||||
|
var physicalPath = Path.Combine(BaseDirectory, safePath);
|
||||||
|
|
||||||
|
if (System.IO.File.Exists(physicalPath) || Directory.Exists(physicalPath))
|
||||||
|
{
|
||||||
|
return Task.FromResult(new DownloadUrlResponse()
|
||||||
|
{
|
||||||
|
Url = $"{Configuration.PublicUrl}/api/admin/system/files/downloadUrl?path={path}"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new HttpApiException("No such file or directory found", 404);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,192 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using MoonCore.Exceptions;
|
||||||
|
using Moonlight.ApiServer.Helpers;
|
||||||
|
using Moonlight.Shared.Http.Responses.Admin.Sys;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Http.Controllers.Admin.Sys.Files;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/system/files")]
|
||||||
|
[Authorize(Policy = "permissions:admin.system.files")]
|
||||||
|
public class FilesController : Controller
|
||||||
|
{
|
||||||
|
private const string BaseDirectory = "storage";
|
||||||
|
|
||||||
|
[HttpPost("touch")]
|
||||||
|
public async Task CreateFileAsync([FromQuery] string path)
|
||||||
|
{
|
||||||
|
var safePath = FilePathHelper.SanitizePath(path);
|
||||||
|
var physicalPath = Path.Combine(BaseDirectory, safePath);
|
||||||
|
|
||||||
|
if (System.IO.File.Exists(physicalPath))
|
||||||
|
throw new HttpApiException("A file already exists at that path", 400);
|
||||||
|
|
||||||
|
if (Directory.Exists(path))
|
||||||
|
throw new HttpApiException("A folder already exists at that path", 400);
|
||||||
|
|
||||||
|
await using var fs = System.IO.File.Create(physicalPath);
|
||||||
|
fs.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("mkdir")]
|
||||||
|
public Task CreateFolderAsync([FromQuery] string path)
|
||||||
|
{
|
||||||
|
var safePath = FilePathHelper.SanitizePath(path);
|
||||||
|
var physicalPath = Path.Combine(BaseDirectory, safePath);
|
||||||
|
|
||||||
|
if (Directory.Exists(path))
|
||||||
|
throw new HttpApiException("A folder already exists at that path", 400);
|
||||||
|
|
||||||
|
if (System.IO.File.Exists(physicalPath))
|
||||||
|
throw new HttpApiException("A file already exists at that path", 400);
|
||||||
|
|
||||||
|
Directory.CreateDirectory(physicalPath);
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("list")]
|
||||||
|
public Task<FileSystemEntryResponse[]> ListAsync([FromQuery] string path)
|
||||||
|
{
|
||||||
|
var safePath = FilePathHelper.SanitizePath(path);
|
||||||
|
var physicalPath = Path.Combine(BaseDirectory, safePath);
|
||||||
|
|
||||||
|
var entries = new List<FileSystemEntryResponse>();
|
||||||
|
|
||||||
|
var files = Directory.GetFiles(physicalPath);
|
||||||
|
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
var fi = new FileInfo(file);
|
||||||
|
|
||||||
|
entries.Add(new FileSystemEntryResponse()
|
||||||
|
{
|
||||||
|
Name = fi.Name,
|
||||||
|
Size = fi.Length,
|
||||||
|
CreatedAt = fi.CreationTimeUtc,
|
||||||
|
IsFolder = false,
|
||||||
|
UpdatedAt = fi.LastWriteTimeUtc
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var directories = Directory.GetDirectories(physicalPath);
|
||||||
|
|
||||||
|
foreach (var directory in directories)
|
||||||
|
{
|
||||||
|
var di = new DirectoryInfo(directory);
|
||||||
|
|
||||||
|
entries.Add(new FileSystemEntryResponse()
|
||||||
|
{
|
||||||
|
Name = di.Name,
|
||||||
|
Size = 0,
|
||||||
|
CreatedAt = di.CreationTimeUtc,
|
||||||
|
UpdatedAt = di.LastWriteTimeUtc,
|
||||||
|
IsFolder = true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.FromResult(
|
||||||
|
entries.ToArray()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("move")]
|
||||||
|
public Task MoveAsync([FromQuery] string oldPath, [FromQuery] string newPath)
|
||||||
|
{
|
||||||
|
var oldSafePath = FilePathHelper.SanitizePath(oldPath);
|
||||||
|
var newSafePath = FilePathHelper.SanitizePath(newPath);
|
||||||
|
|
||||||
|
var oldPhysicalDirPath = Path.Combine(BaseDirectory, oldSafePath);
|
||||||
|
|
||||||
|
if (Directory.Exists(oldPhysicalDirPath))
|
||||||
|
{
|
||||||
|
var newPhysicalDirPath = Path.Combine(BaseDirectory, newSafePath);
|
||||||
|
|
||||||
|
Directory.Move(
|
||||||
|
oldPhysicalDirPath,
|
||||||
|
newPhysicalDirPath
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var oldPhysicalFilePath = Path.Combine(BaseDirectory, oldSafePath);
|
||||||
|
var newPhysicalFilePath = Path.Combine(BaseDirectory, newSafePath);
|
||||||
|
|
||||||
|
System.IO.File.Move(
|
||||||
|
oldPhysicalFilePath,
|
||||||
|
newPhysicalFilePath
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("delete")]
|
||||||
|
public Task DeleteAsync([FromQuery] string path)
|
||||||
|
{
|
||||||
|
var safePath = FilePathHelper.SanitizePath(path);
|
||||||
|
var physicalDirPath = Path.Combine(BaseDirectory, safePath);
|
||||||
|
|
||||||
|
if (Directory.Exists(physicalDirPath))
|
||||||
|
Directory.Delete(physicalDirPath, true);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var physicalFilePath = Path.Combine(BaseDirectory, safePath);
|
||||||
|
|
||||||
|
System.IO.File.Delete(physicalFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("upload")]
|
||||||
|
public async Task<IResult> UploadAsync([FromQuery] string path)
|
||||||
|
{
|
||||||
|
if (Request.Form.Files.Count != 1)
|
||||||
|
return Results.Problem("Only one file is allowed in the request", statusCode: 400);
|
||||||
|
|
||||||
|
var file = Request.Form.Files[0];
|
||||||
|
|
||||||
|
var safePath = FilePathHelper.SanitizePath(path);
|
||||||
|
var physicalPath = Path.Combine(BaseDirectory, safePath);
|
||||||
|
|
||||||
|
// Create directory which the new file should be put into
|
||||||
|
var baseDirectory = Path.GetDirectoryName(physicalPath);
|
||||||
|
|
||||||
|
if(!string.IsNullOrEmpty(baseDirectory))
|
||||||
|
Directory.CreateDirectory(baseDirectory);
|
||||||
|
|
||||||
|
// Create file from provided form
|
||||||
|
await using var dataStream = file.OpenReadStream();
|
||||||
|
|
||||||
|
await using var targetStream = System.IO.File.Open(
|
||||||
|
physicalPath,
|
||||||
|
FileMode.Create,
|
||||||
|
FileAccess.ReadWrite,
|
||||||
|
FileShare.Read
|
||||||
|
);
|
||||||
|
|
||||||
|
// Copy the content to the newly created file
|
||||||
|
await dataStream.CopyToAsync(targetStream);
|
||||||
|
await targetStream.FlushAsync();
|
||||||
|
|
||||||
|
// Close both streams
|
||||||
|
targetStream.Close();
|
||||||
|
dataStream.Close();
|
||||||
|
|
||||||
|
return Results.Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("download")]
|
||||||
|
public async Task DownloadAsync([FromQuery] string path)
|
||||||
|
{
|
||||||
|
var safePath = FilePathHelper.SanitizePath(path);
|
||||||
|
var physicalPath = Path.Combine(BaseDirectory, safePath);
|
||||||
|
|
||||||
|
await using var fs = System.IO.File.Open(physicalPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
|
await fs.CopyToAsync(Response.Body);
|
||||||
|
|
||||||
|
fs.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
using Hangfire;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Moonlight.Shared.Http.Responses.Admin.Hangfire;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Http.Controllers.Admin.Sys;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/system/hangfire")]
|
||||||
|
[Authorize(Policy = "permissions:admin.system.hangfire")]
|
||||||
|
public class HangfireController : Controller
|
||||||
|
{
|
||||||
|
private readonly JobStorage JobStorage;
|
||||||
|
|
||||||
|
public HangfireController(JobStorage jobStorage)
|
||||||
|
{
|
||||||
|
JobStorage = jobStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("stats")]
|
||||||
|
public Task<HangfireStatsResponse> GetStatsAsync()
|
||||||
|
{
|
||||||
|
var statistics = JobStorage.GetMonitoringApi().GetStatistics();
|
||||||
|
|
||||||
|
return Task.FromResult(new HangfireStatsResponse()
|
||||||
|
{
|
||||||
|
Awaiting = statistics.Awaiting,
|
||||||
|
Deleted = statistics.Deleted,
|
||||||
|
Enqueued = statistics.Enqueued,
|
||||||
|
Failed = statistics.Failed,
|
||||||
|
Processing = statistics.Processing,
|
||||||
|
Queues = statistics.Queues,
|
||||||
|
Recurring = statistics.Recurring,
|
||||||
|
Retries = statistics.Retries,
|
||||||
|
Scheduled = statistics.Scheduled,
|
||||||
|
Servers = statistics.Servers,
|
||||||
|
Succeeded = statistics.Succeeded
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Moonlight.ApiServer.Services;
|
||||||
|
using Moonlight.Shared.Http.Responses.Admin.Sys;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Http.Controllers.Admin.Sys;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/system")]
|
||||||
|
public class SystemController : Controller
|
||||||
|
{
|
||||||
|
private readonly ApplicationService ApplicationService;
|
||||||
|
|
||||||
|
public SystemController(ApplicationService applicationService)
|
||||||
|
{
|
||||||
|
ApplicationService = applicationService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Authorize(Policy = "permissions:admin.system.overview")]
|
||||||
|
public async Task<SystemOverviewResponse> GetOverviewAsync()
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Uptime = await ApplicationService.GetUptimeAsync(),
|
||||||
|
CpuUsage = await ApplicationService.GetCpuUsageAsync(),
|
||||||
|
MemoryUsage = await ApplicationService.GetMemoryUsageAsync(),
|
||||||
|
OperatingSystem = await ApplicationService.GetOsNameAsync()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("shutdown")]
|
||||||
|
[Authorize(Policy = "permissions:admin.system.shutdown")]
|
||||||
|
public async Task ShutdownAsync()
|
||||||
|
{
|
||||||
|
await ApplicationService.ShutdownAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,195 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using MoonCore.Common;
|
||||||
|
using MoonCore.Extended.Abstractions;
|
||||||
|
using MoonCore.Extended.Helpers;
|
||||||
|
using Moonlight.ApiServer.Database.Entities;
|
||||||
|
using Moonlight.ApiServer.Services;
|
||||||
|
using Moonlight.ApiServer.Mappers;
|
||||||
|
using Moonlight.Shared.Http.Requests.Admin.Users;
|
||||||
|
using Moonlight.Shared.Http.Responses.Admin.Users;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Http.Controllers.Admin.Users;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/users")]
|
||||||
|
public class UsersController : Controller
|
||||||
|
{
|
||||||
|
private readonly DatabaseRepository<User> UserRepository;
|
||||||
|
|
||||||
|
public UsersController(DatabaseRepository<User> userRepository)
|
||||||
|
{
|
||||||
|
UserRepository = userRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Authorize(Policy = "permissions:admin.users.get")]
|
||||||
|
public async Task<ActionResult<CountedData<UserResponse>>> GetAsync(
|
||||||
|
[FromQuery] int startIndex,
|
||||||
|
[FromQuery] int count,
|
||||||
|
[FromQuery] string? orderBy,
|
||||||
|
[FromQuery] string? filter,
|
||||||
|
[FromQuery] string orderByDir = "asc"
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (count > 100)
|
||||||
|
return Problem("You cannot fetch more items than 100 at a time", statusCode: 400);
|
||||||
|
|
||||||
|
IQueryable<User> query = UserRepository.Get();
|
||||||
|
|
||||||
|
query = orderBy switch
|
||||||
|
{
|
||||||
|
nameof(Database.Entities.User.Id) => orderByDir == "desc"
|
||||||
|
? query.OrderByDescending(x => x.Id)
|
||||||
|
: query.OrderBy(x => x.Id),
|
||||||
|
|
||||||
|
nameof(Database.Entities.User.Username) => orderByDir == "desc"
|
||||||
|
? query.OrderByDescending(x => x.Username)
|
||||||
|
: query.OrderBy(x => x.Username),
|
||||||
|
|
||||||
|
nameof(Database.Entities.User.Email) => orderByDir == "desc"
|
||||||
|
? query.OrderByDescending(x => x.Email)
|
||||||
|
: query.OrderBy(x => x.Email),
|
||||||
|
|
||||||
|
_ => query.OrderBy(x => x.Id)
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(filter))
|
||||||
|
{
|
||||||
|
query = query.Where(x =>
|
||||||
|
EF.Functions.ILike(x.Username, $"%{filter}%") ||
|
||||||
|
EF.Functions.ILike(x.Email, $"%{filter}%")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
var totalCount = await query.CountAsync();
|
||||||
|
|
||||||
|
var items = await query
|
||||||
|
.Skip(startIndex)
|
||||||
|
.Take(count)
|
||||||
|
.AsNoTracking()
|
||||||
|
.ProjectToResponse()
|
||||||
|
.ToArrayAsync();
|
||||||
|
|
||||||
|
return new CountedData<UserResponse>()
|
||||||
|
{
|
||||||
|
Items = items,
|
||||||
|
TotalCount = totalCount
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
[Authorize(Policy = "permissions:admin.users.get")]
|
||||||
|
public async Task<ActionResult<UserResponse>> GetSingleAsync(int id)
|
||||||
|
{
|
||||||
|
var user = await UserRepository
|
||||||
|
.Get()
|
||||||
|
.ProjectToResponse()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
return Problem("No user with that id found", statusCode: 404);
|
||||||
|
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[Authorize(Policy = "permissions:admin.users.create")]
|
||||||
|
public async Task<ActionResult<UserResponse>> CreateAsync([FromBody] CreateUserRequest request)
|
||||||
|
{
|
||||||
|
// Reformat values
|
||||||
|
request.Username = request.Username.ToLower().Trim();
|
||||||
|
request.Email = request.Email.ToLower().Trim();
|
||||||
|
|
||||||
|
// Check for users with the same values
|
||||||
|
if (UserRepository.Get().Any(x => x.Username == request.Username))
|
||||||
|
return Problem("A user with that username already exists", statusCode: 400);
|
||||||
|
|
||||||
|
if (UserRepository.Get().Any(x => x.Email == request.Email))
|
||||||
|
return Problem("A user with that email address already exists", statusCode: 400);
|
||||||
|
|
||||||
|
var hashedPassword = HashHelper.Hash(request.Password);
|
||||||
|
|
||||||
|
var user = new User()
|
||||||
|
{
|
||||||
|
Email = request.Email,
|
||||||
|
Username = request.Username,
|
||||||
|
Password = hashedPassword,
|
||||||
|
Permissions = request.Permissions
|
||||||
|
};
|
||||||
|
|
||||||
|
var finalUser = await UserRepository.AddAsync(user);
|
||||||
|
|
||||||
|
return UserMapper.ToResponse(finalUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPatch("{id}")]
|
||||||
|
[Authorize(Policy = "permissions:admin.users.update")]
|
||||||
|
public async Task<ActionResult<UserResponse>> UpdateAsync([FromRoute] int id, [FromBody] UpdateUserRequest request)
|
||||||
|
{
|
||||||
|
var user = await UserRepository
|
||||||
|
.Get()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
return Problem("No user with that id found", statusCode: 404);
|
||||||
|
|
||||||
|
// Reformat values
|
||||||
|
request.Username = request.Username.ToLower().Trim();
|
||||||
|
request.Email = request.Email.ToLower().Trim();
|
||||||
|
|
||||||
|
// Check for users with the same values
|
||||||
|
if (UserRepository.Get().Any(x => x.Username == request.Username && x.Id != user.Id))
|
||||||
|
return Problem("Another user with that username already exists", statusCode: 400);
|
||||||
|
|
||||||
|
if (UserRepository.Get().Any(x => x.Email == request.Email && x.Id != user.Id))
|
||||||
|
return Problem("Another user with that email address already exists", statusCode: 400);
|
||||||
|
|
||||||
|
// Perform hashing the password if required
|
||||||
|
if (!string.IsNullOrEmpty(request.Password))
|
||||||
|
{
|
||||||
|
user.Password = HashHelper.Hash(request.Password);
|
||||||
|
user.TokenValidTimestamp = DateTime.UtcNow; // Log out user after password change
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.Permissions.Any(x => !user.Permissions.Contains(x)))
|
||||||
|
{
|
||||||
|
user.Permissions = request.Permissions;
|
||||||
|
user.TokenValidTimestamp = DateTime.UtcNow; // Log out user after permission change
|
||||||
|
}
|
||||||
|
|
||||||
|
user.Email = request.Email;
|
||||||
|
user.Username = request.Username;
|
||||||
|
|
||||||
|
await UserRepository.UpdateAsync(user);
|
||||||
|
|
||||||
|
return UserMapper.ToResponse(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
[Authorize(Policy = "permissions:admin.users.delete")]
|
||||||
|
public async Task<ActionResult> DeleteAsync([FromRoute] int id, [FromQuery] bool force = false)
|
||||||
|
{
|
||||||
|
var user = await UserRepository
|
||||||
|
.Get()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
return Problem("No user with that id found", statusCode: 404);
|
||||||
|
|
||||||
|
var deletionService = HttpContext.RequestServices.GetRequiredService<UserDeletionService>();
|
||||||
|
|
||||||
|
if (!force)
|
||||||
|
{
|
||||||
|
var validationResult = await deletionService.ValidateAsync(user);
|
||||||
|
|
||||||
|
if (!validationResult.IsAllowed)
|
||||||
|
return Problem("Unable to delete user", statusCode: 400, title: validationResult.Reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
await deletionService.DeleteAsync(user, force);
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
128
Moonlight.ApiServer/Http/Controllers/Auth/AuthController.cs
Normal file
128
Moonlight.ApiServer/Http/Controllers/Auth/AuthController.cs
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Moonlight.ApiServer.Configuration;
|
||||||
|
using Moonlight.ApiServer.Interfaces;
|
||||||
|
using Moonlight.Shared.Http.Responses.Auth;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Http.Controllers.Auth;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/auth")]
|
||||||
|
public class AuthController : Controller
|
||||||
|
{
|
||||||
|
private readonly IAuthenticationSchemeProvider SchemeProvider;
|
||||||
|
private readonly IEnumerable<IAuthCheckExtension> Extensions;
|
||||||
|
private readonly AppConfiguration Configuration;
|
||||||
|
|
||||||
|
public AuthController(
|
||||||
|
IAuthenticationSchemeProvider schemeProvider,
|
||||||
|
IEnumerable<IAuthCheckExtension> extensions,
|
||||||
|
AppConfiguration configuration
|
||||||
|
)
|
||||||
|
{
|
||||||
|
SchemeProvider = schemeProvider;
|
||||||
|
Extensions = extensions;
|
||||||
|
Configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<AuthSchemeResponse[]> GetSchemesAsync()
|
||||||
|
{
|
||||||
|
var schemes = await SchemeProvider.GetAllSchemesAsync();
|
||||||
|
|
||||||
|
var allowedSchemes = Configuration.Authentication.EnabledSchemes;
|
||||||
|
|
||||||
|
return schemes
|
||||||
|
.Where(x => allowedSchemes.Contains(x.Name))
|
||||||
|
.Select(scheme => new AuthSchemeResponse()
|
||||||
|
{
|
||||||
|
DisplayName = scheme.DisplayName ?? scheme.Name,
|
||||||
|
Identifier = scheme.Name
|
||||||
|
})
|
||||||
|
.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{identifier:alpha}")]
|
||||||
|
public async Task StartSchemeAsync([FromRoute] string identifier)
|
||||||
|
{
|
||||||
|
// Validate identifier against our enable list
|
||||||
|
var allowedSchemes = Configuration.Authentication.EnabledSchemes;
|
||||||
|
|
||||||
|
if (!allowedSchemes.Contains(identifier))
|
||||||
|
{
|
||||||
|
await Results
|
||||||
|
.Problem(
|
||||||
|
"Invalid scheme identifier provided",
|
||||||
|
statusCode: 404
|
||||||
|
)
|
||||||
|
.ExecuteAsync(HttpContext);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now we can check if it even exists
|
||||||
|
var scheme = await SchemeProvider.GetSchemeAsync(identifier);
|
||||||
|
|
||||||
|
if (scheme == null)
|
||||||
|
{
|
||||||
|
await Results
|
||||||
|
.Problem(
|
||||||
|
"Invalid scheme identifier provided",
|
||||||
|
statusCode: 404
|
||||||
|
)
|
||||||
|
.ExecuteAsync(HttpContext);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Everything fine, challenge the frontend
|
||||||
|
await HttpContext.ChallengeAsync(
|
||||||
|
scheme.Name,
|
||||||
|
new AuthenticationProperties()
|
||||||
|
{
|
||||||
|
RedirectUri = "/"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[HttpGet("check")]
|
||||||
|
public async Task<AuthClaimResponse[]> CheckAsync()
|
||||||
|
{
|
||||||
|
var username = User.FindFirstValue(ClaimTypes.Name)!;
|
||||||
|
var id = User.FindFirstValue(ClaimTypes.NameIdentifier)!;
|
||||||
|
var email = User.FindFirstValue(ClaimTypes.Email)!;
|
||||||
|
var userId = User.FindFirstValue("UserId")!;
|
||||||
|
var permissions = User.FindFirstValue("Permissions")!;
|
||||||
|
|
||||||
|
// Create basic set of claims used by the frontend
|
||||||
|
var claims = new List<AuthClaimResponse>()
|
||||||
|
{
|
||||||
|
new(ClaimTypes.Name, username),
|
||||||
|
new(ClaimTypes.NameIdentifier, id),
|
||||||
|
new(ClaimTypes.Email, email),
|
||||||
|
new("UserId", userId),
|
||||||
|
new("Permissions", permissions)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Enrich the frontend claims by extensions (used by plugins)
|
||||||
|
foreach (var extension in Extensions)
|
||||||
|
{
|
||||||
|
claims.AddRange(
|
||||||
|
await extension.GetFrontendClaimsAsync(User)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return claims.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("logout")]
|
||||||
|
public async Task LogoutAsync()
|
||||||
|
{
|
||||||
|
await HttpContext.SignOutAsync();
|
||||||
|
await Results.Redirect("/").ExecuteAsync(HttpContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using System.Text;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Moonlight.ApiServer.Services;
|
||||||
|
using Moonlight.Shared.Misc;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Http.Controllers.Frontend;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("/")]
|
||||||
|
public class FrontendController : Controller
|
||||||
|
{
|
||||||
|
private readonly FrontendService FrontendService;
|
||||||
|
|
||||||
|
public FrontendController(FrontendService frontendService)
|
||||||
|
{
|
||||||
|
FrontendService = frontendService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("frontend.json")]
|
||||||
|
public async Task<FrontendConfiguration> GetConfigurationAsync()
|
||||||
|
=> await FrontendService.GetConfigurationAsync();
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IResult> IndexAsync()
|
||||||
|
{
|
||||||
|
var content = await FrontendService.GenerateIndexHtmlAsync();
|
||||||
|
|
||||||
|
return Results.Text(content, "text/html", Encoding.UTF8);
|
||||||
|
}
|
||||||
|
}
|
||||||
102
Moonlight.ApiServer/Http/Controllers/Frontend/FrontendPage.razor
Normal file
102
Moonlight.ApiServer/Http/Controllers/Frontend/FrontendPage.razor
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
@using Moonlight.ApiServer.Database.Entities
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en" class="bg-base-200 text-base-content font-inter">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<title>@Title</title>
|
||||||
|
<base href="/"/>
|
||||||
|
|
||||||
|
@foreach (var style in Styles)
|
||||||
|
{
|
||||||
|
<link rel="stylesheet" href="@style"/>
|
||||||
|
}
|
||||||
|
|
||||||
|
<link href="manifest.webmanifest" rel="manifest"/>
|
||||||
|
<link rel="apple-touch-icon" sizes="512x512" href="/_content/Moonlight.Client/img/icon-512.png"/>
|
||||||
|
<link rel="apple-touch-icon" sizes="192x192" href="/_content/Moonlight.Client/img/icon-192.png"/>
|
||||||
|
|
||||||
|
@if (Theme != null)
|
||||||
|
{
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--color-base-100: @(Theme.Content.ColorBase100);
|
||||||
|
--color-base-200: @(Theme.Content.ColorBase200);
|
||||||
|
--color-base-300: @(Theme.Content.ColorBase300);
|
||||||
|
--color-base-content: @(Theme.Content.ColorBaseContent);
|
||||||
|
|
||||||
|
--color-primary: @(Theme.Content.ColorPrimary);
|
||||||
|
--color-primary-content: @(Theme.Content.ColorPrimaryContent);
|
||||||
|
|
||||||
|
--color-secondary: @(Theme.Content.ColorSecondary);
|
||||||
|
--color-secondary-content: @(Theme.Content.ColorSecondaryContent);
|
||||||
|
|
||||||
|
--color-accent: @(Theme.Content.ColorAccent);
|
||||||
|
--color-accent-content: @(Theme.Content.ColorAccentContent);
|
||||||
|
|
||||||
|
--color-neutral: @(Theme.Content.ColorNeutral);
|
||||||
|
--color-neutral-content: @(Theme.Content.ColorNeutralContent);
|
||||||
|
|
||||||
|
--color-info: @(Theme.Content.ColorInfo);
|
||||||
|
--color-info-content: @(Theme.Content.ColorInfoContent);
|
||||||
|
|
||||||
|
--color-success: @(Theme.Content.ColorSuccess);
|
||||||
|
--color-success-content: @(Theme.Content.ColorSuccessContent);
|
||||||
|
|
||||||
|
--color-warning: @(Theme.Content.ColorWarning);
|
||||||
|
--color-warning-content: @(Theme.Content.ColorWarningContent);
|
||||||
|
|
||||||
|
--color-error: @(Theme.Content.ColorError);
|
||||||
|
--color-error-content: @(Theme.Content.ColorErrorContent);
|
||||||
|
|
||||||
|
--radius-selector: @(Theme.Content.RadiusSelector)rem;
|
||||||
|
--radius-field: @(Theme.Content.RadiusField)rem;
|
||||||
|
--radius-box: @(Theme.Content.RadiusBox)rem;
|
||||||
|
|
||||||
|
--size-selector: @(Theme.Content.SizeSelector)rem;
|
||||||
|
--size-field: @(Theme.Content.SizeField)rem;
|
||||||
|
|
||||||
|
--border: @(Theme.Content.Border)px;
|
||||||
|
--depth: @(Theme.Content.Depth);
|
||||||
|
--noise: @(Theme.Content.Noise);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
}
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="app">
|
||||||
|
|
||||||
|
<div class="flex h-screen justify-center items-center">
|
||||||
|
<div class="sm:max-w-lg">
|
||||||
|
<div id="blazor-loader-label" class="text-center mb-2 text-lg font-semibold"></div>
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<div class="progress h-3 min-w-sm md:min-w-md" role="progressbar" aria-valuemin="0" aria-valuemax="100">
|
||||||
|
<div id="blazor-loader-progress" class="progress-bar progress-primary"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@foreach (var script in Scripts)
|
||||||
|
{
|
||||||
|
<script src="@script"></script>
|
||||||
|
}
|
||||||
|
|
||||||
|
<script src="/_framework/blazor.webassembly.js"></script>
|
||||||
|
<script>navigator.serviceWorker.register('service-worker.js');</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
[Parameter] public string Title { get; set; }
|
||||||
|
[Parameter] public string[] Scripts { get; set; }
|
||||||
|
[Parameter] public string[] Styles { get; set; }
|
||||||
|
[Parameter] public Theme? Theme { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,202 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using MoonCore.Extended.Abstractions;
|
||||||
|
using MoonCore.Extended.Helpers;
|
||||||
|
using MoonCore.Helpers;
|
||||||
|
using Moonlight.ApiServer.Configuration;
|
||||||
|
using Moonlight.ApiServer.Database.Entities;
|
||||||
|
using Moonlight.ApiServer.Implementations.LocalAuth;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Http.Controllers.LocalAuth;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/localAuth")]
|
||||||
|
public class LocalAuthController : Controller
|
||||||
|
{
|
||||||
|
private readonly DatabaseRepository<User> UserRepository;
|
||||||
|
private readonly IServiceProvider ServiceProvider;
|
||||||
|
private readonly IAuthenticationService AuthenticationService;
|
||||||
|
private readonly IOptionsMonitor<LocalAuthOptions> Options;
|
||||||
|
private readonly ILogger<LocalAuthController> Logger;
|
||||||
|
private readonly AppConfiguration Configuration;
|
||||||
|
|
||||||
|
public LocalAuthController(
|
||||||
|
DatabaseRepository<User> userRepository,
|
||||||
|
IServiceProvider serviceProvider,
|
||||||
|
IAuthenticationService authenticationService,
|
||||||
|
IOptionsMonitor<LocalAuthOptions> options,
|
||||||
|
ILogger<LocalAuthController> logger,
|
||||||
|
AppConfiguration configuration
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UserRepository = userRepository;
|
||||||
|
ServiceProvider = serviceProvider;
|
||||||
|
AuthenticationService = authenticationService;
|
||||||
|
Options = options;
|
||||||
|
Logger = logger;
|
||||||
|
Configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[HttpGet("login")]
|
||||||
|
public async Task<ActionResult> LoginAsync()
|
||||||
|
{
|
||||||
|
var html = await ComponentHelper.RenderToHtmlAsync<Login>(ServiceProvider);
|
||||||
|
|
||||||
|
return Content(html, "text/html");
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("register")]
|
||||||
|
public async Task<ActionResult> RegisterAsync()
|
||||||
|
{
|
||||||
|
var html = await ComponentHelper.RenderToHtmlAsync<Register>(ServiceProvider);
|
||||||
|
|
||||||
|
return Content(html, "text/html");
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[HttpPost("login")]
|
||||||
|
public async Task<ActionResult> LoginAsync([FromForm] string email, [FromForm] string password)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Perform login
|
||||||
|
var user = await InternalLoginAsync(email, password);
|
||||||
|
|
||||||
|
// Login user
|
||||||
|
var options = Options.Get(LocalAuthConstants.AuthenticationScheme);
|
||||||
|
|
||||||
|
await AuthenticationService.SignInAsync(HttpContext, options.SignInScheme, new ClaimsPrincipal(
|
||||||
|
new ClaimsIdentity(
|
||||||
|
[
|
||||||
|
new Claim(ClaimTypes.Email, user.Email),
|
||||||
|
new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
|
||||||
|
new Claim(ClaimTypes.Name, user.Username)
|
||||||
|
],
|
||||||
|
LocalAuthConstants.AuthenticationScheme
|
||||||
|
)
|
||||||
|
), new AuthenticationProperties());
|
||||||
|
|
||||||
|
// Redirect back to wasm app
|
||||||
|
return Redirect("/");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
string errorMessage;
|
||||||
|
|
||||||
|
if (e is AggregateException aggregateException)
|
||||||
|
errorMessage = aggregateException.Message;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errorMessage = "An internal error occured";
|
||||||
|
Logger.LogError(e, "An unhandled error occured while logging in user");
|
||||||
|
}
|
||||||
|
|
||||||
|
var html = await ComponentHelper.RenderToHtmlAsync<Login>(ServiceProvider,
|
||||||
|
parameters => { parameters["ErrorMessage"] = errorMessage; });
|
||||||
|
|
||||||
|
return Content(html, "text/html");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("register")]
|
||||||
|
public async Task<ActionResult> RegisterAsync([FromForm] string email, [FromForm] string password, [FromForm] string username)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Perform register
|
||||||
|
var user = await InternalRegisterAsync(username, email, password);
|
||||||
|
|
||||||
|
// Login user
|
||||||
|
var options = Options.Get(LocalAuthConstants.AuthenticationScheme);
|
||||||
|
|
||||||
|
await AuthenticationService.SignInAsync(HttpContext, options.SignInScheme, new ClaimsPrincipal(
|
||||||
|
new ClaimsIdentity(
|
||||||
|
[
|
||||||
|
new Claim(ClaimTypes.Email, user.Email),
|
||||||
|
new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
|
||||||
|
new Claim(ClaimTypes.Name, user.Username)
|
||||||
|
],
|
||||||
|
LocalAuthConstants.AuthenticationScheme
|
||||||
|
)
|
||||||
|
), new AuthenticationProperties());
|
||||||
|
|
||||||
|
// Redirect back to wasm app
|
||||||
|
return Redirect("/");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
string errorMessage;
|
||||||
|
|
||||||
|
if (e is AggregateException aggregateException)
|
||||||
|
errorMessage = aggregateException.Message;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errorMessage = "An internal error occured";
|
||||||
|
Logger.LogError(e, "An unhandled error occured while logging in user");
|
||||||
|
}
|
||||||
|
|
||||||
|
var html = await ComponentHelper.RenderToHtmlAsync<Register>(ServiceProvider,
|
||||||
|
parameters => { parameters["ErrorMessage"] = errorMessage; });
|
||||||
|
|
||||||
|
return Content(html, "text/html");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<User> InternalRegisterAsync(string username, string email, string password)
|
||||||
|
{
|
||||||
|
email = email.ToLower();
|
||||||
|
username = username.ToLower();
|
||||||
|
|
||||||
|
if (await UserRepository.Get().AnyAsync(x => x.Username == username))
|
||||||
|
throw new AggregateException("A account with that username already exists");
|
||||||
|
|
||||||
|
if (await UserRepository.Get().AnyAsync(x => x.Email == email))
|
||||||
|
throw new AggregateException("A account with that email already exists");
|
||||||
|
|
||||||
|
string[] permissions = [];
|
||||||
|
|
||||||
|
if (Configuration.Authentication.FirstUserAdmin)
|
||||||
|
{
|
||||||
|
var count = await UserRepository
|
||||||
|
.Get()
|
||||||
|
.CountAsync();
|
||||||
|
|
||||||
|
if (count == 0)
|
||||||
|
permissions = ["*"];
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = new User()
|
||||||
|
{
|
||||||
|
Username = username,
|
||||||
|
Email = email,
|
||||||
|
Password = HashHelper.Hash(password),
|
||||||
|
Permissions = permissions
|
||||||
|
};
|
||||||
|
|
||||||
|
var finalUser = await UserRepository.AddAsync(user);
|
||||||
|
|
||||||
|
return finalUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<User> InternalLoginAsync(string email, string password)
|
||||||
|
{
|
||||||
|
email = email.ToLower();
|
||||||
|
|
||||||
|
var user = await UserRepository
|
||||||
|
.Get()
|
||||||
|
.FirstOrDefaultAsync(x => x.Email == email);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
throw new AggregateException("Invalid combination of email and password");
|
||||||
|
|
||||||
|
if (!HashHelper.Verify(password, user.Password))
|
||||||
|
throw new AggregateException("Invalid combination of email and password");
|
||||||
|
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
}
|
||||||
57
Moonlight.ApiServer/Http/Controllers/LocalAuth/Login.razor
Normal file
57
Moonlight.ApiServer/Http/Controllers/LocalAuth/Login.razor
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<html lang="en" class="h-full bg-base-200">
|
||||||
|
<head>
|
||||||
|
<title>Login into your account</title>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/css/style.min.css"/>
|
||||||
|
</head>
|
||||||
|
<body class="h-full">
|
||||||
|
|
||||||
|
<div class="flex h-auto min-h-screen items-center justify-center overflow-x-hidden py-10">
|
||||||
|
<div class="relative flex items-center justify-center px-4 sm:px-6 lg:px-8">
|
||||||
|
<div class="bg-base-100 shadow-base-300/20 z-1 w-full space-y-6 rounded-xl p-6 shadow-md sm:min-w-md lg:p-8">
|
||||||
|
<div class="flex justify-center items-center gap-3">
|
||||||
|
<img src="/_content/Moonlight.Client/svg/logo.svg" class="size-12" alt="brand-logo"/>
|
||||||
|
</div>
|
||||||
|
<div class="text-center">
|
||||||
|
<h3 class="text-base-content mb-1.5 text-2xl font-semibold">Login into your account</h3>
|
||||||
|
<p class="text-base-content/80">After logging in you will be able to manage your services</p>
|
||||||
|
</div>
|
||||||
|
<div class="space-y-4">
|
||||||
|
|
||||||
|
@if (!string.IsNullOrEmpty(ErrorMessage))
|
||||||
|
{
|
||||||
|
<div class="alert alert-error text-center">
|
||||||
|
@ErrorMessage
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
<form class="mb-4 space-y-4" method="post">
|
||||||
|
<div>
|
||||||
|
<label class="label-text" for="email">Email address</label>
|
||||||
|
<input type="email" name="email" placeholder="Enter your email address" class="input" id="email"
|
||||||
|
required/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="label-text" for="password">Password</label>
|
||||||
|
<input class="input" name="password" id="password" type="password" placeholder="············"
|
||||||
|
required/>
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-lg btn-primary btn-gradient btn-block">Login</button>
|
||||||
|
</form>
|
||||||
|
<p class="text-base-content/80 mb-4 text-center">
|
||||||
|
No account?
|
||||||
|
<a href="/api/localAuth/register" class="link link-animated link-primary font-normal">Create an account</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
[Parameter] public string? ErrorMessage { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
<html lang="en" class="h-full bg-base-200">
|
||||||
|
<head>
|
||||||
|
<title>Register a new account</title>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/css/style.min.css"/>
|
||||||
|
</head>
|
||||||
|
<body class="h-full">
|
||||||
|
|
||||||
|
<div class="flex h-auto min-h-screen items-center justify-center overflow-x-hidden py-10">
|
||||||
|
<div class="relative flex items-center justify-center px-4 sm:px-6 lg:px-8">
|
||||||
|
<div class="bg-base-100 shadow-base-300/20 z-1 w-full space-y-6 rounded-xl p-6 shadow-md sm:min-w-md lg:p-8">
|
||||||
|
<div class="flex justify-center items-center gap-3">
|
||||||
|
<img src="/_content/Moonlight.Client/svg/logo.svg" class="size-12" alt="brand-logo"/>
|
||||||
|
</div>
|
||||||
|
<div class="text-center">
|
||||||
|
<h3 class="text-base-content mb-1.5 text-2xl font-semibold">Register a new account</h3>
|
||||||
|
<p class="text-base-content/80">After signing up you will be able to manage your services</p>
|
||||||
|
</div>
|
||||||
|
<div class="space-y-4">
|
||||||
|
|
||||||
|
@if (!string.IsNullOrEmpty(ErrorMessage))
|
||||||
|
{
|
||||||
|
<div class="alert alert-error text-center">
|
||||||
|
@ErrorMessage
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
<form class="mb-4 space-y-4" method="post">
|
||||||
|
<div>
|
||||||
|
<label class="label-text" for="username">Username</label>
|
||||||
|
<input type="text" name="username" placeholder="Enter your username" class="input" id="username"
|
||||||
|
required/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="label-text" for="email">Email address</label>
|
||||||
|
<input type="email" name="email" placeholder="Enter your email address" class="input" id="email"
|
||||||
|
required/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="label-text" for="password">Password</label>
|
||||||
|
<input class="input" name="password" id="password" type="password" placeholder="············"
|
||||||
|
required/>
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-lg btn-primary btn-gradient btn-block">Register</button>
|
||||||
|
</form>
|
||||||
|
<p class="text-base-content/80 mb-4 text-center">
|
||||||
|
Already registered?
|
||||||
|
<a href="/api/localAuth/login" class="link link-animated link-primary font-normal">Login into your account</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
[Parameter] public string? ErrorMessage { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using MoonCore.Helpers;
|
||||||
|
using Moonlight.ApiServer.Configuration;
|
||||||
|
using Moonlight.ApiServer.Models;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Http.Controllers.Swagger;
|
||||||
|
|
||||||
|
[Route("api/swagger")]
|
||||||
|
public class SwaggerController : Controller
|
||||||
|
{
|
||||||
|
private readonly AppConfiguration Configuration;
|
||||||
|
private readonly IServiceProvider ServiceProvider;
|
||||||
|
|
||||||
|
public SwaggerController(
|
||||||
|
AppConfiguration configuration,
|
||||||
|
IServiceProvider serviceProvider
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Configuration = configuration;
|
||||||
|
ServiceProvider = serviceProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<ActionResult> GetAsync()
|
||||||
|
{
|
||||||
|
if (!Configuration.Development.EnableApiDocs)
|
||||||
|
return BadRequest("Api docs are disabled");
|
||||||
|
|
||||||
|
var options = new ApiDocsOptions();
|
||||||
|
var optionsJson = JsonSerializer.Serialize(options);
|
||||||
|
|
||||||
|
var html = await ComponentHelper.RenderToHtmlAsync<SwaggerPage>(
|
||||||
|
ServiceProvider,
|
||||||
|
parameters =>
|
||||||
|
{
|
||||||
|
parameters.Add("Options", optionsJson);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return Content(html, "text/html");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>Moonlight Api Reference</title>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script id="api-reference" data-url="/api/swagger/main"></script>
|
||||||
|
<script>
|
||||||
|
const configuration = @(Options)
|
||||||
|
|
||||||
|
document.getElementById('api-reference').dataset.configuration = JSON.stringify(configuration)
|
||||||
|
</script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/@@scalar/api-reference"></script>
|
||||||
|
<style>.light-mode {
|
||||||
|
--scalar-background-1: #fff;
|
||||||
|
--scalar-background-2: #f8fafc;
|
||||||
|
--scalar-background-3: #e7e7e7;
|
||||||
|
--scalar-background-accent: #8ab4f81f;
|
||||||
|
--scalar-color-1: #000;
|
||||||
|
--scalar-color-2: #6b7280;
|
||||||
|
--scalar-color-3: #9ca3af;
|
||||||
|
--scalar-color-accent: #00c16a;
|
||||||
|
--scalar-border-color: #e5e7eb;
|
||||||
|
--scalar-color-green: #069061;
|
||||||
|
--scalar-color-red: #ef4444;
|
||||||
|
--scalar-color-yellow: #f59e0b;
|
||||||
|
--scalar-color-blue: #1d4ed8;
|
||||||
|
--scalar-color-orange: #fb892c;
|
||||||
|
--scalar-color-purple: #6d28d9;
|
||||||
|
--scalar-button-1: #000;
|
||||||
|
--scalar-button-1-hover: rgba(0, 0, 0, 0.9);
|
||||||
|
--scalar-button-1-color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark-mode {
|
||||||
|
--scalar-background-1: #020420;
|
||||||
|
--scalar-background-2: #121a31;
|
||||||
|
--scalar-background-3: #1e293b;
|
||||||
|
--scalar-background-accent: #8ab4f81f;
|
||||||
|
--scalar-color-1: #fff;
|
||||||
|
--scalar-color-2: #cbd5e1;
|
||||||
|
--scalar-color-3: #94a3b8;
|
||||||
|
--scalar-color-accent: #00dc82;
|
||||||
|
--scalar-border-color: #1e293b;
|
||||||
|
--scalar-color-green: #069061;
|
||||||
|
--scalar-color-red: #f87171;
|
||||||
|
--scalar-color-yellow: #fde68a;
|
||||||
|
--scalar-color-blue: #60a5fa;
|
||||||
|
--scalar-color-orange: #fb892c;
|
||||||
|
--scalar-color-purple: #ddd6fe;
|
||||||
|
--scalar-button-1: hsla(0, 0%, 100%, 0.9);
|
||||||
|
--scalar-button-1-hover: hsla(0, 0%, 100%, 0.8);
|
||||||
|
--scalar-button-1-color: #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark-mode .t-doc__sidebar,
|
||||||
|
.light-mode .t-doc__sidebar {
|
||||||
|
--scalar-sidebar-background-1: var(--scalar-background-1);
|
||||||
|
--scalar-sidebar-color-1: var(--scalar-color-1);
|
||||||
|
--scalar-sidebar-color-2: var(--scalar-color-3);
|
||||||
|
--scalar-sidebar-border-color: var(--scalar-border-color);
|
||||||
|
--scalar-sidebar-item-hover-background: transparent;
|
||||||
|
--scalar-sidebar-item-hover-color: var(--scalar-color-1);
|
||||||
|
--scalar-sidebar-item-active-background: transparent;
|
||||||
|
--scalar-sidebar-color-active: var(--scalar-color-accent);
|
||||||
|
--scalar-sidebar-search-background: transparent;
|
||||||
|
--scalar-sidebar-search-color: var(--scalar-color-3);
|
||||||
|
--scalar-sidebar-search-border-color: var(--scalar-border-color);
|
||||||
|
--scalar-sidebar-indent-border: var(--scalar-border-color);
|
||||||
|
--scalar-sidebar-indent-border-hover: var(--scalar-color-1);
|
||||||
|
--scalar-sidebar-indent-border-active: var(--scalar-color-accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.scalar-card .request-card-footer {
|
||||||
|
--scalar-background-3: var(--scalar-background-2);
|
||||||
|
--scalar-button-1: #0f172a;
|
||||||
|
--scalar-button-1-hover: rgba(30, 41, 59, 0.5);
|
||||||
|
--scalar-button-1-color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.scalar-card .show-api-client-button {
|
||||||
|
border: 1px solid #334155 !important;
|
||||||
|
}</style>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
[Parameter] public string Options { get; set; }
|
||||||
|
}
|
||||||
14
Moonlight.ApiServer/Http/Hubs/DiagnoseHub.cs
Normal file
14
Moonlight.ApiServer/Http/Hubs/DiagnoseHub.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Http.Hubs;
|
||||||
|
|
||||||
|
[Authorize(Policy = "permissions:admin.system.diagnose")]
|
||||||
|
public class DiagnoseHub : Hub
|
||||||
|
{
|
||||||
|
[HubMethodName("Ping")]
|
||||||
|
public async Task PingAsync()
|
||||||
|
{
|
||||||
|
await Clients.All.SendAsync("Pong");
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Moonlight.ApiServer/IAssemblyMarker.cs
Normal file
3
Moonlight.ApiServer/IAssemblyMarker.cs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Moonlight.ApiServer;
|
||||||
|
|
||||||
|
public interface IAssemblyMarker;
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO.Compression;
|
||||||
|
using MoonCore.Yaml;
|
||||||
|
using Moonlight.ApiServer.Configuration;
|
||||||
|
using Moonlight.ApiServer.Extensions;
|
||||||
|
using Moonlight.ApiServer.Interfaces;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Implementations.Diagnose;
|
||||||
|
|
||||||
|
public class CoreConfigDiagnoseProvider : IDiagnoseProvider
|
||||||
|
{
|
||||||
|
private readonly AppConfiguration Configuration;
|
||||||
|
|
||||||
|
public CoreConfigDiagnoseProvider(AppConfiguration configuration)
|
||||||
|
{
|
||||||
|
Configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string CheckForNullOrEmpty(string? content)
|
||||||
|
{
|
||||||
|
return string.IsNullOrEmpty(content)
|
||||||
|
? "ISEMPTY"
|
||||||
|
: "ISNOTEMPTY";
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task ModifyZipArchiveAsync(ZipArchive archive)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var configString = YamlSerializer.Serialize(Configuration);
|
||||||
|
var configuration = YamlSerializer.Deserialize<AppConfiguration>(configString);
|
||||||
|
|
||||||
|
configuration.Database.Password = CheckForNullOrEmpty(configuration.Database.Password);
|
||||||
|
configuration.Authentication.Secret = CheckForNullOrEmpty(configuration.Authentication.Secret);
|
||||||
|
configuration.SignalR.RedisConnectionString = CheckForNullOrEmpty(configuration.SignalR.RedisConnectionString);
|
||||||
|
|
||||||
|
await archive.AddTextAsync(
|
||||||
|
"core/config.txt",
|
||||||
|
YamlSerializer.Serialize(configuration)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
await archive.AddTextAsync("core/config.txt", $"Unable to load config: {e.ToStringDemystified()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using System.IO.Compression;
|
||||||
|
using Moonlight.ApiServer.Extensions;
|
||||||
|
using Moonlight.ApiServer.Interfaces;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Implementations.Diagnose;
|
||||||
|
|
||||||
|
public class LogsDiagnoseProvider : IDiagnoseProvider
|
||||||
|
{
|
||||||
|
public async Task ModifyZipArchiveAsync(ZipArchive archive)
|
||||||
|
{
|
||||||
|
var path = Path.Combine("storage", "logs", "moonlight.log");
|
||||||
|
|
||||||
|
if (File.Exists(path))
|
||||||
|
{
|
||||||
|
var logsContent = await File.ReadAllTextAsync(path);
|
||||||
|
await archive.AddTextAsync("logs.txt", logsContent);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
await archive.AddTextAsync("logs.txt", "Logs file moonlight.log has not been found");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Moonlight.ApiServer.Implementations.LocalAuth;
|
||||||
|
|
||||||
|
public static class LocalAuthConstants
|
||||||
|
{
|
||||||
|
public const string AuthenticationScheme = "LocalAuth";
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using System.Text.Encodings.Web;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Implementations.LocalAuth;
|
||||||
|
|
||||||
|
public class LocalAuthHandler : AuthenticationHandler<LocalAuthOptions>
|
||||||
|
{
|
||||||
|
public LocalAuthHandler(
|
||||||
|
IOptionsMonitor<LocalAuthOptions> options,
|
||||||
|
ILoggerFactory logger,
|
||||||
|
UrlEncoder encoder
|
||||||
|
) : base(options, logger, encoder)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
|
||||||
|
{
|
||||||
|
return Task.FromResult(
|
||||||
|
AuthenticateResult.Fail("Local authentication does not directly support AuthenticateAsync")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task HandleChallengeAsync(AuthenticationProperties properties)
|
||||||
|
{
|
||||||
|
await Results
|
||||||
|
.Redirect("/api/localAuth")
|
||||||
|
.ExecuteAsync(Context);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Implementations.LocalAuth;
|
||||||
|
|
||||||
|
public class LocalAuthOptions : AuthenticationSchemeOptions
|
||||||
|
{
|
||||||
|
public string? SignInScheme { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using System.Diagnostics.Metrics;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Moonlight.ApiServer.Interfaces;
|
||||||
|
using Moonlight.ApiServer.Services;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Implementations.Metrics;
|
||||||
|
|
||||||
|
public class ApplicationMetric : IMetric
|
||||||
|
{
|
||||||
|
private Gauge<long> MemoryUsage;
|
||||||
|
private Gauge<int> CpuUsage;
|
||||||
|
private Gauge<double> Uptime;
|
||||||
|
|
||||||
|
public Task InitializeAsync(Meter meter)
|
||||||
|
{
|
||||||
|
MemoryUsage = meter.CreateGauge<long>("moonlight_memory_usage");
|
||||||
|
CpuUsage = meter.CreateGauge<int>("moonlight_cpu_usage");
|
||||||
|
Uptime = meter.CreateGauge<double>("moonlight_uptime");
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task RunAsync(IServiceProvider provider, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var applicationService = provider.GetRequiredService<ApplicationService>();
|
||||||
|
|
||||||
|
var memory = await applicationService.GetMemoryUsageAsync();
|
||||||
|
MemoryUsage.Record(memory);
|
||||||
|
|
||||||
|
var uptime = await applicationService.GetUptimeAsync();
|
||||||
|
Uptime.Record(uptime.TotalSeconds);
|
||||||
|
|
||||||
|
var cpu = await applicationService.GetCpuUsageAsync();
|
||||||
|
CpuUsage.Record(cpu);
|
||||||
|
}
|
||||||
|
}
|
||||||
28
Moonlight.ApiServer/Implementations/Metrics/UsersMetric.cs
Normal file
28
Moonlight.ApiServer/Implementations/Metrics/UsersMetric.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
using System.Diagnostics.Metrics;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using MoonCore.Extended.Abstractions;
|
||||||
|
using Moonlight.ApiServer.Database.Entities;
|
||||||
|
using Moonlight.ApiServer.Interfaces;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Implementations.Metrics;
|
||||||
|
|
||||||
|
public class UsersMetric : IMetric
|
||||||
|
{
|
||||||
|
private Gauge<int> Users;
|
||||||
|
|
||||||
|
public Task InitializeAsync(Meter meter)
|
||||||
|
{
|
||||||
|
Users = meter.CreateGauge<int>("moonlight_users");
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task RunAsync(IServiceProvider provider, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var usersRepo = provider.GetRequiredService<DatabaseRepository<User>>();
|
||||||
|
var count = await usersRepo.Get().CountAsync(cancellationToken: cancellationToken);
|
||||||
|
|
||||||
|
Users.Record(count);
|
||||||
|
}
|
||||||
|
}
|
||||||
164
Moonlight.ApiServer/Implementations/Startup/CoreStartup.cs
Normal file
164
Moonlight.ApiServer/Implementations/Startup/CoreStartup.cs
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
|
using Moonlight.ApiServer.Configuration;
|
||||||
|
using Moonlight.ApiServer.Database;
|
||||||
|
using Moonlight.ApiServer.Implementations.Diagnose;
|
||||||
|
using Moonlight.ApiServer.Implementations.Metrics;
|
||||||
|
using Moonlight.ApiServer.Interfaces;
|
||||||
|
using Moonlight.ApiServer.Models;
|
||||||
|
using Moonlight.ApiServer.Plugins;
|
||||||
|
using Moonlight.ApiServer.Services;
|
||||||
|
using OpenTelemetry.Logs;
|
||||||
|
using OpenTelemetry.Metrics;
|
||||||
|
using OpenTelemetry.Resources;
|
||||||
|
using OpenTelemetry.Trace;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Implementations.Startup;
|
||||||
|
|
||||||
|
public class CoreStartup : IPluginStartup
|
||||||
|
{
|
||||||
|
public void AddPlugin(WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
var configuration = AppConfiguration.CreateEmpty();
|
||||||
|
builder.Configuration.Bind(configuration);
|
||||||
|
|
||||||
|
#region Api Docs
|
||||||
|
|
||||||
|
if (configuration.Development.EnableApiDocs)
|
||||||
|
{
|
||||||
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
|
|
||||||
|
// Configure swagger api specification generator and set the document title for the api docs to use
|
||||||
|
builder.Services.AddSwaggerGen(options =>
|
||||||
|
{
|
||||||
|
options.SwaggerDoc("main", new OpenApiInfo()
|
||||||
|
{
|
||||||
|
Title = "Moonlight API"
|
||||||
|
});
|
||||||
|
|
||||||
|
options.CustomSchemaIds(x => x.FullName);
|
||||||
|
|
||||||
|
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
|
||||||
|
{
|
||||||
|
Name = "Authorization",
|
||||||
|
In = ParameterLocation.Header,
|
||||||
|
Type = SecuritySchemeType.ApiKey,
|
||||||
|
Scheme = "Bearer"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Database
|
||||||
|
|
||||||
|
builder.Services.AddDbContext<CoreDataContext>();
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Diagnose
|
||||||
|
|
||||||
|
builder.Services.AddSingleton<IDiagnoseProvider, CoreConfigDiagnoseProvider>();
|
||||||
|
builder.Services.AddSingleton<IDiagnoseProvider, LogsDiagnoseProvider>();
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Prometheus
|
||||||
|
|
||||||
|
if (configuration.OpenTelemetry.Enable)
|
||||||
|
{
|
||||||
|
var openTel = builder.Services.AddOpenTelemetry();
|
||||||
|
var openTelConfig = configuration.OpenTelemetry;
|
||||||
|
|
||||||
|
var resourceBuilder = ResourceBuilder.CreateDefault();
|
||||||
|
resourceBuilder.AddService(serviceName: "moonlight");
|
||||||
|
|
||||||
|
openTel.ConfigureResource(x => x.AddService(serviceName: "moonlight"));
|
||||||
|
|
||||||
|
if (openTelConfig.Metrics.Enable)
|
||||||
|
{
|
||||||
|
builder.Services.AddSingleton<MetricsBackgroundService>();
|
||||||
|
builder.Services.AddHostedService(sp => sp.GetRequiredService<MetricsBackgroundService>());
|
||||||
|
|
||||||
|
builder.Services.AddSingleton<IMetric, ApplicationMetric>();
|
||||||
|
builder.Services.AddSingleton<IMetric, UsersMetric>();
|
||||||
|
|
||||||
|
openTel.WithMetrics(providerBuilder =>
|
||||||
|
{
|
||||||
|
providerBuilder.AddAspNetCoreInstrumentation();
|
||||||
|
providerBuilder.AddOtlpExporter();
|
||||||
|
|
||||||
|
if (openTelConfig.Metrics.EnablePrometheus)
|
||||||
|
providerBuilder.AddPrometheusExporter();
|
||||||
|
|
||||||
|
providerBuilder.AddMeter("moonlight");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (openTelConfig.Logs.Enable)
|
||||||
|
{
|
||||||
|
openTel.WithLogging();
|
||||||
|
|
||||||
|
builder.Logging.AddOpenTelemetry(options =>
|
||||||
|
{
|
||||||
|
options.SetResourceBuilder(resourceBuilder);
|
||||||
|
options.AddOtlpExporter();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (openTelConfig.Traces.Enable)
|
||||||
|
{
|
||||||
|
openTel.WithTracing(providerBuilder =>
|
||||||
|
{
|
||||||
|
providerBuilder.AddAspNetCoreInstrumentation();
|
||||||
|
|
||||||
|
providerBuilder.AddOtlpExporter();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Client / Frontend
|
||||||
|
|
||||||
|
if (configuration.Frontend.EnableHosting)
|
||||||
|
{
|
||||||
|
builder.Services.AddSingleton(new FrontendConfigurationOption()
|
||||||
|
{
|
||||||
|
Scripts =
|
||||||
|
[
|
||||||
|
"/_content/Moonlight.Client/js/moonlight.js", "/_content/MoonCore.Blazor.FlyonUi/moonCore.js",
|
||||||
|
"/_content/MoonCore.Blazor.FlyonUi/ace/ace.js"
|
||||||
|
],
|
||||||
|
Styles = ["/css/style.min.css"]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UsePlugin(WebApplication app)
|
||||||
|
{
|
||||||
|
var configuration = AppConfiguration.CreateEmpty();
|
||||||
|
app.Configuration.Bind(configuration);
|
||||||
|
|
||||||
|
#region Prometheus
|
||||||
|
|
||||||
|
if (configuration.OpenTelemetry is { Enable: true, Metrics.EnablePrometheus: true })
|
||||||
|
app.UseOpenTelemetryPrometheusScrapingEndpoint();
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MapPlugin(WebApplication app)
|
||||||
|
{
|
||||||
|
var configuration = AppConfiguration.CreateEmpty();
|
||||||
|
app.Configuration.Bind(configuration);
|
||||||
|
|
||||||
|
if (configuration.Development.EnableApiDocs)
|
||||||
|
app.MapSwagger("/api/swagger/{documentName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
16
Moonlight.ApiServer/Interfaces/IAuthCheckExtension.cs
Normal file
16
Moonlight.ApiServer/Interfaces/IAuthCheckExtension.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using Moonlight.Shared.Http.Responses.Auth;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Interfaces;
|
||||||
|
|
||||||
|
public interface IAuthCheckExtension
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This function will be called by the frontend reaching out to the api server for claim information.
|
||||||
|
/// You can use this function to give your frontend plugins access to user specific data which is
|
||||||
|
/// static for the session. E.g. the avatar url of a user
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="principal">The principal of the current signed-in user</param>
|
||||||
|
/// <returns>An array of claim responses which gets added to the list of claims to send to the frontend</returns>
|
||||||
|
public Task<AuthClaimResponse[]> GetFrontendClaimsAsync(ClaimsPrincipal principal);
|
||||||
|
}
|
||||||
8
Moonlight.ApiServer/Interfaces/IDiagnoseProvider.cs
Normal file
8
Moonlight.ApiServer/Interfaces/IDiagnoseProvider.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using System.IO.Compression;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Interfaces;
|
||||||
|
|
||||||
|
public interface IDiagnoseProvider
|
||||||
|
{
|
||||||
|
public Task ModifyZipArchiveAsync(ZipArchive archive);
|
||||||
|
}
|
||||||
9
Moonlight.ApiServer/Interfaces/IMetric.cs
Normal file
9
Moonlight.ApiServer/Interfaces/IMetric.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using System.Diagnostics.Metrics;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Interfaces;
|
||||||
|
|
||||||
|
public interface IMetric
|
||||||
|
{
|
||||||
|
public Task InitializeAsync(Meter meter);
|
||||||
|
public Task RunAsync(IServiceProvider provider, CancellationToken cancellationToken);
|
||||||
|
}
|
||||||
25
Moonlight.ApiServer/Interfaces/IUserAuthExtension.cs
Normal file
25
Moonlight.ApiServer/Interfaces/IUserAuthExtension.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using Moonlight.ApiServer.Database.Entities;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Interfaces;
|
||||||
|
|
||||||
|
public interface IUserAuthExtension
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This function is called on every sign-in. It should be used to synchronize additional user data from the principal
|
||||||
|
/// or extend the claims saved in the user session
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user">The current user this method is called for</param>
|
||||||
|
/// <param name="principal">The principal after being processed by moonlight itself</param>
|
||||||
|
/// <returns>The result of the synchronisation. Returning false will immediately invalidate the sign-in and no other extensions will be called</returns>
|
||||||
|
public Task<bool> SyncAsync(User user, ClaimsPrincipal principal);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// IMPORTANT: Please note that heavy operations should not occur in this method as it will be called for every request
|
||||||
|
/// of every user
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user">The current user this method is called for</param>
|
||||||
|
/// <param name="principal">The principal after being processed by moonlight itself</param>
|
||||||
|
/// <returns>The result of the validation. Returning false will immediately invalidate the users session and no other extensions will be called</returns>
|
||||||
|
public Task<bool> ValidateAsync(User user, ClaimsPrincipal principal);
|
||||||
|
}
|
||||||
10
Moonlight.ApiServer/Interfaces/IUserDeleteHandler.cs
Normal file
10
Moonlight.ApiServer/Interfaces/IUserDeleteHandler.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using Moonlight.ApiServer.Database.Entities;
|
||||||
|
using Moonlight.ApiServer.Models;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Interfaces;
|
||||||
|
|
||||||
|
public interface IUserDeleteHandler
|
||||||
|
{
|
||||||
|
public Task<UserDeleteValidationResult> ValidateAsync(User user);
|
||||||
|
public Task DeleteAsync(User user, bool force);
|
||||||
|
}
|
||||||
19
Moonlight.ApiServer/Mappers/ApiKeyMapper.cs
Normal file
19
Moonlight.ApiServer/Mappers/ApiKeyMapper.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using Moonlight.ApiServer.Database.Entities;
|
||||||
|
using Moonlight.Shared.Http.Requests.Admin.ApiKeys;
|
||||||
|
using Moonlight.Shared.Http.Responses.Admin.ApiKeys;
|
||||||
|
using Riok.Mapperly.Abstractions;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Mappers;
|
||||||
|
|
||||||
|
[Mapper]
|
||||||
|
public static partial class ApiKeyMapper
|
||||||
|
{
|
||||||
|
// Mappers
|
||||||
|
public static partial ApiKeyResponse ToResponse(ApiKey apiKey);
|
||||||
|
public static partial ApiKey ToApiKey(CreateApiKeyRequest request);
|
||||||
|
public static partial void Merge([MappingTarget] ApiKey apiKey, UpdateApiKeyRequest request);
|
||||||
|
|
||||||
|
// EF Relations
|
||||||
|
|
||||||
|
public static partial IQueryable<ApiKeyResponse> ProjectToResponse(this IQueryable<ApiKey> apiKeys);
|
||||||
|
}
|
||||||
19
Moonlight.ApiServer/Mappers/ThemeMapper.cs
Normal file
19
Moonlight.ApiServer/Mappers/ThemeMapper.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using Moonlight.ApiServer.Database.Entities;
|
||||||
|
using Moonlight.Shared.Http.Requests.Admin.Sys.Theme;
|
||||||
|
using Moonlight.Shared.Http.Responses.Admin;
|
||||||
|
using Riok.Mapperly.Abstractions;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Mappers;
|
||||||
|
|
||||||
|
[Mapper]
|
||||||
|
public static partial class ThemeMapper
|
||||||
|
{
|
||||||
|
// Mappers
|
||||||
|
public static partial ThemeResponse ToResponse(Theme theme);
|
||||||
|
public static partial Theme ToTheme(CreateThemeRequest request);
|
||||||
|
public static partial void Merge([MappingTarget] Theme theme, UpdateThemeRequest request);
|
||||||
|
|
||||||
|
// EF Relations
|
||||||
|
|
||||||
|
public static partial IQueryable<ThemeResponse> ProjectToResponse(this IQueryable<Theme> themes);
|
||||||
|
}
|
||||||
15
Moonlight.ApiServer/Mappers/UserMapper.cs
Normal file
15
Moonlight.ApiServer/Mappers/UserMapper.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using Moonlight.ApiServer.Database.Entities;
|
||||||
|
using Moonlight.Shared.Http.Responses.Admin.Users;
|
||||||
|
using Riok.Mapperly.Abstractions;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Mappers;
|
||||||
|
|
||||||
|
[Mapper]
|
||||||
|
public static partial class UserMapper
|
||||||
|
{
|
||||||
|
// Mappers
|
||||||
|
public static partial UserResponse ToResponse(User user);
|
||||||
|
|
||||||
|
// EF Relations
|
||||||
|
public static partial IQueryable<UserResponse> ProjectToResponse(this IQueryable<User> users);
|
||||||
|
}
|
||||||
43
Moonlight.ApiServer/Models/ApiDocsOptions.cs
Normal file
43
Moonlight.ApiServer/Models/ApiDocsOptions.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
namespace Moonlight.ApiServer.Models;
|
||||||
|
|
||||||
|
// From https://github.com/scalar/scalar/blob/main/packages/scalar.aspnetcore/ScalarOptions.cs
|
||||||
|
|
||||||
|
public class ApiDocsOptions
|
||||||
|
{
|
||||||
|
public string Theme { get; set; } = "purple";
|
||||||
|
|
||||||
|
public bool? DarkMode { get; set; }
|
||||||
|
public bool? HideDownloadButton { get; set; }
|
||||||
|
public bool? ShowSideBar { get; set; }
|
||||||
|
|
||||||
|
public bool? WithDefaultFonts { get; set; }
|
||||||
|
|
||||||
|
public string? Layout { get; set; }
|
||||||
|
|
||||||
|
public string? CustomCss { get; set; }
|
||||||
|
|
||||||
|
public string? SearchHotkey { get; set; }
|
||||||
|
|
||||||
|
public Dictionary<string, string>? Metadata { get; set; }
|
||||||
|
|
||||||
|
public ScalarAuthenticationOptions? Authentication { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ScalarAuthenticationOptions
|
||||||
|
{
|
||||||
|
public string? PreferredSecurityScheme { get; set; }
|
||||||
|
|
||||||
|
public ScalarAuthenticationApiKey? ApiKey { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ScalarAuthenticationoAuth2
|
||||||
|
{
|
||||||
|
public string? ClientId { get; set; }
|
||||||
|
|
||||||
|
public List<string>? Scopes { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ScalarAuthenticationApiKey
|
||||||
|
{
|
||||||
|
public string? Token { get; set; }
|
||||||
|
}
|
||||||
49
Moonlight.ApiServer/Models/ApplicationTheme.cs
Normal file
49
Moonlight.ApiServer/Models/ApplicationTheme.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
namespace Moonlight.ApiServer.Models;
|
||||||
|
|
||||||
|
public class ApplicationTheme
|
||||||
|
{
|
||||||
|
public string ColorBackground { get; set; }
|
||||||
|
|
||||||
|
public string ColorBase100 { get; set; }
|
||||||
|
public string ColorBase150 { get; set; }
|
||||||
|
public string ColorBase200 { get; set; }
|
||||||
|
public string ColorBase250 { get; set; }
|
||||||
|
public string ColorBase300 { get; set; }
|
||||||
|
|
||||||
|
public string ColorBaseContent { get; set; }
|
||||||
|
|
||||||
|
public string ColorPrimary { get; set; }
|
||||||
|
public string ColorPrimaryContent { get; set; }
|
||||||
|
|
||||||
|
public string ColorSecondary { get; set; }
|
||||||
|
public string ColorSecondaryContent { get; set; }
|
||||||
|
|
||||||
|
public string ColorAccent { get; set; }
|
||||||
|
public string ColorAccentContent { get; set; }
|
||||||
|
|
||||||
|
public string ColorNeutral { get; set; }
|
||||||
|
public string ColorNeutralContent { get; set; }
|
||||||
|
|
||||||
|
public string ColorInfo { get; set; }
|
||||||
|
public string ColorInfoContent { get; set; }
|
||||||
|
|
||||||
|
public string ColorSuccess { get; set; }
|
||||||
|
public string ColorSuccessContent { get; set; }
|
||||||
|
|
||||||
|
public string ColorWarning { get; set; }
|
||||||
|
public string ColorWarningContent { get; set; }
|
||||||
|
|
||||||
|
public string ColorError { get; set; }
|
||||||
|
public string ColorErrorContent { get; set; }
|
||||||
|
|
||||||
|
public float RadiusSelector { get; set; }
|
||||||
|
public float RadiusField { get; set; }
|
||||||
|
public float RadiusBox { get; set; }
|
||||||
|
|
||||||
|
public float SizeSelector { get; set; }
|
||||||
|
public float SizeField { get; set; }
|
||||||
|
|
||||||
|
public float Border { get; set; }
|
||||||
|
public int Depth { get; set; }
|
||||||
|
public int Noise { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Moonlight.ApiServer.Models;
|
||||||
|
|
||||||
|
public class FrontendConfigurationOption
|
||||||
|
{
|
||||||
|
public string[] Scripts { get; set; } = [];
|
||||||
|
public string[] Styles { get; set; } = [];
|
||||||
|
}
|
||||||
27
Moonlight.ApiServer/Models/UserDeleteValidateResult.cs
Normal file
27
Moonlight.ApiServer/Models/UserDeleteValidateResult.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
namespace Moonlight.ApiServer.Models;
|
||||||
|
|
||||||
|
public class UserDeleteValidationResult
|
||||||
|
{
|
||||||
|
public bool IsAllowed { get; set; }
|
||||||
|
public string Reason { get; set; }
|
||||||
|
|
||||||
|
public static UserDeleteValidationResult Allow()
|
||||||
|
{
|
||||||
|
return new UserDeleteValidationResult()
|
||||||
|
{
|
||||||
|
IsAllowed = true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UserDeleteValidationResult Deny()
|
||||||
|
=> Deny("No reason provided");
|
||||||
|
|
||||||
|
public static UserDeleteValidationResult Deny(string reason)
|
||||||
|
{
|
||||||
|
return new UserDeleteValidationResult()
|
||||||
|
{
|
||||||
|
IsAllowed = false,
|
||||||
|
Reason = reason
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
43
Moonlight.ApiServer/Moonlight.ApiServer.csproj
Normal file
43
Moonlight.ApiServer/Moonlight.ApiServer.csproj
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Moonlight.Shared\Moonlight.Shared.csproj"/>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Database\Migrations\"/>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<PackageId>Moonlight.ApiServer</PackageId>
|
||||||
|
<Version>2.1.15</Version>
|
||||||
|
<Authors>Moonlight Panel</Authors>
|
||||||
|
<Description>A build of the api server for moonlight development</Description>
|
||||||
|
<PackageProjectUrl>https://github.com/Moonlight-Panel/Moonlight</PackageProjectUrl>
|
||||||
|
<DevelopmentDependency>true</DevelopmentDependency>
|
||||||
|
<PackageTags>apiserver</PackageTags>
|
||||||
|
<IsPackable>true</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.20"/>
|
||||||
|
<PackageReference Include="Hangfire.Core" Version="1.8.20"/>
|
||||||
|
<PackageReference Include="Hangfire.EntityFrameworkCore" Version="0.7.0"/>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="9.0.9" />
|
||||||
|
<PackageReference Include="MoonCore" Version="2.0.6" />
|
||||||
|
<PackageReference Include="MoonCore.Extended" Version="1.4.2" />
|
||||||
|
<PackageReference Include="MoonCore.PluginFramework.Generator" Version="1.0.3" />
|
||||||
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||||
|
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.12.0" />
|
||||||
|
<PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.12.0-beta.1"/>
|
||||||
|
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.12.0"/>
|
||||||
|
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.12.0"/>
|
||||||
|
<PackageReference Include="Riok.Mapperly" Version="4.3.0-next.3" />
|
||||||
|
<PackageReference Include="SharpZipLib" Version="1.4.2"/>
|
||||||
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.4" />
|
||||||
|
<PackageReference Include="Ben.Demystifier" Version="0.4.1"/>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
10
Moonlight.ApiServer/Plugins/IPluginStartup.cs
Normal file
10
Moonlight.ApiServer/Plugins/IPluginStartup.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Plugins;
|
||||||
|
|
||||||
|
public interface IPluginStartup
|
||||||
|
{
|
||||||
|
public void AddPlugin(WebApplicationBuilder builder);
|
||||||
|
public void UsePlugin(WebApplication app);
|
||||||
|
public void MapPlugin(WebApplication app);
|
||||||
|
}
|
||||||
32
Moonlight.ApiServer/Services/ApiKeyAuthService.cs
Normal file
32
Moonlight.ApiServer/Services/ApiKeyAuthService.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using MoonCore.Extended.Abstractions;
|
||||||
|
using Moonlight.ApiServer.Database.Entities;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Services;
|
||||||
|
|
||||||
|
public class ApiKeyAuthService
|
||||||
|
{
|
||||||
|
private readonly DatabaseRepository<ApiKey> ApiKeyRepository;
|
||||||
|
|
||||||
|
public ApiKeyAuthService(DatabaseRepository<ApiKey> apiKeyRepository)
|
||||||
|
{
|
||||||
|
ApiKeyRepository = apiKeyRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> ValidateAsync(ClaimsPrincipal? principal)
|
||||||
|
{
|
||||||
|
// Ignore malformed claims principal
|
||||||
|
if (principal is not { Identity.IsAuthenticated: true })
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var apiKeyIdStr = principal.FindFirstValue("ApiKeyId");
|
||||||
|
|
||||||
|
if (!int.TryParse(apiKeyIdStr, out var apiKeyId))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return await ApiKeyRepository
|
||||||
|
.Get()
|
||||||
|
.AnyAsync(x => x.Id == apiKeyId);
|
||||||
|
}
|
||||||
|
}
|
||||||
53
Moonlight.ApiServer/Services/ApiKeyService.cs
Normal file
53
Moonlight.ApiServer/Services/ApiKeyService.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
|
using System.Text;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using MoonCore.Attributes;
|
||||||
|
using Moonlight.ApiServer.Configuration;
|
||||||
|
using Moonlight.ApiServer.Database.Entities;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Services;
|
||||||
|
|
||||||
|
[Singleton]
|
||||||
|
public class ApiKeyService
|
||||||
|
{
|
||||||
|
private readonly AppConfiguration Configuration;
|
||||||
|
|
||||||
|
public ApiKeyService(AppConfiguration configuration)
|
||||||
|
{
|
||||||
|
Configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GenerateJwt(ApiKey apiKey)
|
||||||
|
{
|
||||||
|
var jwtSecurityTokenHandler = new JwtSecurityTokenHandler();
|
||||||
|
|
||||||
|
var descriptor = new SecurityTokenDescriptor()
|
||||||
|
{
|
||||||
|
Expires = apiKey.ExpiresAt.UtcDateTime,
|
||||||
|
IssuedAt = DateTime.Now,
|
||||||
|
NotBefore = DateTime.Now.AddMinutes(-1),
|
||||||
|
Claims = new Dictionary<string, object>()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
"ApiKeyId",
|
||||||
|
apiKey.Id
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Permissions",
|
||||||
|
string.Join(";", apiKey.Permissions)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
SigningCredentials = new SigningCredentials(
|
||||||
|
new SymmetricSecurityKey(
|
||||||
|
Encoding.UTF8.GetBytes(Configuration.Authentication.Secret)
|
||||||
|
),
|
||||||
|
SecurityAlgorithms.HmacSha256
|
||||||
|
),
|
||||||
|
Issuer = Configuration.PublicUrl,
|
||||||
|
Audience = Configuration.PublicUrl
|
||||||
|
};
|
||||||
|
|
||||||
|
var securityToken = jwtSecurityTokenHandler.CreateJwtSecurityToken(descriptor);
|
||||||
|
return jwtSecurityTokenHandler.WriteToken(securityToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
120
Moonlight.ApiServer/Services/ApplicationService.cs
Normal file
120
Moonlight.ApiServer/Services/ApplicationService.cs
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using MoonCore.Attributes;
|
||||||
|
using MoonCore.Helpers;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Services;
|
||||||
|
|
||||||
|
[Singleton]
|
||||||
|
public class ApplicationService
|
||||||
|
{
|
||||||
|
private ILogger<ApplicationService> Logger;
|
||||||
|
private readonly IHost Host;
|
||||||
|
|
||||||
|
public ApplicationService(ILogger<ApplicationService> logger, IHost host)
|
||||||
|
{
|
||||||
|
Logger = logger;
|
||||||
|
Host = host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<string> GetOsNameAsync()
|
||||||
|
{
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
|
{
|
||||||
|
// Windows platform detected
|
||||||
|
var osVersion = Environment.OSVersion.Version;
|
||||||
|
return Task.FromResult($"Windows {osVersion.Major}.{osVersion.Minor}.{osVersion.Build}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
{
|
||||||
|
var releaseRaw = File
|
||||||
|
.ReadAllLines("/etc/os-release")
|
||||||
|
.FirstOrDefault(x => x.StartsWith("PRETTY_NAME="));
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(releaseRaw))
|
||||||
|
return Task.FromResult("Linux (unknown release)");
|
||||||
|
|
||||||
|
var release = releaseRaw
|
||||||
|
.Replace("PRETTY_NAME=", "")
|
||||||
|
.Replace("\"", "");
|
||||||
|
|
||||||
|
if(string.IsNullOrEmpty(release))
|
||||||
|
return Task.FromResult("Linux (unknown release)");
|
||||||
|
|
||||||
|
return Task.FromResult(release);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||||
|
{
|
||||||
|
// macOS platform detected
|
||||||
|
var osVersion = Environment.OSVersion.Version;
|
||||||
|
return Task.FromResult($"macOS {osVersion.Major}.{osVersion.Minor}.{osVersion.Build}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unknown platform
|
||||||
|
return Task.FromResult("N/A");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<long> GetMemoryUsageAsync()
|
||||||
|
{
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
|
{
|
||||||
|
var process = Process.GetCurrentProcess();
|
||||||
|
return process.PrivateMemorySize64;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var lines = await File.ReadAllLinesAsync("/proc/self/smaps");
|
||||||
|
var kilobytes = 0;
|
||||||
|
|
||||||
|
foreach (var line in lines)
|
||||||
|
{
|
||||||
|
if(!line.StartsWith("pss:", StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var valueString = line
|
||||||
|
.Replace("pss:", "", StringComparison.InvariantCultureIgnoreCase)
|
||||||
|
.Replace("kb", "", StringComparison.InvariantCultureIgnoreCase)
|
||||||
|
.Trim();
|
||||||
|
|
||||||
|
kilobytes += int.Parse(valueString);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ByteConverter.FromKiloBytes(kilobytes).Bytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<TimeSpan> GetUptimeAsync()
|
||||||
|
{
|
||||||
|
var process = Process.GetCurrentProcess();
|
||||||
|
var uptime = DateTime.Now - process.StartTime;
|
||||||
|
return Task.FromResult(uptime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<int> GetCpuUsageAsync()
|
||||||
|
{
|
||||||
|
var process = Process.GetCurrentProcess();
|
||||||
|
var cpuTime = process.TotalProcessorTime;
|
||||||
|
var wallClockTime = DateTime.UtcNow - process.StartTime.ToUniversalTime();
|
||||||
|
|
||||||
|
var cpuUsage = (int)(100.0 * cpuTime.TotalMilliseconds / wallClockTime.TotalMilliseconds / Environment.ProcessorCount);
|
||||||
|
|
||||||
|
return Task.FromResult(cpuUsage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task ShutdownAsync()
|
||||||
|
{
|
||||||
|
Logger.LogCritical("Restart of api server has been requested");
|
||||||
|
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(1));
|
||||||
|
await Host.StopAsync(CancellationToken.None);
|
||||||
|
});
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
96
Moonlight.ApiServer/Services/DiagnoseService.cs
Normal file
96
Moonlight.ApiServer/Services/DiagnoseService.cs
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
using Moonlight.ApiServer.Interfaces;
|
||||||
|
using System.IO.Compression;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using MoonCore.Attributes;
|
||||||
|
using MoonCore.Exceptions;
|
||||||
|
using Moonlight.Shared.Http.Responses.Admin.Sys;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Services;
|
||||||
|
|
||||||
|
[Scoped]
|
||||||
|
public class DiagnoseService
|
||||||
|
{
|
||||||
|
private readonly IEnumerable<IDiagnoseProvider> DiagnoseProviders;
|
||||||
|
private readonly ILogger<DiagnoseService> Logger;
|
||||||
|
|
||||||
|
public DiagnoseService(
|
||||||
|
IEnumerable<IDiagnoseProvider> diagnoseProviders,
|
||||||
|
ILogger<DiagnoseService> logger
|
||||||
|
)
|
||||||
|
{
|
||||||
|
DiagnoseProviders = diagnoseProviders;
|
||||||
|
Logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<DiagnoseProvideResponse[]> GetProvidersAsync()
|
||||||
|
{
|
||||||
|
var availableProviders = new List<DiagnoseProvideResponse>();
|
||||||
|
|
||||||
|
foreach (var diagnoseProvider in DiagnoseProviders)
|
||||||
|
{
|
||||||
|
var name = diagnoseProvider.GetType().Name;
|
||||||
|
|
||||||
|
var type = diagnoseProvider.GetType().FullName;
|
||||||
|
|
||||||
|
// The type name is null if the type is a generic type, unlikely, but still could happen
|
||||||
|
if (type == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
availableProviders.Add(new DiagnoseProvideResponse()
|
||||||
|
{
|
||||||
|
Name = name,
|
||||||
|
Type = type
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.FromResult(
|
||||||
|
availableProviders.ToArray()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<MemoryStream> GenerateDiagnoseAsync(string[] requestedProviders)
|
||||||
|
{
|
||||||
|
IDiagnoseProvider[] providers;
|
||||||
|
|
||||||
|
if (requestedProviders.Length == 0)
|
||||||
|
providers = DiagnoseProviders.ToArray();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var foundProviders = new List<IDiagnoseProvider>();
|
||||||
|
|
||||||
|
foreach (var requestedProvider in requestedProviders)
|
||||||
|
{
|
||||||
|
var provider = DiagnoseProviders.FirstOrDefault(x => x.GetType().FullName == requestedProvider);
|
||||||
|
|
||||||
|
if (provider == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foundProviders.Add(provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
providers = foundProviders.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var outputStream = new MemoryStream();
|
||||||
|
var zipArchive = new ZipArchive(outputStream, ZipArchiveMode.Create, leaveOpen: true);
|
||||||
|
|
||||||
|
foreach (var provider in providers)
|
||||||
|
{
|
||||||
|
await provider.ModifyZipArchiveAsync(zipArchive);
|
||||||
|
}
|
||||||
|
|
||||||
|
zipArchive.Dispose();
|
||||||
|
|
||||||
|
outputStream.Position = 0;
|
||||||
|
return outputStream;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.LogError("An unhandled error occured while generated the diagnose file: {e}", e);
|
||||||
|
|
||||||
|
throw new HttpApiException("An unhandled error occured while generating the diagnose file", 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
168
Moonlight.ApiServer/Services/FrontendService.cs
Normal file
168
Moonlight.ApiServer/Services/FrontendService.cs
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
using System.IO.Compression;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.FileProviders;
|
||||||
|
using MoonCore.Attributes;
|
||||||
|
using MoonCore.Exceptions;
|
||||||
|
using MoonCore.Extended.Abstractions;
|
||||||
|
using MoonCore.Helpers;
|
||||||
|
using Moonlight.ApiServer.Configuration;
|
||||||
|
using Moonlight.ApiServer.Database.Entities;
|
||||||
|
using Moonlight.ApiServer.Http.Controllers.Frontend;
|
||||||
|
using Moonlight.ApiServer.Models;
|
||||||
|
using Moonlight.Shared.Misc;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Services;
|
||||||
|
|
||||||
|
[Scoped]
|
||||||
|
public class FrontendService
|
||||||
|
{
|
||||||
|
private readonly AppConfiguration Configuration;
|
||||||
|
private readonly IWebHostEnvironment WebHostEnvironment;
|
||||||
|
private readonly IEnumerable<FrontendConfigurationOption> ConfigurationOptions;
|
||||||
|
private readonly IServiceProvider ServiceProvider;
|
||||||
|
private readonly DatabaseRepository<Theme> ThemeRepository;
|
||||||
|
|
||||||
|
public FrontendService(
|
||||||
|
AppConfiguration configuration,
|
||||||
|
IWebHostEnvironment webHostEnvironment,
|
||||||
|
IEnumerable<FrontendConfigurationOption> configurationOptions,
|
||||||
|
IServiceProvider serviceProvider,
|
||||||
|
DatabaseRepository<Theme> themeRepository
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Configuration = configuration;
|
||||||
|
WebHostEnvironment = webHostEnvironment;
|
||||||
|
ConfigurationOptions = configurationOptions;
|
||||||
|
ServiceProvider = serviceProvider;
|
||||||
|
ThemeRepository = themeRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<FrontendConfiguration> GetConfigurationAsync()
|
||||||
|
{
|
||||||
|
var configuration = new FrontendConfiguration()
|
||||||
|
{
|
||||||
|
ApiUrl = Configuration.PublicUrl,
|
||||||
|
HostEnvironment = "ApiServer"
|
||||||
|
};
|
||||||
|
|
||||||
|
return Task.FromResult(configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<string> GenerateIndexHtmlAsync() // TODO: Cache
|
||||||
|
{
|
||||||
|
// Load requested theme
|
||||||
|
var theme = await ThemeRepository
|
||||||
|
.Get()
|
||||||
|
.FirstOrDefaultAsync(x => x.IsEnabled);
|
||||||
|
|
||||||
|
// Load configured javascript files
|
||||||
|
var scripts = ConfigurationOptions
|
||||||
|
.SelectMany(x => x.Scripts)
|
||||||
|
.Distinct()
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
// Load configured css files
|
||||||
|
var styles = ConfigurationOptions
|
||||||
|
.SelectMany(x => x.Styles)
|
||||||
|
.Distinct()
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
return await ComponentHelper.RenderToHtmlAsync<FrontendPage>(
|
||||||
|
ServiceProvider,
|
||||||
|
parameters =>
|
||||||
|
{
|
||||||
|
parameters["Theme"] = theme!;
|
||||||
|
parameters["Styles"] = styles;
|
||||||
|
parameters["Scripts"] = scripts;
|
||||||
|
parameters["Title"] = "Moonlight"; // TODO: Config
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Stream> GenerateZipAsync() // TODO: Rework to be able to extract everything successfully
|
||||||
|
{
|
||||||
|
// We only allow the access to this function when we are actually hosting the frontend
|
||||||
|
if (!Configuration.Frontend.EnableHosting)
|
||||||
|
throw new HttpApiException("The hosting of the wasm client has been disabled", 400);
|
||||||
|
|
||||||
|
// Load and check wasm path
|
||||||
|
var wasmMainFile = WebHostEnvironment.WebRootFileProvider.GetFileInfo("index.html");
|
||||||
|
|
||||||
|
if (wasmMainFile is NotFoundFileInfo || string.IsNullOrEmpty(wasmMainFile.PhysicalPath))
|
||||||
|
throw new HttpApiException("Unable to find wasm location", 500);
|
||||||
|
|
||||||
|
var wasmPath = Path.GetDirectoryName(wasmMainFile.PhysicalPath)! + "/";
|
||||||
|
|
||||||
|
// Load and check the blazor framework files
|
||||||
|
var blazorFile = WebHostEnvironment.WebRootFileProvider.GetFileInfo("_framework/blazor.webassembly.js");
|
||||||
|
|
||||||
|
if (blazorFile is NotFoundFileInfo || string.IsNullOrEmpty(blazorFile.PhysicalPath))
|
||||||
|
throw new HttpApiException("Unable to find blazor location", 500);
|
||||||
|
|
||||||
|
var blazorPath = Path.GetDirectoryName(blazorFile.PhysicalPath)! + "/";
|
||||||
|
|
||||||
|
// Create zip
|
||||||
|
var memoryStream = new MemoryStream();
|
||||||
|
var zipArchive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true);
|
||||||
|
|
||||||
|
// Add wasm application
|
||||||
|
await ArchiveFsItemAsync(zipArchive, wasmPath, wasmPath);
|
||||||
|
|
||||||
|
// Add blazor files
|
||||||
|
await ArchiveFsItemAsync(zipArchive, blazorPath, blazorPath, "_framework/");
|
||||||
|
|
||||||
|
// Add frontend.json
|
||||||
|
var frontendConfig = await GetConfigurationAsync();
|
||||||
|
frontendConfig.HostEnvironment = "Static";
|
||||||
|
var frontendJson = JsonSerializer.Serialize(frontendConfig);
|
||||||
|
await ArchiveTextAsync(zipArchive, "frontend.json", frontendJson);
|
||||||
|
|
||||||
|
// Finish zip archive and reset stream so the code calling this function can process it
|
||||||
|
zipArchive.Dispose();
|
||||||
|
await memoryStream.FlushAsync();
|
||||||
|
memoryStream.Position = 0;
|
||||||
|
|
||||||
|
return memoryStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ArchiveFsItemAsync(ZipArchive archive, string path, string prefixToRemove, string prefixToAdd = "")
|
||||||
|
{
|
||||||
|
if (File.Exists(path))
|
||||||
|
{
|
||||||
|
var entryName = prefixToAdd + Formatter.ReplaceStart(path, prefixToRemove, "");
|
||||||
|
|
||||||
|
var entry = archive.CreateEntry(entryName);
|
||||||
|
|
||||||
|
await using var entryStream = entry.Open();
|
||||||
|
await using var fileStream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
|
|
||||||
|
await fileStream.CopyToAsync(entryStream);
|
||||||
|
await entryStream.FlushAsync();
|
||||||
|
|
||||||
|
entryStream.Close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (var directoryItem in Directory.EnumerateFileSystemEntries(path))
|
||||||
|
await ArchiveFsItemAsync(archive, directoryItem, prefixToRemove, prefixToAdd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ArchiveTextAsync(ZipArchive archive, string path, string content)
|
||||||
|
{
|
||||||
|
var data = Encoding.UTF8.GetBytes(content);
|
||||||
|
await ArchiveBytesAsync(archive, path, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ArchiveBytesAsync(ZipArchive archive, string path, byte[] bytes)
|
||||||
|
{
|
||||||
|
var entry = archive.CreateEntry(path);
|
||||||
|
await using var dataStream = entry.Open();
|
||||||
|
|
||||||
|
await dataStream.WriteAsync(bytes);
|
||||||
|
await dataStream.FlushAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
81
Moonlight.ApiServer/Services/MetricsBackgroundService.cs
Normal file
81
Moonlight.ApiServer/Services/MetricsBackgroundService.cs
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
using System.Diagnostics.Metrics;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Moonlight.ApiServer.Configuration;
|
||||||
|
using Moonlight.ApiServer.Interfaces;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Services;
|
||||||
|
|
||||||
|
public class MetricsBackgroundService : BackgroundService
|
||||||
|
{
|
||||||
|
private readonly ILogger<MetricsBackgroundService> Logger;
|
||||||
|
private readonly IServiceProvider ServiceProvider;
|
||||||
|
private readonly AppConfiguration Configuration;
|
||||||
|
|
||||||
|
private readonly IMetric[] Metrics;
|
||||||
|
private readonly Meter Meter;
|
||||||
|
|
||||||
|
public MetricsBackgroundService(
|
||||||
|
IServiceProvider serviceProvider,
|
||||||
|
IMeterFactory meterFactory,
|
||||||
|
IEnumerable<IMetric> metrics,
|
||||||
|
ILogger<MetricsBackgroundService> logger,
|
||||||
|
AppConfiguration configuration
|
||||||
|
)
|
||||||
|
{
|
||||||
|
ServiceProvider = serviceProvider;
|
||||||
|
Logger = logger;
|
||||||
|
Configuration = configuration;
|
||||||
|
|
||||||
|
Meter = meterFactory.Create("moonlight");
|
||||||
|
|
||||||
|
Metrics = metrics.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task InitializeAsync()
|
||||||
|
{
|
||||||
|
Logger.LogDebug(
|
||||||
|
"Initializing metrics: {names}",
|
||||||
|
string.Join(", ", Metrics.Select(x => x.GetType().FullName))
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach (var metric in Metrics)
|
||||||
|
await metric.InitializeAsync(Meter);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
|
{
|
||||||
|
await InitializeAsync();
|
||||||
|
|
||||||
|
while (!stoppingToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
using var scope = ServiceProvider.CreateScope();
|
||||||
|
|
||||||
|
foreach (var metric in Metrics)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await metric.RunAsync(scope.ServiceProvider, stoppingToken);
|
||||||
|
}
|
||||||
|
catch (TaskCanceledException)
|
||||||
|
{
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.LogError(
|
||||||
|
"An unhandled error occured while collecting metric {name}: {e}",
|
||||||
|
metric.GetType().FullName,
|
||||||
|
e
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await Task.Delay(
|
||||||
|
TimeSpan.FromSeconds(Configuration.OpenTelemetry.Metrics.Interval),
|
||||||
|
stoppingToken
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
168
Moonlight.ApiServer/Services/UserAuthService.cs
Normal file
168
Moonlight.ApiServer/Services/UserAuthService.cs
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using MoonCore.Extended.Abstractions;
|
||||||
|
using MoonCore.Extended.Helpers;
|
||||||
|
using MoonCore.Helpers;
|
||||||
|
using Moonlight.ApiServer.Configuration;
|
||||||
|
using Moonlight.ApiServer.Database.Entities;
|
||||||
|
using Moonlight.ApiServer.Interfaces;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Services;
|
||||||
|
|
||||||
|
public class UserAuthService
|
||||||
|
{
|
||||||
|
private readonly ILogger<UserAuthService> Logger;
|
||||||
|
private readonly DatabaseRepository<User> UserRepository;
|
||||||
|
private readonly AppConfiguration Configuration;
|
||||||
|
private readonly IEnumerable<IUserAuthExtension> Extensions;
|
||||||
|
|
||||||
|
private const string UserIdClaim = "UserId";
|
||||||
|
private const string IssuedAtClaim = "IssuedAt";
|
||||||
|
|
||||||
|
public UserAuthService(
|
||||||
|
ILogger<UserAuthService> logger,
|
||||||
|
DatabaseRepository<User> userRepository,
|
||||||
|
AppConfiguration configuration,
|
||||||
|
IEnumerable<IUserAuthExtension> extensions
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Logger = logger;
|
||||||
|
UserRepository = userRepository;
|
||||||
|
Configuration = configuration;
|
||||||
|
Extensions = extensions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> SyncAsync(ClaimsPrincipal? principal)
|
||||||
|
{
|
||||||
|
// Ignore malformed claims principal
|
||||||
|
if (principal is not { Identity.IsAuthenticated: true })
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Search for email and username. We need both to create the user model if required.
|
||||||
|
// We do a ToLower here because external authentication provider might provide case-sensitive data
|
||||||
|
|
||||||
|
var email = principal.FindFirstValue(ClaimTypes.Email)?.ToLower();
|
||||||
|
var username = principal.FindFirstValue(ClaimTypes.Name)?.ToLower();
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(username))
|
||||||
|
{
|
||||||
|
Logger.LogWarning(
|
||||||
|
"The authentication scheme {scheme} did not provide claim types: email, name. These are required to sync to user to the database",
|
||||||
|
principal.Identity.AuthenticationType
|
||||||
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If you plan to use multiple auth providers it can be a good idea
|
||||||
|
// to use an identifier in the user model which consists of the provider and the NameIdentifier
|
||||||
|
// instead of the email address. For simplicity, we just use the email as the identifier so multiple auth providers
|
||||||
|
// can lead to the same account when the email matches
|
||||||
|
var user = await UserRepository
|
||||||
|
.Get()
|
||||||
|
.FirstOrDefaultAsync(u => u.Email == email);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
string[] permissions = [];
|
||||||
|
|
||||||
|
// Yes I know we handle the first user admin thing in the LocalAuth too,
|
||||||
|
// but this only works fo the local auth. So if a user uses an external auth scheme
|
||||||
|
// like oauth2 discord, the first user admin toggle would do nothing
|
||||||
|
if (Configuration.Authentication.FirstUserAdmin)
|
||||||
|
{
|
||||||
|
var count = await UserRepository
|
||||||
|
.Get()
|
||||||
|
.CountAsync();
|
||||||
|
|
||||||
|
if (count == 0)
|
||||||
|
permissions = ["*"];
|
||||||
|
}
|
||||||
|
|
||||||
|
user = await UserRepository.AddAsync(new User()
|
||||||
|
{
|
||||||
|
Email = email,
|
||||||
|
TokenValidTimestamp = DateTimeOffset.UtcNow.AddMinutes(-1),
|
||||||
|
Username = username,
|
||||||
|
Password = HashHelper.Hash(Formatter.GenerateString(64)),
|
||||||
|
Permissions = permissions
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// You can sync other properties here
|
||||||
|
if (user.Username != username)
|
||||||
|
{
|
||||||
|
user.Username = username;
|
||||||
|
await UserRepository.UpdateAsync(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enrich claims with required metadata
|
||||||
|
principal.Identities.First().AddClaims([
|
||||||
|
new Claim(UserIdClaim, user.Id.ToString()),
|
||||||
|
new Claim(IssuedAtClaim, DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString()),
|
||||||
|
new Claim("Permissions", string.Join(';', user.Permissions))
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Call extensions
|
||||||
|
foreach (var extension in Extensions)
|
||||||
|
{
|
||||||
|
var result = await extension.SyncAsync(user, principal);
|
||||||
|
|
||||||
|
if (!result) // Exit immediately if result is false
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> ValidateAsync(ClaimsPrincipal? principal)
|
||||||
|
{
|
||||||
|
// Ignore malformed claims principal
|
||||||
|
if (principal is not { Identity.IsAuthenticated: true })
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Validate if the user still exists, and then we want to validate the token issue time
|
||||||
|
// against the invalidation time
|
||||||
|
|
||||||
|
var userIdStr = principal.FindFirstValue(UserIdClaim);
|
||||||
|
|
||||||
|
if (!int.TryParse(userIdStr, out var userId))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var user = await UserRepository
|
||||||
|
.Get()
|
||||||
|
.FirstOrDefaultAsync(u => u.Id == userId);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Token time validation
|
||||||
|
var issuedAtStr = principal.FindFirstValue(IssuedAtClaim);
|
||||||
|
|
||||||
|
if (!long.TryParse(issuedAtStr, out var issuedAtUnix))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var issuedAt = DateTimeOffset
|
||||||
|
.FromUnixTimeSeconds(issuedAtUnix)
|
||||||
|
.ToUniversalTime();
|
||||||
|
|
||||||
|
// If the issued at timestamp is greater than the token validation timestamp
|
||||||
|
// everything is fine. If not it means that the token should be invalidated
|
||||||
|
// as it is too old
|
||||||
|
|
||||||
|
if (issuedAt < user.TokenValidTimestamp)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Call extensions
|
||||||
|
foreach (var extension in Extensions)
|
||||||
|
{
|
||||||
|
var result = await extension.ValidateAsync(user, principal);
|
||||||
|
|
||||||
|
if (!result) // Exit immediately if result is false
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
42
Moonlight.ApiServer/Services/UserDeletionService.cs
Normal file
42
Moonlight.ApiServer/Services/UserDeletionService.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using MoonCore.Extended.Abstractions;
|
||||||
|
using Moonlight.ApiServer.Database.Entities;
|
||||||
|
using Moonlight.ApiServer.Interfaces;
|
||||||
|
using Moonlight.ApiServer.Models;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Services;
|
||||||
|
|
||||||
|
public class UserDeletionService
|
||||||
|
{
|
||||||
|
private readonly IUserDeleteHandler[] Handlers;
|
||||||
|
private readonly DatabaseRepository<User> UserRepository;
|
||||||
|
|
||||||
|
public UserDeletionService(
|
||||||
|
IEnumerable<IUserDeleteHandler> handlers,
|
||||||
|
DatabaseRepository<User> userRepository
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UserRepository = userRepository;
|
||||||
|
Handlers = handlers.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<UserDeleteValidationResult> ValidateAsync(User user)
|
||||||
|
{
|
||||||
|
foreach (var handler in Handlers)
|
||||||
|
{
|
||||||
|
var result = await handler.ValidateAsync(user);
|
||||||
|
|
||||||
|
if (!result.IsAllowed)
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return UserDeleteValidationResult.Allow();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task DeleteAsync(User user, bool force)
|
||||||
|
{
|
||||||
|
foreach (var handler in Handlers)
|
||||||
|
await handler.DeleteAsync(user, force);
|
||||||
|
|
||||||
|
await UserRepository.RemoveAsync(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
189
Moonlight.ApiServer/Startup/Startup.Auth.cs
Normal file
189
Moonlight.ApiServer/Startup/Startup.Auth.cs
Normal file
@@ -0,0 +1,189 @@
|
|||||||
|
using System.Text;
|
||||||
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using MoonCore.Permissions;
|
||||||
|
using Moonlight.ApiServer.Configuration;
|
||||||
|
using Moonlight.ApiServer.Implementations.LocalAuth;
|
||||||
|
using Moonlight.ApiServer.Services;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Startup;
|
||||||
|
|
||||||
|
public static partial class Startup
|
||||||
|
{
|
||||||
|
private static void AddAuth(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
var configuration = AppConfiguration.CreateEmpty();
|
||||||
|
builder.Configuration.Bind(configuration);
|
||||||
|
|
||||||
|
builder.Services
|
||||||
|
.AddAuthentication(options => { options.DefaultScheme = "MainScheme"; })
|
||||||
|
.AddPolicyScheme("MainScheme", null, options =>
|
||||||
|
{
|
||||||
|
// If an api key is specified via the bearer auth header
|
||||||
|
// we want to use the ApiKey scheme for authenticating the request
|
||||||
|
options.ForwardDefaultSelector = context =>
|
||||||
|
{
|
||||||
|
var headers = context.Request.Headers;
|
||||||
|
|
||||||
|
// For regular api calls
|
||||||
|
if (headers.ContainsKey("Authorization"))
|
||||||
|
return "ApiKey";
|
||||||
|
|
||||||
|
// For websocket requests which cannot use the Authorization header
|
||||||
|
if (headers.Upgrade == "websocket" && headers.Connection == "Upgrade" && context.Request.Query.ContainsKey("access_token"))
|
||||||
|
return "ApiKey";
|
||||||
|
|
||||||
|
// Regular user traffic/auth
|
||||||
|
return "Session";
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.AddJwtBearer("ApiKey", null, options =>
|
||||||
|
{
|
||||||
|
options.TokenValidationParameters = new()
|
||||||
|
{
|
||||||
|
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(
|
||||||
|
configuration.Authentication.Secret
|
||||||
|
)),
|
||||||
|
ValidateIssuerSigningKey = true,
|
||||||
|
ValidateLifetime = true,
|
||||||
|
ClockSkew = TimeSpan.Zero,
|
||||||
|
ValidateAudience = true,
|
||||||
|
ValidAudience = configuration.PublicUrl,
|
||||||
|
ValidateIssuer = true,
|
||||||
|
ValidIssuer = configuration.PublicUrl
|
||||||
|
};
|
||||||
|
|
||||||
|
options.Events = new JwtBearerEvents()
|
||||||
|
{
|
||||||
|
OnTokenValidated = async context =>
|
||||||
|
{
|
||||||
|
var apiKeyAuthService = context
|
||||||
|
.HttpContext
|
||||||
|
.RequestServices
|
||||||
|
.GetRequiredService<ApiKeyAuthService>();
|
||||||
|
|
||||||
|
var result = await apiKeyAuthService.ValidateAsync(context.Principal);
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
context.Fail("API key has been deleted");
|
||||||
|
},
|
||||||
|
|
||||||
|
OnMessageReceived = context =>
|
||||||
|
{
|
||||||
|
var accessToken = context.Request.Query["access_token"];
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(accessToken))
|
||||||
|
context.Token = accessToken;
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.AddCookie("Session", null, options =>
|
||||||
|
{
|
||||||
|
options.ExpireTimeSpan = TimeSpan.FromDays(configuration.Authentication.Sessions.ExpiresIn);
|
||||||
|
|
||||||
|
options.Cookie = new CookieBuilder()
|
||||||
|
{
|
||||||
|
Name = configuration.Authentication.Sessions.CookieName,
|
||||||
|
Path = "/",
|
||||||
|
IsEssential = true,
|
||||||
|
SecurePolicy = CookieSecurePolicy.SameAsRequest
|
||||||
|
};
|
||||||
|
|
||||||
|
// As redirects won't work in our spa which uses API calls
|
||||||
|
// we need to customize the responses when certain actions happen
|
||||||
|
options.Events.OnRedirectToLogin = async context =>
|
||||||
|
{
|
||||||
|
await Results.Problem(
|
||||||
|
title: "Unauthenticated",
|
||||||
|
detail: "You need to authenticate yourself to use this endpoint",
|
||||||
|
statusCode: 401
|
||||||
|
)
|
||||||
|
.ExecuteAsync(context.HttpContext);
|
||||||
|
};
|
||||||
|
|
||||||
|
options.Events.OnRedirectToAccessDenied = async context =>
|
||||||
|
{
|
||||||
|
await Results.Problem(
|
||||||
|
title: "Permission denied",
|
||||||
|
detail: "You are missing the required permissions to access this endpoint",
|
||||||
|
statusCode: 403
|
||||||
|
)
|
||||||
|
.ExecuteAsync(context.HttpContext);
|
||||||
|
};
|
||||||
|
|
||||||
|
options.Events.OnSigningIn = async context =>
|
||||||
|
{
|
||||||
|
var userSyncService = context
|
||||||
|
.HttpContext
|
||||||
|
.RequestServices
|
||||||
|
.GetRequiredService<UserAuthService>();
|
||||||
|
|
||||||
|
var result = await userSyncService.SyncAsync(context.Principal);
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
context.Principal = new();
|
||||||
|
else
|
||||||
|
context.Properties.IsPersistent = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
options.Events.OnValidatePrincipal = async context =>
|
||||||
|
{
|
||||||
|
var userSyncService = context
|
||||||
|
.HttpContext
|
||||||
|
.RequestServices
|
||||||
|
.GetRequiredService<UserAuthService>();
|
||||||
|
|
||||||
|
var result = await userSyncService.ValidateAsync(context.Principal);
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
context.RejectPrincipal();
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.AddScheme<LocalAuthOptions, LocalAuthHandler>(LocalAuthConstants.AuthenticationScheme, "Local Auth", options =>
|
||||||
|
{
|
||||||
|
options.ForwardAuthenticate = "Session";
|
||||||
|
options.ForwardSignIn = "Session";
|
||||||
|
options.ForwardSignOut = "Session";
|
||||||
|
|
||||||
|
options.SignInScheme = "Session";
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.Services.AddAuthorization();
|
||||||
|
|
||||||
|
builder.Services.AddAuthorizationPermissions(options =>
|
||||||
|
{
|
||||||
|
options.ClaimName = "Permissions";
|
||||||
|
options.Prefix = "permissions:";
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.Services.AddScoped<UserAuthService>();
|
||||||
|
builder.Services.AddScoped<ApiKeyAuthService>();
|
||||||
|
|
||||||
|
// Setup data protection storage within storage folder
|
||||||
|
// so its persists in containers
|
||||||
|
var dpKeyPath = Path.Combine("storage", "dataProtectionKeys");
|
||||||
|
|
||||||
|
Directory.CreateDirectory(dpKeyPath);
|
||||||
|
|
||||||
|
builder.Services
|
||||||
|
.AddDataProtection()
|
||||||
|
.PersistKeysToFileSystem(
|
||||||
|
new DirectoryInfo(dpKeyPath)
|
||||||
|
);
|
||||||
|
|
||||||
|
builder.Services.AddScoped<UserDeletionService>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void UseAuth(this WebApplication application)
|
||||||
|
{
|
||||||
|
application.UseAuthentication();
|
||||||
|
application.UseAuthorization();
|
||||||
|
}
|
||||||
|
}
|
||||||
62
Moonlight.ApiServer/Startup/Startup.Base.cs
Normal file
62
Moonlight.ApiServer/Startup/Startup.Base.cs
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using MoonCore.Extended.Extensions;
|
||||||
|
using MoonCore.Extensions;
|
||||||
|
using MoonCore.Helpers;
|
||||||
|
using Moonlight.ApiServer.Configuration;
|
||||||
|
using Moonlight.ApiServer.Plugins;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Startup;
|
||||||
|
|
||||||
|
public static partial class Startup
|
||||||
|
{
|
||||||
|
private static void AddBase(this WebApplicationBuilder builder, IPluginStartup[] startups)
|
||||||
|
{
|
||||||
|
builder.Services.AutoAddServices<IAssemblyMarker>();
|
||||||
|
builder.Services.AddHttpClient();
|
||||||
|
|
||||||
|
builder.Services.AddApiExceptionHandler();
|
||||||
|
|
||||||
|
// Configure controllers
|
||||||
|
var mvcBuilder = builder.Services.AddControllers();
|
||||||
|
|
||||||
|
// Add plugin assemblies as application parts
|
||||||
|
foreach (var pluginStartup in startups.Select(x => x.GetType().Assembly).Distinct())
|
||||||
|
mvcBuilder.AddApplicationPart(pluginStartup.GetType().Assembly);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void UseBase(this WebApplication application)
|
||||||
|
{
|
||||||
|
application.UseRouting();
|
||||||
|
application.UseExceptionHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void MapBase(this WebApplication application)
|
||||||
|
{
|
||||||
|
application.MapControllers();
|
||||||
|
|
||||||
|
// Frontend
|
||||||
|
var configuration = AppConfiguration.CreateEmpty();
|
||||||
|
application.Configuration.Bind(configuration);
|
||||||
|
|
||||||
|
if (configuration.Frontend.EnableHosting)
|
||||||
|
application.MapFallbackToController("Index", "Frontend");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ConfigureKestrel(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
var configuration = AppConfiguration.CreateEmpty();
|
||||||
|
builder.Configuration.Bind(configuration);
|
||||||
|
|
||||||
|
builder.WebHost.ConfigureKestrel(kestrelOptions =>
|
||||||
|
{
|
||||||
|
var maxUploadInBytes = ByteConverter
|
||||||
|
.FromMegaBytes(configuration.Kestrel.UploadLimit)
|
||||||
|
.Bytes;
|
||||||
|
|
||||||
|
kestrelOptions.Limits.MaxRequestBodySize = maxUploadInBytes;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
29
Moonlight.ApiServer/Startup/Startup.Config.cs
Normal file
29
Moonlight.ApiServer/Startup/Startup.Config.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using MoonCore.EnvConfiguration;
|
||||||
|
using MoonCore.Yaml;
|
||||||
|
using Moonlight.ApiServer.Configuration;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Startup;
|
||||||
|
|
||||||
|
public static partial class Startup
|
||||||
|
{
|
||||||
|
private static void AddConfiguration(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
// Yaml
|
||||||
|
var yamlPath = Path.Combine("storage", "config.yml");
|
||||||
|
|
||||||
|
YamlDefaultGenerator.GenerateAsync<AppConfiguration>(yamlPath).Wait();
|
||||||
|
|
||||||
|
builder.Configuration.AddYamlFile(yamlPath);
|
||||||
|
|
||||||
|
// Env
|
||||||
|
builder.Configuration.AddEnvironmentVariables(prefix: "MOONLIGHT_", separator: "_");
|
||||||
|
|
||||||
|
var configuration = AppConfiguration.CreateEmpty();
|
||||||
|
builder.Configuration.Bind(configuration);
|
||||||
|
|
||||||
|
builder.Services.AddSingleton(configuration);
|
||||||
|
}
|
||||||
|
}
|
||||||
17
Moonlight.ApiServer/Startup/Startup.Database.cs
Normal file
17
Moonlight.ApiServer/Startup/Startup.Database.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using MoonCore.Extended.Abstractions;
|
||||||
|
using MoonCore.Extended.Extensions;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Startup;
|
||||||
|
|
||||||
|
public static partial class Startup
|
||||||
|
{
|
||||||
|
private static void AddDatabase(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
builder.Services.AddDbAutoMigrations();
|
||||||
|
builder.Services.AddDatabaseMappings();
|
||||||
|
|
||||||
|
builder.Services.AddScoped(typeof(DatabaseRepository<>));
|
||||||
|
}
|
||||||
|
}
|
||||||
45
Moonlight.ApiServer/Startup/Startup.Hangfire.cs
Normal file
45
Moonlight.ApiServer/Startup/Startup.Hangfire.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using Hangfire;
|
||||||
|
using Hangfire.EntityFrameworkCore;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Moonlight.ApiServer.Database;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Startup;
|
||||||
|
|
||||||
|
public static partial class Startup
|
||||||
|
{
|
||||||
|
private static void AddMoonlightHangfire(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
builder.Services.AddHangfire((provider, configuration) =>
|
||||||
|
{
|
||||||
|
configuration.SetDataCompatibilityLevel(CompatibilityLevel.Version_180);
|
||||||
|
configuration.UseSimpleAssemblyNameTypeSerializer();
|
||||||
|
configuration.UseRecommendedSerializerSettings();
|
||||||
|
configuration.UseEFCoreStorage(() =>
|
||||||
|
{
|
||||||
|
var scope = provider.CreateScope();
|
||||||
|
return scope.ServiceProvider.GetRequiredService<CoreDataContext>();
|
||||||
|
}, new EFCoreStorageOptions());
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.Services.AddHangfireServer();
|
||||||
|
|
||||||
|
builder.Logging.AddFilter(
|
||||||
|
"Hangfire.Server.BackgroundServerProcess",
|
||||||
|
LogLevel.Warning
|
||||||
|
);
|
||||||
|
|
||||||
|
builder.Logging.AddFilter(
|
||||||
|
"Hangfire.BackgroundJobServer",
|
||||||
|
LogLevel.Warning
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void UseMoonlightHangfire(this WebApplication application)
|
||||||
|
{
|
||||||
|
if (application.Environment.IsDevelopment())
|
||||||
|
application.UseHangfireDashboard();
|
||||||
|
}
|
||||||
|
}
|
||||||
57
Moonlight.ApiServer/Startup/Startup.Logging.cs
Normal file
57
Moonlight.ApiServer/Startup/Startup.Logging.cs
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using MoonCore.Logging;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Startup;
|
||||||
|
|
||||||
|
public static partial class Startup
|
||||||
|
{
|
||||||
|
private static void AddLogging(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
// Logging providers
|
||||||
|
builder.Logging.ClearProviders();
|
||||||
|
|
||||||
|
builder.Logging.AddAnsiConsole();
|
||||||
|
builder.Logging.AddFile(Path.Combine("storage", "logs", "moonlight.log"));
|
||||||
|
|
||||||
|
// Logging levels
|
||||||
|
var logConfigPath = Path.Combine("storage", "logConfig.json");
|
||||||
|
|
||||||
|
// Ensure default log levels exist
|
||||||
|
if (!File.Exists(logConfigPath))
|
||||||
|
{
|
||||||
|
var defaultLogLevels = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "Default", "Information" },
|
||||||
|
{ "Microsoft.AspNetCore", "Warning" },
|
||||||
|
{ "System.Net.Http.HttpClient", "Warning" },
|
||||||
|
{ "Moonlight.ApiServer.Implementations.LocalAuth.LocalAuthHandler", "Warning" }
|
||||||
|
};
|
||||||
|
|
||||||
|
var logLevelsJson = JsonSerializer.Serialize(defaultLogLevels);
|
||||||
|
File.WriteAllText(logConfigPath, logLevelsJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read log levels
|
||||||
|
var logLevels = JsonSerializer.Deserialize<Dictionary<string, string>>(
|
||||||
|
File.ReadAllText(logConfigPath)
|
||||||
|
)!;
|
||||||
|
|
||||||
|
// Apply configured log levels
|
||||||
|
foreach (var level in logLevels)
|
||||||
|
builder.Logging.AddFilter(level.Key, Enum.Parse<LogLevel>(level.Value));
|
||||||
|
|
||||||
|
// Mute exception handler middleware
|
||||||
|
// https://github.com/dotnet/aspnetcore/issues/19740
|
||||||
|
builder.Logging.AddFilter(
|
||||||
|
"Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware",
|
||||||
|
LogLevel.Critical
|
||||||
|
);
|
||||||
|
|
||||||
|
builder.Logging.AddFilter(
|
||||||
|
"Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware",
|
||||||
|
LogLevel.Critical
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
70
Moonlight.ApiServer/Startup/Startup.Misc.cs
Normal file
70
Moonlight.ApiServer/Startup/Startup.Misc.cs
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Cors.Infrastructure;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Moonlight.ApiServer.Configuration;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Startup;
|
||||||
|
|
||||||
|
public static partial class Startup
|
||||||
|
{
|
||||||
|
private static void PrintVersionAsync()
|
||||||
|
{
|
||||||
|
// Fancy start console output... yes very fancy :>
|
||||||
|
var rainbow = new Crayon.Rainbow(0.5);
|
||||||
|
foreach (var c in "Moonlight")
|
||||||
|
{
|
||||||
|
Console.Write(
|
||||||
|
rainbow
|
||||||
|
.Next()
|
||||||
|
.Bold()
|
||||||
|
.Text(c.ToString())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void CreateStorageAsync()
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory("storage");
|
||||||
|
Directory.CreateDirectory(Path.Combine("storage", "logs"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddMoonlightCors(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
var configuration = AppConfiguration.CreateEmpty();
|
||||||
|
builder.Configuration.Bind(configuration);
|
||||||
|
|
||||||
|
var allowedOrigins = configuration.Kestrel.AllowedOrigins;
|
||||||
|
|
||||||
|
builder.Services.AddCors(options =>
|
||||||
|
{
|
||||||
|
var cors = new CorsPolicyBuilder();
|
||||||
|
|
||||||
|
if (allowedOrigins.Contains("*"))
|
||||||
|
{
|
||||||
|
cors.SetIsOriginAllowed(_ => true)
|
||||||
|
.AllowAnyMethod()
|
||||||
|
.AllowAnyHeader()
|
||||||
|
.AllowCredentials();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cors.WithOrigins(allowedOrigins)
|
||||||
|
.AllowAnyHeader()
|
||||||
|
.AllowAnyMethod()
|
||||||
|
.AllowCredentials();
|
||||||
|
}
|
||||||
|
|
||||||
|
options.AddDefaultPolicy(
|
||||||
|
cors.Build()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void UseMoonlightCors(this WebApplication application)
|
||||||
|
{
|
||||||
|
application.UseCors();
|
||||||
|
}
|
||||||
|
}
|
||||||
25
Moonlight.ApiServer/Startup/Startup.Plugins.cs
Normal file
25
Moonlight.ApiServer/Startup/Startup.Plugins.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Moonlight.ApiServer.Plugins;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Startup;
|
||||||
|
|
||||||
|
public static partial class Startup
|
||||||
|
{
|
||||||
|
private static void AddPlugins(this WebApplicationBuilder builder, IPluginStartup[] startups)
|
||||||
|
{
|
||||||
|
foreach (var startup in startups)
|
||||||
|
startup.AddPlugin(builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void UsePlugins(this WebApplication application, IPluginStartup[] startups)
|
||||||
|
{
|
||||||
|
foreach (var startup in startups)
|
||||||
|
startup.UsePlugin(application);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void MapPlugins(this WebApplication application, IPluginStartup[] startups)
|
||||||
|
{
|
||||||
|
foreach (var startup in startups)
|
||||||
|
startup.MapPlugin(application);
|
||||||
|
}
|
||||||
|
}
|
||||||
26
Moonlight.ApiServer/Startup/Startup.SignalR.cs
Normal file
26
Moonlight.ApiServer/Startup/Startup.SignalR.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Moonlight.ApiServer.Configuration;
|
||||||
|
using Moonlight.ApiServer.Http.Hubs;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Startup;
|
||||||
|
|
||||||
|
public static partial class Startup
|
||||||
|
{
|
||||||
|
private static void AddMoonlightSignalR(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
var configuration = AppConfiguration.CreateEmpty();
|
||||||
|
builder.Configuration.Bind(configuration);
|
||||||
|
|
||||||
|
var signalRBuilder = builder.Services.AddSignalR();
|
||||||
|
|
||||||
|
if (configuration.SignalR.UseRedis)
|
||||||
|
signalRBuilder.AddStackExchangeRedis(configuration.SignalR.RedisConnectionString);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void MapMoonlightSignalR(this WebApplication application)
|
||||||
|
{
|
||||||
|
application.MapHub<DiagnoseHub>("/api/admin/system/diagnose/ws");
|
||||||
|
}
|
||||||
|
}
|
||||||
42
Moonlight.ApiServer/Startup/Startup.cs
Normal file
42
Moonlight.ApiServer/Startup/Startup.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Moonlight.ApiServer.Plugins;
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Startup;
|
||||||
|
|
||||||
|
public static partial class Startup
|
||||||
|
{
|
||||||
|
public static void AddMoonlight(this WebApplicationBuilder builder, IPluginStartup[] startups)
|
||||||
|
{
|
||||||
|
PrintVersionAsync();
|
||||||
|
CreateStorageAsync();
|
||||||
|
|
||||||
|
builder.AddConfiguration();
|
||||||
|
builder.AddLogging();
|
||||||
|
|
||||||
|
builder.ConfigureKestrel();
|
||||||
|
builder.AddBase(startups);
|
||||||
|
builder.AddDatabase();
|
||||||
|
builder.AddAuth();
|
||||||
|
builder.AddMoonlightCors();
|
||||||
|
builder.AddMoonlightHangfire();
|
||||||
|
builder.AddMoonlightSignalR();
|
||||||
|
|
||||||
|
builder.AddPlugins(startups);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void UseMoonlight(this WebApplication application, IPluginStartup[] startups)
|
||||||
|
{
|
||||||
|
application.UseBase();
|
||||||
|
application.UseMoonlightCors();
|
||||||
|
application.UseAuth();
|
||||||
|
application.UseMoonlightHangfire();
|
||||||
|
application.UsePlugins(startups);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void MapMoonlight(this WebApplication application, IPluginStartup[] startups)
|
||||||
|
{
|
||||||
|
application.MapBase();
|
||||||
|
application.MapMoonlightSignalR();
|
||||||
|
application.MapPlugins(startups);
|
||||||
|
}
|
||||||
|
}
|
||||||
28
Moonlight.Client.Runtime/Moonlight.Client.Runtime.csproj
Normal file
28
Moonlight.Client.Runtime/Moonlight.Client.Runtime.csproj
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<NoDefaultLaunchSettingsFile>True</NoDefaultLaunchSettingsFile>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Moonlight.Client\Moonlight.Client.csproj"/>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MoonCore.PluginFramework" Version="1.0.9" />
|
||||||
|
<PackageReference Include="MoonCore.PluginFramework.Generator" Version="1.0.3" />
|
||||||
|
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.9" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.9" PrivateAssets="all" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="wwwroot\css\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Import Project="Plugins.props" />
|
||||||
|
|
||||||
|
</Project>
|
||||||
10
Moonlight.Client.Runtime/PluginLoader.cs
Normal file
10
Moonlight.Client.Runtime/PluginLoader.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using MoonCore.PluginFramework;
|
||||||
|
using Moonlight.Client.Plugins;
|
||||||
|
|
||||||
|
namespace Moonlight.Client.Runtime;
|
||||||
|
|
||||||
|
[PluginLoader]
|
||||||
|
public partial class PluginLoader : IPluginStartup
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
4
Moonlight.Client.Runtime/Plugins.props
Normal file
4
Moonlight.Client.Runtime/Plugins.props
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<Project>
|
||||||
|
<ItemGroup>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
16
Moonlight.Client.Runtime/Program.cs
Normal file
16
Moonlight.Client.Runtime/Program.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||||||
|
using Moonlight.Client.Runtime;
|
||||||
|
using Moonlight.Client.Startup;
|
||||||
|
|
||||||
|
var pluginLoader = new PluginLoader();
|
||||||
|
pluginLoader.Initialize();
|
||||||
|
|
||||||
|
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
||||||
|
|
||||||
|
builder.AddMoonlight(pluginLoader.Instances);
|
||||||
|
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
|
app.ConfigureMoonlight(pluginLoader.Instances);
|
||||||
|
|
||||||
|
await app.RunAsync();
|
||||||
14
Moonlight.Client.Runtime/Properties/launchSettings.json
Normal file
14
Moonlight.Client.Runtime/Properties/launchSettings.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"profiles": {
|
||||||
|
"http": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": false,
|
||||||
|
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
|
||||||
|
"applicationUrl": "http://localhost:5165",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user