feat:Libmap的MaxAge 与 Logger

This commit is contained in:
Tianpao
2025-10-06 15:36:13 +08:00
parent 8f29a412cf
commit e4e07ac268
8 changed files with 275 additions and 22 deletions

View File

@@ -10,5 +10,14 @@
"port":0,
"host":"",
"logger":true
},
"main":{
"libmap":{
"refresh":0,
"maxage":0
},
"versions":{
"refresh":0
}
}
}

View File

@@ -24,6 +24,9 @@
},
"dependencies": {
"express": "^5.1.0",
"pg": "^8.16.3"
"pg": "^8.16.3",
"pino": "^10.0.0",
"pino-http": "^11.0.0",
"pino-pretty": "^13.1.1"
}
}

190
pnpm-lock.yaml generated
View File

@@ -14,6 +14,15 @@ importers:
pg:
specifier: ^8.16.3
version: 8.16.3
pino:
specifier: ^10.0.0
version: 10.0.0
pino-http:
specifier: ^11.0.0
version: 11.0.0
pino-pretty:
specifier: ^13.1.1
version: 13.1.1
devDependencies:
'@types/express':
specifier: ^5.0.3
@@ -73,6 +82,10 @@ packages:
resolution: {integrity: sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==}
engines: {node: '>= 0.6'}
atomic-sleep@1.0.0:
resolution: {integrity: sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ==}
engines: {node: '>=8.0.0'}
body-parser@2.2.0:
resolution: {integrity: sha512-02qvAaxv8tp7fBa/mw1ga98OGm+eCbqzJOKoRt70sLmfEEi+jyBYVTDGfCL/k06/4EMk/z01gCe7HoCH/f2LTg==}
engines: {node: '>=18'}
@@ -89,6 +102,9 @@ packages:
resolution: {integrity: sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==}
engines: {node: '>= 0.4'}
colorette@2.0.20:
resolution: {integrity: sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==}
content-disposition@1.0.0:
resolution: {integrity: sha512-Au9nRL8VNUut/XSzbQA38+M78dzP4D+eqg3gfJHMIHHYa3bg067xj1KxMUWj+VULbiZMowKngFFbKczUrNJ1mg==}
engines: {node: '>= 0.6'}
@@ -105,6 +121,9 @@ packages:
resolution: {integrity: sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==}
engines: {node: '>= 0.6'}
dateformat@4.6.3:
resolution: {integrity: sha512-2P0p0pFGzHS5EMnhdxQi7aJN+iMheud0UhG4dlE1DLAlvL8JHjJJTX/CSm4JXwV0Ka5nGk3zC5mcb5bUQUxxMA==}
debug@4.4.3:
resolution: {integrity: sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==}
engines: {node: '>=6.0'}
@@ -129,6 +148,9 @@ packages:
resolution: {integrity: sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==}
engines: {node: '>= 0.8'}
end-of-stream@1.4.5:
resolution: {integrity: sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg==}
es-define-property@1.0.1:
resolution: {integrity: sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==}
engines: {node: '>= 0.4'}
@@ -152,6 +174,12 @@ packages:
resolution: {integrity: sha512-DT9ck5YIRU+8GYzzU5kT3eHGA5iL+1Zd0EutOmTE9Dtk+Tvuzd23VBU+ec7HPNSTxXYO55gPV/hq4pSBJDjFpA==}
engines: {node: '>= 18'}
fast-copy@3.0.2:
resolution: {integrity: sha512-dl0O9Vhju8IrcLndv2eU4ldt1ftXMqqfgN4H1cpmGV7P6jeB9FwpN9a2c8DPGE1Ys88rNUJVYDHq73CGAGOPfQ==}
fast-safe-stringify@2.1.1:
resolution: {integrity: sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==}
finalhandler@2.1.0:
resolution: {integrity: sha512-/t88Ty3d5JWQbWYgaOGCCYfXRwV1+be02WqYYlL6h0lEiUAMPM8o8qKGO01YIkOHzka2up08wvgYD0mDiI+q3Q==}
engines: {node: '>= 0.8'}
@@ -167,6 +195,10 @@ packages:
function-bind@1.1.2:
resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==}
get-caller-file@2.0.5:
resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==}
engines: {node: 6.* || 8.* || >= 10.*}
get-intrinsic@1.3.0:
resolution: {integrity: sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==}
engines: {node: '>= 0.4'}
@@ -187,6 +219,9 @@ packages:
resolution: {integrity: sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==}
engines: {node: '>= 0.4'}
help-me@5.0.0:
resolution: {integrity: sha512-7xgomUX6ADmcYzFik0HzAxh/73YlKR9bmFzf51CZwR+b6YtzU2m0u49hQCqV6SvlqIqsaxovfwdvbnsw3b/zpg==}
http-errors@2.0.0:
resolution: {integrity: sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==}
engines: {node: '>= 0.8'}
@@ -209,6 +244,10 @@ packages:
is-promise@4.0.0:
resolution: {integrity: sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==}
joycon@3.1.1:
resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==}
engines: {node: '>=10'}
math-intrinsics@1.1.0:
resolution: {integrity: sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==}
engines: {node: '>= 0.4'}
@@ -229,6 +268,9 @@ packages:
resolution: {integrity: sha512-xRc4oEhT6eaBpU1XF7AjpOFD+xQmXNB5OVKwp4tqCuBpHLS/ZbBDrc07mYTDqVMg6PfxUjjNp85O6Cd2Z/5HWA==}
engines: {node: '>= 0.6'}
minimist@1.2.8:
resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==}
ms@2.1.3:
resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==}
@@ -240,6 +282,10 @@ packages:
resolution: {integrity: sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==}
engines: {node: '>= 0.4'}
on-exit-leak-free@2.1.2:
resolution: {integrity: sha512-0eJJY6hXLGf1udHwfNftBqH+g73EU4B504nZeKpz1sYRKafAghwxEJunB2O7rDZkL4PGfsMVnTXZ2EjibbqcsA==}
engines: {node: '>=14.0.0'}
on-finished@2.4.1:
resolution: {integrity: sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==}
engines: {node: '>= 0.8'}
@@ -288,6 +334,23 @@ packages:
pgpass@1.0.5:
resolution: {integrity: sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==}
pino-abstract-transport@2.0.0:
resolution: {integrity: sha512-F63x5tizV6WCh4R6RHyi2Ml+M70DNRXt/+HANowMflpgGFMAym/VKm6G7ZOQRjqN7XbGxK1Lg9t6ZrtzOaivMw==}
pino-http@11.0.0:
resolution: {integrity: sha512-wqg5XIAGRRIWtTk8qPGxkbrfiwEWz1lgedVLvhLALudKXvg1/L2lTFgTGPJ4Z2e3qcRmxoFxDuSdMdMGNM6I1g==}
pino-pretty@13.1.1:
resolution: {integrity: sha512-TNNEOg0eA0u+/WuqH0MH0Xui7uqVk9D74ESOpjtebSQYbNWJk/dIxCXIxFsNfeN53JmtWqYHP2OrIZjT/CBEnA==}
hasBin: true
pino-std-serializers@7.0.0:
resolution: {integrity: sha512-e906FRY0+tV27iq4juKzSYPbUj2do2X2JX4EzSca1631EB2QJQUqGbDuERal7LCtOpxl6x3+nvo9NPZcmjkiFA==}
pino@10.0.0:
resolution: {integrity: sha512-eI9pKwWEix40kfvSzqEP6ldqOoBIN7dwD/o91TY5z8vQI12sAffpR/pOqAD1IVVwIVHDpHjkq0joBPdJD0rafA==}
hasBin: true
postgres-array@2.0.0:
resolution: {integrity: sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==}
engines: {node: '>=4'}
@@ -304,14 +367,23 @@ packages:
resolution: {integrity: sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==}
engines: {node: '>=0.10.0'}
process-warning@5.0.0:
resolution: {integrity: sha512-a39t9ApHNx2L4+HBnQKqxxHNs1r7KF+Intd8Q/g1bUh6q0WIp9voPXJ/x0j+ZL45KF1pJd9+q2jLIRMfvEshkA==}
proxy-addr@2.0.7:
resolution: {integrity: sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==}
engines: {node: '>= 0.10'}
pump@3.0.3:
resolution: {integrity: sha512-todwxLMY7/heScKmntwQG8CXVkWUOdYxIvY2s0VWAAMh/nd8SoYiRaKjlr7+iCs984f2P8zvrfWcDDYVb73NfA==}
qs@6.14.0:
resolution: {integrity: sha512-YWWTjgABSKcvs/nWBi9PycY/JiPJqOD4JA6o9Sej2AtvSGarXxKC3OQSk4pAarbdQlKAh5D4FCQkJNkW+GAn3w==}
engines: {node: '>=0.6'}
quick-format-unescaped@4.0.4:
resolution: {integrity: sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg==}
range-parser@1.2.1:
resolution: {integrity: sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==}
engines: {node: '>= 0.6'}
@@ -320,6 +392,10 @@ packages:
resolution: {integrity: sha512-9G8cA+tuMS75+6G/TzW8OtLzmBDMo8p1JRxN5AZ+LAp8uxGA8V8GZm4GQ4/N5QNQEnLmg6SS7wyuSmbKepiKqA==}
engines: {node: '>= 0.10'}
real-require@0.2.0:
resolution: {integrity: sha512-57frrGM/OCTLqLOAh0mhVA9VBMHd+9U7Zb2THMGdBUoZVOtGbJzjxsYGDJ3A9AYYCP4hn6y1TVbaOfzWtm5GFg==}
engines: {node: '>= 12.13.0'}
router@2.2.0:
resolution: {integrity: sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==}
engines: {node: '>= 18'}
@@ -327,9 +403,16 @@ packages:
safe-buffer@5.2.1:
resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==}
safe-stable-stringify@2.5.0:
resolution: {integrity: sha512-b3rppTKm9T+PsVCBEOUR46GWI7fdOs00VKZ1+9c1EWDaDMvjQc6tUwuFyIprgGgTcWoVHSKrU8H31ZHA2e0RHA==}
engines: {node: '>=10'}
safer-buffer@2.1.2:
resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==}
secure-json-parse@4.1.0:
resolution: {integrity: sha512-l4KnYfEyqYJxDwlNVyRfO2E4NTHfMKAWdUuA8J0yve2Dz/E/PdBepY03RvyJpssIpRFwJoCD55wA+mEDs6ByWA==}
send@1.2.0:
resolution: {integrity: sha512-uaW0WwXKpL9blXE2o0bRhoL2EGXIrZxQ2ZQ4mgcfoBxdFmQold+qWsD2jLrfZ0trjKL6vOw0j//eAwcALFjKSw==}
engines: {node: '>= 18'}
@@ -357,6 +440,12 @@ packages:
resolution: {integrity: sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==}
engines: {node: '>= 0.4'}
slow-redact@0.3.1:
resolution: {integrity: sha512-NvFvl1GuLZNW4U046Tfi8b26zXo8aBzgCAS2f7yVJR/fArN93mOqSA99cB9uITm92ajSz01bsu1K7SCVVjIMpQ==}
sonic-boom@4.2.0:
resolution: {integrity: sha512-INb7TM37/mAcsGmc9hyyI6+QR3rR1zVRu36B0NeGXKnOOLiZOfER5SA+N7X7k3yUYRzLWafduTDvJAfDswwEww==}
split2@4.2.0:
resolution: {integrity: sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==}
engines: {node: '>= 10.x'}
@@ -369,6 +458,13 @@ packages:
resolution: {integrity: sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==}
engines: {node: '>= 0.8'}
strip-json-comments@5.0.3:
resolution: {integrity: sha512-1tB5mhVo7U+ETBKNf92xT4hrQa3pm0MZ0PQvuDnWgAAGHDsfp4lPSpiS6psrSiet87wyGPh9ft6wmhOMQ0hDiw==}
engines: {node: '>=14.16'}
thread-stream@3.1.0:
resolution: {integrity: sha512-OqyPZ9u96VohAyMfJykzmivOrY2wfMSf3C5TtFJVgN+Hm6aj+voFhlK+kZEIv2FBh1X6Xp3DlnCOfEQ3B2J86A==}
toidentifier@1.0.1:
resolution: {integrity: sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==}
engines: {node: '>=0.6'}
@@ -462,6 +558,8 @@ snapshots:
mime-types: 3.0.1
negotiator: 1.0.0
atomic-sleep@1.0.0: {}
body-parser@2.2.0:
dependencies:
bytes: 3.1.2
@@ -488,6 +586,8 @@ snapshots:
call-bind-apply-helpers: 1.0.2
get-intrinsic: 1.3.0
colorette@2.0.20: {}
content-disposition@1.0.0:
dependencies:
safe-buffer: 5.2.1
@@ -498,6 +598,8 @@ snapshots:
cookie@0.7.2: {}
dateformat@4.6.3: {}
debug@4.4.3:
dependencies:
ms: 2.1.3
@@ -514,6 +616,10 @@ snapshots:
encodeurl@2.0.0: {}
end-of-stream@1.4.5:
dependencies:
once: 1.4.0
es-define-property@1.0.1: {}
es-errors@1.3.0: {}
@@ -558,6 +664,10 @@ snapshots:
transitivePeerDependencies:
- supports-color
fast-copy@3.0.2: {}
fast-safe-stringify@2.1.1: {}
finalhandler@2.1.0:
dependencies:
debug: 4.4.3
@@ -575,6 +685,8 @@ snapshots:
function-bind@1.1.2: {}
get-caller-file@2.0.5: {}
get-intrinsic@1.3.0:
dependencies:
call-bind-apply-helpers: 1.0.2
@@ -601,6 +713,8 @@ snapshots:
dependencies:
function-bind: 1.1.2
help-me@5.0.0: {}
http-errors@2.0.0:
dependencies:
depd: 2.0.0
@@ -623,6 +737,8 @@ snapshots:
is-promise@4.0.0: {}
joycon@3.1.1: {}
math-intrinsics@1.1.0: {}
media-typer@1.1.0: {}
@@ -635,12 +751,16 @@ snapshots:
dependencies:
mime-db: 1.54.0
minimist@1.2.8: {}
ms@2.1.3: {}
negotiator@1.0.0: {}
object-inspect@1.13.4: {}
on-exit-leak-free@2.1.2: {}
on-finished@2.4.1:
dependencies:
ee-first: 1.1.1
@@ -688,6 +808,49 @@ snapshots:
dependencies:
split2: 4.2.0
pino-abstract-transport@2.0.0:
dependencies:
split2: 4.2.0
pino-http@11.0.0:
dependencies:
get-caller-file: 2.0.5
pino: 10.0.0
pino-std-serializers: 7.0.0
process-warning: 5.0.0
pino-pretty@13.1.1:
dependencies:
colorette: 2.0.20
dateformat: 4.6.3
fast-copy: 3.0.2
fast-safe-stringify: 2.1.1
help-me: 5.0.0
joycon: 3.1.1
minimist: 1.2.8
on-exit-leak-free: 2.1.2
pino-abstract-transport: 2.0.0
pump: 3.0.3
secure-json-parse: 4.1.0
sonic-boom: 4.2.0
strip-json-comments: 5.0.3
pino-std-serializers@7.0.0: {}
pino@10.0.0:
dependencies:
atomic-sleep: 1.0.0
on-exit-leak-free: 2.1.2
pino-abstract-transport: 2.0.0
pino-std-serializers: 7.0.0
process-warning: 5.0.0
quick-format-unescaped: 4.0.4
real-require: 0.2.0
safe-stable-stringify: 2.5.0
slow-redact: 0.3.1
sonic-boom: 4.2.0
thread-stream: 3.1.0
postgres-array@2.0.0: {}
postgres-bytea@1.0.0: {}
@@ -698,15 +861,24 @@ snapshots:
dependencies:
xtend: 4.0.2
process-warning@5.0.0: {}
proxy-addr@2.0.7:
dependencies:
forwarded: 0.2.0
ipaddr.js: 1.9.1
pump@3.0.3:
dependencies:
end-of-stream: 1.4.5
once: 1.4.0
qs@6.14.0:
dependencies:
side-channel: 1.1.0
quick-format-unescaped@4.0.4: {}
range-parser@1.2.1: {}
raw-body@3.0.1:
@@ -716,6 +888,8 @@ snapshots:
iconv-lite: 0.7.0
unpipe: 1.0.0
real-require@0.2.0: {}
router@2.2.0:
dependencies:
debug: 4.4.3
@@ -728,8 +902,12 @@ snapshots:
safe-buffer@5.2.1: {}
safe-stable-stringify@2.5.0: {}
safer-buffer@2.1.2: {}
secure-json-parse@4.1.0: {}
send@1.2.0:
dependencies:
debug: 4.4.3
@@ -785,12 +963,24 @@ snapshots:
side-channel-map: 1.0.1
side-channel-weakmap: 1.0.2
slow-redact@0.3.1: {}
sonic-boom@4.2.0:
dependencies:
atomic-sleep: 1.0.0
split2@4.2.0: {}
statuses@2.0.1: {}
statuses@2.0.2: {}
strip-json-comments@5.0.3: {}
thread-stream@3.1.0:
dependencies:
real-require: 0.2.0
toidentifier@1.0.1: {}
type-is@2.0.1:

View File

@@ -1,20 +1,35 @@
import { createHash } from "node:crypto";
import { Pool } from "pg";
import { ILibraries, ILibrariesMap, IVersion, IVersionPool } from "../types/versionlist.types.js";
import {
ILibraries,
ILibrariesMap,
IVersion,
IVersionPool,
} from "../types/versionlist.types.js";
import { logger } from "../utils/logger.js";
import config, { IConfig } from "../utils/config.js";
export class VersionListController {
versionCache: IVersion[];
private versionCache: IVersion[];
private pool: Pool;
hashList: string[];
libmap: Map<string, ILibrariesMap>;
private config: IConfig;
private hashList: string[];
private libmap: Map<string, ILibrariesMap>;
constructor(pool: Pool) {
this.pool = pool;
this.config = config;
this.versionCache = [];
this.hashList = ["md5", "sha1", "sha256"];
this.libmap = new Map();
this._refreshCache(); // 初始化缓存
setInterval(this._refreshCache.bind(this), 1000 * 60 * 60 * 2); // 2小时刷新缓存傻逼this
setInterval(this._refreshLib.bind(this),1000*60*60*1) // 1小时刷新libmap
setInterval(
this._refreshCache.bind(this),
1000 * 60 * 60 * this.config.main.versions.refresh
); // 2小时刷新缓存傻逼this
setInterval(
this._refreshLib.bind(this),
1000 * 60 * 60 * this.config.main.libmap.refresh
); // 1小时刷新libmap
}
async getVersionList() {
@@ -55,6 +70,9 @@ ORDER BY "Date" DESC
time: row.Date,
});
});
logger.info(
`Version list refresh: [${arr.length - this.versionCache.length}]`
);
this.versionCache = arr;
}
@@ -66,13 +84,13 @@ ORDER BY "Date" DESC
) {
return;
}
const ver = `${id}-${arch}`
const ver = `${id}-${arch}`;
let value = this.libmap.get(ver)
if (value){
value.hits++
console.log("lib hits"+value.hits)
return {libraries:value.libraries}
let value = this.libmap.get(ver);
if (value) {
value.hits++;
console.log("lib hits" + value.hits);
return { libraries: value.libraries };
}
const r = (
@@ -106,15 +124,23 @@ WHERE variation_files_data."variationId" = $1
[r[0].id]
)
).rows; //获取信息
this.libmap.set(ver,{libraries:data,hits:0}) //初始化
return { libraries: data};
this.libmap.set(ver, { libraries: data, hits: 0, date: Date.now() }); //初始化
return { libraries: data };
}
_refreshLib(){
this.libmap.forEach((val,key)=>{
if (val.hits<15){
_refreshLib() {
const size = this.libmap.size;
let index = 0;
this.libmap.forEach((val, key) => {
const isDel =
val.date <
Date.now() - 1000 * 60 * 60 * this.config.main.libmap.maxage ||
val.hits < 15;
if (isDel) {
this.libmap.delete(key);
index++;
}
})
});
logger.info(`Libraries map refresh:[${index}/${size}]`);
}
}

View File

@@ -4,6 +4,7 @@ import versionlistRouter from "./router/versionlist.router.js";
import downloadRouter from "./router/download.router.js";
const app = express();
app.set('trust proxy', true)
app.use('/mc',versionlistRouter)
app.use('/download',downloadRouter)

View File

@@ -25,4 +25,5 @@ export interface ILibraries {
export interface ILibrariesMap {
libraries: ILibraries[];
hits: number;
date: number;
}

View File

@@ -1,5 +1,5 @@
import fs from "fs";
interface Config {
export interface IConfig {
database: {
host: string;
port: number;
@@ -10,10 +10,19 @@ interface Config {
express:{
port:number;
logger:boolean;
},
main:{
libmap:{
refresh:number; //单位: 小时
maxage:number; //单位:小时
}
versions:{
refresh:number; //单位:小时
}
}
}
const config:Config = (() => {
const config:IConfig = (() => {
if (!fs.existsSync(`./config.json`)) {
throw new Error(`config is not defined`);
}

14
src/utils/logger.ts Normal file
View File

@@ -0,0 +1,14 @@
import {pino} from 'pino'
export const logger = pino({
level: process.env.LOGLEVEL || 'info',
transport: process.env.PLAIN_LOG
? undefined
: {
target: 'pino-pretty',
options: {
translateTime: 'SYS:standard',
singleLine: true,
},
},
})