@yinuo-ngm/server 1.0.15 → 1.0.17
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.
- package/lib/app.js +3 -15
- package/lib/common/editor.js +2 -2
- package/lib/env.d.ts +1 -0
- package/lib/env.js +1 -0
- package/lib/plugins/error-handler.plugin.d.ts +2 -2
- package/lib/plugins/error-handler.plugin.js +97 -88
- package/lib/plugins/ws/topics/nginx.ws.js +2 -1
- package/lib/plugins/ws/topics/svn.ws.d.ts +2 -1
- package/lib/plugins/ws/topics/svn.ws.js +3 -2
- package/lib/plugins/ws/topics/syslog.ws.d.ts +1 -1
- package/lib/plugins/ws/topics/task.ws.d.ts +2 -1
- package/lib/plugins/ws/topics/task.ws.js +2 -1
- package/lib/plugins/ws/ws.context.d.ts +1 -1
- package/lib/plugins/ws/ws.plugin.js +4 -3
- package/lib/plugins/ws/ws.router.d.ts +2 -2
- package/lib/plugins/ws/ws.router.js +8 -7
- package/lib/routes/api-client/collection.routes.js +8 -6
- package/lib/routes/api-client/env.routes.js +4 -3
- package/lib/routes/api-client/history.routes.js +3 -2
- package/lib/routes/api-client/hub-token.routes.js +32 -10
- package/lib/routes/api-client/request.routes.js +7 -6
- package/lib/routes/api-client/send.routes.js +3 -2
- package/lib/routes/config.routes.js +5 -5
- package/lib/routes/hub.routes.js +10 -10
- package/lib/routes/index.js +2 -0
- package/lib/routes/nginx/nginx-lifecycle.routes.js +4 -0
- package/lib/routes/nginx/nginx-route.context.js +23 -7
- package/lib/routes/nginx/nginx-server.routes.js +158 -6
- package/lib/routes/node-version.routes.d.ts +2 -0
- package/lib/routes/node-version.routes.js +56 -0
- package/lib/routes/project.routes.js +14 -9
- package/lib/routes/rss.routes.js +3 -3
- package/lib/routes/sprite-browse.routes.js +21 -6
- package/lib/routes/sprite.routes.js +18 -12
- package/lib/routes/static-files.routes.js +21 -5
- package/lib/routes/svn.routes.js +5 -3
- package/lib/routes/system.routes.js +20 -1
- package/lib/routes/task.routes.js +10 -3
- package/package.json +13 -6
- package/www/3rdpartylicenses.txt +66 -118
- package/www/browser/chunk-2L7NUOMX.js +2 -0
- package/www/browser/chunk-2NZJ7CN2.js +20 -0
- package/www/browser/chunk-3CM4SKDO.js +15 -0
- package/www/browser/chunk-3I7BQCXS.js +1 -0
- package/www/browser/chunk-3M56F2S2.js +1 -0
- package/www/browser/chunk-3OHBKMAA.js +1 -0
- package/www/browser/chunk-3XNNQFWR.js +1 -0
- package/www/browser/chunk-4BRW6LCZ.js +4 -0
- package/www/browser/chunk-4LBSLURA.js +1 -0
- package/www/browser/chunk-4X42HB6N.js +2 -0
- package/www/browser/chunk-5DYX4DUX.js +11 -0
- package/www/browser/chunk-6SYVDN5L.js +1 -0
- package/www/browser/chunk-6YYNHZ2A.js +1 -0
- package/www/browser/chunk-75W3GVSO.js +1 -0
- package/www/browser/chunk-7U44RF5F.js +63 -0
- package/www/browser/chunk-AELTP6YN.js +1 -0
- package/www/browser/chunk-AMXRL4GR.js +1 -0
- package/www/browser/chunk-AV2ZODEH.js +1 -0
- package/www/browser/chunk-AZ6SIMYH.js +1 -0
- package/www/browser/chunk-B3C35ET3.js +2 -0
- package/www/browser/chunk-BTQIUVTQ.js +1 -0
- package/www/browser/chunk-CN5J4WNO.js +1 -0
- package/www/browser/chunk-D2ODDESN.js +1 -0
- package/www/browser/chunk-DE6E23ET.js +1 -0
- package/www/browser/chunk-DIJPUYIA.js +1 -0
- package/www/browser/chunk-DLGJD6YU.js +4 -0
- package/www/browser/chunk-EEDA5U4V.js +1 -0
- package/www/browser/chunk-FK6Z4HLL.js +1 -0
- package/www/browser/chunk-FL6GDGHW.js +1 -0
- package/www/browser/chunk-FXCG34QS.js +1 -0
- package/www/browser/chunk-H2USFIYR.js +1 -0
- package/www/browser/chunk-H5HGMOE6.js +1 -0
- package/www/browser/chunk-HB3HECPD.js +1 -0
- package/www/browser/chunk-HDNG236Q.js +1 -0
- package/www/browser/chunk-HFZLJHYR.js +1 -0
- package/www/browser/chunk-HJTXXSMC.js +1 -0
- package/www/browser/chunk-HUMCWAKJ.js +3 -0
- package/www/browser/chunk-IKB3EQCP.js +2 -0
- package/www/browser/chunk-K7PESFPY.js +1 -0
- package/www/browser/chunk-KRYMOHYF.js +2 -0
- package/www/browser/chunk-M4QRBV3K.js +1 -0
- package/www/browser/chunk-N2PELLMM.js +30 -0
- package/www/browser/chunk-ONXBYGIG.js +1 -0
- package/www/browser/chunk-OSBDR36P.js +1 -0
- package/www/browser/chunk-OZCK4XVV.js +1 -0
- package/www/browser/chunk-QJP5F735.js +1 -0
- package/www/browser/chunk-RGOYDY7H.js +1 -0
- package/www/browser/chunk-UJKK4A7Y.js +1 -0
- package/www/browser/chunk-WD2EKZQC.js +1 -0
- package/www/browser/chunk-WUA5JFDD.js +1 -0
- package/www/browser/chunk-XLFHB7RS.js +3 -0
- package/www/browser/chunk-YNW4HEJO.js +37 -0
- package/www/browser/chunk-ZTDLWBW5.js +1 -0
- package/www/browser/dark.css +1 -30433
- package/www/browser/default.css +1 -30149
- package/www/browser/index.html +3 -3
- package/www/browser/main-N64WJCHX.js +34 -0
- package/www/browser/scripts-U25HCVEI.js +6 -0
- package/www/browser/styles-ROAHD7MY.css +1 -0
- package/www/browser/add-widget-drawer.component.css.map +0 -7
- package/www/browser/advanced-editor.component.css.map +0 -7
- package/www/browser/api-client.component.css.map +0 -7
- package/www/browser/api-history-drawer.component.css.map +0 -7
- package/www/browser/app.css.map +0 -7
- package/www/browser/attachment-viewer.component.css.map +0 -7
- package/www/browser/auth-editor.component.css.map +0 -7
- package/www/browser/body-editor.component.css.map +0 -7
- package/www/browser/chunk-2YSUXBGC.js +0 -627
- package/www/browser/chunk-2YSUXBGC.js.map +0 -1
- package/www/browser/chunk-3G2GEOPV.js +0 -456
- package/www/browser/chunk-3G2GEOPV.js.map +0 -1
- package/www/browser/chunk-3L72DF3R.js +0 -1683
- package/www/browser/chunk-3L72DF3R.js.map +0 -1
- package/www/browser/chunk-3MCIETCQ.js +0 -8279
- package/www/browser/chunk-3MCIETCQ.js.map +0 -1
- package/www/browser/chunk-665WC4RU.js +0 -5383
- package/www/browser/chunk-665WC4RU.js.map +0 -1
- package/www/browser/chunk-6QMSEZPT.js +0 -10044
- package/www/browser/chunk-6QMSEZPT.js.map +0 -1
- package/www/browser/chunk-6TBQERYX.js +0 -280
- package/www/browser/chunk-6TBQERYX.js.map +0 -1
- package/www/browser/chunk-6UW4MRJZ.js +0 -43
- package/www/browser/chunk-6UW4MRJZ.js.map +0 -7
- package/www/browser/chunk-6XUMIL3W.js +0 -5495
- package/www/browser/chunk-6XUMIL3W.js.map +0 -1
- package/www/browser/chunk-724YOJI3.js +0 -903
- package/www/browser/chunk-724YOJI3.js.map +0 -1
- package/www/browser/chunk-766T7YES.js +0 -437
- package/www/browser/chunk-766T7YES.js.map +0 -1
- package/www/browser/chunk-7FC7DN65.js +0 -728
- package/www/browser/chunk-7FC7DN65.js.map +0 -1
- package/www/browser/chunk-APGQRYWX.js +0 -156
- package/www/browser/chunk-APGQRYWX.js.map +0 -7
- package/www/browser/chunk-AQHSGTHS.js +0 -1960
- package/www/browser/chunk-AQHSGTHS.js.map +0 -1
- package/www/browser/chunk-CTOEAJQK.js +0 -40
- package/www/browser/chunk-CTOEAJQK.js.map +0 -7
- package/www/browser/chunk-DEGQJKKZ.js +0 -409
- package/www/browser/chunk-DEGQJKKZ.js.map +0 -1
- package/www/browser/chunk-DIJX2663.js +0 -1166
- package/www/browser/chunk-DIJX2663.js.map +0 -1
- package/www/browser/chunk-E4XD4GLT.js +0 -427
- package/www/browser/chunk-E4XD4GLT.js.map +0 -1
- package/www/browser/chunk-EQOY6A3M.js +0 -212
- package/www/browser/chunk-EQOY6A3M.js.map +0 -1
- package/www/browser/chunk-ETTBRXVA.js +0 -2643
- package/www/browser/chunk-ETTBRXVA.js.map +0 -1
- package/www/browser/chunk-FLSUSPBD.js +0 -5569
- package/www/browser/chunk-FLSUSPBD.js.map +0 -1
- package/www/browser/chunk-FZNHBEAZ.js +0 -102
- package/www/browser/chunk-FZNHBEAZ.js.map +0 -1
- package/www/browser/chunk-GJC7CZIJ.js +0 -361
- package/www/browser/chunk-GJC7CZIJ.js.map +0 -7
- package/www/browser/chunk-GMCNMOTD.js +0 -844
- package/www/browser/chunk-GMCNMOTD.js.map +0 -7
- package/www/browser/chunk-H43HGCRW.js +0 -198
- package/www/browser/chunk-H43HGCRW.js.map +0 -7
- package/www/browser/chunk-J447GBHM.js +0 -160
- package/www/browser/chunk-J447GBHM.js.map +0 -1
- package/www/browser/chunk-JN3VOWP7.js +0 -384
- package/www/browser/chunk-JN3VOWP7.js.map +0 -1
- package/www/browser/chunk-KSHAGY2M.js +0 -399
- package/www/browser/chunk-KSHAGY2M.js.map +0 -7
- package/www/browser/chunk-KV72AKOD.js +0 -59
- package/www/browser/chunk-KV72AKOD.js.map +0 -7
- package/www/browser/chunk-LAVMY2SJ.js +0 -26
- package/www/browser/chunk-LAVMY2SJ.js.map +0 -7
- package/www/browser/chunk-LLRVGHG5.js +0 -73
- package/www/browser/chunk-LLRVGHG5.js.map +0 -7
- package/www/browser/chunk-LPME4AJ3.js +0 -196
- package/www/browser/chunk-LPME4AJ3.js.map +0 -1
- package/www/browser/chunk-LVPSURVU.js +0 -4615
- package/www/browser/chunk-LVPSURVU.js.map +0 -1
- package/www/browser/chunk-MMPO7QLO.js +0 -4146
- package/www/browser/chunk-MMPO7QLO.js.map +0 -7
- package/www/browser/chunk-O7LB6VFM.js +0 -1953
- package/www/browser/chunk-O7LB6VFM.js.map +0 -1
- package/www/browser/chunk-P5CWA4FO.js +0 -685
- package/www/browser/chunk-P5CWA4FO.js.map +0 -1
- package/www/browser/chunk-RBWIWNTL.js +0 -203
- package/www/browser/chunk-RBWIWNTL.js.map +0 -7
- package/www/browser/chunk-RUXJCM3V.js +0 -26199
- package/www/browser/chunk-RUXJCM3V.js.map +0 -1
- package/www/browser/chunk-S77VVYUZ.js +0 -168
- package/www/browser/chunk-S77VVYUZ.js.map +0 -1
- package/www/browser/chunk-SCXPYFOB.js +0 -4316
- package/www/browser/chunk-SCXPYFOB.js.map +0 -1
- package/www/browser/chunk-SS73S33S.js +0 -471
- package/www/browser/chunk-SS73S33S.js.map +0 -7
- package/www/browser/chunk-T6UAOWNP.js +0 -600
- package/www/browser/chunk-T6UAOWNP.js.map +0 -1
- package/www/browser/chunk-TEW4MY4J.js +0 -148
- package/www/browser/chunk-TEW4MY4J.js.map +0 -7
- package/www/browser/chunk-TVORF3SF.js +0 -82
- package/www/browser/chunk-TVORF3SF.js.map +0 -7
- package/www/browser/chunk-UAN42EUZ.js +0 -2147
- package/www/browser/chunk-UAN42EUZ.js.map +0 -1
- package/www/browser/chunk-ULOHDK7Y.js +0 -1
- package/www/browser/chunk-ULOHDK7Y.js.map +0 -7
- package/www/browser/chunk-UYJ3FVRV.js +0 -3978
- package/www/browser/chunk-UYJ3FVRV.js.map +0 -1
- package/www/browser/chunk-VXHZMSDM.js +0 -5509
- package/www/browser/chunk-VXHZMSDM.js.map +0 -1
- package/www/browser/chunk-VYNQPZQO.js +0 -281
- package/www/browser/chunk-VYNQPZQO.js.map +0 -1
- package/www/browser/chunk-W3J23PZI.js +0 -9213
- package/www/browser/chunk-W3J23PZI.js.map +0 -1
- package/www/browser/chunk-W5HGHCQT.js +0 -1642
- package/www/browser/chunk-W5HGHCQT.js.map +0 -7
- package/www/browser/chunk-XF5H7E4L.js +0 -4723
- package/www/browser/chunk-XF5H7E4L.js.map +0 -1
- package/www/browser/chunk-XNFNEBMY.js +0 -398
- package/www/browser/chunk-XNFNEBMY.js.map +0 -7
- package/www/browser/chunk-XQY5SPGI.js +0 -30811
- package/www/browser/chunk-XQY5SPGI.js.map +0 -1
- package/www/browser/chunk-Y7JBZHNK.js +0 -514
- package/www/browser/chunk-Y7JBZHNK.js.map +0 -1
- package/www/browser/chunk-YWHRP4X3.js +0 -406
- package/www/browser/chunk-YWHRP4X3.js.map +0 -1
- package/www/browser/chunk-Z7FJIV62.js +0 -95
- package/www/browser/chunk-Z7FJIV62.js.map +0 -7
- package/www/browser/chunk-ZBZHXS46.js +0 -1674
- package/www/browser/chunk-ZBZHXS46.js.map +0 -1
- package/www/browser/chunk-ZZA5NVAI.js +0 -735
- package/www/browser/chunk-ZZA5NVAI.js.map +0 -1
- package/www/browser/collection-modal.component.css.map +0 -7
- package/www/browser/collection-tree-item.component.css.map +0 -7
- package/www/browser/collection-tree.component.css.map +0 -7
- package/www/browser/config-change-bar-component.css.map +0 -7
- package/www/browser/config-item-component.css.map +0 -7
- package/www/browser/config-nav-component.css.map +0 -7
- package/www/browser/config-section-component.css.map +0 -7
- package/www/browser/create-summary-aside.component.css.map +0 -7
- package/www/browser/curl-actions.component.css.map +0 -7
- package/www/browser/dark.css.map +0 -7
- package/www/browser/dashboard-canvas.component.css.map +0 -7
- package/www/browser/dashboard.component.css.map +0 -7
- package/www/browser/default.css.map +0 -7
- package/www/browser/detail-item-card.component.css.map +0 -7
- package/www/browser/ellipsis-text.component.css.map +0 -7
- package/www/browser/env-modal.component.css.map +0 -7
- package/www/browser/env-picker.component.css.map +0 -7
- package/www/browser/feedback.component.css.map +0 -7
- package/www/browser/fs-explorer.component.css.map +0 -7
- package/www/browser/git-import-modal.component.css.map +0 -7
- package/www/browser/hub-v2-personal-token-modal.component.css.map +0 -7
- package/www/browser/issue-action-area.component.css.map +0 -7
- package/www/browser/issue-add-participants-dialog.component.css.map +0 -7
- package/www/browser/issue-assign-dialog.component.css.map +0 -7
- package/www/browser/issue-attachment-area.component.css.map +0 -7
- package/www/browser/issue-base-info-area.component.css.map +0 -7
- package/www/browser/issue-branches.component.css.map +0 -7
- package/www/browser/issue-close-dialog.component.css.map +0 -7
- package/www/browser/issue-collaborators-panel.component.css.map +0 -7
- package/www/browser/issue-comment-editor.component.css.map +0 -7
- package/www/browser/issue-create-branch-dialog.component.css.map +0 -7
- package/www/browser/issue-description-area.component.css.map +0 -7
- package/www/browser/issue-detail.component.css.map +0 -7
- package/www/browser/issue-resolve-dialog.component.css.map +0 -7
- package/www/browser/issue-start-own-branch-dialog.component.css.map +0 -7
- package/www/browser/issues-list-table.component.css.map +0 -7
- package/www/browser/issues.component.css.map +0 -7
- package/www/browser/kill-port-widget.component.css.map +0 -7
- package/www/browser/kv-table.component.css.map +0 -7
- package/www/browser/layout-footer.component.css.map +0 -7
- package/www/browser/layout-header.component.css.map +0 -7
- package/www/browser/layout-menu.component.css.map +0 -7
- package/www/browser/layout-project-nav.component.css.map +0 -7
- package/www/browser/layout-sidebar.component.css.map +0 -7
- package/www/browser/layout.component.css.map +0 -7
- package/www/browser/less-viewport-component.css.map +0 -7
- package/www/browser/main.js +0 -1872
- package/www/browser/main.js.map +0 -1
- package/www/browser/markdown-viewer.component.css.map +0 -7
- package/www/browser/news-feed-widget.component.css.map +0 -7
- package/www/browser/ng-devtool.component.css.map +0 -7
- package/www/browser/nginx-config-editor.component.css.map +0 -7
- package/www/browser/nginx-log-viewer.component.css.map +0 -7
- package/www/browser/nginx-secondary-logs-tab.component.css.map +0 -7
- package/www/browser/nginx-secondary-perf-tab.component.css.map +0 -7
- package/www/browser/nginx-secondary-settings-tab.component.css.map +0 -7
- package/www/browser/nginx-secondary-ssl-tab.component.css.map +0 -7
- package/www/browser/nginx-secondary-test-tab.component.css.map +0 -7
- package/www/browser/nginx-secondary-traffic-tab.component.css.map +0 -7
- package/www/browser/nginx-secondary-upstream-tab.component.css.map +0 -7
- package/www/browser/nginx-section-card.component.css.map +0 -7
- package/www/browser/nginx-server-drawer.component.css.map +0 -7
- package/www/browser/nginx-server-list.component.css.map +0 -7
- package/www/browser/nginx-stat-card.component.css.map +0 -7
- package/www/browser/nginx.component.css.map +0 -7
- package/www/browser/page-layout.component.css.map +0 -7
- package/www/browser/pick-workspace-modal.component.css.map +0 -7
- package/www/browser/polyfills.js +0 -26584
- package/www/browser/polyfills.js.map +0 -7
- package/www/browser/project-conf.component.css.map +0 -7
- package/www/browser/project-create-modal.component.css.map +0 -7
- package/www/browser/project-create.component.css.map +0 -7
- package/www/browser/project-deps.component.css.map +0 -7
- package/www/browser/project-edit-modal.component.css.map +0 -7
- package/www/browser/project-import.component.css.map +0 -7
- package/www/browser/project-item-popover.component.css.map +0 -7
- package/www/browser/project-item.component.css.map +0 -7
- package/www/browser/project-list.component.css.map +0 -7
- package/www/browser/projects.component.css.map +0 -7
- package/www/browser/quick-task-widget.component.css.map +0 -7
- package/www/browser/rd-action-area.component.css.map +0 -7
- package/www/browser/rd-advance-stage-dialog.component.css.map +0 -7
- package/www/browser/rd-block-dialog.component.css.map +0 -7
- package/www/browser/rd-create-dialog.component.css.map +0 -7
- package/www/browser/rd-detail.component.css.map +0 -7
- package/www/browser/rd-item-card.component.css.map +0 -7
- package/www/browser/rd-list-board.component.css.map +0 -7
- package/www/browser/rd-list-table.component.css.map +0 -7
- package/www/browser/rd.component.css.map +0 -7
- package/www/browser/request-collections.component.css.map +0 -7
- package/www/browser/request-editor.component.css.map +0 -7
- package/www/browser/request-list-item.component.css.map +0 -7
- package/www/browser/request-list.component.css.map +0 -7
- package/www/browser/request-tabs-bar.component.css.map +0 -7
- package/www/browser/request-tabs.component.css.map +0 -7
- package/www/browser/request-urlbar.component.css.map +0 -7
- package/www/browser/response-viewer.component.css.map +0 -7
- package/www/browser/scripts.js +0 -245
- package/www/browser/scripts.js.map +0 -7
- package/www/browser/setting.component.css.map +0 -7
- package/www/browser/sprite-conf-modal.component.css.map +0 -7
- package/www/browser/sprite-icons-panel-component.css.map +0 -7
- package/www/browser/sprite-images-panel-component.css.map +0 -7
- package/www/browser/sprite-result-tabs.component.css.map +0 -7
- package/www/browser/sprite-viewport-component.css.map +0 -7
- package/www/browser/sprite.component.css.map +0 -7
- package/www/browser/step-advance.component.css.map +0 -7
- package/www/browser/step-basic.component.css.map +0 -7
- package/www/browser/step-config.component.css.map +0 -7
- package/www/browser/step-features.component.css.map +0 -7
- package/www/browser/step-preset.component.css.map +0 -7
- package/www/browser/step-summary-aside.component.css.map +0 -7
- package/www/browser/styles.css +0 -258
- package/www/browser/styles.css.map +0 -7
- package/www/browser/system-log.component.css.map +0 -7
- package/www/browser/task-actions.component.css.map +0 -7
- package/www/browser/task-console.component.css.map +0 -7
- package/www/browser/task-header.component.css.map +0 -7
- package/www/browser/task-list.component.css.map +0 -7
- package/www/browser/tasks.component.css.map +0 -7
- package/www/browser/terminal-view.component.css.map +0 -7
- package/www/browser/welcome-widget.component.css.map +0 -7
- package/www/browser/widget-base.component.css.map +0 -7
- package/www/browser/widget-host.component.css.map +0 -7
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.apiClientHubTokenRoutes = apiClientHubTokenRoutes;
|
|
4
|
-
const
|
|
4
|
+
const errors_1 = require("@yinuo-ngm/errors");
|
|
5
5
|
const api_1 = require("@yinuo-ngm/api");
|
|
6
6
|
const node_stream_1 = require("node:stream");
|
|
7
7
|
function normalizeNonEmptyString(value, field) {
|
|
8
8
|
if (typeof value !== "string" || value.trim() === "") {
|
|
9
|
-
throw new
|
|
9
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, `${field} is required`);
|
|
10
10
|
}
|
|
11
11
|
return value.trim();
|
|
12
12
|
}
|
|
@@ -32,13 +32,13 @@ async function resolveHubTokenConfig(app, body, tokenType) {
|
|
|
32
32
|
return { baseUrl: inlineBaseUrl, token: inlineToken };
|
|
33
33
|
}
|
|
34
34
|
if (!body.projectId) {
|
|
35
|
-
throw new
|
|
35
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "projectId is required when baseUrl/token are not provided");
|
|
36
36
|
}
|
|
37
37
|
const project = await app.core.project.get(body.projectId);
|
|
38
38
|
const config = readHubTokenConfigFromProject(project);
|
|
39
39
|
const resolvedToken = tokenType === "personal" ? body.personalToken?.trim() || config.personalToken : config.token;
|
|
40
40
|
if (!config.baseUrl || !resolvedToken) {
|
|
41
|
-
throw new
|
|
41
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, tokenType === "personal"
|
|
42
42
|
? "project hub-v2 config missing (NGM_HUB_V2_BASE_URL/NGM_HUB_V2_PERSONAL_TOKEN)"
|
|
43
43
|
: "project hub-v2 config missing (NGM_HUB_V2_BASE_URL/NGM_HUB_V2_TOKEN)");
|
|
44
44
|
}
|
|
@@ -59,7 +59,7 @@ async function apiClientHubTokenRoutes(fastify) {
|
|
|
59
59
|
const response = await requestHubApiRaw(baseUrl, "/api/token", token, "GET", normalizedPath);
|
|
60
60
|
if (!response.ok) {
|
|
61
61
|
const payload = await parseJson(response);
|
|
62
|
-
throw new
|
|
62
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, payload?.message || `hub-v2 request failed (${response.status})`, {
|
|
63
63
|
status: response.status,
|
|
64
64
|
response: payload,
|
|
65
65
|
});
|
|
@@ -81,7 +81,29 @@ async function apiClientHubTokenRoutes(fastify) {
|
|
|
81
81
|
const response = await requestHubApiRaw(baseUrl, "/api/token", token, "GET", normalizedPath);
|
|
82
82
|
if (!response.ok) {
|
|
83
83
|
const payload = await parseJson(response);
|
|
84
|
-
throw new
|
|
84
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, payload?.message || `hub-v2 request failed (${response.status})`, {
|
|
85
|
+
status: response.status,
|
|
86
|
+
response: payload,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
copyRawResponseHeaders(response, reply);
|
|
90
|
+
const body = response.body;
|
|
91
|
+
if (!body) {
|
|
92
|
+
return reply.status(response.status).send();
|
|
93
|
+
}
|
|
94
|
+
return reply.status(response.status).send(node_stream_1.Readable.fromWeb(body));
|
|
95
|
+
});
|
|
96
|
+
fastify.get("/projects/:projectId/rd-items/:itemId/uploads/:uploadId/raw", async (req, reply) => {
|
|
97
|
+
const params = (req.params ?? {});
|
|
98
|
+
const projectId = normalizeNonEmptyString(params.projectId, "projectId");
|
|
99
|
+
const itemId = normalizeNonEmptyString(params.itemId, "itemId");
|
|
100
|
+
const uploadId = normalizeNonEmptyString(params.uploadId, "uploadId");
|
|
101
|
+
const { baseUrl, token, projectKey } = await resolveHubTokenConfig(fastify, { projectId }, "project");
|
|
102
|
+
const normalizedPath = normalizeHubTokenPath(`/rd-items/${itemId}/uploads/${uploadId}/raw`, projectKey);
|
|
103
|
+
const response = await requestHubApiRaw(baseUrl, "/api/token", token, "GET", normalizedPath);
|
|
104
|
+
if (!response.ok) {
|
|
105
|
+
const payload = await parseJson(response);
|
|
106
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, payload?.message || `hub-v2 request failed (${response.status})`, {
|
|
85
107
|
status: response.status,
|
|
86
108
|
response: payload,
|
|
87
109
|
});
|
|
@@ -184,14 +206,14 @@ async function requestHubApi(baseUrl, apiPrefix, token, method, path, query, bod
|
|
|
184
206
|
});
|
|
185
207
|
const payload = await parseJson(response);
|
|
186
208
|
if (!response.ok) {
|
|
187
|
-
throw new
|
|
209
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, payload?.message || `hub-v2 request failed (${response.status})`, {
|
|
188
210
|
status: response.status,
|
|
189
211
|
response: payload,
|
|
190
212
|
});
|
|
191
213
|
}
|
|
192
214
|
if (payload && typeof payload === "object" && "code" in payload) {
|
|
193
215
|
if (payload.code !== "OK") {
|
|
194
|
-
throw new
|
|
216
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, payload.message || "hub-v2 response error", {
|
|
195
217
|
response: payload,
|
|
196
218
|
});
|
|
197
219
|
}
|
|
@@ -237,7 +259,7 @@ function assertPathProjectSegmentNotLocalProjectId(path, projectId) {
|
|
|
237
259
|
}
|
|
238
260
|
const projectSegment = (matched[1] ?? "").trim();
|
|
239
261
|
if (projectSegment && projectSegment === localProjectId) {
|
|
240
|
-
throw new
|
|
262
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "path must use projectKey (or business relative path), not local projectId");
|
|
241
263
|
}
|
|
242
264
|
}
|
|
243
265
|
function normalizeHubTokenPath(path, projectKey) {
|
|
@@ -249,7 +271,7 @@ function normalizeHubTokenPath(path, projectKey) {
|
|
|
249
271
|
return `/projects/${key}${rest}`;
|
|
250
272
|
}
|
|
251
273
|
if (!projectKey) {
|
|
252
|
-
throw new
|
|
274
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "projectKey is required when path does not include /projects/:projectKey");
|
|
253
275
|
}
|
|
254
276
|
return `/projects/${projectKey}${p}`;
|
|
255
277
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.apiClientRequestsRoutes = apiClientRequestsRoutes;
|
|
4
|
+
const errors_1 = require("@yinuo-ngm/errors");
|
|
4
5
|
function parseScope(q) {
|
|
5
6
|
const scope = (q?.scope ?? "project");
|
|
6
7
|
const projectId = q?.projectId;
|
|
7
8
|
if (scope === "project" && !projectId) {
|
|
8
|
-
throw new
|
|
9
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "projectId is required when scope=project");
|
|
9
10
|
}
|
|
10
11
|
return { scope, projectId };
|
|
11
12
|
}
|
|
@@ -30,9 +31,9 @@ async function apiClientRequestsRoutes(fastify) {
|
|
|
30
31
|
const body = req.body;
|
|
31
32
|
const scope = body?.scope ?? "project";
|
|
32
33
|
if (scope === "project" && !body.projectId)
|
|
33
|
-
throw new
|
|
34
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "projectId is required when scope=project");
|
|
34
35
|
if (!body?.request?.id)
|
|
35
|
-
throw new
|
|
36
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "request.id is required");
|
|
36
37
|
await api.saveRequest(body.request, scope, body.projectId);
|
|
37
38
|
return { id: body.request.id };
|
|
38
39
|
});
|
|
@@ -40,12 +41,12 @@ async function apiClientRequestsRoutes(fastify) {
|
|
|
40
41
|
const body = req.body;
|
|
41
42
|
const scope = body?.scope ?? "project";
|
|
42
43
|
if (scope === "project" && !body.projectId)
|
|
43
|
-
throw new
|
|
44
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "projectId is required when scope=project");
|
|
44
45
|
if (!body?.request?.id)
|
|
45
|
-
throw new
|
|
46
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "request.id is required");
|
|
46
47
|
const old = await api.getRequest(body.request.id, scope, body.projectId);
|
|
47
48
|
if (!old)
|
|
48
|
-
throw new
|
|
49
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.NOT_FOUND, "request not found: " + body.request.id);
|
|
49
50
|
const updated = {
|
|
50
51
|
...old,
|
|
51
52
|
...body.request,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.apiClientSendRoutes = apiClientSendRoutes;
|
|
4
|
+
const errors_1 = require("@yinuo-ngm/errors");
|
|
4
5
|
const hub_cookie_jar_1 = require("./hub-cookie-jar");
|
|
5
6
|
async function apiClientSendRoutes(fastify) {
|
|
6
7
|
const api = fastify.api;
|
|
@@ -8,9 +9,9 @@ async function apiClientSendRoutes(fastify) {
|
|
|
8
9
|
const body = req.body;
|
|
9
10
|
const scope = body.scope ?? "project";
|
|
10
11
|
if (scope === "project" && !body.projectId)
|
|
11
|
-
throw new
|
|
12
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "projectId is required when scope=project");
|
|
12
13
|
if (!body.request && !body.requestId)
|
|
13
|
-
throw new
|
|
14
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "request or requestId is required");
|
|
14
15
|
const useCookieJar = body.useCookieJar !== false;
|
|
15
16
|
const sessionKey = body.sessionKey ?? `${scope}:${body.projectId ?? "global"}:${body.envId ?? "default"}`;
|
|
16
17
|
if (body.clearCookieJar) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = configRoutes;
|
|
4
|
-
const
|
|
4
|
+
const errors_1 = require("@yinuo-ngm/errors");
|
|
5
5
|
const editor_1 = require("../common/editor");
|
|
6
6
|
async function configRoutes(fastify) {
|
|
7
7
|
fastify.get("/catalog/:projectId", async (req) => {
|
|
@@ -17,7 +17,7 @@ async function configRoutes(fastify) {
|
|
|
17
17
|
const body = req.body;
|
|
18
18
|
const next = body?.raw ?? body?.data;
|
|
19
19
|
if (next === undefined) {
|
|
20
|
-
throw new
|
|
20
|
+
throw new errors_1.CoreError(errors_1.CoreErrorCodes.CONFIG_WRITE_FAILED, "missing body.raw or body.data", { projectId, docId });
|
|
21
21
|
}
|
|
22
22
|
return await fastify.core.config.writeDoc(projectId, docId, next);
|
|
23
23
|
});
|
|
@@ -29,7 +29,7 @@ async function configRoutes(fastify) {
|
|
|
29
29
|
return { ok: true };
|
|
30
30
|
}
|
|
31
31
|
catch (e) {
|
|
32
|
-
throw new
|
|
32
|
+
throw new errors_1.CoreError(errors_1.CoreErrorCodes.EDITOR_LAUNCH_FAILED, e?.message || "openInEditor failed");
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
35
|
fastify.get("/readSchema/:projectId/:domainId", async (req) => {
|
|
@@ -41,7 +41,7 @@ async function configRoutes(fastify) {
|
|
|
41
41
|
const body = req.body;
|
|
42
42
|
const vm = body?.vm;
|
|
43
43
|
if (vm === undefined) {
|
|
44
|
-
throw new
|
|
44
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "missing body.vm");
|
|
45
45
|
}
|
|
46
46
|
await fastify.core.config.writeDomainSchema(projectId, domainId, vm);
|
|
47
47
|
return {
|
|
@@ -58,7 +58,7 @@ async function configRoutes(fastify) {
|
|
|
58
58
|
const body = req.body;
|
|
59
59
|
const vm = body?.vm;
|
|
60
60
|
if (vm === undefined) {
|
|
61
|
-
throw new
|
|
61
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "missing body.vm");
|
|
62
62
|
}
|
|
63
63
|
return await fastify.core.config.diffDomainSchema(projectId, domainId, vm);
|
|
64
64
|
});
|
package/lib/routes/hub.routes.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = hubRoutes;
|
|
4
|
-
const
|
|
4
|
+
const errors_1 = require("@yinuo-ngm/errors");
|
|
5
5
|
const DEFAULT_HUB_PUBLIC_BASE_URL = "http://192.168.1.31:7070/api/public";
|
|
6
6
|
function normalizeText(value, maxLen, fieldName) {
|
|
7
7
|
if (value === undefined || value === null)
|
|
8
8
|
return undefined;
|
|
9
9
|
if (typeof value !== "string") {
|
|
10
|
-
throw new
|
|
10
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, `${fieldName} must be string`);
|
|
11
11
|
}
|
|
12
12
|
const text = value.trim();
|
|
13
13
|
if (text.length > maxLen) {
|
|
14
|
-
throw new
|
|
14
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, `${fieldName} length must <= ${maxLen}`);
|
|
15
15
|
}
|
|
16
16
|
return text;
|
|
17
17
|
}
|
|
18
18
|
function validateBody(input) {
|
|
19
19
|
if (!input || typeof input !== "object") {
|
|
20
|
-
throw new
|
|
20
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "invalid feedback payload");
|
|
21
21
|
}
|
|
22
22
|
const body = input;
|
|
23
23
|
const category = body.category;
|
|
@@ -29,13 +29,13 @@ function validateBody(input) {
|
|
|
29
29
|
const clientVersion = normalizeText(body.clientVersion, 60, "clientVersion");
|
|
30
30
|
const osInfo = normalizeText(body.osInfo, 200, "osInfo");
|
|
31
31
|
if (!category || !["bug", "suggestion", "feature", "other"].includes(category)) {
|
|
32
|
-
throw new
|
|
32
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "invalid feedback category");
|
|
33
33
|
}
|
|
34
34
|
if (!title) {
|
|
35
|
-
throw new
|
|
35
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "feedback title is required");
|
|
36
36
|
}
|
|
37
37
|
if (!content) {
|
|
38
|
-
throw new
|
|
38
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "feedback content is required");
|
|
39
39
|
}
|
|
40
40
|
return {
|
|
41
41
|
category,
|
|
@@ -82,7 +82,7 @@ async function hubRoutes(app) {
|
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
84
|
catch (error) {
|
|
85
|
-
throw new
|
|
85
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.UNKNOWN_ERROR, "failed to connect hub service", { cause: error?.message || String(error), targetUrl });
|
|
86
86
|
}
|
|
87
87
|
let payload = null;
|
|
88
88
|
try {
|
|
@@ -93,10 +93,10 @@ async function hubRoutes(app) {
|
|
|
93
93
|
}
|
|
94
94
|
if (!response.ok) {
|
|
95
95
|
const message = payload?.message || `hub response error (${response.status})`;
|
|
96
|
-
throw new
|
|
96
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.UNKNOWN_ERROR, message, { status: response.status, payload });
|
|
97
97
|
}
|
|
98
98
|
if (payload?.code !== "OK") {
|
|
99
|
-
throw new
|
|
99
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.UNKNOWN_ERROR, payload?.message || "hub feedback submit failed", { payload });
|
|
100
100
|
}
|
|
101
101
|
return payload?.data ?? payload;
|
|
102
102
|
});
|
package/lib/routes/index.js
CHANGED
|
@@ -19,6 +19,7 @@ const svn_routes_1 = __importDefault(require("./svn.routes"));
|
|
|
19
19
|
const sprite_browse_routes_1 = __importDefault(require("./sprite-browse.routes"));
|
|
20
20
|
const static_files_routes_1 = __importDefault(require("./static-files.routes"));
|
|
21
21
|
const hub_routes_1 = __importDefault(require("./hub.routes"));
|
|
22
|
+
const node_version_routes_1 = __importDefault(require("./node-version.routes"));
|
|
22
23
|
async function routes(fastify) {
|
|
23
24
|
await fastify.register(system_routes_1.default);
|
|
24
25
|
await fastify.register(task_routes_1.default, { prefix: '/api/tasks' });
|
|
@@ -40,4 +41,5 @@ async function routes(fastify) {
|
|
|
40
41
|
await fastify.register(api_client_1.apiClientCollectionsRoutes, { prefix: '/api/client/collections' });
|
|
41
42
|
await fastify.register(api_client_1.apiClientHubTokenRoutes, { prefix: '/api/client/hub-token' });
|
|
42
43
|
await fastify.register(nginx_routes_1.nginxRoutes, { prefix: '/api/nginx' });
|
|
44
|
+
await fastify.register(node_version_routes_1.default, { prefix: '/api/node-version' });
|
|
43
45
|
}
|
|
@@ -65,6 +65,10 @@ function registerNginxLifecycleRoutes(context) {
|
|
|
65
65
|
success: true,
|
|
66
66
|
});
|
|
67
67
|
});
|
|
68
|
+
fastify.get('/local-ip', async (_request, reply) => {
|
|
69
|
+
const result = await nginx.service.getLocalIp();
|
|
70
|
+
return reply.send(result);
|
|
71
|
+
});
|
|
68
72
|
fastify.post('/start', async (_request, reply) => {
|
|
69
73
|
const result = await nginx.service.start();
|
|
70
74
|
if (result.success) {
|
|
@@ -2,23 +2,39 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createNginxRouteContext = createNginxRouteContext;
|
|
4
4
|
exports.sendBadRequest = sendBadRequest;
|
|
5
|
+
const promises_1 = require("fs/promises");
|
|
5
6
|
const path_1 = require("path");
|
|
6
|
-
const
|
|
7
|
+
const errors_1 = require("@yinuo-ngm/errors");
|
|
7
8
|
function createNginxRouteContext(fastify) {
|
|
8
9
|
const nginx = fastify.nginx;
|
|
9
10
|
const normalizeFsPath = (filePath) => (0, path_1.resolve)(filePath).replace(/\\/g, '/').toLowerCase();
|
|
10
11
|
const ensureManageableConfigFile = async (rawPath) => {
|
|
11
12
|
const filePath = rawPath?.trim();
|
|
12
13
|
if (!filePath) {
|
|
13
|
-
throw new
|
|
14
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, '配置文件路径不能为空');
|
|
14
15
|
}
|
|
15
16
|
const included = await nginx.config.getIncludedConfigs();
|
|
16
|
-
const includedSet = new Set(
|
|
17
|
-
const
|
|
17
|
+
const includedSet = new Set();
|
|
18
|
+
for (const item of included) {
|
|
19
|
+
try {
|
|
20
|
+
includedSet.add(normalizeFsPath(await (0, promises_1.realpath)(item)));
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
includedSet.add(normalizeFsPath((0, path_1.resolve)(item)));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const resolvedTarget = (0, path_1.resolve)(filePath);
|
|
27
|
+
let normalizedTarget;
|
|
28
|
+
try {
|
|
29
|
+
normalizedTarget = normalizeFsPath(await (0, promises_1.realpath)(resolvedTarget));
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
normalizedTarget = normalizeFsPath(resolvedTarget);
|
|
33
|
+
}
|
|
18
34
|
if (!includedSet.has(normalizedTarget)) {
|
|
19
|
-
throw new
|
|
35
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.OP_NOT_FOUND, '配置文件不在当前可管理列表中');
|
|
20
36
|
}
|
|
21
|
-
return
|
|
37
|
+
return resolvedTarget;
|
|
22
38
|
};
|
|
23
39
|
return {
|
|
24
40
|
fastify,
|
|
@@ -29,7 +45,7 @@ function createNginxRouteContext(fastify) {
|
|
|
29
45
|
}
|
|
30
46
|
function sendBadRequest(reply, error) {
|
|
31
47
|
const message = error instanceof Error ? error.message : String(error ?? '未知错误');
|
|
32
|
-
throw new
|
|
48
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, message, {
|
|
33
49
|
route: reply.request?.url,
|
|
34
50
|
method: reply.request?.method,
|
|
35
51
|
});
|
|
@@ -1,16 +1,80 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.registerNginxServerRoutes = registerNginxServerRoutes;
|
|
4
|
-
const
|
|
4
|
+
const errors_1 = require("@yinuo-ngm/errors");
|
|
5
5
|
const nginx_route_context_1 = require("./nginx-route.context");
|
|
6
6
|
function registerNginxServerRoutes(context) {
|
|
7
7
|
const { fastify, nginx } = context;
|
|
8
|
+
const buildRuntimeStatus = (enabled, nginxRunning, pendingReload) => {
|
|
9
|
+
if (!enabled) {
|
|
10
|
+
return 'disabled';
|
|
11
|
+
}
|
|
12
|
+
if (nginxRunning === null) {
|
|
13
|
+
return 'unknown';
|
|
14
|
+
}
|
|
15
|
+
if (pendingReload) {
|
|
16
|
+
return 'pending';
|
|
17
|
+
}
|
|
18
|
+
return nginxRunning ? 'running' : 'stopped';
|
|
19
|
+
};
|
|
20
|
+
const parseIsoMs = (value) => {
|
|
21
|
+
const text = String(value || '').trim();
|
|
22
|
+
if (!text) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const ms = Date.parse(text);
|
|
26
|
+
return Number.isFinite(ms) ? ms : null;
|
|
27
|
+
};
|
|
28
|
+
const isServerPendingReload = (server, nginxRunning, lastAppliedAt) => {
|
|
29
|
+
if (!server.enabled || !nginxRunning) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (lastAppliedAt === null) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
const changedAt = parseIsoMs(server.updatedAt) ?? parseIsoMs(server.createdAt);
|
|
36
|
+
if (changedAt === null) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return changedAt > lastAppliedAt;
|
|
40
|
+
};
|
|
41
|
+
const resolveActor = (request) => {
|
|
42
|
+
const directHeader = request.headers['x-ngm-user'] || request.headers['x-user'] || request.headers['x-username'];
|
|
43
|
+
if (typeof directHeader === 'string' && directHeader.trim()) {
|
|
44
|
+
return directHeader.trim();
|
|
45
|
+
}
|
|
46
|
+
const user = request?.user;
|
|
47
|
+
if (typeof user?.name === 'string' && user.name.trim()) {
|
|
48
|
+
return user.name.trim();
|
|
49
|
+
}
|
|
50
|
+
if (typeof user?.username === 'string' && user.username.trim()) {
|
|
51
|
+
return user.username.trim();
|
|
52
|
+
}
|
|
53
|
+
if (typeof user?.id === 'string' && user.id.trim()) {
|
|
54
|
+
return user.id.trim();
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
};
|
|
8
58
|
fastify.get('/servers', async (_request, reply) => {
|
|
9
59
|
try {
|
|
10
60
|
const servers = await nginx.server.getAllServers();
|
|
61
|
+
let nginxRunning = null;
|
|
62
|
+
let lastAppliedAt = null;
|
|
63
|
+
try {
|
|
64
|
+
const status = await nginx.service.getStatus();
|
|
65
|
+
nginxRunning = Boolean(status.isRunning);
|
|
66
|
+
lastAppliedAt = nginx.service.getLastConfigAppliedAt();
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
nginxRunning = null;
|
|
70
|
+
}
|
|
71
|
+
const enriched = servers.map(server => ({
|
|
72
|
+
...server,
|
|
73
|
+
runtimeStatus: buildRuntimeStatus(Boolean(server.enabled), nginxRunning, isServerPendingReload(server, nginxRunning, lastAppliedAt)),
|
|
74
|
+
}));
|
|
11
75
|
return reply.send({
|
|
12
76
|
success: true,
|
|
13
|
-
servers,
|
|
77
|
+
servers: enriched,
|
|
14
78
|
});
|
|
15
79
|
}
|
|
16
80
|
catch (error) {
|
|
@@ -22,11 +86,25 @@ function registerNginxServerRoutes(context) {
|
|
|
22
86
|
try {
|
|
23
87
|
const server = await nginx.server.getServer(id);
|
|
24
88
|
if (!server) {
|
|
25
|
-
throw new
|
|
89
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.NOT_FOUND, 'Server 不存在');
|
|
90
|
+
}
|
|
91
|
+
let nginxRunning = null;
|
|
92
|
+
let lastAppliedAt = null;
|
|
93
|
+
try {
|
|
94
|
+
const status = await nginx.service.getStatus();
|
|
95
|
+
nginxRunning = Boolean(status.isRunning);
|
|
96
|
+
lastAppliedAt = nginx.service.getLastConfigAppliedAt();
|
|
26
97
|
}
|
|
98
|
+
catch {
|
|
99
|
+
nginxRunning = null;
|
|
100
|
+
}
|
|
101
|
+
const enriched = {
|
|
102
|
+
...server,
|
|
103
|
+
runtimeStatus: buildRuntimeStatus(Boolean(server.enabled), nginxRunning, isServerPendingReload(server, nginxRunning, lastAppliedAt)),
|
|
104
|
+
};
|
|
27
105
|
return reply.send({
|
|
28
106
|
success: true,
|
|
29
|
-
server,
|
|
107
|
+
server: enriched,
|
|
30
108
|
});
|
|
31
109
|
}
|
|
32
110
|
catch (error) {
|
|
@@ -35,7 +113,11 @@ function registerNginxServerRoutes(context) {
|
|
|
35
113
|
});
|
|
36
114
|
fastify.post('/servers', async (request, reply) => {
|
|
37
115
|
try {
|
|
38
|
-
const
|
|
116
|
+
const actor = resolveActor(request);
|
|
117
|
+
const payload = actor
|
|
118
|
+
? { ...request.body, createdBy: request.body?.createdBy || actor }
|
|
119
|
+
: { ...request.body };
|
|
120
|
+
const server = await nginx.server.createServer(payload);
|
|
39
121
|
return reply.send({
|
|
40
122
|
success: true,
|
|
41
123
|
server,
|
|
@@ -61,9 +143,26 @@ function registerNginxServerRoutes(context) {
|
|
|
61
143
|
fastify.delete('/servers/:id', async (request, reply) => {
|
|
62
144
|
const { id } = request.params;
|
|
63
145
|
try {
|
|
64
|
-
await nginx.server.deleteServer(id);
|
|
146
|
+
const result = await nginx.server.deleteServer(id);
|
|
147
|
+
return reply.send({
|
|
148
|
+
success: true,
|
|
149
|
+
snapshotId: result.snapshotId,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
fastify.post('/servers/restore-deleted', async (request, reply) => {
|
|
157
|
+
try {
|
|
158
|
+
const snapshotId = String(request.body?.snapshotId || '').trim();
|
|
159
|
+
if (!snapshotId) {
|
|
160
|
+
throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, 'snapshotId 不能为空');
|
|
161
|
+
}
|
|
162
|
+
const server = await nginx.server.restoreDeletedServer(snapshotId);
|
|
65
163
|
return reply.send({
|
|
66
164
|
success: true,
|
|
165
|
+
server,
|
|
67
166
|
});
|
|
68
167
|
}
|
|
69
168
|
catch (error) {
|
|
@@ -94,4 +193,57 @@ function registerNginxServerRoutes(context) {
|
|
|
94
193
|
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
95
194
|
}
|
|
96
195
|
});
|
|
196
|
+
fastify.post('/servers/import/parse', async (request, reply) => {
|
|
197
|
+
try {
|
|
198
|
+
const content = String(request.body?.content || '').trim();
|
|
199
|
+
if (!content) {
|
|
200
|
+
return reply.send({
|
|
201
|
+
success: true,
|
|
202
|
+
candidates: [],
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
const candidates = await nginx.server.parseImportCandidates(content);
|
|
206
|
+
return reply.send({
|
|
207
|
+
success: true,
|
|
208
|
+
candidates,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
fastify.post('/servers/import/analyze', async (request, reply) => {
|
|
216
|
+
try {
|
|
217
|
+
const requests = Array.isArray(request.body?.requests) ? request.body.requests : [];
|
|
218
|
+
const candidates = await nginx.server.analyzeImportRequests(requests);
|
|
219
|
+
return reply.send({
|
|
220
|
+
success: true,
|
|
221
|
+
candidates,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
fastify.post('/servers/validate-ssl-paths', async (request, reply) => {
|
|
229
|
+
try {
|
|
230
|
+
const certPath = String(request.body?.sslCert || '').trim();
|
|
231
|
+
const keyPath = String(request.body?.sslKey || '').trim();
|
|
232
|
+
const cert = certPath
|
|
233
|
+
? await nginx.service.validateFileReadable(certPath)
|
|
234
|
+
: { exists: false, readable: false, error: '证书路径为空' };
|
|
235
|
+
const key = keyPath
|
|
236
|
+
? await nginx.service.validateFileReadable(keyPath)
|
|
237
|
+
: { exists: false, readable: false, error: '私钥路径为空' };
|
|
238
|
+
return reply.send({
|
|
239
|
+
success: true,
|
|
240
|
+
valid: cert.exists && cert.readable && key.exists && key.readable,
|
|
241
|
+
cert,
|
|
242
|
+
key,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
return (0, nginx_route_context_1.sendBadRequest)(reply, error);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
97
249
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = nodeVersionRoutes;
|
|
4
|
+
const errors_1 = require("@yinuo-ngm/errors");
|
|
5
|
+
async function nodeVersionRoutes(fastify) {
|
|
6
|
+
fastify.get('/current', async () => {
|
|
7
|
+
const service = fastify.core.nodeVersion;
|
|
8
|
+
return await service.getCurrentVersion();
|
|
9
|
+
});
|
|
10
|
+
fastify.post('/switch', async (req) => {
|
|
11
|
+
const { version } = req.body || {};
|
|
12
|
+
if (!version) {
|
|
13
|
+
throw new errors_1.CoreError(errors_1.CoreErrorCodes.VERSION_REQUIRED, '请指定要切换的 Node 版本', {});
|
|
14
|
+
}
|
|
15
|
+
const service = fastify.core.nodeVersion;
|
|
16
|
+
return await service.switchVersion(version);
|
|
17
|
+
});
|
|
18
|
+
fastify.post('/project-requirement', async (req) => {
|
|
19
|
+
const { projectPath } = req.body || {};
|
|
20
|
+
if (!projectPath) {
|
|
21
|
+
throw new errors_1.CoreError(errors_1.CoreErrorCodes.PROJECT_PATH_REQUIRED, '请指定项目路径', {});
|
|
22
|
+
}
|
|
23
|
+
const service = fastify.core.nodeVersion;
|
|
24
|
+
return await service.detectProjectRequirement(projectPath);
|
|
25
|
+
});
|
|
26
|
+
fastify.post('/install', async (req) => {
|
|
27
|
+
const { version } = req.body || {};
|
|
28
|
+
if (!version) {
|
|
29
|
+
throw new errors_1.CoreError(errors_1.CoreErrorCodes.VERSION_REQUIRED, '请指定要安装的 Node 版本', {});
|
|
30
|
+
}
|
|
31
|
+
const service = fastify.core.nodeVersion;
|
|
32
|
+
const result = await service.installNodeVersion(version);
|
|
33
|
+
return result;
|
|
34
|
+
});
|
|
35
|
+
fastify.post('/uninstall', async (req) => {
|
|
36
|
+
const { version } = req.body || {};
|
|
37
|
+
if (!version) {
|
|
38
|
+
throw new errors_1.CoreError(errors_1.CoreErrorCodes.VERSION_REQUIRED, '请指定要卸载的 Node 版本', {});
|
|
39
|
+
}
|
|
40
|
+
const service = fastify.core.nodeVersion;
|
|
41
|
+
const success = await service.uninstallNodeVersion(version);
|
|
42
|
+
return { success };
|
|
43
|
+
});
|
|
44
|
+
fastify.post('/write-engine-config', async (req) => {
|
|
45
|
+
const { projectPath, version } = req.body || {};
|
|
46
|
+
if (!projectPath) {
|
|
47
|
+
throw new errors_1.CoreError(errors_1.CoreErrorCodes.PROJECT_PATH_REQUIRED, '请指定项目路径', {});
|
|
48
|
+
}
|
|
49
|
+
if (!version) {
|
|
50
|
+
throw new errors_1.CoreError(errors_1.CoreErrorCodes.VERSION_REQUIRED, '请指定版本要求', {});
|
|
51
|
+
}
|
|
52
|
+
const service = fastify.core.nodeVersion;
|
|
53
|
+
const success = await service.writeEngineConfig(projectPath, version);
|
|
54
|
+
return { success };
|
|
55
|
+
});
|
|
56
|
+
}
|