Compare commits
816 Commits
v1b15
...
feat/Restr
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d1e6e1690 | |||
| 1257e8b950 | |||
| 93de9c5d00 | |||
| 3dff8c8f6d | |||
| 95a848e571 | |||
| 9d557eea4e | |||
| 94c1aac0ac | |||
| 3bddd64d91 | |||
| 5ad7a6db7b | |||
| 9b9272cd6e | |||
| 31cf34ed04 | |||
| a9b0020131 | |||
| e3b432aae6 | |||
| 06f27605ba | |||
| 0bd138df63 | |||
| d7b725f541 | |||
| 0f26aaf803 | |||
| c45e177001 | |||
| 627e9bb161 | |||
| 1fc33ebf03 | |||
| 64e4d7201e | |||
| 816aa01319 | |||
| 5627e78843 | |||
| 795cec149f | |||
| 83fcb4a921 | |||
| 741a60adc6 | |||
| 6f941a220c | |||
| dd44e5bb86 | |||
| 7b38662f8f | |||
| 6d854d82d3 | |||
| ac1c28d20d | |||
| 5efe591f85 | |||
| 4daf986f3e | |||
| cc7f55c988 | |||
| 11a2f9818a | |||
| 6a151394a7 | |||
| 178ac5ac20 | |||
| 91944a5ef6 | |||
| affdadf3aa | |||
| 8d9a7bb8b3 | |||
| 1f631be1c7 | |||
| 5b4959771c | |||
| b8e1bbb28c | |||
| c8fe11bd2b | |||
| 09b11cc4ad | |||
| 660319afec | |||
| 8181404f0c | |||
| e1207b8d9b | |||
| 97a676ccd7 | |||
| 136620f1e6 | |||
| 9b11360a0e | |||
| deb69e6014 | |||
| 4e96905fb2 | |||
| e2f344ab4e | |||
| 76a8a72e83 | |||
| 3e302198a2 | |||
| 4187f9da4e | |||
| d85b07bde7 | |||
| 3cbdd3b203 | |||
| 56b14f60f1 | |||
| 01c86406dc | |||
| a28b8aca7a | |||
| bee381702b | |||
| 10cd0f0b09 | |||
| fcaa0dcd07 | |||
| ea35ddb0dc | |||
| b4536ca6e9 | |||
| 7f482fd6c3 | |||
| 1d1dfc2c1c | |||
| a197d7d980 | |||
| 06063b94b3 | |||
| 43d43a6d7d | |||
| 1849cda2f5 | |||
| f836657603 | |||
| 7e0b427137 | |||
| b79c8fe476 | |||
| f71bad3da3 | |||
| 170cac2091 | |||
| ba942b2f8f | |||
| 05c05f1b72 | |||
| ec6782160c | |||
| 1581276854 | |||
| e1c0645428 | |||
| be3cdb8235 | |||
| bfc7d9993a | |||
| ca69d410f2 | |||
| a2d4edc0e5 | |||
| 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 | ||
|
|
f48ec2245c | ||
|
|
37a3a35120 | ||
|
|
c549d45d54 | ||
|
|
42a011541c | ||
|
|
71a8839f5f | ||
|
|
b99e8b5476 | ||
|
|
5793bd9747 | ||
|
|
24ce51a62e | ||
|
|
762d3cc1a1 | ||
|
|
ea19105006 | ||
|
|
a372c756e4 | ||
|
|
18b7c82613 | ||
|
|
5d91077d42 | ||
|
|
c0872d0d02 | ||
|
|
00722c4046 | ||
|
|
f16a29dafb | ||
|
|
6da8393612 | ||
|
|
2ef00b81b8 | ||
|
|
0be4ebc7ff | ||
|
|
e0d5e754b7 | ||
|
|
6972c2bb32 | ||
|
|
95ba81eab4 | ||
|
|
b9c094cafa | ||
|
|
bada1e829b | ||
|
|
1d33cf3110 | ||
|
|
abfcefba60 | ||
|
|
6efb443481 | ||
|
|
10c017932a | ||
|
|
a4be4bdc52 | ||
|
|
88d5a1de86 | ||
|
|
1b88827d16 | ||
|
|
12e25dc4bc | ||
|
|
37c3fc7a53 | ||
|
|
0c6cbe0ba7 | ||
|
|
5cf63240a3 | ||
|
|
4d04d12a39 | ||
|
|
b846b28802 | ||
|
|
b94217abc0 | ||
|
|
de0d6a3808 | ||
|
|
eca9b6ec52 | ||
|
|
b6e048e982 | ||
|
|
b8b2ae7865 | ||
|
|
0611988019 | ||
|
|
f9fd7199b6 | ||
|
|
6ff4861fc6 | ||
|
|
2db7748703 | ||
|
|
87744e4846 | ||
|
|
ce7125b50b | ||
|
|
31d8c3f469 | ||
|
|
c80622c2fd | ||
|
|
95e659e5f7 | ||
|
|
c155909e82 | ||
|
|
0011ed29b7 | ||
|
|
52c4ca0c0a | ||
|
|
c197d0ca96 | ||
|
|
25902034e9 | ||
|
|
b10db643fe | ||
|
|
4c7ffe6714 | ||
|
|
a0c2b45a61 | ||
|
|
e49a9d3505 | ||
|
|
7ddae9c3e1 | ||
|
|
290e865ae0 | ||
|
|
00ee625e2e | ||
|
|
274e2d93f2 | ||
|
|
781171f7c5 | ||
|
|
4a8618da79 | ||
|
|
296cf0db6f | ||
|
|
48cdba5155 | ||
|
|
35c1b255b5 | ||
|
|
244b920305 | ||
|
|
3d4a2128e2 | ||
|
|
1cf8430ad8 | ||
|
|
a9b7d10fb0 | ||
|
|
47e333630e | ||
|
|
8b41a9fc13 | ||
|
|
d09957fdac | ||
|
|
f9ecb61d71 | ||
|
|
ef92dd47ad | ||
|
|
c2c533675b | ||
|
|
569dd69bdd | ||
|
|
242870b3e1 | ||
|
|
30b6e45235 | ||
|
|
cd62fdc5f6 | ||
|
|
2c54b91e6c | ||
|
|
388deacf60 | ||
|
|
aa547038de | ||
|
|
78bfd68d63 | ||
|
|
17e3345b8a | ||
|
|
f95312c1e3 | ||
|
|
2144ca3823 | ||
|
|
de45ff40d8 | ||
|
|
606085c012 | ||
|
|
00525d8099 | ||
|
|
26617d67f5 | ||
|
|
600bec3417 | ||
|
|
4e85d1755a | ||
|
|
0832936933 | ||
|
|
ecda2ec6d1 | ||
|
|
6f3765a3bf | ||
|
|
29002d3445 | ||
|
|
6d0456a008 | ||
|
|
3e698123bb | ||
|
|
f3fb86819a | ||
|
|
e2248a8444 | ||
|
|
2cf2b77090 | ||
|
|
fedc9278d4 | ||
|
|
f29206a69b | ||
|
|
0658e55a78 | ||
|
|
21bea974a9 | ||
|
|
33ef09433e | ||
|
|
173bff67df | ||
|
|
512a989609 | ||
|
|
2d7dac5089 |
@@ -1,5 +1,4 @@
|
|||||||
**/.classpath
|
**/.dockerignore
|
||||||
**/.dockerignore
|
|
||||||
**/.env
|
**/.env
|
||||||
**/.git
|
**/.git
|
||||||
**/.gitignore
|
**/.gitignore
|
||||||
@@ -8,6 +7,7 @@
|
|||||||
**/.toolstarget
|
**/.toolstarget
|
||||||
**/.vs
|
**/.vs
|
||||||
**/.vscode
|
**/.vscode
|
||||||
|
**/.idea
|
||||||
**/*.*proj.user
|
**/*.*proj.user
|
||||||
**/*.dbmdl
|
**/*.dbmdl
|
||||||
**/*.jfm
|
**/*.jfm
|
||||||
@@ -21,5 +21,10 @@
|
|||||||
**/obj
|
**/obj
|
||||||
**/secrets.dev.yaml
|
**/secrets.dev.yaml
|
||||||
**/values.dev.yaml
|
**/values.dev.yaml
|
||||||
|
**/appsettings.json
|
||||||
|
**/appsettings.Development.json
|
||||||
|
**/appsettings*
|
||||||
|
**/compose.*
|
||||||
|
**/.env.example
|
||||||
LICENSE
|
LICENSE
|
||||||
README.md
|
README.md
|
||||||
10
.env.example
Normal file
10
.env.example
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
DATABASE_HOST=localhost
|
||||||
|
DATABASE_PORT=5432
|
||||||
|
DATABASE_USERNAME=user
|
||||||
|
DATABASE_PASSWORD=user
|
||||||
|
DATABASE_DATABASE=user
|
||||||
|
OIDC_AUTHORITY=http://localhost:8092
|
||||||
|
OIDC_AUTHORITY=http://localhost:8092
|
||||||
|
OIDC_CLIENT_ID=client_id
|
||||||
|
OIDC_CLIENT_SECRET=client_secret
|
||||||
|
OIDC_REQUIRE_HTTPS_METADATA=false
|
||||||
10
.gitattributes
vendored
10
.gitattributes
vendored
@@ -1,10 +0,0 @@
|
|||||||
# Auto detect text files and perform LF normalization
|
|
||||||
* 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
|
|
||||||
66
.gitea/workflows/publish-nuget.yml
Normal file
66
.gitea/workflows/publish-nuget.yml
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
name: "Dev Publish: Nuget"
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- v2.1
|
||||||
|
paths:
|
||||||
|
- 'Moonlight.*/*.csproj'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
publish:
|
||||||
|
name: Publish Dev Packages
|
||||||
|
|
||||||
|
runs-on: linux_amd64
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# Publish api server
|
||||||
|
- name: Build project
|
||||||
|
run: dotnet build Moonlight.Api --configuration Debug
|
||||||
|
|
||||||
|
- name: Publish NuGet package
|
||||||
|
run: dotnet pack Moonlight.Api --configuration Debug --output ./artifacts
|
||||||
|
|
||||||
|
- name: Push nuget package
|
||||||
|
run: dotnet nuget push ./artifacts/*.nupkg --skip-duplicate --source https://git.battlestati.one/api/packages/Moonlight-Panel/nuget/index.json --api-key ${{ secrets.ACCESS_TOKEN }}
|
||||||
|
|
||||||
|
- name: Remove artifacts
|
||||||
|
run: rm -rf ./artifacts
|
||||||
|
|
||||||
|
# Publish frontend
|
||||||
|
# We need to build it first so the class list files generate
|
||||||
|
- name: Build project
|
||||||
|
run: dotnet build Hosts/Moonlight.Frontend.Host --configuration Debug
|
||||||
|
|
||||||
|
- name: Build tailwind styles and extract class list
|
||||||
|
working-directory: Hosts/Moonlight.Frontend.Host/Styles
|
||||||
|
run: npm install && npm run build
|
||||||
|
|
||||||
|
- name: Build project
|
||||||
|
run: dotnet build Moonlight.Frontend --configuration Debug
|
||||||
|
|
||||||
|
- name: Publish NuGet package
|
||||||
|
run: dotnet pack Moonlight.Frontend --configuration Debug --output ./artifacts
|
||||||
|
|
||||||
|
- name: Push nuget package
|
||||||
|
run: dotnet nuget push ./artifacts/*.nupkg --skip-duplicate --source https://git.battlestati.one/api/packages/Moonlight-Panel/nuget/index.json --api-key ${{ secrets.ACCESS_TOKEN }}
|
||||||
|
|
||||||
|
- name: Remove artifacts
|
||||||
|
run: rm -rf ./artifacts
|
||||||
|
|
||||||
|
# Publish shared
|
||||||
|
- name: Build project
|
||||||
|
run: dotnet build Moonlight.Shared --configuration Debug
|
||||||
|
|
||||||
|
- name: Publish NuGet package
|
||||||
|
run: dotnet pack Moonlight.Shared --configuration Debug --output ./artifacts
|
||||||
|
|
||||||
|
- name: Push nuget package
|
||||||
|
run: dotnet nuget push ./artifacts/*.nupkg --skip-duplicate --source https://git.battlestati.one/api/packages/Moonlight-Panel/nuget/index.json --api-key ${{ secrets.ACCESS_TOKEN }}
|
||||||
|
|
||||||
|
- name: Remove artifacts
|
||||||
|
run: rm -rf ./artifacts
|
||||||
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 .
|
|
||||||
438
.gitignore
vendored
438
.gitignore
vendored
@@ -1,45 +1,409 @@
|
|||||||
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
|
||||||
|
|
||||||
storage/
|
# Business Intelligence projects
|
||||||
Moonlight/publish.ps1
|
*.rdl.data
|
||||||
Moonlight/version
|
*.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
|
||||||
|
**/.idea/**
|
||||||
|
|
||||||
|
# Style builds
|
||||||
|
**/style.min.css
|
||||||
|
**/package-lock.json
|
||||||
|
**/bun.lock
|
||||||
|
|
||||||
|
# Secrets
|
||||||
|
**/.env
|
||||||
|
**/appsettings.json
|
||||||
|
**/appsettings.Development.json
|
||||||
|
**/storage
|
||||||
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>
|
|
||||||
14
.idea/.idea.Moonlight/.idea/icon.svg
generated
14
.idea/.idea.Moonlight/.idea/icon.svg
generated
@@ -1,14 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<svg width="256px" height="301px" viewBox="0 0 256 301" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid">
|
|
||||||
<defs>
|
|
||||||
<linearGradient x1="2.17771739%" y1="34.7938955%" x2="92.7221942%" y2="91.3419405%" id="linearGradient-1">
|
|
||||||
<stop stop-color="#41A7EF" offset="0%"></stop>
|
|
||||||
<stop stop-color="#813DDE" offset="54.2186236%"></stop>
|
|
||||||
<stop stop-color="#8F2EE2" offset="74.4988788%"></stop>
|
|
||||||
<stop stop-color="#A11CE6" offset="100%"></stop>
|
|
||||||
</linearGradient>
|
|
||||||
</defs>
|
|
||||||
<g>
|
|
||||||
<path d="M124.183681,101.699 C124.183681,66.515 136.256681,34.152 156.486681,8.525 C159.197681,5.092 156.787681,0.069 152.412681,0.012 C151.775681,0.004 151.136681,0 150.497681,0 C67.6206813,0 0.390681343,66.99 0.00168134279,149.775 C-0.386318657,232.369 66.4286813,300.195 149.019681,300.988 C189.884681,301.381 227.036681,285.484 254.376681,259.395 C257.519681,256.396 255.841681,251.082 251.548681,250.42 C179.413681,239.291 124.183681,176.949 124.183681,101.699" fill="url(#linearGradient-1)"></path>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 1.1 KiB |
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>
|
|
||||||
6
Hosts/Moonlight.Api.Host/Api.props
Normal file
6
Hosts/Moonlight.Api.Host/Api.props
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<Project>
|
||||||
|
<ItemGroup>
|
||||||
|
<!-- Put your plugin references here -->
|
||||||
|
<!-- E.g. <PackageReference Include="MoonlightServers.Api" Version="2.1.0" /> -->
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
77
Hosts/Moonlight.Api.Host/Dockerfile
Normal file
77
Hosts/Moonlight.Api.Host/Dockerfile
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
# Base image
|
||||||
|
FROM git.battlestati.one/moonlight-panel/app_base:moonlight AS base
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
||||||
|
|
||||||
|
# Install required packages
|
||||||
|
RUN apt-get update; apt-get install unzip -y; apt-get clean
|
||||||
|
RUN curl -fsSL https://bun.sh/install | bash
|
||||||
|
ENV PATH="/root/.bun/bin:${PATH}"
|
||||||
|
|
||||||
|
# Build options
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
|
||||||
|
# Download npm packages
|
||||||
|
WORKDIR /src/Hosts/Moonlight.Frontend.Host/Styles
|
||||||
|
|
||||||
|
COPY ["Hosts/Moonlight.Frontend.Host/Styles/package.json", "package.json"]
|
||||||
|
|
||||||
|
RUN bun install
|
||||||
|
|
||||||
|
# Restore nuget packages
|
||||||
|
WORKDIR /src
|
||||||
|
|
||||||
|
COPY ["Moonlight.Api/Moonlight.Api.csproj", "Moonlight.Api/"]
|
||||||
|
COPY ["Moonlight.Frontend/Moonlight.Frontend.csproj", "Moonlight.Frontend/"]
|
||||||
|
COPY ["Moonlight.Shared/Moonlight.Shared.csproj", "Moonlight.Shared/"]
|
||||||
|
|
||||||
|
COPY ["Hosts/Moonlight.Frontend.Host/Moonlight.Frontend.Host.csproj", "Hosts/Moonlight.Frontend.Host/"]
|
||||||
|
COPY ["Hosts/Moonlight.Api.Host/Moonlight.Api.Host.csproj", "Hosts/Moonlight.Api.Host/"]
|
||||||
|
|
||||||
|
COPY ["Hosts/Moonlight.Frontend.Host/Frontend.props", "Hosts/Moonlight.Frontend.Host/"]
|
||||||
|
COPY ["Hosts/Moonlight.Api.Host/Api.props", "Hosts/Moonlight.Api.Host/"]
|
||||||
|
|
||||||
|
RUN dotnet restore "Hosts/Moonlight.Api.Host/Moonlight.Api.Host.csproj"
|
||||||
|
RUN dotnet restore "Hosts/Moonlight.Frontend.Host/Moonlight.Frontend.Host.csproj"
|
||||||
|
|
||||||
|
# Copy over the whole sources
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Build styles
|
||||||
|
# We need to build it before, so the class lists get generated
|
||||||
|
WORKDIR "/src/Hosts/Moonlight.Frontend.Host"
|
||||||
|
RUN dotnet build "./Moonlight.Frontend.Host.csproj" -c $BUILD_CONFIGURATION -o /app/build-frontend
|
||||||
|
|
||||||
|
WORKDIR "/src/Hosts/Moonlight.Frontend.Host/Styles"
|
||||||
|
RUN bun run build
|
||||||
|
|
||||||
|
# Build projects
|
||||||
|
WORKDIR "/src/Hosts/Moonlight.Api.Host"
|
||||||
|
RUN dotnet build "./Moonlight.Api.Host.csproj" -c $BUILD_CONFIGURATION -o /app/build-api
|
||||||
|
|
||||||
|
WORKDIR "/src/Hosts/Moonlight.Frontend.Host"
|
||||||
|
RUN dotnet build "./Moonlight.Frontend.Host.csproj" -c $BUILD_CONFIGURATION -o /app/build-frontend
|
||||||
|
|
||||||
|
FROM build AS publish
|
||||||
|
|
||||||
|
# Publish options
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
|
||||||
|
# Publish applications
|
||||||
|
WORKDIR "/src/Hosts/Moonlight.Api.Host"
|
||||||
|
RUN dotnet publish "./Moonlight.Api.Host.csproj" -c $BUILD_CONFIGURATION -o /app/publish-api /p:UseAppHost=false
|
||||||
|
|
||||||
|
WORKDIR "/src/Hosts/Moonlight.Frontend.Host"
|
||||||
|
RUN dotnet publish "./Moonlight.Frontend.Host.csproj" -c $BUILD_CONFIGURATION -o /app/publish-frontend /p:UseAppHost=false
|
||||||
|
|
||||||
|
FROM base AS final
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY --from=publish /app/publish-api .
|
||||||
|
COPY --from=publish /app/publish-frontend/wwwroot ./wwwroot
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 CMD ["/usr/bin/curl", "-sf", "-o", "/dev/null", "http://localhost:8080/"]
|
||||||
|
|
||||||
|
ENTRYPOINT ["dotnet", "Moonlight.Api.Host.dll"]
|
||||||
31
Hosts/Moonlight.Api.Host/Moonlight.Api.Host.csproj
Normal file
31
Hosts/Moonlight.Api.Host/Moonlight.Api.Host.csproj
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.5">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
|
||||||
|
<PackageReference Include="SimplePlugin" Version="1.0.2"/>
|
||||||
|
<PackageReference Include="SimplePlugin.Abstractions" Version="1.0.2"/>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\Moonlight.Api\Moonlight.Api.csproj"/>
|
||||||
|
<ProjectReference Include="..\Moonlight.Frontend.Host\Moonlight.Frontend.Host.csproj"/>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="..\..\.dockerignore">
|
||||||
|
<Link>.dockerignore</Link>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Import Project="Api.props"/>
|
||||||
|
</Project>
|
||||||
9
Hosts/Moonlight.Api.Host/Program.cs
Normal file
9
Hosts/Moonlight.Api.Host/Program.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using Moonlight.Api;
|
||||||
|
using SimplePlugin.Generated;
|
||||||
|
|
||||||
|
var plugins = PluginRegistry
|
||||||
|
.Modules
|
||||||
|
.OfType<MoonlightPlugin>()
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
await StartupHandler.RunAsync(args, plugins);
|
||||||
14
Hosts/Moonlight.Api.Host/Properties/launchSettings.json
Normal file
14
Hosts/Moonlight.Api.Host/Properties/launchSettings.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||||
|
"profiles": {
|
||||||
|
"http": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": false,
|
||||||
|
"applicationUrl": "http://localhost:5240",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
6
Hosts/Moonlight.Frontend.Host/Frontend.props
Normal file
6
Hosts/Moonlight.Frontend.Host/Frontend.props
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<Project>
|
||||||
|
<ItemGroup>
|
||||||
|
<!-- Put your plugin references here -->
|
||||||
|
<!-- E.g. <PackageReference Include="MoonlightServers.Frontend" Version="2.1.0" /> -->
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
28
Hosts/Moonlight.Frontend.Host/Moonlight.Frontend.Host.csproj
Normal file
28
Hosts/Moonlight.Frontend.Host/Moonlight.Frontend.Host.csproj
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
|
||||||
|
<StaticWebAssetsEnabled>True</StaticWebAssetsEnabled>
|
||||||
|
<OverrideHtmlAssetPlaceholders>true</OverrideHtmlAssetPlaceholders>
|
||||||
|
<WasmEnableSIMD>true</WasmEnableSIMD>
|
||||||
|
<PublishTrimmed>true</PublishTrimmed>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.5" />
|
||||||
|
<PackageReference Include="Microsoft.DotNet.HotReload.WebAssembly.Browser" Version="10.0.201" />
|
||||||
|
<PackageReference Include="Microsoft.NET.ILLink.Tasks" Version="10.0.5" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Sdk.WebAssembly.Pack" Version="10.0.5" />
|
||||||
|
<PackageReference Include="SimplePlugin" Version="1.0.2"/>
|
||||||
|
<PackageReference Include="SimplePlugin.Abstractions" Version="1.0.2"/>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\Moonlight.Frontend\Moonlight.Frontend.csproj"/>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Import Project="Frontend.props"/>
|
||||||
|
</Project>
|
||||||
9
Hosts/Moonlight.Frontend.Host/Program.cs
Normal file
9
Hosts/Moonlight.Frontend.Host/Program.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using Moonlight.Frontend;
|
||||||
|
using SimplePlugin.Generated;
|
||||||
|
|
||||||
|
var plugins = PluginRegistry
|
||||||
|
.Modules
|
||||||
|
.OfType<MoonlightPlugin>()
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
await StartupHandler.RunAsync(args, plugins);
|
||||||
15
Hosts/Moonlight.Frontend.Host/Properties/launchSettings.json
Normal file
15
Hosts/Moonlight.Frontend.Host/Properties/launchSettings.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||||
|
"profiles": {
|
||||||
|
"http": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": true,
|
||||||
|
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
|
||||||
|
"applicationUrl": "http://localhost:5250",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
25
Hosts/Moonlight.Frontend.Host/Styles/extract-classes.mjs
Normal file
25
Hosts/Moonlight.Frontend.Host/Styles/extract-classes.mjs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
import selectorParser from 'postcss-selector-parser';
|
||||||
|
|
||||||
|
export default function extractTailwindClasses(opts = {}) {
|
||||||
|
const classSet = new Set();
|
||||||
|
|
||||||
|
return {
|
||||||
|
postcssPlugin: 'extract-tailwind-classes',
|
||||||
|
Rule(rule) {
|
||||||
|
selectorParser(selectors => {
|
||||||
|
selectors.walkClasses(node => {
|
||||||
|
classSet.add(node.value);
|
||||||
|
});
|
||||||
|
}).processSync(rule.selector);
|
||||||
|
},
|
||||||
|
OnceExit() {
|
||||||
|
const classArray = Array.from(classSet).sort();
|
||||||
|
fs.mkdirSync('../../../Moonlight.Frontend/Styles', {recursive: true});
|
||||||
|
fs.writeFileSync('../../../Moonlight.Frontend/Styles/Moonlight.Frontend.map', classArray.join('\n'));
|
||||||
|
console.log(`Extracted classes ${classArray.length}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
extractTailwindClasses.postcss = true;
|
||||||
19
Hosts/Moonlight.Frontend.Host/Styles/package.json
Normal file
19
Hosts/Moonlight.Frontend.Host/Styles/package.json
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"scripts": {
|
||||||
|
"dev": "npx postcss styles.css -o ../wwwroot/style.min.css --watch",
|
||||||
|
"dev-build": "npx postcss styles.css -o ../wwwroot/style.min.css",
|
||||||
|
"build": "cross-env EXTRACT_CLASSES=true npx postcss styles.css -o ../wwwroot/style.min.css"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@tailwindcss/postcss": "^4.1.18",
|
||||||
|
"cssnano": "^7.1.2",
|
||||||
|
"postcss": "^8.5.6",
|
||||||
|
"postcss-cli": "^11.0.1",
|
||||||
|
"postcss-selector-parser": "^7.1.1",
|
||||||
|
"tailwindcss": "^4.1.18",
|
||||||
|
"tw-animate-css": "^1.4.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"cross-env": "^10.1.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
18
Hosts/Moonlight.Frontend.Host/Styles/postcss.config.mjs
Normal file
18
Hosts/Moonlight.Frontend.Host/Styles/postcss.config.mjs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import tailwindcss from '@tailwindcss/postcss';
|
||||||
|
import cssnano from 'cssnano';
|
||||||
|
import extractTailwindClasses from './extract-classes.mjs';
|
||||||
|
|
||||||
|
const plugins = [
|
||||||
|
tailwindcss,
|
||||||
|
cssnano({
|
||||||
|
preset: 'default'
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
|
if (process.env.EXTRACT_CLASSES === "true") {
|
||||||
|
plugins.push(extractTailwindClasses());
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
plugins
|
||||||
|
};
|
||||||
32
Hosts/Moonlight.Frontend.Host/Styles/styles.css
Normal file
32
Hosts/Moonlight.Frontend.Host/Styles/styles.css
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
@import "tailwindcss";
|
||||||
|
@import "tw-animate-css";
|
||||||
|
|
||||||
|
@import "../bin/ShadcnBlazor/scrollbar.css";
|
||||||
|
@import "../bin/ShadcnBlazor/default-theme.css";
|
||||||
|
@import "./theme.css";
|
||||||
|
|
||||||
|
@source "../bin/ShadcnBlazor/ShadcnBlazor.map";
|
||||||
|
|
||||||
|
@source "../../../Moonlight.Api/**/*.razor";
|
||||||
|
@source "../../../Moonlight.Api/**/*.cs";
|
||||||
|
@source "../../../Moonlight.Api/**/*.html";
|
||||||
|
|
||||||
|
@source "../../../Moonlight.Frontend/**/*.razor";
|
||||||
|
@source "../../../Moonlight.Frontend/**/*.cs";
|
||||||
|
@source "../../../Moonlight.Frontend/**/*.html";
|
||||||
|
|
||||||
|
@custom-variant dark (&:is(.dark *));
|
||||||
|
|
||||||
|
#blazor-error-ui {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
@layer base {
|
||||||
|
* {
|
||||||
|
@apply border-border outline-ring/50;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
@apply bg-background text-foreground;
|
||||||
|
}
|
||||||
|
}
|
||||||
132
Hosts/Moonlight.Frontend.Host/Styles/theme.css
Normal file
132
Hosts/Moonlight.Frontend.Host/Styles/theme.css
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
:root {
|
||||||
|
--radius: 0.625rem;
|
||||||
|
--background: oklch(1 0 0);
|
||||||
|
--foreground: oklch(0.129 0.042 264.695);
|
||||||
|
--card: oklch(1 0 0);
|
||||||
|
--card-foreground: oklch(0.129 0.042 264.695);
|
||||||
|
--popover: oklch(1 0 0);
|
||||||
|
--popover-foreground: oklch(0.129 0.042 264.695);
|
||||||
|
--primary: oklch(0.208 0.042 265.755);
|
||||||
|
--primary-foreground: oklch(0.984 0.003 247.858);
|
||||||
|
--secondary: oklch(0.968 0.007 247.896);
|
||||||
|
--secondary-foreground: oklch(0.208 0.042 265.755);
|
||||||
|
--muted: oklch(0.968 0.007 247.896);
|
||||||
|
--muted-foreground: oklch(0.554 0.046 257.417);
|
||||||
|
--accent: oklch(0.968 0.007 247.896);
|
||||||
|
--accent-foreground: oklch(0.208 0.042 265.755);
|
||||||
|
--destructive: oklch(0.577 0.245 27.325);
|
||||||
|
--border: oklch(0.929 0.013 255.508);
|
||||||
|
--input: oklch(0.929 0.013 255.508);
|
||||||
|
--ring: oklch(0.704 0.04 256.788);
|
||||||
|
--chart-1: oklch(0.646 0.222 41.116);
|
||||||
|
--chart-2: oklch(0.6 0.118 184.704);
|
||||||
|
--chart-3: oklch(0.398 0.07 227.392);
|
||||||
|
--chart-4: oklch(0.828 0.189 84.429);
|
||||||
|
--chart-5: oklch(0.769 0.188 70.08);
|
||||||
|
|
||||||
|
--sidebar: var(--background);
|
||||||
|
--sidebar-foreground: var(--foreground);
|
||||||
|
--sidebar-primary: var(--primary);
|
||||||
|
--sidebar-primary-foreground: var(--primary-foreground);
|
||||||
|
--sidebar-accent: var(--accent);
|
||||||
|
--sidebar-accent-foreground: var(--accent-foreground);
|
||||||
|
--sidebar-border: var(--border);
|
||||||
|
--sidebar-ring: var(--ring);
|
||||||
|
|
||||||
|
--font-sans: Inter, sans-serif;
|
||||||
|
--font-serif: Georgia, serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark {
|
||||||
|
/* Deep blue-slate background with purple undertones */
|
||||||
|
--background: oklch(0.16 0.028 260);
|
||||||
|
--foreground: oklch(0.98 0.008 260);
|
||||||
|
|
||||||
|
/* Cards with slightly lighter blue-slate */
|
||||||
|
--card: oklch(0.21 0.032 260);
|
||||||
|
--card-foreground: oklch(0.98 0.008 260);
|
||||||
|
|
||||||
|
/* Popovers with medium depth */
|
||||||
|
--popover: oklch(0.24 0.035 260);
|
||||||
|
--popover-foreground: oklch(0.98 0.008 260);
|
||||||
|
|
||||||
|
/* Vibrant blue-purple primary */
|
||||||
|
--primary: oklch(0.62 0.18 270);
|
||||||
|
--primary-foreground: oklch(0.99 0.005 260);
|
||||||
|
|
||||||
|
/* Secondary with blue-slate tone */
|
||||||
|
--secondary: oklch(0.27 0.038 260);
|
||||||
|
--secondary-foreground: oklch(0.98 0.008 260);
|
||||||
|
|
||||||
|
/* Muted elements */
|
||||||
|
--muted: oklch(0.25 0.035 260);
|
||||||
|
--muted-foreground: oklch(0.66 0.025 260);
|
||||||
|
|
||||||
|
/* Accent with purple-blue blend */
|
||||||
|
--accent: oklch(0.36 0.065 268);
|
||||||
|
--accent-foreground: oklch(0.98 0.008 260);
|
||||||
|
|
||||||
|
/* Destructive red with good contrast */
|
||||||
|
--destructive: oklch(0.62 0.22 25);
|
||||||
|
--destructive-foreground: oklch(0.99 0.005 260);
|
||||||
|
|
||||||
|
/* Subtle borders and inputs */
|
||||||
|
--border: oklch(0.32 0.025 260);
|
||||||
|
--input: oklch(0.30 0.030 260);
|
||||||
|
--ring: oklch(0.62 0.18 270);
|
||||||
|
|
||||||
|
/* Chart colors with blue-purple harmony */
|
||||||
|
--chart-1: oklch(0.58 0.18 270);
|
||||||
|
--chart-2: oklch(0.62 0.16 245);
|
||||||
|
--chart-3: oklch(0.68 0.15 290);
|
||||||
|
--chart-4: oklch(0.60 0.20 260);
|
||||||
|
--chart-5: oklch(0.65 0.14 280);
|
||||||
|
|
||||||
|
/* Sidebar with slightly different depth */
|
||||||
|
--sidebar: oklch(0.18 0.030 260);
|
||||||
|
--sidebar-foreground: oklch(0.97 0.008 260);
|
||||||
|
--sidebar-primary: oklch(0.60 0.17 270);
|
||||||
|
--sidebar-primary-foreground: oklch(0.99 0.005 260);
|
||||||
|
--sidebar-accent: oklch(0.26 0.038 260);
|
||||||
|
--sidebar-accent-foreground: oklch(0.98 0.008 260);
|
||||||
|
--sidebar-border: oklch(0.30 0.025 260);
|
||||||
|
--sidebar-ring: oklch(0.58 0.17 270);
|
||||||
|
}
|
||||||
|
|
||||||
|
@theme inline {
|
||||||
|
--radius-sm: calc(var(--radius) - 4px);
|
||||||
|
--radius-md: calc(var(--radius) - 2px);
|
||||||
|
--radius-lg: var(--radius);
|
||||||
|
--radius-xl: calc(var(--radius) + 4px);
|
||||||
|
--color-background: var(--background);
|
||||||
|
--color-foreground: var(--foreground);
|
||||||
|
--color-card: var(--card);
|
||||||
|
--color-card-foreground: var(--card-foreground);
|
||||||
|
--color-popover: var(--popover);
|
||||||
|
--color-popover-foreground: var(--popover-foreground);
|
||||||
|
--color-primary: var(--primary);
|
||||||
|
--color-primary-foreground: var(--primary-foreground);
|
||||||
|
--color-secondary: var(--secondary);
|
||||||
|
--color-secondary-foreground: var(--secondary-foreground);
|
||||||
|
--color-muted: var(--muted);
|
||||||
|
--color-muted-foreground: var(--muted-foreground);
|
||||||
|
--color-accent: var(--accent);
|
||||||
|
--color-accent-foreground: var(--accent-foreground);
|
||||||
|
--color-destructive: var(--destructive);
|
||||||
|
--color-border: var(--border);
|
||||||
|
--color-input: var(--input);
|
||||||
|
--color-ring: var(--ring);
|
||||||
|
--color-chart-1: var(--chart-1);
|
||||||
|
--color-chart-2: var(--chart-2);
|
||||||
|
--color-chart-3: var(--chart-3);
|
||||||
|
--color-chart-4: var(--chart-4);
|
||||||
|
--color-chart-5: var(--chart-5);
|
||||||
|
--color-sidebar: var(--sidebar);
|
||||||
|
--color-sidebar-foreground: var(--sidebar-foreground);
|
||||||
|
--color-sidebar-primary: var(--sidebar-primary);
|
||||||
|
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
||||||
|
--color-sidebar-accent: var(--sidebar-accent);
|
||||||
|
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
||||||
|
--color-sidebar-border: var(--sidebar-border);
|
||||||
|
--color-sidebar-ring: var(--sidebar-ring);
|
||||||
|
}
|
||||||
108
Hosts/Moonlight.Frontend.Host/wwwroot/index.html
Normal file
108
Hosts/Moonlight.Frontend.Host/wwwroot/index.html
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html class="dark" lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
|
||||||
|
<title>Moonlight</title>
|
||||||
|
<base href="/"/>
|
||||||
|
<link id="webassembly" rel="preload"/>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=fallback" rel="stylesheet"/>
|
||||||
|
<link href="style.min.css" rel="stylesheet"/>
|
||||||
|
<script type="importmap"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
window.frontendConfig = {
|
||||||
|
STYLE_TAG_ID: 'theme-variables',
|
||||||
|
configuration: {},
|
||||||
|
|
||||||
|
applyTheme: function (cssContent) {
|
||||||
|
// Find or create the style tag
|
||||||
|
let styleTag = document.getElementById(this.STYLE_TAG_ID);
|
||||||
|
|
||||||
|
if (!styleTag) {
|
||||||
|
styleTag = document.createElement('style');
|
||||||
|
styleTag.id = this.STYLE_TAG_ID;
|
||||||
|
document.head.appendChild(styleTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the style tag content
|
||||||
|
styleTag.textContent = cssContent;
|
||||||
|
},
|
||||||
|
|
||||||
|
reloadConfiguration: function () {
|
||||||
|
try {
|
||||||
|
const xhr = new XMLHttpRequest();
|
||||||
|
xhr.open('GET', '/api/frontend/config', false);
|
||||||
|
xhr.send(null);
|
||||||
|
|
||||||
|
if (xhr.status === 200) {
|
||||||
|
this.configuration = JSON.parse(xhr.responseText);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to load initial theme:', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
getConfiguration: function () {
|
||||||
|
return this.configuration;
|
||||||
|
},
|
||||||
|
|
||||||
|
reload: function () {
|
||||||
|
this.reloadConfiguration();
|
||||||
|
|
||||||
|
document.title = this.configuration.name;
|
||||||
|
this.applyTheme(this.configuration.themeCss);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.frontendConfig.reload();
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body class="bg-background text-foreground">
|
||||||
|
<div id="app">
|
||||||
|
<div class="h-screen w-full flex items-center justify-center">
|
||||||
|
|
||||||
|
<div class="flex min-w-0 flex-1 flex-col items-center justify-center gap-3 rounded-lg border-dashed p-6 text-center text-balance md:p-12">
|
||||||
|
<div class="flex max-w-sm flex-col items-center gap-2 text-center">
|
||||||
|
<div class="flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0 bg-muted text-foreground size-10 rounded-lg [&_svg:not([class*='size-'])]:size-6">
|
||||||
|
|
||||||
|
<svg class="lucide lucide-zap-icon lucide-zap size-6" fill="none" height="24" stroke="currentColor" stroke-linecap="round"
|
||||||
|
stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="24"
|
||||||
|
xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z"/>
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="text-lg font-medium tracking-tight">
|
||||||
|
Loading application
|
||||||
|
</div>
|
||||||
|
<div class="flex w-full max-w-sm min-w-0 flex-col items-center gap-4 text-sm text-balance">
|
||||||
|
|
||||||
|
<div class="bg-primary/20 w-full relative h-2 overflow-hidden rounded-full">
|
||||||
|
<div class="bg-primary h-full w-[var(--blazor-load-percentage,0)] flex-1 transition-all">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="blazor-error-ui">
|
||||||
|
An unhandled error has occurred.
|
||||||
|
<a class="reload" href=".">Reload</a>
|
||||||
|
<span class="dismiss">🗙</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script defer src="/_content/ShadcnBlazor/interop.js"></script>
|
||||||
|
<script defer src="/_content/ShadcnBlazor.Extras/interop.js"></script>
|
||||||
|
<script defer src="/_content/ShadcnBlazor.Extras/codemirror-bundle.js"></script>
|
||||||
|
<script src="_framework/blazor.webassembly#[.{fingerprint}].js"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
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.
|
|
||||||
128
Moonlight.Api/Admin/Setup/SetupController.cs
Normal file
128
Moonlight.Api/Admin/Setup/SetupController.cs
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Moonlight.Api.Admin.Sys.Settings;
|
||||||
|
using Moonlight.Api.Infrastructure.Database;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
using Moonlight.Shared;
|
||||||
|
using Moonlight.Shared.Admin.Setup;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Setup;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/setup")]
|
||||||
|
public class SetupController : Controller
|
||||||
|
{
|
||||||
|
private const string StateSettingsKey = "Moonlight.Api.Setup.State";
|
||||||
|
private readonly DatabaseRepository<Role> RolesRepository;
|
||||||
|
private readonly SettingsService SettingsService;
|
||||||
|
private readonly DatabaseRepository<User> UsersRepository;
|
||||||
|
|
||||||
|
public SetupController(
|
||||||
|
SettingsService settingsService,
|
||||||
|
DatabaseRepository<User> usersRepository,
|
||||||
|
DatabaseRepository<Role> rolesRepository
|
||||||
|
)
|
||||||
|
{
|
||||||
|
SettingsService = settingsService;
|
||||||
|
UsersRepository = usersRepository;
|
||||||
|
RolesRepository = rolesRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public async Task<ActionResult> GetSetupAsync()
|
||||||
|
{
|
||||||
|
var hasBeenSetup = await SettingsService.GetValueAsync<bool>(StateSettingsKey);
|
||||||
|
|
||||||
|
if (hasBeenSetup)
|
||||||
|
return Problem("This instance is already configured", statusCode: 405);
|
||||||
|
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public async Task<ActionResult> ApplySetupAsync([FromBody] ApplySetupDto dto)
|
||||||
|
{
|
||||||
|
var adminRole = await RolesRepository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(x => x.Name == "Administrators");
|
||||||
|
|
||||||
|
if (adminRole == null)
|
||||||
|
adminRole = await RolesRepository.AddAsync(new Role
|
||||||
|
{
|
||||||
|
Name = "Administrators",
|
||||||
|
Description = "Automatically generated group for full administrator permissions",
|
||||||
|
Permissions =
|
||||||
|
[
|
||||||
|
Permissions.ApiKeys.View,
|
||||||
|
Permissions.ApiKeys.Create,
|
||||||
|
Permissions.ApiKeys.Edit,
|
||||||
|
Permissions.ApiKeys.Delete,
|
||||||
|
|
||||||
|
Permissions.Roles.View,
|
||||||
|
Permissions.Roles.Create,
|
||||||
|
Permissions.Roles.Edit,
|
||||||
|
Permissions.Roles.Delete,
|
||||||
|
Permissions.Roles.Members,
|
||||||
|
|
||||||
|
Permissions.Users.View,
|
||||||
|
Permissions.Users.Create,
|
||||||
|
Permissions.Users.Edit,
|
||||||
|
Permissions.Users.Delete,
|
||||||
|
Permissions.Users.Logout,
|
||||||
|
|
||||||
|
Permissions.Themes.View,
|
||||||
|
Permissions.Themes.Create,
|
||||||
|
Permissions.Themes.Edit,
|
||||||
|
Permissions.Themes.Delete,
|
||||||
|
|
||||||
|
Permissions.System.Info,
|
||||||
|
Permissions.System.Diagnose,
|
||||||
|
Permissions.System.Versions,
|
||||||
|
Permissions.System.Instance
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
var user = await UsersRepository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(u => u.Email == dto.AdminEmail);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
await UsersRepository.AddAsync(new User
|
||||||
|
{
|
||||||
|
Email = dto.AdminEmail,
|
||||||
|
Username = dto.AdminUsername,
|
||||||
|
RoleMemberships =
|
||||||
|
[
|
||||||
|
new RoleMember
|
||||||
|
{
|
||||||
|
Role = adminRole,
|
||||||
|
CreatedAt = DateTimeOffset.UtcNow,
|
||||||
|
UpdatedAt = DateTimeOffset.UtcNow
|
||||||
|
}
|
||||||
|
],
|
||||||
|
CreatedAt = DateTimeOffset.UtcNow,
|
||||||
|
UpdatedAt = DateTimeOffset.UtcNow
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
user.RoleMemberships.Add(new RoleMember
|
||||||
|
{
|
||||||
|
Role = adminRole,
|
||||||
|
CreatedAt = DateTimeOffset.UtcNow,
|
||||||
|
UpdatedAt = DateTimeOffset.UtcNow
|
||||||
|
});
|
||||||
|
|
||||||
|
await UsersRepository.UpdateAsync(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
await SettingsService.SetValueAsync(StateSettingsKey, true);
|
||||||
|
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
136
Moonlight.Api/Admin/Sys/ApiKeys/ApiKeyController.cs
Normal file
136
Moonlight.Api/Admin/Sys/ApiKeys/ApiKeyController.cs
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Caching.Hybrid;
|
||||||
|
using Moonlight.Api.Admin.Sys.ApiKeys.Scheme;
|
||||||
|
using Moonlight.Api.Infrastructure.Database;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
using Moonlight.Shared;
|
||||||
|
using Moonlight.Shared.Admin.Sys.ApiKeys;
|
||||||
|
using Moonlight.Shared.Shared;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys.ApiKeys;
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/apiKeys")]
|
||||||
|
public class ApiKeyController : Controller
|
||||||
|
{
|
||||||
|
private readonly HybridCache HybridCache;
|
||||||
|
private readonly DatabaseRepository<ApiKey> KeyRepository;
|
||||||
|
|
||||||
|
public ApiKeyController(DatabaseRepository<ApiKey> keyRepository, HybridCache hybridCache)
|
||||||
|
{
|
||||||
|
KeyRepository = keyRepository;
|
||||||
|
HybridCache = hybridCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Authorize(Policy = Permissions.ApiKeys.View)]
|
||||||
|
public async Task<ActionResult<PagedData<ApiKeyDto>>> GetAsync(
|
||||||
|
[FromQuery] int startIndex,
|
||||||
|
[FromQuery] int length,
|
||||||
|
[FromQuery] FilterOptions? filterOptions
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Validation
|
||||||
|
if (startIndex < 0)
|
||||||
|
return Problem("Invalid start index specified", statusCode: 400);
|
||||||
|
|
||||||
|
if (length is < 1 or > 100)
|
||||||
|
return Problem("Invalid length specified");
|
||||||
|
|
||||||
|
// Query building
|
||||||
|
var query = KeyRepository.Query();
|
||||||
|
|
||||||
|
// Filters
|
||||||
|
if (filterOptions != null)
|
||||||
|
foreach (var filterOption in filterOptions.Filters)
|
||||||
|
query = filterOption.Key switch
|
||||||
|
{
|
||||||
|
nameof(ApiKey.Name) =>
|
||||||
|
query.Where(k => EF.Functions.ILike(k.Name, $"%{filterOption.Value}%")),
|
||||||
|
|
||||||
|
nameof(ApiKey.Description) =>
|
||||||
|
query.Where(k => EF.Functions.ILike(k.Description, $"%{filterOption.Value}%")),
|
||||||
|
|
||||||
|
_ => query
|
||||||
|
};
|
||||||
|
|
||||||
|
// Pagination
|
||||||
|
var data = await query
|
||||||
|
.OrderBy(k => k.Id)
|
||||||
|
.ProjectToDto()
|
||||||
|
.Skip(startIndex)
|
||||||
|
.Take(length)
|
||||||
|
.ToArrayAsync();
|
||||||
|
|
||||||
|
var total = await query.CountAsync();
|
||||||
|
|
||||||
|
return new PagedData<ApiKeyDto>(data, total);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id:int}")]
|
||||||
|
[Authorize(Policy = Permissions.ApiKeys.View)]
|
||||||
|
public async Task<ActionResult<ApiKeyDto>> GetAsync([FromRoute] int id)
|
||||||
|
{
|
||||||
|
var key = await KeyRepository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(k => k.Id == id);
|
||||||
|
|
||||||
|
if (key == null)
|
||||||
|
return Problem("No API key with this id found", statusCode: 404);
|
||||||
|
|
||||||
|
return ApiKeyMapper.ToDto(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[Authorize(Policy = Permissions.ApiKeys.Create)]
|
||||||
|
public async Task<ActionResult<ApiKeyDto>> CreateAsync([FromBody] CreateApiKeyDto request)
|
||||||
|
{
|
||||||
|
var apiKey = ApiKeyMapper.ToEntity(request);
|
||||||
|
|
||||||
|
apiKey.Key = Guid.NewGuid().ToString("N").Substring(0, 32);
|
||||||
|
|
||||||
|
var finalKey = await KeyRepository.AddAsync(apiKey);
|
||||||
|
|
||||||
|
return ApiKeyMapper.ToDto(finalKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPatch("{id:int}")]
|
||||||
|
[Authorize(Policy = Permissions.ApiKeys.Edit)]
|
||||||
|
public async Task<ActionResult<ApiKeyDto>> UpdateAsync([FromRoute] int id, [FromBody] UpdateApiKeyDto request)
|
||||||
|
{
|
||||||
|
var apiKey = await KeyRepository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(k => k.Id == id);
|
||||||
|
|
||||||
|
if (apiKey == null)
|
||||||
|
return Problem("No API key with this id found", statusCode: 404);
|
||||||
|
|
||||||
|
ApiKeyMapper.Merge(apiKey, request);
|
||||||
|
await KeyRepository.UpdateAsync(apiKey);
|
||||||
|
|
||||||
|
await HybridCache.RemoveAsync(string.Format(ApiKeySchemeHandler.CacheKeyFormat, apiKey.Key));
|
||||||
|
|
||||||
|
return ApiKeyMapper.ToDto(apiKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("{id:int}")]
|
||||||
|
[Authorize(Policy = Permissions.ApiKeys.Delete)]
|
||||||
|
public async Task<ActionResult> DeleteAsync([FromRoute] int id)
|
||||||
|
{
|
||||||
|
var apiKey = await KeyRepository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(k => k.Id == id);
|
||||||
|
|
||||||
|
if (apiKey == null)
|
||||||
|
return Problem("No API key with this id found", statusCode: 404);
|
||||||
|
|
||||||
|
await KeyRepository.RemoveAsync(apiKey);
|
||||||
|
|
||||||
|
await HybridCache.RemoveAsync(string.Format(ApiKeySchemeHandler.CacheKeyFormat, apiKey.Key));
|
||||||
|
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
20
Moonlight.Api/Admin/Sys/ApiKeys/ApiKeyMapper.cs
Normal file
20
Moonlight.Api/Admin/Sys/ApiKeys/ApiKeyMapper.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
using Moonlight.Shared.Admin.Sys.ApiKeys;
|
||||||
|
using Riok.Mapperly.Abstractions;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys.ApiKeys;
|
||||||
|
|
||||||
|
[Mapper]
|
||||||
|
[SuppressMessage("Mapper", "RMG020:No members are mapped in an object mapping")]
|
||||||
|
[SuppressMessage("Mapper", "RMG012:No members are mapped in an object mapping")]
|
||||||
|
public static partial class ApiKeyMapper
|
||||||
|
{
|
||||||
|
public static partial IQueryable<ApiKeyDto> ProjectToDto(this IQueryable<ApiKey> apiKeys);
|
||||||
|
|
||||||
|
public static partial ApiKeyDto ToDto(ApiKey apiKey);
|
||||||
|
|
||||||
|
public static partial void Merge([MappingTarget] ApiKey apiKey, UpdateApiKeyDto request);
|
||||||
|
|
||||||
|
public static partial ApiKey ToEntity(CreateApiKeyDto request);
|
||||||
|
}
|
||||||
7
Moonlight.Api/Admin/Sys/ApiKeys/ApiOptions.cs
Normal file
7
Moonlight.Api/Admin/Sys/ApiKeys/ApiOptions.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Moonlight.Api.Admin.Sys.ApiKeys;
|
||||||
|
|
||||||
|
public class ApiOptions
|
||||||
|
{
|
||||||
|
public TimeSpan LookupCacheL1Expiry { get; set; } = TimeSpan.FromSeconds(30);
|
||||||
|
public TimeSpan LookupCacheL2Expiry { get; set; } = TimeSpan.FromMinutes(3);
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using System.Text.Encodings.Web;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Caching.Hybrid;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using Moonlight.Api.Infrastructure.Database;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
using Moonlight.Shared;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys.ApiKeys.Scheme;
|
||||||
|
|
||||||
|
public class ApiKeySchemeHandler : AuthenticationHandler<ApiKeySchemeOptions>
|
||||||
|
{
|
||||||
|
public const string CacheKeyFormat = $"Moonlight.Api.{nameof(ApiKeySchemeHandler)}.{{0}}";
|
||||||
|
private readonly DatabaseRepository<ApiKey> ApiKeyRepository;
|
||||||
|
private readonly HybridCache HybridCache;
|
||||||
|
|
||||||
|
public ApiKeySchemeHandler(
|
||||||
|
IOptionsMonitor<ApiKeySchemeOptions> options,
|
||||||
|
ILoggerFactory logger,
|
||||||
|
UrlEncoder encoder,
|
||||||
|
DatabaseRepository<ApiKey> apiKeyRepository,
|
||||||
|
HybridCache hybridCache
|
||||||
|
) : base(options, logger, encoder)
|
||||||
|
{
|
||||||
|
ApiKeyRepository = apiKeyRepository;
|
||||||
|
HybridCache = hybridCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
|
||||||
|
{
|
||||||
|
var authHeaderValue = Request.Headers.Authorization.FirstOrDefault() ?? null;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(authHeaderValue))
|
||||||
|
return AuthenticateResult.NoResult();
|
||||||
|
|
||||||
|
if (authHeaderValue.Length > 32)
|
||||||
|
return AuthenticateResult.Fail("Invalid api key specified");
|
||||||
|
|
||||||
|
var cacheKey = string.Format(CacheKeyFormat, authHeaderValue);
|
||||||
|
|
||||||
|
var apiKey = await HybridCache.GetOrCreateAsync<ApiKeySession?>(
|
||||||
|
cacheKey,
|
||||||
|
async ct =>
|
||||||
|
{
|
||||||
|
return await ApiKeyRepository
|
||||||
|
.Query()
|
||||||
|
.Where(x => x.Key == authHeaderValue)
|
||||||
|
.Select(x => new ApiKeySession(x.Permissions, x.ValidUntil))
|
||||||
|
.FirstOrDefaultAsync(ct);
|
||||||
|
},
|
||||||
|
new HybridCacheEntryOptions
|
||||||
|
{
|
||||||
|
LocalCacheExpiration = Options.LookupL1CacheTime,
|
||||||
|
Expiration = Options.LookupL2CacheTime
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (apiKey == null)
|
||||||
|
return AuthenticateResult.Fail("Invalid api key specified");
|
||||||
|
|
||||||
|
if (DateTimeOffset.UtcNow > apiKey.ValidUntil)
|
||||||
|
return AuthenticateResult.Fail("Api key expired");
|
||||||
|
|
||||||
|
return AuthenticateResult.Success(new AuthenticationTicket(
|
||||||
|
new ClaimsPrincipal(
|
||||||
|
new ClaimsIdentity(
|
||||||
|
apiKey.Permissions.Select(x => new Claim(Permissions.ClaimType, x)).ToArray()
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Scheme.Name
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private record ApiKeySession(string[] Permissions, DateTimeOffset ValidUntil);
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys.ApiKeys.Scheme;
|
||||||
|
|
||||||
|
public class ApiKeySchemeOptions : AuthenticationSchemeOptions
|
||||||
|
{
|
||||||
|
public TimeSpan LookupL1CacheTime { get; set; }
|
||||||
|
public TimeSpan LookupL2CacheTime { get; set; }
|
||||||
|
}
|
||||||
89
Moonlight.Api/Admin/Sys/ApplicationService.cs
Normal file
89
Moonlight.Api/Admin/Sys/ApplicationService.cs
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using VersionService = Moonlight.Api.Admin.Sys.Versions.VersionService;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys;
|
||||||
|
|
||||||
|
public class ApplicationService : IHostedService
|
||||||
|
{
|
||||||
|
private readonly ILogger<ApplicationService> Logger;
|
||||||
|
private readonly VersionService VersionService;
|
||||||
|
|
||||||
|
public ApplicationService(VersionService versionService, ILogger<ApplicationService> logger)
|
||||||
|
{
|
||||||
|
VersionService = versionService;
|
||||||
|
Logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DateTimeOffset StartedAt { get; private set; }
|
||||||
|
public string VersionName { get; private set; } = "N/A";
|
||||||
|
public bool IsUpToDate { get; set; } = true;
|
||||||
|
public string OperatingSystem { get; private set; } = "N/A";
|
||||||
|
|
||||||
|
public async Task StartAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
StartedAt = DateTimeOffset.UtcNow;
|
||||||
|
|
||||||
|
OperatingSystem = OsHelper.GetName();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var currentVersion = await VersionService.GetInstanceVersionAsync();
|
||||||
|
var latestVersion = await VersionService.GetLatestVersionAsync();
|
||||||
|
|
||||||
|
VersionName = currentVersion.Identifier;
|
||||||
|
IsUpToDate = latestVersion == null || currentVersion.Identifier == latestVersion.Identifier;
|
||||||
|
|
||||||
|
Logger.LogInformation("Running Moonlight Panel {version} on {operatingSystem}", VersionName,
|
||||||
|
OperatingSystem);
|
||||||
|
|
||||||
|
if (!IsUpToDate)
|
||||||
|
Logger.LogWarning("Your instance is not up-to-date");
|
||||||
|
|
||||||
|
if (currentVersion.IsDevelopment)
|
||||||
|
Logger.LogWarning("Your instance is running a development version");
|
||||||
|
|
||||||
|
if (currentVersion.IsPreRelease)
|
||||||
|
Logger.LogWarning("Your instance is running a pre-release version");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.LogError(e, "An unhandled exception occurred while fetching version details");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task StopAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<long> GetMemoryUsageAsync()
|
||||||
|
{
|
||||||
|
using var currentProcess = Process.GetCurrentProcess();
|
||||||
|
return Task.FromResult(currentProcess.WorkingSet64);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<double> GetCpuUsageAsync()
|
||||||
|
{
|
||||||
|
using var currentProcess = Process.GetCurrentProcess();
|
||||||
|
|
||||||
|
// Get initial values
|
||||||
|
var startCpuTime = currentProcess.TotalProcessorTime;
|
||||||
|
var startTime = DateTime.UtcNow;
|
||||||
|
|
||||||
|
// Wait a bit to calculate the diff
|
||||||
|
await Task.Delay(500);
|
||||||
|
|
||||||
|
// New values
|
||||||
|
var endCpuTime = currentProcess.TotalProcessorTime;
|
||||||
|
var endTime = DateTime.UtcNow;
|
||||||
|
|
||||||
|
// Calculate CPU usage
|
||||||
|
var cpuUsedMs = (endCpuTime - startCpuTime).TotalMilliseconds;
|
||||||
|
var totalMsPassed = (endTime - startTime).TotalMilliseconds;
|
||||||
|
var cpuUsagePercent = cpuUsedMs / (Environment.ProcessorCount * totalMsPassed) * 100;
|
||||||
|
|
||||||
|
return Math.Round(cpuUsagePercent, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using Moonlight.Shared;
|
||||||
|
using Moonlight.Shared.Admin.Sys.ContainerHelper;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys.ContainerHelper;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/ch")]
|
||||||
|
[Authorize(Policy = Permissions.System.Instance)]
|
||||||
|
public class ContainerHelperController : Controller
|
||||||
|
{
|
||||||
|
private readonly ContainerHelperService ContainerHelperService;
|
||||||
|
private readonly IOptions<ContainerHelperOptions> Options;
|
||||||
|
|
||||||
|
public ContainerHelperController(ContainerHelperService containerHelperService,
|
||||||
|
IOptions<ContainerHelperOptions> options)
|
||||||
|
{
|
||||||
|
ContainerHelperService = containerHelperService;
|
||||||
|
Options = options;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("status")]
|
||||||
|
public async Task<ActionResult<ContainerHelperStatusDto>> GetStatusAsync()
|
||||||
|
{
|
||||||
|
if (!Options.Value.IsEnabled)
|
||||||
|
return new ContainerHelperStatusDto(false, false);
|
||||||
|
|
||||||
|
var status = await ContainerHelperService.CheckConnectionAsync();
|
||||||
|
|
||||||
|
return new ContainerHelperStatusDto(true, status);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("rebuild")]
|
||||||
|
public Task<IResult> RebuildAsync([FromBody] RequestRebuildDto request)
|
||||||
|
{
|
||||||
|
var result = ContainerHelperService.RebuildAsync(request.NoBuildCache);
|
||||||
|
var mappedResult = result.Select(ContainerHelperMapper.ToDto);
|
||||||
|
|
||||||
|
return Task.FromResult<IResult>(
|
||||||
|
TypedResults.ServerSentEvents(mappedResult)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("version")]
|
||||||
|
public async Task<ActionResult> SetVersionAsync([FromBody] SetVersionDto request)
|
||||||
|
{
|
||||||
|
await ContainerHelperService.SetVersionAsync(request.Version);
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Moonlight.Shared.Admin.Sys.ContainerHelper;
|
||||||
|
using Riok.Mapperly.Abstractions;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys.ContainerHelper;
|
||||||
|
|
||||||
|
[Mapper]
|
||||||
|
[SuppressMessage("Mapper", "RMG020:No members are mapped in an object mapping")]
|
||||||
|
[SuppressMessage("Mapper", "RMG012:No members are mapped in an object mapping")]
|
||||||
|
public static partial class ContainerHelperMapper
|
||||||
|
{
|
||||||
|
public static partial RebuildEventDto ToDto(Models.Events.RebuildEventDto rebuildEventDto);
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Moonlight.Api.Admin.Sys.ContainerHelper;
|
||||||
|
|
||||||
|
public class ContainerHelperOptions
|
||||||
|
{
|
||||||
|
public bool IsEnabled { get; set; }
|
||||||
|
public string Url { get; set; } = "http://helper:8080";
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
using System.Net.Http.Json;
|
||||||
|
using System.Text.Json;
|
||||||
|
using Moonlight.Api.Admin.Sys.ContainerHelper.Models;
|
||||||
|
using Moonlight.Api.Admin.Sys.ContainerHelper.Models.Events;
|
||||||
|
using Moonlight.Api.Admin.Sys.ContainerHelper.Models.Requests;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys.ContainerHelper;
|
||||||
|
|
||||||
|
public class ContainerHelperService
|
||||||
|
{
|
||||||
|
private readonly IHttpClientFactory HttpClientFactory;
|
||||||
|
|
||||||
|
public ContainerHelperService(IHttpClientFactory httpClientFactory)
|
||||||
|
{
|
||||||
|
HttpClientFactory = httpClientFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> CheckConnectionAsync()
|
||||||
|
{
|
||||||
|
var client = HttpClientFactory.CreateClient("ContainerHelper");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var response = await client.GetAsync("api/ping");
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async IAsyncEnumerable<RebuildEventDto> RebuildAsync(bool noBuildCache)
|
||||||
|
{
|
||||||
|
var client = HttpClientFactory.CreateClient("ContainerHelper");
|
||||||
|
|
||||||
|
var request = new HttpRequestMessage(HttpMethod.Post, "api/rebuild");
|
||||||
|
|
||||||
|
request.Content = JsonContent.Create(
|
||||||
|
new RequestRebuildDto(noBuildCache),
|
||||||
|
null,
|
||||||
|
SerializationContext.Default.Options
|
||||||
|
);
|
||||||
|
|
||||||
|
var response = await client.SendAsync(
|
||||||
|
request,
|
||||||
|
HttpCompletionOption.ResponseHeadersRead
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
var responseText = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
|
yield return new RebuildEventDto
|
||||||
|
{
|
||||||
|
Type = RebuildEventType.Failed,
|
||||||
|
Data = responseText
|
||||||
|
};
|
||||||
|
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
|
await using var responseStream = await response.Content.ReadAsStreamAsync();
|
||||||
|
using var streamReader = new StreamReader(responseStream);
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
var line = await streamReader.ReadLineAsync();
|
||||||
|
|
||||||
|
if (line == null)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(line))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var data = line.Trim("data: ");
|
||||||
|
var deserializedData =
|
||||||
|
JsonSerializer.Deserialize<RebuildEventDto>(data, SerializationContext.Default.Options);
|
||||||
|
|
||||||
|
yield return deserializedData;
|
||||||
|
|
||||||
|
// Exit if service will go down for a clean exit
|
||||||
|
if (deserializedData is { Type: RebuildEventType.Step, Data: "ServiceDown" })
|
||||||
|
yield break;
|
||||||
|
} while (true);
|
||||||
|
|
||||||
|
yield return new RebuildEventDto
|
||||||
|
{
|
||||||
|
Type = RebuildEventType.Succeeded,
|
||||||
|
Data = string.Empty
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SetVersionAsync(string version)
|
||||||
|
{
|
||||||
|
var client = HttpClientFactory.CreateClient("ContainerHelper");
|
||||||
|
|
||||||
|
var response = await client.PostAsJsonAsync(
|
||||||
|
"api/configuration/version",
|
||||||
|
new SetVersionDto(version),
|
||||||
|
SerializationContext.Default.Options
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var problemDetails =
|
||||||
|
await response.Content.ReadFromJsonAsync<ProblemDetails>(SerializationContext.Default.Options);
|
||||||
|
|
||||||
|
if (problemDetails == null)
|
||||||
|
throw new HttpRequestException($"Failed to set version: {response.ReasonPhrase}");
|
||||||
|
|
||||||
|
throw new HttpRequestException($"Failed to set version: {problemDetails.Detail ?? problemDetails.Title}");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys.ContainerHelper.Models.Events;
|
||||||
|
|
||||||
|
public struct RebuildEventDto
|
||||||
|
{
|
||||||
|
[JsonPropertyName("type")] public RebuildEventType Type { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("data")] public string Data { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum RebuildEventType
|
||||||
|
{
|
||||||
|
Log = 0,
|
||||||
|
Failed = 1,
|
||||||
|
Succeeded = 2,
|
||||||
|
Step = 3
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
namespace Moonlight.Api.Admin.Sys.ContainerHelper.Models;
|
||||||
|
|
||||||
|
public class ProblemDetails
|
||||||
|
{
|
||||||
|
public string Type { get; set; }
|
||||||
|
public string Title { get; set; }
|
||||||
|
public int Status { get; set; }
|
||||||
|
public string? Detail { get; set; }
|
||||||
|
public Dictionary<string, string[]>? Errors { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Moonlight.Api.Admin.Sys.ContainerHelper.Models.Requests;
|
||||||
|
|
||||||
|
public record RequestRebuildDto(bool NoBuildCache);
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Moonlight.Api.Admin.Sys.ContainerHelper.Models.Requests;
|
||||||
|
|
||||||
|
public record SetVersionDto(string Version);
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using Moonlight.Api.Admin.Sys.ContainerHelper.Models.Events;
|
||||||
|
using Moonlight.Api.Admin.Sys.ContainerHelper.Models.Requests;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys.ContainerHelper.Models;
|
||||||
|
|
||||||
|
[JsonSerializable(typeof(SetVersionDto))]
|
||||||
|
[JsonSerializable(typeof(ProblemDetails))]
|
||||||
|
[JsonSerializable(typeof(RebuildEventDto))]
|
||||||
|
[JsonSerializable(typeof(RequestRebuildDto))]
|
||||||
|
[JsonSourceGenerationOptions(JsonSerializerDefaults.Web)]
|
||||||
|
public partial class SerializationContext : JsonSerializerContext
|
||||||
|
{
|
||||||
|
}
|
||||||
30
Moonlight.Api/Admin/Sys/Diagnose/DiagnoseController.cs
Normal file
30
Moonlight.Api/Admin/Sys/Diagnose/DiagnoseController.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Moonlight.Shared;
|
||||||
|
using Moonlight.Shared.Admin.Sys.Diagnose;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys.Diagnose;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Authorize(Policy = Permissions.System.Diagnose)]
|
||||||
|
[Route("api/admin/system/diagnose")]
|
||||||
|
public class DiagnoseController : Controller
|
||||||
|
{
|
||||||
|
private readonly DiagnoseService DiagnoseService;
|
||||||
|
|
||||||
|
public DiagnoseController(DiagnoseService diagnoseService)
|
||||||
|
{
|
||||||
|
DiagnoseService = diagnoseService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<ActionResult<DiagnoseResultDto[]>> GetAsync()
|
||||||
|
{
|
||||||
|
var results = await DiagnoseService.DiagnoseAsync();
|
||||||
|
|
||||||
|
return results
|
||||||
|
.OrderBy(x => x.Level)
|
||||||
|
.ToDto()
|
||||||
|
.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
17
Moonlight.Api/Admin/Sys/Diagnose/DiagnoseResult.cs
Normal file
17
Moonlight.Api/Admin/Sys/Diagnose/DiagnoseResult.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
namespace Moonlight.Api.Admin.Sys.Diagnose;
|
||||||
|
|
||||||
|
public record DiagnoseResult(
|
||||||
|
DiagnoseLevel Level,
|
||||||
|
string Title,
|
||||||
|
string[] Tags,
|
||||||
|
string? Message,
|
||||||
|
string? StackStrace,
|
||||||
|
string? SolutionUrl,
|
||||||
|
string? ReportUrl);
|
||||||
|
|
||||||
|
public enum DiagnoseLevel
|
||||||
|
{
|
||||||
|
Error = 0,
|
||||||
|
Warning = 1,
|
||||||
|
Healthy = 2
|
||||||
|
}
|
||||||
13
Moonlight.Api/Admin/Sys/Diagnose/DiagnoseResultMapper.cs
Normal file
13
Moonlight.Api/Admin/Sys/Diagnose/DiagnoseResultMapper.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Moonlight.Shared.Admin.Sys.Diagnose;
|
||||||
|
using Riok.Mapperly.Abstractions;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys.Diagnose;
|
||||||
|
|
||||||
|
[Mapper]
|
||||||
|
[SuppressMessage("Mapper", "RMG020:No members are mapped in an object mapping")]
|
||||||
|
[SuppressMessage("Mapper", "RMG012:No members are mapped in an object mapping")]
|
||||||
|
public static partial class DiagnoseResultMapper
|
||||||
|
{
|
||||||
|
public static partial IEnumerable<DiagnoseResultDto> ToDto(this IEnumerable<DiagnoseResult> results);
|
||||||
|
}
|
||||||
35
Moonlight.Api/Admin/Sys/Diagnose/DiagnoseService.cs
Normal file
35
Moonlight.Api/Admin/Sys/Diagnose/DiagnoseService.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Moonlight.Api.Infrastructure.Hooks;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys.Diagnose;
|
||||||
|
|
||||||
|
public class DiagnoseService
|
||||||
|
{
|
||||||
|
private readonly ILogger<DiagnoseService> Logger;
|
||||||
|
private readonly IEnumerable<IDiagnoseProvider> Providers;
|
||||||
|
|
||||||
|
public DiagnoseService(IEnumerable<IDiagnoseProvider> providers, ILogger<DiagnoseService> logger)
|
||||||
|
{
|
||||||
|
Providers = providers;
|
||||||
|
Logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<DiagnoseResult[]> DiagnoseAsync()
|
||||||
|
{
|
||||||
|
var results = new List<DiagnoseResult>();
|
||||||
|
|
||||||
|
foreach (var provider in Providers)
|
||||||
|
try
|
||||||
|
{
|
||||||
|
results.AddRange(
|
||||||
|
await provider.DiagnoseAsync()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.LogError(e, "An unhandled error occured while processing provider");
|
||||||
|
}
|
||||||
|
|
||||||
|
return results.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
88
Moonlight.Api/Admin/Sys/OsHelper.cs
Normal file
88
Moonlight.Api/Admin/Sys/OsHelper.cs
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys;
|
||||||
|
|
||||||
|
public class OsHelper
|
||||||
|
{
|
||||||
|
public static string GetName()
|
||||||
|
{
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
|
return GetWindowsVersion();
|
||||||
|
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
return GetLinuxVersion();
|
||||||
|
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||||
|
return "Goofy OS";
|
||||||
|
|
||||||
|
return "Unknown OS";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetWindowsVersion()
|
||||||
|
{
|
||||||
|
var version = Environment.OSVersion.Version;
|
||||||
|
|
||||||
|
// Windows 11 is version 10.0 build 22000+
|
||||||
|
if (version.Major == 10 && version.Build >= 22000)
|
||||||
|
return $"Windows 11 ({version.Build})";
|
||||||
|
|
||||||
|
if (version.Major == 10)
|
||||||
|
return $"Windows 10 ({version.Build})";
|
||||||
|
|
||||||
|
if (version.Major == 6 && version.Minor == 3)
|
||||||
|
return "Windows 8.1";
|
||||||
|
|
||||||
|
if (version.Major == 6 && version.Minor == 2)
|
||||||
|
return "Windows 8";
|
||||||
|
|
||||||
|
if (version.Major == 6 && version.Minor == 1)
|
||||||
|
return "Windows 7";
|
||||||
|
|
||||||
|
return $"Windows {version.Major}.{version.Minor}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetLinuxVersion()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Read /etc/os-release, should work everywhere
|
||||||
|
if (File.Exists("/etc/os-release"))
|
||||||
|
{
|
||||||
|
var lines = File.ReadAllLines("/etc/os-release");
|
||||||
|
string? name = null;
|
||||||
|
string? version = null;
|
||||||
|
|
||||||
|
foreach (var line in lines)
|
||||||
|
if (line.StartsWith("NAME="))
|
||||||
|
name = line.Substring(5).Trim('"');
|
||||||
|
else if (line.StartsWith("VERSION_ID="))
|
||||||
|
version = line.Substring(11).Trim('"');
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(name)) return string.IsNullOrEmpty(version) ? name : $"{name} {version}";
|
||||||
|
}
|
||||||
|
|
||||||
|
//If for some weird reason it still uses lsb release
|
||||||
|
if (File.Exists("/etc/lsb-release"))
|
||||||
|
{
|
||||||
|
var lines = File.ReadAllLines("/etc/lsb-release");
|
||||||
|
string? name = null;
|
||||||
|
string? version = null;
|
||||||
|
|
||||||
|
foreach (var line in lines)
|
||||||
|
if (line.StartsWith("DISTRIB_ID="))
|
||||||
|
name = line.Substring(11);
|
||||||
|
else if (line.StartsWith("DISTRIB_RELEASE="))
|
||||||
|
version = line.Substring(16);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(name)) return string.IsNullOrEmpty(version) ? name : $"{name} {version}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback
|
||||||
|
return $"Linux {Environment.OSVersion.Version}";
|
||||||
|
}
|
||||||
|
}
|
||||||
7
Moonlight.Api/Admin/Sys/Settings/SettingsOptions.cs
Normal file
7
Moonlight.Api/Admin/Sys/Settings/SettingsOptions.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Moonlight.Api.Admin.Sys.Settings;
|
||||||
|
|
||||||
|
public class SettingsOptions
|
||||||
|
{
|
||||||
|
public TimeSpan LookupL1CacheTime { get; set; } = TimeSpan.FromMinutes(1);
|
||||||
|
public TimeSpan LookupL2CacheTime { get; set; } = TimeSpan.FromMinutes(5);
|
||||||
|
}
|
||||||
83
Moonlight.Api/Admin/Sys/Settings/SettingsService.cs
Normal file
83
Moonlight.Api/Admin/Sys/Settings/SettingsService.cs
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Caching.Hybrid;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using Moonlight.Api.Infrastructure.Database;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys.Settings;
|
||||||
|
|
||||||
|
public class SettingsService
|
||||||
|
{
|
||||||
|
private const string CacheKey = "Moonlight.Api.SettingsService.{0}";
|
||||||
|
private readonly HybridCache HybridCache;
|
||||||
|
private readonly IOptions<SettingsOptions> Options;
|
||||||
|
private readonly DatabaseRepository<SettingsOption> Repository;
|
||||||
|
|
||||||
|
public SettingsService(
|
||||||
|
DatabaseRepository<SettingsOption> repository,
|
||||||
|
IOptions<SettingsOptions> options,
|
||||||
|
HybridCache hybridCache
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Repository = repository;
|
||||||
|
HybridCache = hybridCache;
|
||||||
|
Options = options;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<T?> GetValueAsync<T>(string key)
|
||||||
|
{
|
||||||
|
var cacheKey = string.Format(CacheKey, key);
|
||||||
|
|
||||||
|
var value = await HybridCache.GetOrCreateAsync<string?>(
|
||||||
|
cacheKey,
|
||||||
|
async ct =>
|
||||||
|
{
|
||||||
|
return await Repository
|
||||||
|
.Query()
|
||||||
|
.Where(x => x.Key == key)
|
||||||
|
.Select(o => o.ValueJson)
|
||||||
|
.FirstOrDefaultAsync(ct);
|
||||||
|
},
|
||||||
|
new HybridCacheEntryOptions
|
||||||
|
{
|
||||||
|
LocalCacheExpiration = Options.Value.LookupL1CacheTime,
|
||||||
|
Expiration = Options.Value.LookupL2CacheTime
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(value))
|
||||||
|
return default;
|
||||||
|
|
||||||
|
return JsonSerializer.Deserialize<T>(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SetValueAsync<T>(string key, T value)
|
||||||
|
{
|
||||||
|
var cacheKey = string.Format(CacheKey, key);
|
||||||
|
|
||||||
|
var option = await Repository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(x => x.Key == key);
|
||||||
|
|
||||||
|
var json = JsonSerializer.Serialize(value);
|
||||||
|
|
||||||
|
if (option != null)
|
||||||
|
{
|
||||||
|
option.ValueJson = json;
|
||||||
|
await Repository.UpdateAsync(option);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
option = new SettingsOption
|
||||||
|
{
|
||||||
|
Key = key,
|
||||||
|
ValueJson = json
|
||||||
|
};
|
||||||
|
|
||||||
|
await Repository.AddAsync(option);
|
||||||
|
}
|
||||||
|
|
||||||
|
await HybridCache.RemoveAsync(cacheKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
47
Moonlight.Api/Admin/Sys/Settings/WhiteLabelingController.cs
Normal file
47
Moonlight.Api/Admin/Sys/Settings/WhiteLabelingController.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Moonlight.Api.Shared.Frontend;
|
||||||
|
using Moonlight.Shared;
|
||||||
|
using Moonlight.Shared.Admin.Sys.Settings;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys.Settings;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Authorize(Policy = Permissions.System.Settings)]
|
||||||
|
[Route("api/admin/system/settings/whiteLabeling")]
|
||||||
|
public class WhiteLabelingController : Controller
|
||||||
|
{
|
||||||
|
private readonly FrontendService FrontendService;
|
||||||
|
private readonly SettingsService SettingsService;
|
||||||
|
|
||||||
|
public WhiteLabelingController(SettingsService settingsService, FrontendService frontendService)
|
||||||
|
{
|
||||||
|
SettingsService = settingsService;
|
||||||
|
FrontendService = frontendService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<ActionResult<WhiteLabelingDto>> GetAsync()
|
||||||
|
{
|
||||||
|
var dto = new WhiteLabelingDto
|
||||||
|
{
|
||||||
|
Name = await SettingsService.GetValueAsync<string>(FrontendSettingConstants.Name) ?? "Moonlight"
|
||||||
|
};
|
||||||
|
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<ActionResult<WhiteLabelingDto>> PostAsync([FromBody] SetWhiteLabelingDto request)
|
||||||
|
{
|
||||||
|
await SettingsService.SetValueAsync(FrontendSettingConstants.Name, request.Name);
|
||||||
|
await FrontendService.ResetCacheAsync();
|
||||||
|
|
||||||
|
var dto = new WhiteLabelingDto
|
||||||
|
{
|
||||||
|
Name = await SettingsService.GetValueAsync<string>(FrontendSettingConstants.Name) ?? "Moonlight"
|
||||||
|
};
|
||||||
|
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
}
|
||||||
35
Moonlight.Api/Admin/Sys/SystemController.cs
Normal file
35
Moonlight.Api/Admin/Sys/SystemController.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Moonlight.Shared;
|
||||||
|
using Moonlight.Shared.Admin.Sys;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/system")]
|
||||||
|
public class SystemController : Controller
|
||||||
|
{
|
||||||
|
private readonly ApplicationService ApplicationService;
|
||||||
|
|
||||||
|
public SystemController(ApplicationService applicationService)
|
||||||
|
{
|
||||||
|
ApplicationService = applicationService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("info")]
|
||||||
|
[Authorize(Policy = Permissions.System.Info)]
|
||||||
|
public async Task<ActionResult<SystemInfoDto>> GetInfoAsync()
|
||||||
|
{
|
||||||
|
var cpuUsage = await ApplicationService.GetCpuUsageAsync();
|
||||||
|
var memoryUsage = await ApplicationService.GetMemoryUsageAsync();
|
||||||
|
|
||||||
|
return new SystemInfoDto(
|
||||||
|
cpuUsage,
|
||||||
|
memoryUsage,
|
||||||
|
ApplicationService.OperatingSystem,
|
||||||
|
DateTimeOffset.UtcNow - ApplicationService.StartedAt,
|
||||||
|
ApplicationService.VersionName,
|
||||||
|
ApplicationService.IsUpToDate
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
20
Moonlight.Api/Admin/Sys/Themes/ThemeMapper.cs
Normal file
20
Moonlight.Api/Admin/Sys/Themes/ThemeMapper.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
using Moonlight.Shared.Admin.Sys.Themes;
|
||||||
|
using Riok.Mapperly.Abstractions;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys.Themes;
|
||||||
|
|
||||||
|
[Mapper]
|
||||||
|
[SuppressMessage("Mapper", "RMG020:No members are mapped in an object mapping")]
|
||||||
|
[SuppressMessage("Mapper", "RMG012:No members are mapped in an object mapping")]
|
||||||
|
public static partial class ThemeMapper
|
||||||
|
{
|
||||||
|
public static partial IQueryable<ThemeDto> ProjectToDto(this IQueryable<Theme> themes);
|
||||||
|
|
||||||
|
public static partial ThemeDto ToDto(Theme theme);
|
||||||
|
|
||||||
|
public static partial void Merge([MappingTarget] Theme theme, UpdateThemeDto request);
|
||||||
|
|
||||||
|
public static partial Theme ToEntity(CreateThemeDto request);
|
||||||
|
}
|
||||||
12
Moonlight.Api/Admin/Sys/Themes/ThemeTransferModel.cs
Normal file
12
Moonlight.Api/Admin/Sys/Themes/ThemeTransferModel.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using VYaml.Annotations;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys.Themes;
|
||||||
|
|
||||||
|
[YamlObject]
|
||||||
|
public partial class ThemeTransferModel
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Version { get; set; }
|
||||||
|
public string Author { get; set; }
|
||||||
|
public string CssContent { get; set; }
|
||||||
|
}
|
||||||
138
Moonlight.Api/Admin/Sys/Themes/ThemesController.cs
Normal file
138
Moonlight.Api/Admin/Sys/Themes/ThemesController.cs
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Moonlight.Api.Infrastructure.Database;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
using Moonlight.Api.Shared.Frontend;
|
||||||
|
using Moonlight.Shared;
|
||||||
|
using Moonlight.Shared.Admin.Sys.Themes;
|
||||||
|
using Moonlight.Shared.Shared;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys.Themes;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/themes")]
|
||||||
|
public class ThemesController : Controller
|
||||||
|
{
|
||||||
|
private readonly FrontendService FrontendService;
|
||||||
|
private readonly DatabaseRepository<Theme> ThemeRepository;
|
||||||
|
|
||||||
|
public ThemesController(DatabaseRepository<Theme> themeRepository, FrontendService frontendService)
|
||||||
|
{
|
||||||
|
ThemeRepository = themeRepository;
|
||||||
|
FrontendService = frontendService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Authorize(Policy = Permissions.Themes.View)]
|
||||||
|
public async Task<ActionResult<PagedData<ThemeDto>>> GetAsync(
|
||||||
|
[FromQuery] int startIndex,
|
||||||
|
[FromQuery] int length,
|
||||||
|
[FromQuery] FilterOptions? filterOptions
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Validation
|
||||||
|
if (startIndex < 0)
|
||||||
|
return Problem("Invalid start index specified", statusCode: 400);
|
||||||
|
|
||||||
|
if (length is < 1 or > 100)
|
||||||
|
return Problem("Invalid length specified");
|
||||||
|
|
||||||
|
// Query building
|
||||||
|
|
||||||
|
var query = ThemeRepository
|
||||||
|
.Query();
|
||||||
|
|
||||||
|
// Filters
|
||||||
|
if (filterOptions != null)
|
||||||
|
foreach (var filterOption in filterOptions.Filters)
|
||||||
|
query = filterOption.Key switch
|
||||||
|
{
|
||||||
|
nameof(Theme.Name) =>
|
||||||
|
query.Where(user => EF.Functions.ILike(user.Name, $"%{filterOption.Value}%")),
|
||||||
|
|
||||||
|
nameof(Theme.Version) =>
|
||||||
|
query.Where(user => EF.Functions.ILike(user.Version, $"%{filterOption.Value}%")),
|
||||||
|
|
||||||
|
nameof(Theme.Author) =>
|
||||||
|
query.Where(user => EF.Functions.ILike(user.Author, $"%{filterOption.Value}%")),
|
||||||
|
|
||||||
|
_ => query
|
||||||
|
};
|
||||||
|
|
||||||
|
// Pagination
|
||||||
|
var data = await query
|
||||||
|
.OrderBy(x => x.Id)
|
||||||
|
.ProjectToDto()
|
||||||
|
.Skip(startIndex)
|
||||||
|
.Take(length)
|
||||||
|
.ToArrayAsync();
|
||||||
|
|
||||||
|
var total = await query.CountAsync();
|
||||||
|
|
||||||
|
return new PagedData<ThemeDto>(data, total);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id:int}")]
|
||||||
|
[Authorize(Policy = Permissions.Themes.View)]
|
||||||
|
public async Task<ActionResult<ThemeDto>> GetAsync([FromRoute] int id)
|
||||||
|
{
|
||||||
|
var item = await ThemeRepository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
|
||||||
|
if (item == null)
|
||||||
|
return Problem("No theme with this id", statusCode: 404);
|
||||||
|
|
||||||
|
return ThemeMapper.ToDto(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[Authorize(Policy = Permissions.Themes.Create)]
|
||||||
|
public async Task<ActionResult<ThemeDto>> CreateAsync([FromBody] CreateThemeDto request)
|
||||||
|
{
|
||||||
|
var theme = ThemeMapper.ToEntity(request);
|
||||||
|
|
||||||
|
var finalTheme = await ThemeRepository.AddAsync(theme);
|
||||||
|
await FrontendService.ResetCacheAsync();
|
||||||
|
|
||||||
|
return ThemeMapper.ToDto(finalTheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPatch("{id:int}")]
|
||||||
|
[Authorize(Policy = Permissions.Themes.Edit)]
|
||||||
|
public async Task<ActionResult<ThemeDto>> UpdateAsync([FromRoute] int id, [FromBody] UpdateThemeDto request)
|
||||||
|
{
|
||||||
|
var theme = await ThemeRepository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
|
||||||
|
if (theme == null)
|
||||||
|
return Problem("No theme with this id found", statusCode: 404);
|
||||||
|
|
||||||
|
ThemeMapper.Merge(theme, request);
|
||||||
|
await ThemeRepository.UpdateAsync(theme);
|
||||||
|
|
||||||
|
await FrontendService.ResetCacheAsync();
|
||||||
|
|
||||||
|
return ThemeMapper.ToDto(theme);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("{id:int}")]
|
||||||
|
[Authorize(Policy = Permissions.Themes.Delete)]
|
||||||
|
public async Task<ActionResult> DeleteAsync([FromRoute] int id)
|
||||||
|
{
|
||||||
|
var theme = await ThemeRepository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
|
||||||
|
if (theme == null)
|
||||||
|
return Problem("No theme with this id found", statusCode: 404);
|
||||||
|
|
||||||
|
await ThemeRepository.RemoveAsync(theme);
|
||||||
|
|
||||||
|
await FrontendService.ResetCacheAsync();
|
||||||
|
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
74
Moonlight.Api/Admin/Sys/Themes/TransferController.cs
Normal file
74
Moonlight.Api/Admin/Sys/Themes/TransferController.cs
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Moonlight.Api.Infrastructure.Database;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
using Moonlight.Shared;
|
||||||
|
using Moonlight.Shared.Admin.Sys.Themes;
|
||||||
|
using VYaml.Serialization;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys.Themes;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/themes")]
|
||||||
|
[Authorize(Policy = Permissions.Themes.View)]
|
||||||
|
public class TransferController : Controller
|
||||||
|
{
|
||||||
|
private readonly DatabaseRepository<Theme> ThemeRepository;
|
||||||
|
|
||||||
|
public TransferController(DatabaseRepository<Theme> themeRepository)
|
||||||
|
{
|
||||||
|
ThemeRepository = themeRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id:int}/export")]
|
||||||
|
public async Task<ActionResult> ExportAsync([FromRoute] int id)
|
||||||
|
{
|
||||||
|
var theme = await ThemeRepository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
|
||||||
|
if (theme == null)
|
||||||
|
return Problem("No theme with that id found", statusCode: 404);
|
||||||
|
|
||||||
|
var yml = YamlSerializer.Serialize(new ThemeTransferModel
|
||||||
|
{
|
||||||
|
Name = theme.Name,
|
||||||
|
Author = theme.Author,
|
||||||
|
CssContent = theme.CssContent,
|
||||||
|
Version = theme.Version
|
||||||
|
});
|
||||||
|
|
||||||
|
return File(yml.ToArray(), "text/yaml", $"{theme.Name}.yml");
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("import")]
|
||||||
|
public async Task<ActionResult<ThemeDto>> ImportAsync()
|
||||||
|
{
|
||||||
|
var themeToImport = await YamlSerializer.DeserializeAsync<ThemeTransferModel>(Request.Body);
|
||||||
|
|
||||||
|
var existingTheme = await ThemeRepository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(x => x.Name == themeToImport.Name && x.Author == themeToImport.Author);
|
||||||
|
|
||||||
|
if (existingTheme == null)
|
||||||
|
{
|
||||||
|
var finalTheme = await ThemeRepository.AddAsync(new Theme
|
||||||
|
{
|
||||||
|
Name = themeToImport.Name,
|
||||||
|
Author = themeToImport.Author,
|
||||||
|
CssContent = themeToImport.CssContent,
|
||||||
|
Version = themeToImport.Version
|
||||||
|
});
|
||||||
|
|
||||||
|
return ThemeMapper.ToDto(finalTheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
existingTheme.CssContent = themeToImport.CssContent;
|
||||||
|
existingTheme.Version = themeToImport.Version;
|
||||||
|
|
||||||
|
await ThemeRepository.UpdateAsync(existingTheme);
|
||||||
|
|
||||||
|
return ThemeMapper.ToDto(existingTheme);
|
||||||
|
}
|
||||||
|
}
|
||||||
7
Moonlight.Api/Admin/Sys/Versions/FrontendOptions.cs
Normal file
7
Moonlight.Api/Admin/Sys/Versions/FrontendOptions.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Moonlight.Api.Admin.Sys.Versions;
|
||||||
|
|
||||||
|
public class FrontendOptions
|
||||||
|
{
|
||||||
|
public bool Enabled { get; set; } = true;
|
||||||
|
public int CacheMinutes { get; set; } = 3;
|
||||||
|
}
|
||||||
12
Moonlight.Api/Admin/Sys/Versions/MoonlightVersion.cs
Normal file
12
Moonlight.Api/Admin/Sys/Versions/MoonlightVersion.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
namespace Moonlight.Api.Admin.Sys.Versions;
|
||||||
|
|
||||||
|
// Notes:
|
||||||
|
// Identifier - This needs to be the branch to clone to build this version if
|
||||||
|
// you want to use the container helper
|
||||||
|
|
||||||
|
public record MoonlightVersion(
|
||||||
|
string Identifier,
|
||||||
|
bool IsPreRelease,
|
||||||
|
bool IsDevelopment,
|
||||||
|
DateTimeOffset CreatedAt
|
||||||
|
);
|
||||||
14
Moonlight.Api/Admin/Sys/Versions/VersionMapper.cs
Normal file
14
Moonlight.Api/Admin/Sys/Versions/VersionMapper.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Moonlight.Shared.Admin.Sys.Versions;
|
||||||
|
using Riok.Mapperly.Abstractions;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys.Versions;
|
||||||
|
|
||||||
|
[Mapper]
|
||||||
|
[SuppressMessage("Mapper", "RMG020:Source member is not mapped to any target member")]
|
||||||
|
[SuppressMessage("Mapper", "RMG012:Source member was not found for target member")]
|
||||||
|
public static partial class VersionMapper
|
||||||
|
{
|
||||||
|
public static partial IEnumerable<VersionDto> ToDtos(IEnumerable<MoonlightVersion> versions);
|
||||||
|
public static partial VersionDto ToDto(MoonlightVersion version);
|
||||||
|
}
|
||||||
7
Moonlight.Api/Admin/Sys/Versions/VersionOptions.cs
Normal file
7
Moonlight.Api/Admin/Sys/Versions/VersionOptions.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Moonlight.Api.Admin.Sys.Versions;
|
||||||
|
|
||||||
|
public class VersionOptions
|
||||||
|
{
|
||||||
|
public bool OfflineMode { get; set; }
|
||||||
|
public string? CurrentOverride { get; set; }
|
||||||
|
}
|
||||||
135
Moonlight.Api/Admin/Sys/Versions/VersionService.cs
Normal file
135
Moonlight.Api/Admin/Sys/Versions/VersionService.cs
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
using System.Text.Json.Nodes;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys.Versions;
|
||||||
|
|
||||||
|
public partial class VersionService
|
||||||
|
{
|
||||||
|
private const string VersionPath = "/app/version";
|
||||||
|
private const string GiteaServer = "https://git.battlestati.one";
|
||||||
|
private const string GiteaRepository = "Moonlight-Panel/Moonlight";
|
||||||
|
private readonly IHttpClientFactory HttpClientFactory;
|
||||||
|
private readonly IOptions<VersionOptions> Options;
|
||||||
|
|
||||||
|
public VersionService(
|
||||||
|
IOptions<VersionOptions> options,
|
||||||
|
IHttpClientFactory httpClientFactory
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Options = options;
|
||||||
|
HttpClientFactory = httpClientFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
[GeneratedRegex(@"^v(?!1(\.|$))\d+\.[A-Za-z0-9]+(\.[A-Za-z0-9]+)*$")]
|
||||||
|
private static partial Regex RegexFilter();
|
||||||
|
|
||||||
|
public async Task<MoonlightVersion[]> GetVersionsAsync()
|
||||||
|
{
|
||||||
|
if (Options.Value.OfflineMode)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
var versions = new List<MoonlightVersion>();
|
||||||
|
var httpClient = HttpClientFactory.CreateClient();
|
||||||
|
|
||||||
|
// Tags
|
||||||
|
const string tagsPath = $"{GiteaServer}/api/v1/repos/{GiteaRepository}/tags";
|
||||||
|
|
||||||
|
await using var tagsJsonStream = await httpClient.GetStreamAsync(tagsPath);
|
||||||
|
var tagsJson = await JsonNode.ParseAsync(tagsJsonStream);
|
||||||
|
|
||||||
|
if (tagsJson != null)
|
||||||
|
foreach (var node in tagsJson.AsArray())
|
||||||
|
{
|
||||||
|
if (node == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var name = node["name"]?.GetValue<string>() ?? "N/A";
|
||||||
|
var createdAt = node["createdAt"]?.GetValue<DateTimeOffset>() ?? DateTimeOffset.MinValue;
|
||||||
|
|
||||||
|
if (!RegexFilter().IsMatch(name))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
versions.Add(new MoonlightVersion(
|
||||||
|
name,
|
||||||
|
name.EndsWith('b'),
|
||||||
|
false,
|
||||||
|
createdAt
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Branches
|
||||||
|
const string branchesPath = $"{GiteaServer}/api/v1/repos/{GiteaRepository}/branches";
|
||||||
|
|
||||||
|
await using var branchesJsonStream = await httpClient.GetStreamAsync(branchesPath);
|
||||||
|
var branchesJson = await JsonNode.ParseAsync(branchesJsonStream);
|
||||||
|
|
||||||
|
if (branchesJson != null)
|
||||||
|
foreach (var node in branchesJson.AsArray())
|
||||||
|
{
|
||||||
|
if (node == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var name = node["name"]?.GetValue<string>() ?? "N/A";
|
||||||
|
var commit = node["commit"];
|
||||||
|
|
||||||
|
if (commit == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var createdAt = commit["timestamp"]?.GetValue<DateTimeOffset>() ?? DateTimeOffset.MinValue;
|
||||||
|
|
||||||
|
if (!RegexFilter().IsMatch(name))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
versions.Add(new MoonlightVersion(
|
||||||
|
name,
|
||||||
|
name.EndsWith('b'),
|
||||||
|
true,
|
||||||
|
createdAt
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return versions.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<MoonlightVersion> GetInstanceVersionAsync()
|
||||||
|
{
|
||||||
|
var knownVersions = await GetVersionsAsync();
|
||||||
|
|
||||||
|
string versionIdentifier;
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(Options.Value.CurrentOverride))
|
||||||
|
{
|
||||||
|
versionIdentifier = Options.Value.CurrentOverride;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (File.Exists(VersionPath))
|
||||||
|
versionIdentifier = await File.ReadAllTextAsync(VersionPath);
|
||||||
|
else
|
||||||
|
versionIdentifier = "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
var version = knownVersions.FirstOrDefault(x => x.Identifier == versionIdentifier);
|
||||||
|
|
||||||
|
if (version != null)
|
||||||
|
return version;
|
||||||
|
|
||||||
|
return new MoonlightVersion(
|
||||||
|
versionIdentifier,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
DateTimeOffset.UtcNow
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<MoonlightVersion?> GetLatestVersionAsync()
|
||||||
|
{
|
||||||
|
var versions = await GetVersionsAsync();
|
||||||
|
|
||||||
|
return versions
|
||||||
|
.Where(x => x is { IsDevelopment: false, IsPreRelease: false })
|
||||||
|
.OrderByDescending(x => x.CreatedAt)
|
||||||
|
.FirstOrDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
44
Moonlight.Api/Admin/Sys/Versions/VersionsController.cs
Normal file
44
Moonlight.Api/Admin/Sys/Versions/VersionsController.cs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Moonlight.Shared;
|
||||||
|
using Moonlight.Shared.Admin.Sys.Versions;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Sys.Versions;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/versions")]
|
||||||
|
[Authorize(Policy = Permissions.System.Versions)]
|
||||||
|
public class VersionsController : Controller
|
||||||
|
{
|
||||||
|
private readonly VersionService VersionService;
|
||||||
|
|
||||||
|
public VersionsController(VersionService versionService)
|
||||||
|
{
|
||||||
|
VersionService = versionService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<ActionResult<VersionDto[]>> GetAsync()
|
||||||
|
{
|
||||||
|
var versions = await VersionService.GetVersionsAsync();
|
||||||
|
return VersionMapper.ToDtos(versions).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("instance")]
|
||||||
|
public async Task<ActionResult<VersionDto>> GetInstanceAsync()
|
||||||
|
{
|
||||||
|
var version = await VersionService.GetInstanceVersionAsync();
|
||||||
|
return VersionMapper.ToDto(version);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("latest")]
|
||||||
|
public async Task<ActionResult<VersionDto>> GetLatestAsync()
|
||||||
|
{
|
||||||
|
var version = await VersionService.GetLatestVersionAsync();
|
||||||
|
|
||||||
|
if (version == null)
|
||||||
|
return Problem("Unable to retrieve latest version", statusCode: 404);
|
||||||
|
|
||||||
|
return VersionMapper.ToDto(version);
|
||||||
|
}
|
||||||
|
}
|
||||||
20
Moonlight.Api/Admin/Users/Roles/RoleMapper.cs
Normal file
20
Moonlight.Api/Admin/Users/Roles/RoleMapper.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
using Moonlight.Shared.Admin.Users.Roles;
|
||||||
|
using Riok.Mapperly.Abstractions;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Users.Roles;
|
||||||
|
|
||||||
|
[Mapper]
|
||||||
|
[SuppressMessage("Mapper", "RMG020:Source member is not mapped to any target member")]
|
||||||
|
[SuppressMessage("Mapper", "RMG012:Source member was not found for target member")]
|
||||||
|
public static partial class RoleMapper
|
||||||
|
{
|
||||||
|
[MapProperty([nameof(Role.Members), nameof(Role.Members.Count)], nameof(RoleDto.MemberCount))]
|
||||||
|
public static partial RoleDto ToDto(Role role);
|
||||||
|
|
||||||
|
public static partial Role ToEntity(CreateRoleDto request);
|
||||||
|
public static partial void Merge([MappingTarget] Role role, UpdateRoleDto request);
|
||||||
|
|
||||||
|
public static partial IQueryable<RoleDto> ProjectToDto(this IQueryable<Role> roles);
|
||||||
|
}
|
||||||
165
Moonlight.Api/Admin/Users/Roles/RoleMembersController.cs
Normal file
165
Moonlight.Api/Admin/Users/Roles/RoleMembersController.cs
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Moonlight.Api.Admin.Users.Users;
|
||||||
|
using Moonlight.Api.Infrastructure.Database;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
using Moonlight.Shared;
|
||||||
|
using Moonlight.Shared.Admin.Users.Users;
|
||||||
|
using Moonlight.Shared.Shared;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Users.Roles;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Authorize(Policy = Permissions.Roles.Members)]
|
||||||
|
[Route("api/admin/roles/{roleId:int}/members")]
|
||||||
|
public class RoleMembersController : Controller
|
||||||
|
{
|
||||||
|
private readonly DatabaseRepository<RoleMember> RoleMembersRepository;
|
||||||
|
private readonly DatabaseRepository<Role> RolesRepository;
|
||||||
|
private readonly DatabaseRepository<User> UsersRepository;
|
||||||
|
|
||||||
|
public RoleMembersController(
|
||||||
|
DatabaseRepository<User> usersRepository,
|
||||||
|
DatabaseRepository<Role> rolesRepository,
|
||||||
|
DatabaseRepository<RoleMember> roleMembersRepository
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UsersRepository = usersRepository;
|
||||||
|
RolesRepository = rolesRepository;
|
||||||
|
RoleMembersRepository = roleMembersRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<ActionResult<PagedData<UserDto>>> GetAsync(
|
||||||
|
[FromRoute] int roleId,
|
||||||
|
[FromQuery] int startIndex, [FromQuery] int length,
|
||||||
|
[FromQuery] string? searchTerm
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Validation
|
||||||
|
if (startIndex < 0)
|
||||||
|
return Problem("Invalid start index specified", statusCode: 400);
|
||||||
|
|
||||||
|
if (length is < 1 or > 100)
|
||||||
|
return Problem("Invalid length specified");
|
||||||
|
|
||||||
|
// Query building
|
||||||
|
|
||||||
|
var query = RoleMembersRepository
|
||||||
|
.Query()
|
||||||
|
.Where(x => x.Role.Id == roleId)
|
||||||
|
.Select(x => x.User);
|
||||||
|
|
||||||
|
// Filtering
|
||||||
|
if (!string.IsNullOrWhiteSpace(searchTerm))
|
||||||
|
query = query.Where(x =>
|
||||||
|
EF.Functions.ILike(x.Username, $"%{searchTerm}%") ||
|
||||||
|
EF.Functions.ILike(x.Email, $"%{searchTerm}%")
|
||||||
|
);
|
||||||
|
|
||||||
|
// Pagination
|
||||||
|
var items = UserMapper.ProjectToDto(query
|
||||||
|
.OrderBy(x => x.Id)
|
||||||
|
.Skip(startIndex)
|
||||||
|
.Take(length))
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
var totalCount = await query.CountAsync();
|
||||||
|
|
||||||
|
return new PagedData<UserDto>(items, totalCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("available")]
|
||||||
|
public async Task<ActionResult<PagedData<UserDto>>> GetAvailableAsync(
|
||||||
|
[FromRoute] int roleId,
|
||||||
|
[FromQuery] int startIndex, [FromQuery] int length,
|
||||||
|
[FromQuery] string? searchTerm
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Validation
|
||||||
|
if (startIndex < 0)
|
||||||
|
return Problem("Invalid start index specified", statusCode: 400);
|
||||||
|
|
||||||
|
if (length is < 1 or > 100)
|
||||||
|
return Problem("Invalid length specified");
|
||||||
|
|
||||||
|
// Query building
|
||||||
|
|
||||||
|
var query = UsersRepository
|
||||||
|
.Query()
|
||||||
|
.Where(x => x.RoleMemberships.All(y => y.Role.Id != roleId));
|
||||||
|
|
||||||
|
// Filtering
|
||||||
|
if (!string.IsNullOrWhiteSpace(searchTerm))
|
||||||
|
query = query.Where(x =>
|
||||||
|
EF.Functions.ILike(x.Username, $"%{searchTerm}%") ||
|
||||||
|
EF.Functions.ILike(x.Email, $"%{searchTerm}%")
|
||||||
|
);
|
||||||
|
|
||||||
|
// Pagination
|
||||||
|
var items = UserMapper.ProjectToDto(query
|
||||||
|
.OrderBy(x => x.Id)
|
||||||
|
.Skip(startIndex)
|
||||||
|
.Take(length))
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
var totalCount = await query.CountAsync();
|
||||||
|
|
||||||
|
return new PagedData<UserDto>(items, totalCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPut("{userId:int}")]
|
||||||
|
public async Task<ActionResult> AddMemberAsync([FromRoute] int roleId, [FromRoute] int userId)
|
||||||
|
{
|
||||||
|
// Check and load role
|
||||||
|
var role = await RolesRepository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == roleId);
|
||||||
|
|
||||||
|
if (role == null)
|
||||||
|
return Problem("Role not found", statusCode: 404);
|
||||||
|
|
||||||
|
// Check and load user
|
||||||
|
var user = await UsersRepository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == userId);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
return Problem("User not found", statusCode: 404);
|
||||||
|
|
||||||
|
// Check if a role member already exists with these details
|
||||||
|
var isUserInRole = await RoleMembersRepository
|
||||||
|
.Query()
|
||||||
|
.AnyAsync(x => x.Role.Id == roleId && x.User.Id == userId);
|
||||||
|
|
||||||
|
if (isUserInRole)
|
||||||
|
return Problem("User is already a member of this role", statusCode: 400);
|
||||||
|
|
||||||
|
var roleMember = new RoleMember
|
||||||
|
{
|
||||||
|
Role = role,
|
||||||
|
User = user
|
||||||
|
};
|
||||||
|
|
||||||
|
await RoleMembersRepository.AddAsync(roleMember);
|
||||||
|
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("{userId:int}")]
|
||||||
|
public async Task<ActionResult> RemoveMemberAsync([FromRoute] int roleId, [FromRoute] int userId)
|
||||||
|
{
|
||||||
|
var roleMember = await RoleMembersRepository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(x => x.User.Id == userId && x.Role.Id == roleId);
|
||||||
|
|
||||||
|
if (roleMember == null)
|
||||||
|
return Problem("User is not a member of this role, the role does not exist or the user does not exist",
|
||||||
|
statusCode: 404);
|
||||||
|
|
||||||
|
await RoleMembersRepository.RemoveAsync(roleMember);
|
||||||
|
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
124
Moonlight.Api/Admin/Users/Roles/RolesController.cs
Normal file
124
Moonlight.Api/Admin/Users/Roles/RolesController.cs
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Moonlight.Api.Infrastructure.Database;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
using Moonlight.Shared;
|
||||||
|
using Moonlight.Shared.Admin.Users.Roles;
|
||||||
|
using Moonlight.Shared.Shared;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Users.Roles;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/roles")]
|
||||||
|
public class RolesController : Controller
|
||||||
|
{
|
||||||
|
private readonly DatabaseRepository<Role> RoleRepository;
|
||||||
|
|
||||||
|
public RolesController(DatabaseRepository<Role> roleRepository)
|
||||||
|
{
|
||||||
|
RoleRepository = roleRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Authorize(Policy = Permissions.Roles.View)]
|
||||||
|
public async Task<ActionResult<PagedData<RoleDto>>> GetAsync(
|
||||||
|
[FromQuery] int startIndex,
|
||||||
|
[FromQuery] int length,
|
||||||
|
[FromQuery] FilterOptions? filterOptions
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Validation
|
||||||
|
if (startIndex < 0)
|
||||||
|
return Problem("Invalid start index specified", statusCode: 400);
|
||||||
|
|
||||||
|
if (length is < 1 or > 100)
|
||||||
|
return Problem("Invalid length specified");
|
||||||
|
|
||||||
|
// Query building
|
||||||
|
|
||||||
|
var query = RoleRepository
|
||||||
|
.Query();
|
||||||
|
|
||||||
|
// Filters
|
||||||
|
if (filterOptions != null)
|
||||||
|
foreach (var filterOption in filterOptions.Filters)
|
||||||
|
query = filterOption.Key switch
|
||||||
|
{
|
||||||
|
nameof(Role.Name) =>
|
||||||
|
query.Where(role => EF.Functions.ILike(role.Name, $"%{filterOption.Value}%")),
|
||||||
|
|
||||||
|
_ => query
|
||||||
|
};
|
||||||
|
|
||||||
|
// Pagination
|
||||||
|
var data = await query
|
||||||
|
.OrderBy(x => x.Id)
|
||||||
|
.ProjectToDto()
|
||||||
|
.Skip(startIndex)
|
||||||
|
.Take(length)
|
||||||
|
.ToArrayAsync();
|
||||||
|
|
||||||
|
var total = await query.CountAsync();
|
||||||
|
|
||||||
|
return new PagedData<RoleDto>(data, total);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id:int}")]
|
||||||
|
[Authorize(Policy = Permissions.Roles.View)]
|
||||||
|
public async Task<ActionResult<RoleDto>> GetAsync([FromRoute] int id)
|
||||||
|
{
|
||||||
|
var role = await RoleRepository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
|
||||||
|
if (role == null)
|
||||||
|
return Problem("No role with this id found", statusCode: 404);
|
||||||
|
|
||||||
|
return RoleMapper.ToDto(role);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[Authorize(Policy = Permissions.Roles.Create)]
|
||||||
|
public async Task<ActionResult<RoleDto>> CreateAsync([FromBody] CreateRoleDto request)
|
||||||
|
{
|
||||||
|
var role = RoleMapper.ToEntity(request);
|
||||||
|
|
||||||
|
var finalRole = await RoleRepository.AddAsync(role);
|
||||||
|
|
||||||
|
return RoleMapper.ToDto(finalRole);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPatch("{id:int}")]
|
||||||
|
[Authorize(Policy = Permissions.Roles.Edit)]
|
||||||
|
public async Task<ActionResult<RoleDto>> UpdateAsync([FromRoute] int id, [FromBody] UpdateRoleDto request)
|
||||||
|
{
|
||||||
|
var role = await RoleRepository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
|
||||||
|
if (role == null)
|
||||||
|
return Problem("No role with this id found", statusCode: 404);
|
||||||
|
|
||||||
|
RoleMapper.Merge(role, request);
|
||||||
|
|
||||||
|
await RoleRepository.UpdateAsync(role);
|
||||||
|
|
||||||
|
return RoleMapper.ToDto(role);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("{id:int}")]
|
||||||
|
[Authorize(Policy = Permissions.Roles.Delete)]
|
||||||
|
public async Task<ActionResult> DeleteAsync([FromRoute] int id)
|
||||||
|
{
|
||||||
|
var role = await RoleRepository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
|
||||||
|
if (role == null)
|
||||||
|
return Problem("No role with this id found", statusCode: 404);
|
||||||
|
|
||||||
|
await RoleRepository.RemoveAsync(role);
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
156
Moonlight.Api/Admin/Users/Users/UserAuthService.cs
Normal file
156
Moonlight.Api/Admin/Users/Users/UserAuthService.cs
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Caching.Hybrid;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using Moonlight.Api.Infrastructure.Database;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
using Moonlight.Api.Infrastructure.Hooks;
|
||||||
|
using Moonlight.Shared;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Users.Users;
|
||||||
|
|
||||||
|
public class UserAuthService
|
||||||
|
{
|
||||||
|
public const string CacheKeyPattern = $"Moonlight.{nameof(UserAuthService)}.{nameof(ValidateAsync)}-{{0}}";
|
||||||
|
|
||||||
|
private const string UserIdClaim = "UserId";
|
||||||
|
private const string IssuedAtClaim = "IssuedAt";
|
||||||
|
|
||||||
|
private readonly IEnumerable<IUserAuthHook> Hooks;
|
||||||
|
private readonly HybridCache HybridCache;
|
||||||
|
private readonly ILogger<UserAuthService> Logger;
|
||||||
|
private readonly IOptions<UserOptions> Options;
|
||||||
|
private readonly DatabaseRepository<User> UserRepository;
|
||||||
|
|
||||||
|
public UserAuthService(
|
||||||
|
DatabaseRepository<User> userRepository,
|
||||||
|
ILogger<UserAuthService> logger,
|
||||||
|
IOptions<UserOptions> options,
|
||||||
|
IEnumerable<IUserAuthHook> hooks,
|
||||||
|
HybridCache hybridCache
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UserRepository = userRepository;
|
||||||
|
Logger = logger;
|
||||||
|
Options = options;
|
||||||
|
Hooks = hooks;
|
||||||
|
HybridCache = hybridCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> SyncAsync(ClaimsPrincipal? principal)
|
||||||
|
{
|
||||||
|
if (principal is null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var username = principal.FindFirstValue(ClaimTypes.Name);
|
||||||
|
var email = principal.FindFirstValue(ClaimTypes.Email);
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(email))
|
||||||
|
{
|
||||||
|
Logger.LogWarning("Unable to sync user to database as name and/or email claims are missing");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We use email as the primary identifier here
|
||||||
|
var user = await UserRepository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(user => user.Email == email);
|
||||||
|
|
||||||
|
if (user == null) // Sync user if not already existing in the database
|
||||||
|
{
|
||||||
|
user = await UserRepository.AddAsync(new User
|
||||||
|
{
|
||||||
|
Username = username,
|
||||||
|
Email = email,
|
||||||
|
InvalidateTimestamp = DateTimeOffset.UtcNow.AddMinutes(-1)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else // Update properties of existing user
|
||||||
|
{
|
||||||
|
user.Username = username;
|
||||||
|
|
||||||
|
await UserRepository.UpdateAsync(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
principal.Identities.First().AddClaims([
|
||||||
|
new Claim(UserIdClaim, user.Id.ToString()),
|
||||||
|
new Claim(IssuedAtClaim, DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString())
|
||||||
|
]);
|
||||||
|
|
||||||
|
foreach (var hook in Hooks)
|
||||||
|
// Run every hook, and if any returns false, we return false as well
|
||||||
|
if (!await hook.SyncAsync(principal, user))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> ValidateAsync(ClaimsPrincipal? principal)
|
||||||
|
{
|
||||||
|
// Ignore malformed claims principal
|
||||||
|
if (principal is not { Identity.IsAuthenticated: true })
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var userIdString = principal.FindFirstValue(UserIdClaim);
|
||||||
|
|
||||||
|
if (!int.TryParse(userIdString, out var userId))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var cacheKey = string.Format(CacheKeyPattern, userId);
|
||||||
|
|
||||||
|
var user = await HybridCache.GetOrCreateAsync<UserSession?>(
|
||||||
|
cacheKey,
|
||||||
|
async ct =>
|
||||||
|
{
|
||||||
|
return await UserRepository
|
||||||
|
.Query()
|
||||||
|
.AsNoTracking()
|
||||||
|
.Where(u => u.Id == userId)
|
||||||
|
.Select(u => new UserSession(
|
||||||
|
u.InvalidateTimestamp,
|
||||||
|
u.RoleMemberships.SelectMany(x => x.Role.Permissions).ToArray())
|
||||||
|
)
|
||||||
|
.FirstOrDefaultAsync(ct);
|
||||||
|
},
|
||||||
|
new HybridCacheEntryOptions
|
||||||
|
{
|
||||||
|
LocalCacheExpiration = Options.Value.ValidationCacheL1Expiry,
|
||||||
|
Expiration = Options.Value.ValidationCacheL2Expiry
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var issuedAtString = principal.FindFirstValue(IssuedAtClaim);
|
||||||
|
|
||||||
|
if (!long.TryParse(issuedAtString, 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.InvalidateTimestamp)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Load every permission as claim
|
||||||
|
principal.Identities.First().AddClaims(
|
||||||
|
user.Permissions.Select(x => new Claim(Permissions.ClaimType, x))
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach (var hook in Hooks)
|
||||||
|
// Run every hook, and if any returns false we return false as well
|
||||||
|
if (!await hook.ValidateAsync(principal, userId))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A small model which contains data queried per session validation after the defined cache time.
|
||||||
|
// Used for projection
|
||||||
|
private record UserSession(DateTimeOffset InvalidateTimestamp, string[] Permissions);
|
||||||
|
}
|
||||||
54
Moonlight.Api/Admin/Users/Users/UserDeletionController.cs
Normal file
54
Moonlight.Api/Admin/Users/Users/UserDeletionController.cs
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Moonlight.Api.Infrastructure.Database;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
using Moonlight.Shared;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Users.Users;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/users")]
|
||||||
|
[Authorize(Policy = Permissions.Users.Delete)]
|
||||||
|
public class UserDeletionController : Controller
|
||||||
|
{
|
||||||
|
private readonly DatabaseRepository<User> Repository;
|
||||||
|
private readonly UserDeletionService UserDeletionService;
|
||||||
|
|
||||||
|
public UserDeletionController(UserDeletionService userDeletionService, DatabaseRepository<User> repository)
|
||||||
|
{
|
||||||
|
UserDeletionService = userDeletionService;
|
||||||
|
Repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("{id:int}")]
|
||||||
|
public async Task<ActionResult> DeleteAsync([FromRoute] int id)
|
||||||
|
{
|
||||||
|
var userExists = await Repository
|
||||||
|
.Query()
|
||||||
|
.AnyAsync(user => user.Id == id);
|
||||||
|
|
||||||
|
if (!userExists)
|
||||||
|
return Problem("No user with this id found", statusCode: 404);
|
||||||
|
|
||||||
|
var validationResult = await UserDeletionService.ValidateAsync(id);
|
||||||
|
|
||||||
|
if (!validationResult.IsValid)
|
||||||
|
{
|
||||||
|
return ValidationProblem(
|
||||||
|
new ValidationProblemDetails(
|
||||||
|
new Dictionary<string, string[]>
|
||||||
|
{
|
||||||
|
{
|
||||||
|
string.Empty,
|
||||||
|
validationResult.ErrorMessages.ToArray()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await UserDeletionService.DeleteAsync(id);
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
66
Moonlight.Api/Admin/Users/Users/UserDeletionService.cs
Normal file
66
Moonlight.Api/Admin/Users/Users/UserDeletionService.cs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Caching.Hybrid;
|
||||||
|
using Moonlight.Api.Infrastructure.Database;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
using Moonlight.Api.Infrastructure.Hooks;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Users.Users;
|
||||||
|
|
||||||
|
public class UserDeletionService
|
||||||
|
{
|
||||||
|
private readonly IEnumerable<IUserDeletionHook> Hooks;
|
||||||
|
private readonly HybridCache HybridCache;
|
||||||
|
private readonly DatabaseRepository<User> Repository;
|
||||||
|
|
||||||
|
public UserDeletionService(
|
||||||
|
DatabaseRepository<User> repository,
|
||||||
|
IEnumerable<IUserDeletionHook> hooks,
|
||||||
|
HybridCache hybridCache
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Repository = repository;
|
||||||
|
Hooks = hooks;
|
||||||
|
HybridCache = hybridCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<UserDeletionValidationResult> ValidateAsync(int userId)
|
||||||
|
{
|
||||||
|
var user = await Repository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == userId);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
throw new AggregateException($"User with id {userId} not found");
|
||||||
|
|
||||||
|
var errorMessages = new List<string>();
|
||||||
|
|
||||||
|
foreach (var hook in Hooks)
|
||||||
|
{
|
||||||
|
if (await hook.ValidateAsync(user, errorMessages))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
return new UserDeletionValidationResult(false, errorMessages);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new UserDeletionValidationResult(true, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task DeleteAsync(int userId)
|
||||||
|
{
|
||||||
|
var user = await Repository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == userId);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
throw new AggregateException($"User with id {userId} not found");
|
||||||
|
|
||||||
|
foreach (var hook in Hooks)
|
||||||
|
await hook.ExecuteAsync(user);
|
||||||
|
|
||||||
|
await Repository.RemoveAsync(user);
|
||||||
|
|
||||||
|
await HybridCache.RemoveAsync(string.Format(UserAuthService.CacheKeyPattern, user.Id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record UserDeletionValidationResult(bool IsValid, IEnumerable<string> ErrorMessages);
|
||||||
40
Moonlight.Api/Admin/Users/Users/UserLogoutController.cs
Normal file
40
Moonlight.Api/Admin/Users/Users/UserLogoutController.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Moonlight.Api.Infrastructure.Database;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
using Moonlight.Shared;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Users.Users;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/admin/users/{id:int}/logout")]
|
||||||
|
[Authorize(Policy = Permissions.Users.Logout)]
|
||||||
|
public class UserLogoutController : Controller
|
||||||
|
{
|
||||||
|
private readonly UserLogoutService LogoutService;
|
||||||
|
private readonly DatabaseRepository<User> Repository;
|
||||||
|
|
||||||
|
public UserLogoutController(
|
||||||
|
UserLogoutService logoutService,
|
||||||
|
DatabaseRepository<User> repository
|
||||||
|
)
|
||||||
|
{
|
||||||
|
LogoutService = logoutService;
|
||||||
|
Repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<ActionResult> LogoutAsync([FromRoute] int id)
|
||||||
|
{
|
||||||
|
var userExists = await Repository
|
||||||
|
.Query()
|
||||||
|
.AnyAsync(user => user.Id == id);
|
||||||
|
|
||||||
|
if (!userExists)
|
||||||
|
return Problem("No user with this id found", statusCode: 404);
|
||||||
|
|
||||||
|
await LogoutService.LogoutAsync(id);
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
43
Moonlight.Api/Admin/Users/Users/UserLogoutService.cs
Normal file
43
Moonlight.Api/Admin/Users/Users/UserLogoutService.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Caching.Hybrid;
|
||||||
|
using Moonlight.Api.Infrastructure.Database;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
using Moonlight.Api.Infrastructure.Hooks;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Users.Users;
|
||||||
|
|
||||||
|
public class UserLogoutService
|
||||||
|
{
|
||||||
|
private readonly IEnumerable<IUserLogoutHook> Hooks;
|
||||||
|
private readonly HybridCache HybridCache;
|
||||||
|
private readonly DatabaseRepository<User> Repository;
|
||||||
|
|
||||||
|
public UserLogoutService(
|
||||||
|
DatabaseRepository<User> repository,
|
||||||
|
IEnumerable<IUserLogoutHook> hooks,
|
||||||
|
HybridCache hybridCache
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Repository = repository;
|
||||||
|
Hooks = hooks;
|
||||||
|
HybridCache = hybridCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LogoutAsync(int userId)
|
||||||
|
{
|
||||||
|
var user = await Repository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == userId);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
throw new AggregateException($"User with id {userId} not found");
|
||||||
|
|
||||||
|
foreach (var hook in Hooks)
|
||||||
|
await hook.ExecuteAsync(user);
|
||||||
|
|
||||||
|
user.InvalidateTimestamp = DateTimeOffset.UtcNow;
|
||||||
|
await Repository.UpdateAsync(user);
|
||||||
|
|
||||||
|
await HybridCache.RemoveAsync(string.Format(UserAuthService.CacheKeyPattern, user.Id));
|
||||||
|
}
|
||||||
|
}
|
||||||
20
Moonlight.Api/Admin/Users/Users/UserMapper.cs
Normal file
20
Moonlight.Api/Admin/Users/Users/UserMapper.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
using Moonlight.Shared.Admin.Users.Users;
|
||||||
|
using Riok.Mapperly.Abstractions;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Users.Users;
|
||||||
|
|
||||||
|
[Mapper]
|
||||||
|
[SuppressMessage("Mapper", "RMG020:No members are mapped in an object mapping")]
|
||||||
|
[SuppressMessage("Mapper", "RMG012:No members are mapped in an object mapping")]
|
||||||
|
public static partial class UserMapper
|
||||||
|
{
|
||||||
|
public static partial IQueryable<UserDto> ProjectToDto(this IQueryable<User> users);
|
||||||
|
|
||||||
|
public static partial UserDto ToDto(User user);
|
||||||
|
|
||||||
|
public static partial void Merge([MappingTarget] User user, UpdateUserDto request);
|
||||||
|
|
||||||
|
public static partial User ToEntity(CreateUserDto request);
|
||||||
|
}
|
||||||
7
Moonlight.Api/Admin/Users/Users/UserOptions.cs
Normal file
7
Moonlight.Api/Admin/Users/Users/UserOptions.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Moonlight.Api.Admin.Users.Users;
|
||||||
|
|
||||||
|
public class UserOptions
|
||||||
|
{
|
||||||
|
public TimeSpan ValidationCacheL1Expiry { get; set; } = TimeSpan.FromSeconds(30);
|
||||||
|
public TimeSpan ValidationCacheL2Expiry { get; set; } = TimeSpan.FromMinutes(3);
|
||||||
|
}
|
||||||
117
Moonlight.Api/Admin/Users/Users/UsersController.cs
Normal file
117
Moonlight.Api/Admin/Users/Users/UsersController.cs
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Moonlight.Api.Infrastructure.Database;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
using Moonlight.Shared;
|
||||||
|
using Moonlight.Shared.Admin.Users.Users;
|
||||||
|
using Moonlight.Shared.Shared;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Admin.Users.Users;
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[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.Users.View)]
|
||||||
|
public async Task<ActionResult<PagedData<UserDto>>> GetAsync(
|
||||||
|
[FromQuery] int startIndex,
|
||||||
|
[FromQuery] int length,
|
||||||
|
[FromQuery] FilterOptions? filterOptions
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Validation
|
||||||
|
if (startIndex < 0)
|
||||||
|
return Problem("Invalid start index specified", statusCode: 400);
|
||||||
|
|
||||||
|
if (length is < 1 or > 100)
|
||||||
|
return Problem("Invalid length specified");
|
||||||
|
|
||||||
|
// Query building
|
||||||
|
|
||||||
|
var query = UserRepository
|
||||||
|
.Query();
|
||||||
|
|
||||||
|
// Filters
|
||||||
|
if (filterOptions != null)
|
||||||
|
{
|
||||||
|
foreach (var filterOption in filterOptions.Filters)
|
||||||
|
{
|
||||||
|
query = filterOption.Key switch
|
||||||
|
{
|
||||||
|
nameof(Infrastructure.Database.Entities.User.Email) =>
|
||||||
|
query.Where(user => EF.Functions.ILike(user.Email, $"%{filterOption.Value}%")),
|
||||||
|
|
||||||
|
nameof(Infrastructure.Database.Entities.User.Username) =>
|
||||||
|
query.Where(user => EF.Functions.ILike(user.Username, $"%{filterOption.Value}%")),
|
||||||
|
|
||||||
|
_ => query
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pagination
|
||||||
|
var data = await query
|
||||||
|
.OrderBy(x => x.Id)
|
||||||
|
.ProjectToDto()
|
||||||
|
.Skip(startIndex)
|
||||||
|
.Take(length)
|
||||||
|
.ToArrayAsync();
|
||||||
|
|
||||||
|
var total = await query.CountAsync();
|
||||||
|
|
||||||
|
return new PagedData<UserDto>(data, total);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id:int}")]
|
||||||
|
[Authorize(Policy = Permissions.Users.View)]
|
||||||
|
public async Task<ActionResult<UserDto>> GetAsync([FromRoute] int id)
|
||||||
|
{
|
||||||
|
var user = await UserRepository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
return Problem("No user with this id found", statusCode: 404);
|
||||||
|
|
||||||
|
return UserMapper.ToDto(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[Authorize(Policy = Permissions.Users.Create)]
|
||||||
|
public async Task<ActionResult<UserDto>> CreateAsync([FromBody] CreateUserDto request)
|
||||||
|
{
|
||||||
|
var user = UserMapper.ToEntity(request);
|
||||||
|
user.InvalidateTimestamp = DateTimeOffset.UtcNow.AddMinutes(-1);
|
||||||
|
|
||||||
|
var finalUser = await UserRepository.AddAsync(user);
|
||||||
|
|
||||||
|
return UserMapper.ToDto(finalUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPatch("{id:int}")]
|
||||||
|
[Authorize(Policy = Permissions.Users.Edit)]
|
||||||
|
public async Task<ActionResult<UserDto>> UpdateAsync([FromRoute] int id, [FromBody] UpdateUserDto request)
|
||||||
|
{
|
||||||
|
var user = await UserRepository
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
return Problem("No user with this id found", statusCode: 404);
|
||||||
|
|
||||||
|
UserMapper.Merge(user, request);
|
||||||
|
await UserRepository.UpdateAsync(user);
|
||||||
|
|
||||||
|
return UserMapper.ToDto(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Moonlight.Api.Infrastructure.Configuration;
|
||||||
|
|
||||||
|
public class CacheOptions
|
||||||
|
{
|
||||||
|
public bool EnableLayer2 { get; set; }
|
||||||
|
}
|
||||||
12
Moonlight.Api/Infrastructure/Configuration/OidcOptions.cs
Normal file
12
Moonlight.Api/Infrastructure/Configuration/OidcOptions.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
namespace Moonlight.Api.Infrastructure.Configuration;
|
||||||
|
|
||||||
|
public class OidcOptions
|
||||||
|
{
|
||||||
|
public string Authority { get; set; }
|
||||||
|
public bool RequireHttpsMetadata { get; set; } = true;
|
||||||
|
public bool DisableHttpsOnlyCookies { get; set; }
|
||||||
|
public string ResponseType { get; set; } = "code";
|
||||||
|
public string[]? Scopes { get; set; }
|
||||||
|
public string ClientId { get; set; }
|
||||||
|
public string ClientSecret { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Moonlight.Api.Infrastructure.Configuration;
|
||||||
|
|
||||||
|
public class RedisOptions
|
||||||
|
{
|
||||||
|
public bool Enable { get; set; }
|
||||||
|
public string ConnectionString { get; set; }
|
||||||
|
}
|
||||||
48
Moonlight.Api/Infrastructure/Database/DataContext.cs
Normal file
48
Moonlight.Api/Infrastructure/Database/DataContext.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Infrastructure.Database;
|
||||||
|
|
||||||
|
public class DataContext : DbContext
|
||||||
|
{
|
||||||
|
private readonly IOptions<DatabaseOptions> Options;
|
||||||
|
|
||||||
|
public DataContext(IOptions<DatabaseOptions> options)
|
||||||
|
{
|
||||||
|
Options = options;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DbSet<User> Users { get; set; }
|
||||||
|
public DbSet<SettingsOption> SettingsOptions { get; set; }
|
||||||
|
public DbSet<Role> Roles { get; set; }
|
||||||
|
public DbSet<RoleMember> RoleMembers { get; set; }
|
||||||
|
public DbSet<ApiKey> ApiKeys { get; set; }
|
||||||
|
public DbSet<Theme> Themes { get; set; }
|
||||||
|
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
if (optionsBuilder.IsConfigured)
|
||||||
|
return;
|
||||||
|
|
||||||
|
optionsBuilder.UseNpgsql(
|
||||||
|
$"Host={Options.Value.Host};" +
|
||||||
|
$"Port={Options.Value.Port};" +
|
||||||
|
$"Username={Options.Value.Username};" +
|
||||||
|
$"Password={Options.Value.Password};" +
|
||||||
|
$"Database={Options.Value.Database}",
|
||||||
|
builder =>
|
||||||
|
{
|
||||||
|
builder.MigrationsAssembly(typeof(DataContext).Assembly);
|
||||||
|
builder.MigrationsHistoryTable("MigrationsHistory", "core");
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.HasDefaultSchema("core");
|
||||||
|
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
10
Moonlight.Api/Infrastructure/Database/DatabaseOptions.cs
Normal file
10
Moonlight.Api/Infrastructure/Database/DatabaseOptions.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace Moonlight.Api.Infrastructure.Database;
|
||||||
|
|
||||||
|
public class DatabaseOptions
|
||||||
|
{
|
||||||
|
public string Host { get; set; }
|
||||||
|
public int Port { get; set; } = 5432;
|
||||||
|
public string Username { get; set; }
|
||||||
|
public string Password { get; set; }
|
||||||
|
public string Database { get; set; }
|
||||||
|
}
|
||||||
49
Moonlight.Api/Infrastructure/Database/DatabaseRepository.cs
Normal file
49
Moonlight.Api/Infrastructure/Database/DatabaseRepository.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Interfaces;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Infrastructure.Database;
|
||||||
|
|
||||||
|
public class DatabaseRepository<T> where T : class
|
||||||
|
{
|
||||||
|
private readonly DataContext DataContext;
|
||||||
|
private readonly DbSet<T> Set;
|
||||||
|
|
||||||
|
public DatabaseRepository(DataContext dataContext)
|
||||||
|
{
|
||||||
|
DataContext = dataContext;
|
||||||
|
Set = DataContext.Set<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IQueryable<T> Query()
|
||||||
|
{
|
||||||
|
return Set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<T> AddAsync(T entity)
|
||||||
|
{
|
||||||
|
if (entity is IActionTimestamps actionTimestamps)
|
||||||
|
{
|
||||||
|
actionTimestamps.CreatedAt = DateTimeOffset.UtcNow;
|
||||||
|
actionTimestamps.UpdatedAt = DateTimeOffset.UtcNow;
|
||||||
|
}
|
||||||
|
|
||||||
|
var final = Set.Add(entity);
|
||||||
|
await DataContext.SaveChangesAsync();
|
||||||
|
return final.Entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task UpdateAsync(T entity)
|
||||||
|
{
|
||||||
|
if (entity is IActionTimestamps actionTimestamps)
|
||||||
|
actionTimestamps.UpdatedAt = DateTimeOffset.UtcNow;
|
||||||
|
|
||||||
|
Set.Update(entity);
|
||||||
|
await DataContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task RemoveAsync(T entity)
|
||||||
|
{
|
||||||
|
Set.Remove(entity);
|
||||||
|
await DataContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
67
Moonlight.Api/Infrastructure/Database/DbMigrationService.cs
Normal file
67
Moonlight.Api/Infrastructure/Database/DbMigrationService.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Infrastructure.Database;
|
||||||
|
|
||||||
|
public class DbMigrationService : IHostedLifecycleService
|
||||||
|
{
|
||||||
|
private readonly ILogger<DbMigrationService> Logger;
|
||||||
|
private readonly IServiceProvider ServiceProvider;
|
||||||
|
|
||||||
|
public DbMigrationService(ILogger<DbMigrationService> logger, IServiceProvider serviceProvider)
|
||||||
|
{
|
||||||
|
Logger = logger;
|
||||||
|
ServiceProvider = serviceProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task StartingAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
Logger.LogTrace("Checking for pending migrations");
|
||||||
|
|
||||||
|
await using var scope = ServiceProvider.CreateAsyncScope();
|
||||||
|
var context = scope.ServiceProvider.GetRequiredService<DataContext>();
|
||||||
|
|
||||||
|
var pendingMigrations = await context.Database.GetPendingMigrationsAsync(cancellationToken);
|
||||||
|
var migrationNames = pendingMigrations.ToArray();
|
||||||
|
|
||||||
|
if (migrationNames.Length == 0)
|
||||||
|
{
|
||||||
|
Logger.LogTrace("No pending migrations found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.LogInformation("Pending migrations: {names}", string.Join(", ", migrationNames));
|
||||||
|
Logger.LogInformation("Migration started");
|
||||||
|
|
||||||
|
await context.Database.MigrateAsync(cancellationToken);
|
||||||
|
|
||||||
|
Logger.LogInformation("Migration complete");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task StartAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task StopAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task StartedAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task StoppedAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task StoppingAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
Moonlight.Api/Infrastructure/Database/Entities/ApiKey.cs
Normal file
22
Moonlight.Api/Infrastructure/Database/Entities/ApiKey.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Interfaces;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
|
||||||
|
public class ApiKey : IActionTimestamps
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[MaxLength(30)] public required string Name { get; set; }
|
||||||
|
|
||||||
|
[MaxLength(300)] public required string Description { get; set; }
|
||||||
|
|
||||||
|
public string[] Permissions { get; set; } = [];
|
||||||
|
public DateTimeOffset ValidUntil { get; set; }
|
||||||
|
|
||||||
|
[MaxLength(32)] public string Key { get; set; }
|
||||||
|
|
||||||
|
// Action timestamps
|
||||||
|
public DateTimeOffset CreatedAt { get; set; }
|
||||||
|
public DateTimeOffset UpdatedAt { get; set; }
|
||||||
|
}
|
||||||
22
Moonlight.Api/Infrastructure/Database/Entities/Role.cs
Normal file
22
Moonlight.Api/Infrastructure/Database/Entities/Role.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Interfaces;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
|
||||||
|
public class Role : IActionTimestamps
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[MaxLength(30)] public required string Name { get; set; }
|
||||||
|
|
||||||
|
[MaxLength(300)] public required string Description { get; set; }
|
||||||
|
|
||||||
|
public string[] Permissions { get; set; } = [];
|
||||||
|
|
||||||
|
// Relations
|
||||||
|
public List<RoleMember> Members { get; set; } = [];
|
||||||
|
|
||||||
|
// Action timestamps
|
||||||
|
public DateTimeOffset CreatedAt { get; set; }
|
||||||
|
public DateTimeOffset UpdatedAt { get; set; }
|
||||||
|
}
|
||||||
15
Moonlight.Api/Infrastructure/Database/Entities/RoleMember.cs
Normal file
15
Moonlight.Api/Infrastructure/Database/Entities/RoleMember.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using Moonlight.Api.Infrastructure.Database.Interfaces;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
|
||||||
|
public class RoleMember : IActionTimestamps
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public Role Role { get; set; }
|
||||||
|
public User User { get; set; }
|
||||||
|
|
||||||
|
// Action timestamps
|
||||||
|
public DateTimeOffset CreatedAt { get; set; }
|
||||||
|
public DateTimeOffset UpdatedAt { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
|
||||||
|
public class SettingsOption
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[MaxLength(256)] public required string Key { get; set; }
|
||||||
|
|
||||||
|
[MaxLength(4096)]
|
||||||
|
[Column(TypeName = "jsonb")]
|
||||||
|
public required string ValueJson { get; set; }
|
||||||
|
}
|
||||||
18
Moonlight.Api/Infrastructure/Database/Entities/Theme.cs
Normal file
18
Moonlight.Api/Infrastructure/Database/Entities/Theme.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
|
||||||
|
public class Theme
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[MaxLength(30)] public required string Name { get; set; }
|
||||||
|
|
||||||
|
[MaxLength(30)] public required string Version { get; set; }
|
||||||
|
|
||||||
|
[MaxLength(30)] public required string Author { get; set; }
|
||||||
|
|
||||||
|
public bool IsEnabled { get; set; }
|
||||||
|
|
||||||
|
[MaxLength(20_000)] public required string CssContent { get; set; }
|
||||||
|
}
|
||||||
24
Moonlight.Api/Infrastructure/Database/Entities/User.cs
Normal file
24
Moonlight.Api/Infrastructure/Database/Entities/User.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Moonlight.Api.Infrastructure.Database.Interfaces;
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Infrastructure.Database.Entities;
|
||||||
|
|
||||||
|
public class User : IActionTimestamps
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
// Base information
|
||||||
|
[MaxLength(50)] public required string Username { get; set; }
|
||||||
|
|
||||||
|
[MaxLength(254)] public required string Email { get; set; }
|
||||||
|
|
||||||
|
// Authentication
|
||||||
|
public DateTimeOffset InvalidateTimestamp { get; set; }
|
||||||
|
|
||||||
|
// Relations
|
||||||
|
public List<RoleMember> RoleMemberships { get; set; } = [];
|
||||||
|
|
||||||
|
// Action timestamps
|
||||||
|
public DateTimeOffset CreatedAt { get; set; }
|
||||||
|
public DateTimeOffset UpdatedAt { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Moonlight.Api.Infrastructure.Database.Interfaces;
|
||||||
|
|
||||||
|
internal interface IActionTimestamps
|
||||||
|
{
|
||||||
|
public DateTimeOffset CreatedAt { get; set; }
|
||||||
|
public DateTimeOffset UpdatedAt { get; set; }
|
||||||
|
}
|
||||||
81
Moonlight.Api/Infrastructure/Database/Migrations/20251225202335_AddedUsersAndSettings.Designer.cs
generated
Normal file
81
Moonlight.Api/Infrastructure/Database/Migrations/20251225202335_AddedUsersAndSettings.Designer.cs
generated
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Moonlight.Api.Database;
|
||||||
|
using Moonlight.Api.Infrastructure.Database;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Database.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(DataContext))]
|
||||||
|
[Migration("20251225202335_AddedUsersAndSettings")]
|
||||||
|
partial class AddedUsersAndSettings
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasDefaultSchema("core")
|
||||||
|
.HasAnnotation("ProductVersion", "10.0.1")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.SettingsOption", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("Value")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(4096)
|
||||||
|
.HasColumnType("character varying(4096)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("SettingsOptions", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(254)
|
||||||
|
.HasColumnType("character varying(254)");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("InvalidateTimestamp")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("character varying(50)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users", "core");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Database.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddedUsersAndSettings : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.EnsureSchema(
|
||||||
|
name: "core");
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "SettingsOptions",
|
||||||
|
schema: "core",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
Key = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
||||||
|
Value = table.Column<string>(type: "character varying(4096)", maxLength: 4096, nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_SettingsOptions", 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: "character varying(50)", maxLength: 50, nullable: false),
|
||||||
|
Email = table.Column<string>(type: "character varying(254)", maxLength: 254, nullable: false),
|
||||||
|
InvalidateTimestamp = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Users", x => x.Id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "SettingsOptions",
|
||||||
|
schema: "core");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Users",
|
||||||
|
schema: "core");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,178 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Moonlight.Api.Database;
|
||||||
|
using Moonlight.Api.Infrastructure.Database;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Database.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(DataContext))]
|
||||||
|
[Migration("20251230200748_AddedRolesAndActionTimestamps")]
|
||||||
|
partial class AddedRolesAndActionTimestamps
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasDefaultSchema("core")
|
||||||
|
.HasAnnotation("ProductVersion", "10.0.1")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.Role", 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()
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.HasColumnType("character varying(100)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(15)
|
||||||
|
.HasColumnType("character varying(15)");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("Permissions")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("UpdatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Roles", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.RoleMember", 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<int>("RoleId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("UpdatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<int>("UserId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("RoleId");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("RoleMembers", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.SettingsOption", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("Value")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(4096)
|
||||||
|
.HasColumnType("character varying(4096)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("SettingsOptions", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.User", 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>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(254)
|
||||||
|
.HasColumnType("character varying(254)");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("InvalidateTimestamp")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("UpdatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("character varying(50)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.RoleMember", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Moonlight.Api.Database.Entities.Role", "Role")
|
||||||
|
.WithMany("Members")
|
||||||
|
.HasForeignKey("RoleId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("Moonlight.Api.Database.Entities.User", "User")
|
||||||
|
.WithMany("RoleMemberships")
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Role");
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.Role", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Members");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.User", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("RoleMemberships");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Database.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddedRolesAndActionTimestamps : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<DateTimeOffset>(
|
||||||
|
name: "CreatedAt",
|
||||||
|
schema: "core",
|
||||||
|
table: "Users",
|
||||||
|
type: "timestamp with time zone",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: new DateTimeOffset(new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)));
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<DateTimeOffset>(
|
||||||
|
name: "UpdatedAt",
|
||||||
|
schema: "core",
|
||||||
|
table: "Users",
|
||||||
|
type: "timestamp with time zone",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: new DateTimeOffset(new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)));
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Roles",
|
||||||
|
schema: "core",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
Name = table.Column<string>(type: "character varying(15)", maxLength: 15, nullable: false),
|
||||||
|
Description = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
||||||
|
Permissions = table.Column<string[]>(type: "text[]", nullable: false),
|
||||||
|
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||||
|
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Roles", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "RoleMembers",
|
||||||
|
schema: "core",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
RoleId = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
UserId = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||||
|
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_RoleMembers", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_RoleMembers_Roles_RoleId",
|
||||||
|
column: x => x.RoleId,
|
||||||
|
principalSchema: "core",
|
||||||
|
principalTable: "Roles",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_RoleMembers_Users_UserId",
|
||||||
|
column: x => x.UserId,
|
||||||
|
principalSchema: "core",
|
||||||
|
principalTable: "Users",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_RoleMembers_RoleId",
|
||||||
|
schema: "core",
|
||||||
|
table: "RoleMembers",
|
||||||
|
column: "RoleId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_RoleMembers_UserId",
|
||||||
|
schema: "core",
|
||||||
|
table: "RoleMembers",
|
||||||
|
column: "UserId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "RoleMembers",
|
||||||
|
schema: "core");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Roles",
|
||||||
|
schema: "core");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "CreatedAt",
|
||||||
|
schema: "core",
|
||||||
|
table: "Users");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "UpdatedAt",
|
||||||
|
schema: "core",
|
||||||
|
table: "Users");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
216
Moonlight.Api/Infrastructure/Database/Migrations/20260116133404_AddedApiKeys.Designer.cs
generated
Normal file
216
Moonlight.Api/Infrastructure/Database/Migrations/20260116133404_AddedApiKeys.Designer.cs
generated
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Moonlight.Api.Database;
|
||||||
|
using Moonlight.Api.Infrastructure.Database;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Database.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(DataContext))]
|
||||||
|
[Migration("20260116133404_AddedApiKeys")]
|
||||||
|
partial class AddedApiKeys
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasDefaultSchema("core")
|
||||||
|
.HasAnnotation("ProductVersion", "10.0.1")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.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()
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.HasColumnType("character varying(100)");
|
||||||
|
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(32)
|
||||||
|
.HasColumnType("character varying(32)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(15)
|
||||||
|
.HasColumnType("character varying(15)");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("Permissions")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("UpdatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("ApiKeys", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.Role", 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()
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.HasColumnType("character varying(100)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(15)
|
||||||
|
.HasColumnType("character varying(15)");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("Permissions")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("UpdatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Roles", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.RoleMember", 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<int>("RoleId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("UpdatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<int>("UserId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("RoleId");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("RoleMembers", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.SettingsOption", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("Value")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(4096)
|
||||||
|
.HasColumnType("character varying(4096)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("SettingsOptions", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.User", 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>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(254)
|
||||||
|
.HasColumnType("character varying(254)");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("InvalidateTimestamp")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("UpdatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("character varying(50)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.RoleMember", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Moonlight.Api.Database.Entities.Role", "Role")
|
||||||
|
.WithMany("Members")
|
||||||
|
.HasForeignKey("RoleId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("Moonlight.Api.Database.Entities.User", "User")
|
||||||
|
.WithMany("RoleMemberships")
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Role");
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.Role", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Members");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.User", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("RoleMemberships");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Database.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddedApiKeys : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "ApiKeys",
|
||||||
|
schema: "core",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
Name = table.Column<string>(type: "character varying(15)", maxLength: 15, nullable: false),
|
||||||
|
Description = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
||||||
|
Permissions = table.Column<string[]>(type: "text[]", nullable: false),
|
||||||
|
Key = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||||
|
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||||
|
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_ApiKeys", x => x.Id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "ApiKeys",
|
||||||
|
schema: "core");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,216 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Moonlight.Api.Database;
|
||||||
|
using Moonlight.Api.Infrastructure.Database;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Database.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(DataContext))]
|
||||||
|
[Migration("20260116134322_AdjustedLenghtsOfRoleAndApiKeyStrings")]
|
||||||
|
partial class AdjustedLenghtsOfRoleAndApiKeyStrings
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasDefaultSchema("core")
|
||||||
|
.HasAnnotation("ProductVersion", "10.0.1")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.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()
|
||||||
|
.HasMaxLength(300)
|
||||||
|
.HasColumnType("character varying(300)");
|
||||||
|
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(32)
|
||||||
|
.HasColumnType("character varying(32)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(30)
|
||||||
|
.HasColumnType("character varying(30)");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("Permissions")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("UpdatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("ApiKeys", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.Role", 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()
|
||||||
|
.HasMaxLength(300)
|
||||||
|
.HasColumnType("character varying(300)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(30)
|
||||||
|
.HasColumnType("character varying(30)");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("Permissions")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("UpdatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Roles", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.RoleMember", 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<int>("RoleId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("UpdatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<int>("UserId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("RoleId");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("RoleMembers", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.SettingsOption", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("Value")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(4096)
|
||||||
|
.HasColumnType("character varying(4096)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("SettingsOptions", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.User", 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>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(254)
|
||||||
|
.HasColumnType("character varying(254)");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("InvalidateTimestamp")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("UpdatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("character varying(50)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.RoleMember", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Moonlight.Api.Database.Entities.Role", "Role")
|
||||||
|
.WithMany("Members")
|
||||||
|
.HasForeignKey("RoleId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("Moonlight.Api.Database.Entities.User", "User")
|
||||||
|
.WithMany("RoleMemberships")
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Role");
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.Role", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Members");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.User", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("RoleMemberships");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Database.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AdjustedLenghtsOfRoleAndApiKeyStrings : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Name",
|
||||||
|
schema: "core",
|
||||||
|
table: "Roles",
|
||||||
|
type: "character varying(30)",
|
||||||
|
maxLength: 30,
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(15)",
|
||||||
|
oldMaxLength: 15);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Description",
|
||||||
|
schema: "core",
|
||||||
|
table: "Roles",
|
||||||
|
type: "character varying(300)",
|
||||||
|
maxLength: 300,
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(100)",
|
||||||
|
oldMaxLength: 100);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Name",
|
||||||
|
schema: "core",
|
||||||
|
table: "ApiKeys",
|
||||||
|
type: "character varying(30)",
|
||||||
|
maxLength: 30,
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(15)",
|
||||||
|
oldMaxLength: 15);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Description",
|
||||||
|
schema: "core",
|
||||||
|
table: "ApiKeys",
|
||||||
|
type: "character varying(300)",
|
||||||
|
maxLength: 300,
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(100)",
|
||||||
|
oldMaxLength: 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Name",
|
||||||
|
schema: "core",
|
||||||
|
table: "Roles",
|
||||||
|
type: "character varying(15)",
|
||||||
|
maxLength: 15,
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(30)",
|
||||||
|
oldMaxLength: 30);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Description",
|
||||||
|
schema: "core",
|
||||||
|
table: "Roles",
|
||||||
|
type: "character varying(100)",
|
||||||
|
maxLength: 100,
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(300)",
|
||||||
|
oldMaxLength: 300);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Name",
|
||||||
|
schema: "core",
|
||||||
|
table: "ApiKeys",
|
||||||
|
type: "character varying(15)",
|
||||||
|
maxLength: 15,
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(30)",
|
||||||
|
oldMaxLength: 30);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Description",
|
||||||
|
schema: "core",
|
||||||
|
table: "ApiKeys",
|
||||||
|
type: "character varying(100)",
|
||||||
|
maxLength: 100,
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "character varying(300)",
|
||||||
|
oldMaxLength: 300);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
252
Moonlight.Api/Infrastructure/Database/Migrations/20260118005634_AddedThemes.Designer.cs
generated
Normal file
252
Moonlight.Api/Infrastructure/Database/Migrations/20260118005634_AddedThemes.Designer.cs
generated
Normal file
@@ -0,0 +1,252 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Moonlight.Api.Database;
|
||||||
|
using Moonlight.Api.Infrastructure.Database;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Database.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(DataContext))]
|
||||||
|
[Migration("20260118005634_AddedThemes")]
|
||||||
|
partial class AddedThemes
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasDefaultSchema("core")
|
||||||
|
.HasAnnotation("ProductVersion", "10.0.1")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.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()
|
||||||
|
.HasMaxLength(300)
|
||||||
|
.HasColumnType("character varying(300)");
|
||||||
|
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(32)
|
||||||
|
.HasColumnType("character varying(32)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(30)
|
||||||
|
.HasColumnType("character varying(30)");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("Permissions")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("UpdatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("ApiKeys", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.Role", 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()
|
||||||
|
.HasMaxLength(300)
|
||||||
|
.HasColumnType("character varying(300)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(30)
|
||||||
|
.HasColumnType("character varying(30)");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("Permissions")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("UpdatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Roles", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.RoleMember", 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<int>("RoleId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("UpdatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<int>("UserId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("RoleId");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("RoleMembers", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.SettingsOption", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("Value")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(4096)
|
||||||
|
.HasColumnType("character varying(4096)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("SettingsOptions", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.Theme", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Author")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(30)
|
||||||
|
.HasColumnType("character varying(30)");
|
||||||
|
|
||||||
|
b.Property<string>("CssContent")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(20000)
|
||||||
|
.HasColumnType("character varying(20000)");
|
||||||
|
|
||||||
|
b.Property<bool>("IsEnabled")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(30)
|
||||||
|
.HasColumnType("character varying(30)");
|
||||||
|
|
||||||
|
b.Property<string>("Version")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(30)
|
||||||
|
.HasColumnType("character varying(30)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Themes", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.User", 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>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(254)
|
||||||
|
.HasColumnType("character varying(254)");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("InvalidateTimestamp")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("UpdatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("character varying(50)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users", "core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.RoleMember", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Moonlight.Api.Database.Entities.Role", "Role")
|
||||||
|
.WithMany("Members")
|
||||||
|
.HasForeignKey("RoleId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("Moonlight.Api.Database.Entities.User", "User")
|
||||||
|
.WithMany("RoleMemberships")
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Role");
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.Role", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Members");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.Api.Database.Entities.User", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("RoleMemberships");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Moonlight.Api.Database.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddedThemes : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Themes",
|
||||||
|
schema: "core",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
Name = table.Column<string>(type: "character varying(30)", maxLength: 30, nullable: false),
|
||||||
|
Version = table.Column<string>(type: "character varying(30)", maxLength: 30, nullable: false),
|
||||||
|
Author = table.Column<string>(type: "character varying(30)", maxLength: 30, nullable: false),
|
||||||
|
IsEnabled = table.Column<bool>(type: "boolean", nullable: false),
|
||||||
|
CssContent = table.Column<string>(type: "character varying(20000)", maxLength: 20000, nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Themes", x => x.Id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Themes",
|
||||||
|
schema: "core");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user