@weibaohui/dsh-git-server 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/README.md +43 -0
  2. package/client/bundle.js +2356 -0
  3. package/client/index.js +2342 -0
  4. package/cordis.patch.yml +11 -0
  5. package/package.json +70 -0
  6. package/server/dist/api/v1.js +2029 -0
  7. package/server/dist/authx/password.js +43 -0
  8. package/server/dist/authx/um.js +157 -0
  9. package/server/dist/conf.js +323 -0
  10. package/server/dist/context.js +701 -0
  11. package/server/dist/db/actions.js +202 -0
  12. package/server/dist/db/db.js +838 -0
  13. package/server/dist/dshapi.js +1416 -0
  14. package/server/dist/editorconfig.js +104 -0
  15. package/server/dist/gitx/git.js +580 -0
  16. package/server/dist/gitx/http.js +232 -0
  17. package/server/dist/gitx/paths.js +28 -0
  18. package/server/dist/gitx/service.js +251 -0
  19. package/server/dist/gosprintf.js +167 -0
  20. package/server/dist/hook.js +53 -0
  21. package/server/dist/index.js +112 -0
  22. package/server/dist/lfsx.js +265 -0
  23. package/server/dist/mailer.js +127 -0
  24. package/server/dist/markup.js +317 -0
  25. package/server/dist/metrics.js +18 -0
  26. package/server/dist/mirror.js +203 -0
  27. package/server/dist/multipart.js +33 -0
  28. package/server/dist/repox.js +99 -0
  29. package/server/dist/router.js +185 -0
  30. package/server/dist/serv.js +43 -0
  31. package/server/dist/server.js +382 -0
  32. package/server/dist/sshx/dispatch.js +160 -0
  33. package/server/dist/sshx/lfs-transfer.js +289 -0
  34. package/server/dist/sshx/server.js +107 -0
  35. package/server/dist/toolx.js +108 -0
  36. package/server/dist/twofactor.js +160 -0
  37. package/server/dist/webapi.js +377 -0
  38. package/server/dist/webhook.js +128 -0
  39. package/server/package.json +34 -0
  40. package/server/public/img/avatar_default.png +0 -0
  41. package/server/tsconfig.json +19 -0
  42. package/server/vendored-conf/app.ini +538 -0
  43. package/server/vendored-conf/gitignore/Actionscript +11 -0
  44. package/server/vendored-conf/gitignore/Ada +5 -0
  45. package/server/vendored-conf/gitignore/Agda +1 -0
  46. package/server/vendored-conf/gitignore/Android +32 -0
  47. package/server/vendored-conf/gitignore/Anjuta +3 -0
  48. package/server/vendored-conf/gitignore/AppEngine +2 -0
  49. package/server/vendored-conf/gitignore/AppceleratorTitanium +3 -0
  50. package/server/vendored-conf/gitignore/ArchLinuxPackages +13 -0
  51. package/server/vendored-conf/gitignore/Archives +27 -0
  52. package/server/vendored-conf/gitignore/Autotools +14 -0
  53. package/server/vendored-conf/gitignore/BricxCC +4 -0
  54. package/server/vendored-conf/gitignore/C +32 -0
  55. package/server/vendored-conf/gitignore/C Sharp +108 -0
  56. package/server/vendored-conf/gitignore/C++ +28 -0
  57. package/server/vendored-conf/gitignore/CFWheels +12 -0
  58. package/server/vendored-conf/gitignore/CMake +6 -0
  59. package/server/vendored-conf/gitignore/CUDA +6 -0
  60. package/server/vendored-conf/gitignore/CakePHP +13 -0
  61. package/server/vendored-conf/gitignore/ChefCookbook +9 -0
  62. package/server/vendored-conf/gitignore/Cloud9 +3 -0
  63. package/server/vendored-conf/gitignore/CodeIgniter +6 -0
  64. package/server/vendored-conf/gitignore/CodeKit +3 -0
  65. package/server/vendored-conf/gitignore/CommonLisp +3 -0
  66. package/server/vendored-conf/gitignore/Composer +6 -0
  67. package/server/vendored-conf/gitignore/Concrete5 +3 -0
  68. package/server/vendored-conf/gitignore/Coq +3 -0
  69. package/server/vendored-conf/gitignore/CraftCMS +3 -0
  70. package/server/vendored-conf/gitignore/DM +5 -0
  71. package/server/vendored-conf/gitignore/Dart +15 -0
  72. package/server/vendored-conf/gitignore/DartEditor +2 -0
  73. package/server/vendored-conf/gitignore/Delphi +57 -0
  74. package/server/vendored-conf/gitignore/Dreamweaver +3 -0
  75. package/server/vendored-conf/gitignore/Drupal +36 -0
  76. package/server/vendored-conf/gitignore/EPiServer +4 -0
  77. package/server/vendored-conf/gitignore/Eagle +36 -0
  78. package/server/vendored-conf/gitignore/Eclipse +39 -0
  79. package/server/vendored-conf/gitignore/EiffelStudio +2 -0
  80. package/server/vendored-conf/gitignore/Elisp +5 -0
  81. package/server/vendored-conf/gitignore/Elixir +4 -0
  82. package/server/vendored-conf/gitignore/Emacs +32 -0
  83. package/server/vendored-conf/gitignore/Ensime +4 -0
  84. package/server/vendored-conf/gitignore/Erlang +10 -0
  85. package/server/vendored-conf/gitignore/Espresso +1 -0
  86. package/server/vendored-conf/gitignore/ExpressionEngine +19 -0
  87. package/server/vendored-conf/gitignore/ExtJs +4 -0
  88. package/server/vendored-conf/gitignore/Fancy +2 -0
  89. package/server/vendored-conf/gitignore/Finale +13 -0
  90. package/server/vendored-conf/gitignore/FlexBuilder +3 -0
  91. package/server/vendored-conf/gitignore/ForceDotCom +4 -0
  92. package/server/vendored-conf/gitignore/FuelPHP +2 -0
  93. package/server/vendored-conf/gitignore/GWT +28 -0
  94. package/server/vendored-conf/gitignore/Gcov +5 -0
  95. package/server/vendored-conf/gitignore/GitBook +16 -0
  96. package/server/vendored-conf/gitignore/Go +24 -0
  97. package/server/vendored-conf/gitignore/Gradle +8 -0
  98. package/server/vendored-conf/gitignore/Grails +33 -0
  99. package/server/vendored-conf/gitignore/Haskell +16 -0
  100. package/server/vendored-conf/gitignore/IGORPro +5 -0
  101. package/server/vendored-conf/gitignore/IPythonNotebook +2 -0
  102. package/server/vendored-conf/gitignore/Idris +2 -0
  103. package/server/vendored-conf/gitignore/JDeveloper +13 -0
  104. package/server/vendored-conf/gitignore/Java +12 -0
  105. package/server/vendored-conf/gitignore/Jboss +19 -0
  106. package/server/vendored-conf/gitignore/Jekyll +3 -0
  107. package/server/vendored-conf/gitignore/JetBrains +46 -0
  108. package/server/vendored-conf/gitignore/Joomla +525 -0
  109. package/server/vendored-conf/gitignore/KDevelop4 +2 -0
  110. package/server/vendored-conf/gitignore/Kate +3 -0
  111. package/server/vendored-conf/gitignore/KiCAD +13 -0
  112. package/server/vendored-conf/gitignore/Kohana +2 -0
  113. package/server/vendored-conf/gitignore/LabVIEW +16 -0
  114. package/server/vendored-conf/gitignore/Laravel +4 -0
  115. package/server/vendored-conf/gitignore/Lazarus +30 -0
  116. package/server/vendored-conf/gitignore/Leiningen +12 -0
  117. package/server/vendored-conf/gitignore/LemonStand +21 -0
  118. package/server/vendored-conf/gitignore/LibreOffice +2 -0
  119. package/server/vendored-conf/gitignore/Lilypond +6 -0
  120. package/server/vendored-conf/gitignore/Linux +7 -0
  121. package/server/vendored-conf/gitignore/Lithium +2 -0
  122. package/server/vendored-conf/gitignore/Lua +41 -0
  123. package/server/vendored-conf/gitignore/LyX +4 -0
  124. package/server/vendored-conf/gitignore/Magento +126 -0
  125. package/server/vendored-conf/gitignore/Matlab +16 -0
  126. package/server/vendored-conf/gitignore/Maven +9 -0
  127. package/server/vendored-conf/gitignore/Mercurial +6 -0
  128. package/server/vendored-conf/gitignore/Mercury +13 -0
  129. package/server/vendored-conf/gitignore/MetaProgrammingSystem +16 -0
  130. package/server/vendored-conf/gitignore/MicrosoftOffice +10 -0
  131. package/server/vendored-conf/gitignore/ModelSim +23 -0
  132. package/server/vendored-conf/gitignore/Momentics +8 -0
  133. package/server/vendored-conf/gitignore/MonoDevelop +8 -0
  134. package/server/vendored-conf/gitignore/Nanoc +10 -0
  135. package/server/vendored-conf/gitignore/NetBeans +8 -0
  136. package/server/vendored-conf/gitignore/Nim +1 -0
  137. package/server/vendored-conf/gitignore/Ninja +2 -0
  138. package/server/vendored-conf/gitignore/Node +28 -0
  139. package/server/vendored-conf/gitignore/NotepadPP +2 -0
  140. package/server/vendored-conf/gitignore/OCaml +20 -0
  141. package/server/vendored-conf/gitignore/Objective-C +43 -0
  142. package/server/vendored-conf/gitignore/Opa +13 -0
  143. package/server/vendored-conf/gitignore/OpenCart +11 -0
  144. package/server/vendored-conf/gitignore/OracleForms +8 -0
  145. package/server/vendored-conf/gitignore/Packer +5 -0
  146. package/server/vendored-conf/gitignore/Perl +20 -0
  147. package/server/vendored-conf/gitignore/Phalcon +2 -0
  148. package/server/vendored-conf/gitignore/PhpStorm +63 -0
  149. package/server/vendored-conf/gitignore/PlayFramework +17 -0
  150. package/server/vendored-conf/gitignore/Plone +18 -0
  151. package/server/vendored-conf/gitignore/Prestashop +25 -0
  152. package/server/vendored-conf/gitignore/Processing +7 -0
  153. package/server/vendored-conf/gitignore/Python +58 -0
  154. package/server/vendored-conf/gitignore/Qooxdoo +5 -0
  155. package/server/vendored-conf/gitignore/Qt +34 -0
  156. package/server/vendored-conf/gitignore/R +16 -0
  157. package/server/vendored-conf/gitignore/ROS +47 -0
  158. package/server/vendored-conf/gitignore/Rails +35 -0
  159. package/server/vendored-conf/gitignore/Redcar +1 -0
  160. package/server/vendored-conf/gitignore/Redis +3 -0
  161. package/server/vendored-conf/gitignore/RhodesRhomobile +9 -0
  162. package/server/vendored-conf/gitignore/Ruby +36 -0
  163. package/server/vendored-conf/gitignore/Rust +11 -0
  164. package/server/vendored-conf/gitignore/SBT +9 -0
  165. package/server/vendored-conf/gitignore/SCons +2 -0
  166. package/server/vendored-conf/gitignore/SVN +1 -0
  167. package/server/vendored-conf/gitignore/Sass +2 -0
  168. package/server/vendored-conf/gitignore/Scala +17 -0
  169. package/server/vendored-conf/gitignore/Scrivener +7 -0
  170. package/server/vendored-conf/gitignore/Sdcc +8 -0
  171. package/server/vendored-conf/gitignore/SeamGen +26 -0
  172. package/server/vendored-conf/gitignore/SketchUp +1 -0
  173. package/server/vendored-conf/gitignore/SlickEdit +11 -0
  174. package/server/vendored-conf/gitignore/Stella +12 -0
  175. package/server/vendored-conf/gitignore/SublimeText +14 -0
  176. package/server/vendored-conf/gitignore/SugarCRM +25 -0
  177. package/server/vendored-conf/gitignore/Swift +43 -0
  178. package/server/vendored-conf/gitignore/Symfony +37 -0
  179. package/server/vendored-conf/gitignore/SymphonyCMS +6 -0
  180. package/server/vendored-conf/gitignore/SynopsysVCS +36 -0
  181. package/server/vendored-conf/gitignore/Tags +14 -0
  182. package/server/vendored-conf/gitignore/TeX +136 -0
  183. package/server/vendored-conf/gitignore/TextMate +3 -0
  184. package/server/vendored-conf/gitignore/Textpattern +11 -0
  185. package/server/vendored-conf/gitignore/TortoiseGit +2 -0
  186. package/server/vendored-conf/gitignore/TurboGears2 +20 -0
  187. package/server/vendored-conf/gitignore/Typo3 +20 -0
  188. package/server/vendored-conf/gitignore/Umbraco +17 -0
  189. package/server/vendored-conf/gitignore/Unity +21 -0
  190. package/server/vendored-conf/gitignore/UnrealEngine +76 -0
  191. package/server/vendored-conf/gitignore/VVVV +6 -0
  192. package/server/vendored-conf/gitignore/Vagrant +1 -0
  193. package/server/vendored-conf/gitignore/Vim +6 -0
  194. package/server/vendored-conf/gitignore/VirtualEnv +10 -0
  195. package/server/vendored-conf/gitignore/VisualStudio +217 -0
  196. package/server/vendored-conf/gitignore/VisualStudioCode +2 -0
  197. package/server/vendored-conf/gitignore/Waf +3 -0
  198. package/server/vendored-conf/gitignore/WebMethods +14 -0
  199. package/server/vendored-conf/gitignore/WebStorm +63 -0
  200. package/server/vendored-conf/gitignore/Windows +18 -0
  201. package/server/vendored-conf/gitignore/WordPress +18 -0
  202. package/server/vendored-conf/gitignore/Xcode +23 -0
  203. package/server/vendored-conf/gitignore/XilinxISE +57 -0
  204. package/server/vendored-conf/gitignore/Xojo +11 -0
  205. package/server/vendored-conf/gitignore/Yeoman +6 -0
  206. package/server/vendored-conf/gitignore/Yii +6 -0
  207. package/server/vendored-conf/gitignore/ZendFramework +20 -0
  208. package/server/vendored-conf/gitignore/Zephir +26 -0
  209. package/server/vendored-conf/gitignore/macOS +25 -0
  210. package/server/vendored-conf/label/Default +7 -0
  211. package/server/vendored-conf/license/Abstyles License +10 -0
  212. package/server/vendored-conf/license/Academic Free License v1.1 +22 -0
  213. package/server/vendored-conf/license/Academic Free License v1.2 +27 -0
  214. package/server/vendored-conf/license/Academic Free License v2.0 +43 -0
  215. package/server/vendored-conf/license/Academic Free License v2.1 +44 -0
  216. package/server/vendored-conf/license/Academic Free License v3.0 +42 -0
  217. package/server/vendored-conf/license/Affero General Public License v1.0 +84 -0
  218. package/server/vendored-conf/license/Apache License 1.0 +19 -0
  219. package/server/vendored-conf/license/Apache License 1.1 +20 -0
  220. package/server/vendored-conf/license/Apache License 2.0 +72 -0
  221. package/server/vendored-conf/license/Artistic License 1.0 +48 -0
  222. package/server/vendored-conf/license/Artistic License 2.0 +84 -0
  223. package/server/vendored-conf/license/BSD 2-clause License +8 -0
  224. package/server/vendored-conf/license/BSD 3-clause License +10 -0
  225. package/server/vendored-conf/license/BSD 4-clause License +13 -0
  226. package/server/vendored-conf/license/Creative Commons CC0 1.0 Universal +39 -0
  227. package/server/vendored-conf/license/Eclipse Public License 1.0 +72 -0
  228. package/server/vendored-conf/license/Educational Community License v1.0 +22 -0
  229. package/server/vendored-conf/license/Educational Community License v2.0 +97 -0
  230. package/server/vendored-conf/license/GNU Affero General Public License v3.0 +241 -0
  231. package/server/vendored-conf/license/GNU Free Documentation License v1.1 +118 -0
  232. package/server/vendored-conf/license/GNU Free Documentation License v1.2 +129 -0
  233. package/server/vendored-conf/license/GNU Free Documentation License v1.3 +148 -0
  234. package/server/vendored-conf/license/GNU General Public License v1.0 +99 -0
  235. package/server/vendored-conf/license/GNU General Public License v2.0 +116 -0
  236. package/server/vendored-conf/license/GNU General Public License v3.0 +231 -0
  237. package/server/vendored-conf/license/GNU Lesser General Public License v2.1 +174 -0
  238. package/server/vendored-conf/license/GNU Lesser General Public License v3.0 +70 -0
  239. package/server/vendored-conf/license/GNU Library General Public License v2.0 +173 -0
  240. package/server/vendored-conf/license/ISC license +6 -0
  241. package/server/vendored-conf/license/MIT License +8 -0
  242. package/server/vendored-conf/license/Mozilla Public License 1.0 +122 -0
  243. package/server/vendored-conf/license/Mozilla Public License 1.1 +142 -0
  244. package/server/vendored-conf/license/Mozilla Public License 2.0 +143 -0
  245. package/server/vendored-conf/readme/Default +3 -0
  246. package/src/dsh-host.js +168 -0
  247. package/src/index.js +682 -0
  248. package/src/runner.js +364 -0
@@ -0,0 +1,143 @@
1
+ Mozilla Public License Version 2.0
2
+ 1. Definitions
3
+
4
+ 1.1. "Contributor" means each individual or legal entity that creates, contributes to the creation of, or owns Covered Software.
5
+
6
+ 1.2. "Contributor Version" means the combination of the Contributions of others (if any) used by a Contributor and that particular Contributor's Contribution.
7
+
8
+ 1.3. "Contribution" means Covered Software of a particular Contributor.
9
+
10
+ 1.4. "Covered Software" means Source Code Form to which the initial Contributor has attached the notice in Exhibit A, the Executable Form of such Source Code Form, and Modifications of such Source Code Form, in each case including portions thereof.
11
+
12
+ 1.5. "Incompatible With Secondary Licenses" means
13
+
14
+ (a) that the initial Contributor has attached the notice described in Exhibit B to the Covered Software; or
15
+
16
+ (b) that the Covered Software was made available under the terms of version 1.1 or earlier of the License, but not also under the terms of a Secondary License.
17
+
18
+ 1.6. "Executable Form" means any form of the work other than Source Code Form.
19
+
20
+ 1.7. "Larger Work" means a work that combines Covered Software with other material, in a separate file or files, that is not Covered Software.
21
+
22
+ 1.8. "License" means this document.
23
+
24
+ 1.9. "Licensable" means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently, any and all of the rights conveyed by this License.
25
+
26
+ 1.10. "Modifications" means any of the following:
27
+
28
+ (a) any file in Source Code Form that results from an addition to, deletion from, or modification of the contents of Covered Software; or
29
+
30
+ (b) any new file in Source Code Form that contains any Covered Software.
31
+
32
+ 1.11. "Patent Claims" of a Contributor means any patent claim(s), including without limitation, method, process, and apparatus claims, in any patent Licensable by such Contributor that would be infringed, but for the grant of the License, by the making, using, selling, offering for sale, having made, import, or transfer of either its Contributions or its Contributor Version.
33
+
34
+ 1.12. "Secondary License" means either the GNU General Public License, Version 2.0, the GNU Lesser General Public License, Version 2.1, the GNU Affero General Public License, Version 3.0, or any later versions of those licenses.
35
+
36
+ 1.13. "Source Code Form" means the form of the work preferred for making modifications.
37
+
38
+ 1.14. "You" (or "Your") means an individual or a legal entity exercising rights under this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity.
39
+
40
+ 2. License Grants and Conditions
41
+
42
+ 2.1. Grants
43
+ Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license:
44
+
45
+ (a) under intellectual property rights (other than patent or trademark) Licensable by such Contributor to use, reproduce, make available, modify, display, perform, distribute, and otherwise exploit its Contributions, either on an unmodified basis, with Modifications, or as part of a Larger Work; and
46
+
47
+ (b) under Patent Claims of such Contributor to make, use, sell, offer for sale, have made, import, and otherwise transfer either its Contributions or its Contributor Version.
48
+
49
+ 2.2. Effective Date
50
+ The licenses granted in Section 2.1 with respect to any Contribution become effective for each Contribution on the date the Contributor first distributes such Contribution.
51
+
52
+ 2.3. Limitations on Grant Scope
53
+ The licenses granted in this Section 2 are the only rights granted under this License. No additional rights or licenses will be implied from the distribution or licensing of Covered Software under this License. Notwithstanding Section 2.1(b) above, no patent license is granted by a Contributor:
54
+
55
+ (a) for any code that a Contributor has removed from Covered Software; or
56
+
57
+ (b) for infringements caused by: (i) Your and any other third party's modifications of Covered Software, or (ii) the combination of its Contributions with other software (except as part of its Contributor Version); or
58
+
59
+ (c) under Patent Claims infringed by Covered Software in the absence of its Contributions.
60
+
61
+ This License does not grant any rights in the trademarks, service marks, or logos of any Contributor (except as may be necessary to comply with the notice requirements in Section 3.4).
62
+
63
+ 2.4. Subsequent Licenses
64
+ No Contributor makes additional grants as a result of Your choice to distribute the Covered Software under a subsequent version of this License (see Section 10.2) or under the terms of a Secondary License (if permitted under the terms of Section 3.3).
65
+
66
+ 2.5. Representation
67
+ Each Contributor represents that the Contributor believes its Contributions are its original creation(s) or it has sufficient rights to grant the rights to its Contributions conveyed by this License.
68
+
69
+ 2.6. Fair Use
70
+ This License is not intended to limit any rights You have under applicable copyright doctrines of fair use, fair dealing, or other equivalents.
71
+
72
+ 2.7. Conditions
73
+ Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in Section 2.1.
74
+
75
+ 3. Responsibilities
76
+
77
+ 3.1. Distribution of Source Form
78
+ All distribution of Covered Software in Source Code Form, including any Modifications that You create or to which You contribute, must be under the terms of this License. You must inform recipients that the Source Code Form of the Covered Software is governed by the terms of this License, and how they can obtain a copy of this License. You may not attempt to alter or restrict the recipients' rights in the Source Code Form.
79
+
80
+ 3.2. Distribution of Executable Form
81
+ If You distribute Covered Software in Executable Form then:
82
+
83
+ (a) such Covered Software must also be made available in Source Code Form, as described in Section 3.1, and You must inform recipients of the Executable Form how they can obtain a copy of such Source Code Form by reasonable means in a timely manner, at a charge no more than the cost of distribution to the recipient; and
84
+
85
+ (b) You may distribute such Executable Form under the terms of this License, or sublicense it under different terms, provided that the license for the Executable Form does not attempt to limit or alter the recipients' rights in the Source Code Form under this License.
86
+
87
+ 3.3. Distribution of a Larger Work
88
+ You may create and distribute a Larger Work under terms of Your choice, provided that You also comply with the requirements of this License for the Covered Software. If the Larger Work is a combination of Covered Software with a work governed by one or more Secondary Licenses, and the Covered Software is not Incompatible With Secondary Licenses, this License permits You to additionally distribute such Covered Software under the terms of such Secondary License(s), so that the recipient of the Larger Work may, at their option, further distribute the Covered Software under the terms of either this License or such Secondary License(s).
89
+
90
+ 3.4. Notices
91
+ You may not remove or alter the substance of any license notices (including copyright notices, patent notices, disclaimers of warranty, or limitations of liability) contained within the Source Code Form of the Covered Software, except that You may alter any license notices to the extent required to remedy known factual inaccuracies.
92
+
93
+ 3.5. Application of Additional Terms
94
+ You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, You may do so only on Your own behalf, and not on behalf of any Contributor. You must make it absolutely clear that any such warranty, support, indemnity, or liability obligation is offered by You alone, and You hereby agree to indemnify every Contributor for any liability incurred by such Contributor as a result of warranty, support, indemnity or liability terms You offer. You may include additional disclaimers of warranty and limitations of liability specific to any jurisdiction.
95
+
96
+ 4. Inability to Comply Due to Statute or Regulation
97
+ If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Software due to statute, judicial order, or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be placed in a text file included with all distributions of the Covered Software under this License. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it.
98
+
99
+ 5. Termination
100
+
101
+ 5.1. The rights granted under this License will terminate automatically if You fail to comply with any of its terms. However, if You become compliant, then the rights granted under this License from a particular Contributor are reinstated (a) provisionally, unless and until such Contributor explicitly and finally terminates Your grants, and (b) on an ongoing basis, if such Contributor fails to notify You of the non-compliance by some reasonable means prior to 60 days after You have come back into compliance. Moreover, Your grants from a particular Contributor are reinstated on an ongoing basis if such Contributor notifies You of the non-compliance by some reasonable means, this is the first time You have received notice of non-compliance with this License from such Contributor, and You become compliant prior to 30 days after Your receipt of the notice.
102
+
103
+ 5.2. If You initiate litigation against any entity by asserting a patent infringement claim (excluding declaratory judgment actions, counter-claims, and cross-claims) alleging that a Contributor Version directly or indirectly infringes any patent, then the rights granted to You by any and all Contributors for the Covered Software under Section 2.1 of this License shall terminate.
104
+
105
+ 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user license agreements (excluding distributors and resellers) which have been validly granted by You or Your distributors under this License prior to termination shall survive termination.
106
+
107
+ 6. Disclaimer of Warranty
108
+ Covered Software is provided under this License on an "as is" basis, without warranty of any kind, either expressed, implied, or statutory, including, without limitation, warranties that the Covered Software is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire risk as to the quality and performance of the Covered Software is with You. Should any Covered Software prove defective in any respect, You (not any Contributor) assume the cost of any necessary servicing, repair, or correction. This disclaimer of warranty constitutes an essential part of this License. No use of any Covered Software is authorized under this License except under this disclaimer.
109
+
110
+ 7. Limitation of Liability
111
+ Under no circumstances and under no legal theory, whether tort (including negligence), contract, or otherwise, shall any Contributor, or anyone who distributes Covered Software as permitted above, be liable to You for any direct, indirect, special, incidental, or consequential damages of any character including, without limitation, damages for lost profits, loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses, even if such party shall have been informed of the possibility of such damages. This limitation of liability shall not apply to liability for death or personal injury resulting from such party's negligence to the extent applicable law prohibits such limitation. Some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages, so this exclusion and limitation may not apply to You.
112
+
113
+ 8. Litigation
114
+ Any litigation relating to this License may be brought only in the courts of a jurisdiction where the defendant maintains its principal place of business and such litigation shall be governed by laws of that jurisdiction, without reference to its conflict-of-law provisions. Nothing in this Section shall prevent a party's ability to bring cross-claims or counter-claims.
115
+
116
+ 9. Miscellaneous
117
+ This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not be used to construe this License against a Contributor.
118
+
119
+ 10. Versions of the License
120
+
121
+ 10.1. New Versions
122
+ Mozilla Foundation is the license steward. Except as provided in Section 10.3, no one other than the license steward has the right to modify or publish new versions of this License. Each version will be given a distinguishing version number.
123
+
124
+ 10.2. Effect of New Versions
125
+ You may distribute the Covered Software under the terms of the version of the License under which You originally received the Covered Software, or under the terms of any subsequent version published by the license steward.
126
+
127
+ 10.3. Modified Versions
128
+ If you create software not governed by this License, and you want to create a new license for such software, you may create and use a modified version of this License if you rename the license and remove any references to the name of the license steward (except to note that such modified license differs from this License).
129
+
130
+ 10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses
131
+ If You choose to distribute Source Code Form that is Incompatible With Secondary Licenses under the terms of this version of the License, the notice described in Exhibit B of this License must be attached.
132
+
133
+ Exhibit A - Source Code Form License Notice
134
+
135
+ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
136
+
137
+ If it is not possible or desirable to put the notice in a particular file, then You may include the notice in a location (such as a LICENSE file in a relevant directory) where a recipient would be likely to look for such a notice.
138
+
139
+ You may add additional accurate notices of copyright ownership.
140
+
141
+ Exhibit B - "Incompatible With Secondary Licenses" Notice
142
+
143
+ This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
@@ -0,0 +1,3 @@
1
+ # {Name}
2
+
3
+ {Description}
@@ -0,0 +1,168 @@
1
+ // dsh 私有 API 的宿主进程内实现:把内核 server/dist/dshapi.js 的
2
+ // registerDshRoutes 直接在宿主进程里跑(动态导入 ESM dist),省掉
3
+ // 「铸个人令牌 + localhost HTTP 跳转」这一层。git HTTP/LFS、/api/v1、
4
+ // /api/web 身份链仍在内核子进程。
5
+ //
6
+ // 机制:
7
+ // - lazy init:conf.load 用与内核子进程一致的 workDir/customDir,然后
8
+ // 动态导入 dist 的 db/git/markup/svc/dshapi;
9
+ // - 注册一个伪 Router 收集 dshapi 的全部路由;
10
+ // - dispatch() 每请求:宿主已知登录用户 → 铸个人令牌(仅做内核侧鉴权
11
+ // 校验的通道,不再发 HTTP)→ 构造精简 Context 壳 → 匹配路由执行;
12
+ // - archive 下载等二进制直接写真实 res(不再被 JSON 化)。
13
+ //
14
+ // SQLite 并发:host 与内核子进程共享同一个 gogs.db(WAL 模式),
15
+ // better-sqlite3 同步写入偶发 SQLITE_BUSY——批量写路径(issues 等)在
16
+ // 内核侧仍是单一写者,宿主侧只做配置/查询级写入,风险可接受。
17
+
18
+ const path = require('node:path');
19
+ const { pathToFileURL } = require('node:url');
20
+
21
+ let _ready = null;
22
+
23
+ async function ensureInit(cfg) {
24
+ if (_ready) return _ready;
25
+ _ready = (async () => {
26
+ const serverDir = path.join(__dirname, '..', 'server');
27
+ const customDir = path.join(cfg.dataDir, 'custom');
28
+ const customConf = path.join(customDir, 'conf', 'app.ini');
29
+ const { conf } = await import(pathToFileURL(path.join(serverDir, 'dist', 'conf.js')).href);
30
+ conf.load(serverDir, customDir, customConf);
31
+ const dshapi = await import(pathToFileURL(path.join(serverDir, 'dist', 'dshapi.js')).href);
32
+ const um = await import(pathToFileURL(path.join(serverDir, 'dist', 'authx', 'um.js')).href);
33
+ const pw = await import(pathToFileURL(path.join(serverDir, 'dist', 'authx', 'password.js')).href);
34
+ const dbm = await import(pathToFileURL(path.join(serverDir, 'dist', 'db', 'db.js')).href);
35
+ const routes = [];
36
+ const fake = {
37
+ get: (p, ...h) => routes.push({ method: 'GET', pattern: p, handler: h[0] }),
38
+ post: (p, ...h) => routes.push({ method: 'POST', pattern: p, handler: h[0] }),
39
+ patch: (p, ...h) => routes.push({ method: 'PATCH', pattern: p, handler: h[0] }),
40
+ delete: (p, ...h) => routes.push({ method: 'DELETE', pattern: p, handler: h[0] }),
41
+ };
42
+ dshapi.registerDshRoutes(fake);
43
+ return { routes, um, pw, dbm };
44
+ })();
45
+ return _ready;
46
+ }
47
+
48
+ // 路径匹配:静态段 > :param 单段 > :* 通配剩余
49
+ function matchRoute(pattern, pathname) {
50
+ const pp = pattern.split('/').filter(Boolean);
51
+ const segs = pathname.split('/').filter(Boolean);
52
+ const params = {};
53
+ let i = 0, j = 0;
54
+ while (i < pp.length && j < segs.length) {
55
+ const seg = pp[i];
56
+ if (seg === ':*' || seg === '*') { params[':*'] = segs.slice(j).join('/'); return params; }
57
+ if (seg.startsWith(':')) params[seg] = decodeURIComponent(segs[j]);
58
+ else if (seg !== segs[j]) return null;
59
+ i++; j++;
60
+ }
61
+ if (i === pp.length && j === segs.length) return params;
62
+ return null;
63
+ }
64
+
65
+ class ShimContext {
66
+ constructor({ req, res, params, pathname, query, body, user }) {
67
+ this.req = req;
68
+ this.res = res;
69
+ this.params = params;
70
+ this.pathname = pathname;
71
+ this.query = query;
72
+ this.formObj = body;
73
+ this.user = user;
74
+ this.rendered = false;
75
+ }
76
+ Params(name) { return this.params[name] ?? ''; }
77
+ ParamsInt64(name) { return Number(this.params[name]) || 0; }
78
+ Query(name) { return this.query.get(name) ?? ''; }
79
+ QueryInt(name) { return Number(this.query.get(name)) || 0; }
80
+ async form() { return this.formObj; }
81
+ get IsLogged() { return !!this.user; }
82
+ JSON(status, obj) {
83
+ this.res.statusCode = status;
84
+ this.res.setHeader('Content-Type', 'application/json; charset=utf-8');
85
+ this.res.end(JSON.stringify(obj));
86
+ this.rendered = true;
87
+ }
88
+ JSONSuccess(obj) { this.JSON(200, obj); }
89
+ Path() { return this.pathname; }
90
+ }
91
+
92
+ /**
93
+ * 进程内执行 /api/dsh/* 请求。
94
+ * @param cfg 插件配置(含 dataDir/port)
95
+ * @param actor 当前登录用户名(已铸个人令牌,仅用于内核侧鉴权字段)
96
+ * @param method HTTP 方法
97
+ * @param rest /dsh/... 路径(相对 /dsh-git-server/api 前缀已剥)
98
+ * @param req 原始请求
99
+ * @param res 原始响应
100
+ * @returns true=已处理;false=路由不存在(回退 HTTP 转发)
101
+ */
102
+ async function dispatch(cfg, actor, method, rest, req, res, token) {
103
+ const { routes } = await ensureInit(cfg);
104
+ // dshapi 的路由都是 /api/dsh/... 前缀;rest 是 'dsh/...' 形态
105
+ const pathname = '/api/' + rest;
106
+ const url = new URL(pathname, 'http://internal');
107
+ for (const r of routes) {
108
+ if (r.method !== method) continue;
109
+ const params = matchRoute(r.pattern, url.pathname);
110
+ if (!params) continue;
111
+ const body = await readBodyJson(req);
112
+ // 内核 authRepo 从 authorization 头取令牌;塞入 actor 的个人令牌
113
+ req.headers.authorization = 'token ' + token;
114
+ const c = new ShimContext({ req, res, params, pathname: url.pathname, query: url.searchParams, body, user: null });
115
+ await r.handler(c);
116
+ return true;
117
+ }
118
+ return false;
119
+ }
120
+
121
+ async function readBodyJson(req) {
122
+ if (req.method === 'GET' || req.method === 'HEAD') return {};
123
+ const chunks = [];
124
+ for await (const chunk of req) chunks.push(chunk);
125
+ const text = Buffer.concat(chunks).toString('utf8');
126
+ try { return JSON.parse(text || '{}'); } catch { return {}; }
127
+ }
128
+
129
+ module.exports = { dispatch };
130
+
131
+ // ── 身份链(宿主侧,全程无内核 HTTP) ──────────────────────────────────────
132
+ // dsh 会话已知用户名(网关已认证);宿主直接:读 UM users.json 取角色 →
133
+ // ensureShadowUser 建/对齐影子号(同一 gogs.db)→ 直接往 access_token 表铸令牌。
134
+
135
+ function umProfileFor(username) {
136
+ try {
137
+ const { join } = require('node:path');
138
+ const file = join(process.env.DSH_HOME || path.join(require('node:os').homedir(), '.dsh'), 'user-management', 'users.json');
139
+ const doc = JSON.parse(require('node:fs').readFileSync(file, 'utf8'));
140
+ const u = (doc.users || []).find((x) => x.username === username);
141
+ if (!u) return null;
142
+ return { username: u.username, role: u.role, disabled: !!u.disabled, totpEnabled: !!u.totpSecret };
143
+ } catch { return null }
144
+ }
145
+
146
+ /** 影子建号(幂等)。返回是否成功。 */
147
+ async function ensureShadowHost(cfg, username) {
148
+ const { um } = await ensureInit(cfg);
149
+ const profile = umProfileFor(username);
150
+ if (!profile) return false;
151
+ um.ensureShadowUser(profile);
152
+ return true;
153
+ }
154
+
155
+ /** 宿主直接铸个人令牌(写共享的 access_token 表,内核侧读同一库)。 */
156
+ async function mintTokenHost(cfg, username) {
157
+ const { pw, dbm } = await ensureInit(cfg);
158
+ await ensureShadowHost(cfg, username);
159
+ const u = dbm.getUserByUsername(username);
160
+ if (!u) throw new Error('影子用户缺失: ' + username);
161
+ const sha1 = pw.newTokenSHA1();
162
+ const now = Math.floor(Date.now() / 1000);
163
+ dbm.db().prepare('INSERT INTO access_token (uid, name, sha1, sha256, created_unix, updated_unix) VALUES (?,?,?,?,?,?)')
164
+ .run(u.id, 'dsh-' + now.toString(36), sha1, pw.sha256(sha1), now, now);
165
+ return sha1;
166
+ }
167
+
168
+ module.exports = { dispatch, ensureShadowHost, mintTokenHost };