@yinuo-ngm/server 1.0.20 → 1.0.22

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 (113) hide show
  1. package/lib/app.js +0 -4
  2. package/lib/env.js +5 -1
  3. package/lib/plugins/success-handle.plugin.js +1 -1
  4. package/lib/plugins/ws/topics/nginx.ws.js +1 -1
  5. package/lib/plugins/ws/ws.context.js +3 -1
  6. package/lib/plugins/ws/ws.plugin.js +14 -2
  7. package/lib/routes/api-client/collection.routes.js +35 -35
  8. package/lib/routes/api-client/env.routes.js +12 -8
  9. package/lib/routes/api-client/history.routes.js +10 -5
  10. package/lib/routes/api-client/request.routes.js +14 -8
  11. package/lib/routes/api-client/route-mappers.d.ts +7 -0
  12. package/lib/routes/api-client/route-mappers.js +78 -0
  13. package/lib/routes/api-client/send.routes.js +12 -8
  14. package/lib/routes/config.routes.js +73 -49
  15. package/lib/routes/deps.route.js +47 -5
  16. package/lib/routes/index.js +5 -3
  17. package/lib/routes/nginx/nginx-config.routes.js +3 -3
  18. package/lib/routes/nginx/nginx-lifecycle.routes.js +14 -13
  19. package/lib/routes/nginx/nginx-module.routes.js +6 -6
  20. package/lib/routes/nginx/nginx-route.context.d.ts +16 -1
  21. package/lib/routes/nginx/nginx-route.context.js +136 -1
  22. package/lib/routes/nginx/nginx-server.routes.js +5 -5
  23. package/lib/routes/node-runtime.routes.d.ts +2 -0
  24. package/lib/routes/node-runtime.routes.js +69 -0
  25. package/lib/routes/project.routes.js +117 -13
  26. package/lib/routes/sprite/sprite-browse.routes.d.ts +2 -0
  27. package/lib/routes/sprite/sprite-browse.routes.js +137 -0
  28. package/lib/routes/sprite/sprite-quick.utils.d.ts +19 -0
  29. package/lib/routes/sprite/sprite-quick.utils.js +247 -0
  30. package/lib/routes/sprite/sprite.routes.d.ts +2 -0
  31. package/lib/routes/sprite/sprite.routes.js +212 -0
  32. package/lib/routes/sprite-browse.routes.js +17 -11
  33. package/lib/routes/sprite.routes.d.ts +1 -1
  34. package/lib/routes/sprite.routes.js +68 -11
  35. package/lib/routes/svn.routes.js +48 -14
  36. package/lib/routes/task.routes.js +99 -7
  37. package/package.json +7 -7
  38. package/www/3rdpartylicenses.txt +5 -5
  39. package/www/browser/{chunk-OZCK4XVV.js → chunk-2VJVGBXG.js} +1 -1
  40. package/www/browser/{chunk-FL6GDGHW.js → chunk-3ODVU46S.js} +1 -1
  41. package/www/browser/chunk-442QFABJ.js +1 -0
  42. package/www/browser/{chunk-WD2EKZQC.js → chunk-6J6G7JEP.js} +1 -1
  43. package/www/browser/{chunk-7U44RF5F.js → chunk-6UFDNETG.js} +1 -1
  44. package/www/browser/{chunk-75W3GVSO.js → chunk-7AKVG375.js} +1 -1
  45. package/www/browser/chunk-7GLWEFTM.js +1 -0
  46. package/www/browser/{chunk-DIJPUYIA.js → chunk-7QR6RHLA.js} +1 -1
  47. package/www/browser/{chunk-HJTXXSMC.js → chunk-CO3CQHKV.js} +1 -1
  48. package/www/browser/{chunk-3XNNQFWR.js → chunk-CPJTSA6E.js} +1 -1
  49. package/www/browser/chunk-DENFXXOY.js +1 -0
  50. package/www/browser/{chunk-HDNG236Q.js → chunk-HC5KLPHD.js} +1 -1
  51. package/www/browser/chunk-HJAP6WBI.js +1 -0
  52. package/www/browser/{chunk-N2PELLMM.js → chunk-JM6DCZP6.js} +7 -7
  53. package/www/browser/chunk-K6C5ZIV2.js +20 -0
  54. package/www/browser/chunk-M6NZ6C2R.js +2 -0
  55. package/www/browser/{chunk-RGOYDY7H.js → chunk-MBPB43C6.js} +1 -1
  56. package/www/browser/chunk-MPLGMTLT.js +3 -0
  57. package/www/browser/chunk-NNOWADVM.js +1 -0
  58. package/www/browser/{chunk-M4QRBV3K.js → chunk-NREWZQVN.js} +1 -1
  59. package/www/browser/{chunk-6YYNHZ2A.js → chunk-OUGN4APK.js} +1 -1
  60. package/www/browser/chunk-PB2LGZNW.js +1 -0
  61. package/www/browser/chunk-PDI3HSSH.js +4 -0
  62. package/www/browser/chunk-PUG3VNTI.js +3 -0
  63. package/www/browser/{chunk-QJP5F735.js → chunk-PY3AUTHC.js} +1 -1
  64. package/www/browser/{chunk-3M56F2S2.js → chunk-R4HSZU2J.js} +1 -1
  65. package/www/browser/{chunk-DE6E23ET.js → chunk-RKK4I2RT.js} +1 -1
  66. package/www/browser/chunk-RMIYLAEM.js +1 -0
  67. package/www/browser/chunk-RZA3IFQV.js +2 -0
  68. package/www/browser/{chunk-K7PESFPY.js → chunk-SD2HFD54.js} +1 -1
  69. package/www/browser/{chunk-BTQIUVTQ.js → chunk-SEJGGBE2.js} +1 -1
  70. package/www/browser/chunk-SSCUT2GF.js +1 -0
  71. package/www/browser/chunk-TCBOC5FF.js +1 -0
  72. package/www/browser/{chunk-AZ6SIMYH.js → chunk-TS5ZQYYY.js} +1 -1
  73. package/www/browser/chunk-TVJHI463.js +1 -0
  74. package/www/browser/{chunk-YNW4HEJO.js → chunk-TXAXE73U.js} +17 -17
  75. package/www/browser/{chunk-4X42HB6N.js → chunk-U2YWR3HF.js} +1 -1
  76. package/www/browser/{chunk-D2ODDESN.js → chunk-U3EUR236.js} +1 -1
  77. package/www/browser/chunk-UKCMUTYL.js +1 -0
  78. package/www/browser/{chunk-DLGJD6YU.js → chunk-UPOORT3S.js} +1 -1
  79. package/www/browser/chunk-VW3S7C2Z.js +1 -0
  80. package/www/browser/chunk-VZYJ3MSW.js +15 -0
  81. package/www/browser/{chunk-AELTP6YN.js → chunk-WCHN62X6.js} +1 -1
  82. package/www/browser/chunk-WWIPELAV.js +1 -0
  83. package/www/browser/{chunk-B3C35ET3.js → chunk-WYNERG74.js} +1 -1
  84. package/www/browser/{chunk-ZTDLWBW5.js → chunk-XJDJL3TQ.js} +1 -1
  85. package/www/browser/{chunk-EEDA5U4V.js → chunk-YV6QPLF5.js} +1 -1
  86. package/www/browser/{chunk-ONXBYGIG.js → chunk-YVRGRFK2.js} +1 -1
  87. package/www/browser/index.html +1 -1
  88. package/www/browser/main-7GYUOEJY.js +38 -0
  89. package/lib/plugins/api-client.plugin.d.ts +0 -3
  90. package/lib/plugins/api-client.plugin.js +0 -55
  91. package/lib/plugins/nginx.binding.store.d.ts +0 -4
  92. package/lib/plugins/nginx.binding.store.js +0 -39
  93. package/lib/plugins/nginx.plugin.d.ts +0 -3
  94. package/lib/plugins/nginx.plugin.js +0 -23
  95. package/www/browser/chunk-2L7NUOMX.js +0 -2
  96. package/www/browser/chunk-2NZJ7CN2.js +0 -20
  97. package/www/browser/chunk-3CM4SKDO.js +0 -15
  98. package/www/browser/chunk-3OHBKMAA.js +0 -1
  99. package/www/browser/chunk-4LBSLURA.js +0 -1
  100. package/www/browser/chunk-5DYX4DUX.js +0 -11
  101. package/www/browser/chunk-6SYVDN5L.js +0 -1
  102. package/www/browser/chunk-AMXRL4GR.js +0 -1
  103. package/www/browser/chunk-AV2ZODEH.js +0 -1
  104. package/www/browser/chunk-CN5J4WNO.js +0 -1
  105. package/www/browser/chunk-FK6Z4HLL.js +0 -1
  106. package/www/browser/chunk-FXCG34QS.js +0 -1
  107. package/www/browser/chunk-H5HGMOE6.js +0 -1
  108. package/www/browser/chunk-HB3HECPD.js +0 -1
  109. package/www/browser/chunk-HUMCWAKJ.js +0 -3
  110. package/www/browser/chunk-IKB3EQCP.js +0 -2
  111. package/www/browser/chunk-OSBDR36P.js +0 -1
  112. package/www/browser/chunk-XLFHB7RS.js +0 -3
  113. package/www/browser/main-N64WJCHX.js +0 -34
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = nodeRuntimeRoutes;
4
+ function toNodeRuntimeConfig(input) {
5
+ return input;
6
+ }
7
+ function toNodeRuntimeRecordDto(record) {
8
+ return {
9
+ id: record.id,
10
+ name: record.name,
11
+ version: record.version,
12
+ platform: String(record.platform),
13
+ arch: String(record.arch),
14
+ rootDir: record.rootDir,
15
+ nodePath: record.nodePath,
16
+ npmPath: record.npmPath,
17
+ npxPath: record.npxPath,
18
+ pnpmPath: record.pnpmPath,
19
+ yarnPath: record.yarnPath,
20
+ npmCliPath: record.npmCliPath,
21
+ npxCliPath: record.npxCliPath,
22
+ source: record.source,
23
+ };
24
+ }
25
+ function toResolvedNodeRuntimeDto(runtime) {
26
+ return {
27
+ type: runtime.type,
28
+ name: runtime.name,
29
+ version: runtime.version,
30
+ packageManager: runtime.packageManager,
31
+ rootDir: runtime.rootDir,
32
+ binDir: runtime.binDir,
33
+ nodePath: runtime.nodePath,
34
+ npmPath: runtime.npmPath,
35
+ npxPath: runtime.npxPath,
36
+ pnpmPath: runtime.pnpmPath,
37
+ yarnPath: runtime.yarnPath,
38
+ npmCliPath: runtime.npmCliPath,
39
+ npxCliPath: runtime.npxCliPath,
40
+ env: runtime.env,
41
+ source: runtime.source,
42
+ };
43
+ }
44
+ function toNodeRuntimeTestResultDto(result) {
45
+ return {
46
+ ok: result.ok,
47
+ nodeVersion: result.nodeVersion,
48
+ npmVersion: result.npmVersion,
49
+ nodePath: result.nodePath,
50
+ npmLaunchCommand: result.npmLaunchCommand,
51
+ errors: result.errors,
52
+ };
53
+ }
54
+ async function nodeRuntimeRoutes(fastify) {
55
+ fastify.get("/", async () => {
56
+ const runtimes = await fastify.core.nodeRuntime.listRuntimes();
57
+ return runtimes.map(toNodeRuntimeRecordDto);
58
+ });
59
+ fastify.post("/resolve", async (req) => {
60
+ const body = req.body;
61
+ const runtime = await fastify.core.nodeRuntime.resolveRuntime(toNodeRuntimeConfig(body?.runtime));
62
+ return toResolvedNodeRuntimeDto(runtime);
63
+ });
64
+ fastify.post("/test", async (req) => {
65
+ const body = req.body;
66
+ const result = await fastify.core.nodeRuntime.testRuntime(toNodeRuntimeConfig(body?.runtime) || { type: "system" });
67
+ return toNodeRuntimeTestResultDto(result);
68
+ });
69
+ }
@@ -37,10 +37,84 @@ exports.default = projectRoutes;
37
37
  const errors_1 = require("@yinuo-ngm/errors");
38
38
  const path = __importStar(require("path"));
39
39
  const editor_1 = require("../common/editor");
40
+ function toProjectAssetSourceSvnDto(source) {
41
+ return {
42
+ kind: source.kind,
43
+ id: source.id,
44
+ label: source.label,
45
+ url: source.url,
46
+ localDir: source.localDir,
47
+ mode: source.mode,
48
+ };
49
+ }
50
+ function toProjectAssetsDto(assets) {
51
+ if (!assets)
52
+ return undefined;
53
+ return {
54
+ iconsSvn: assets.iconsSvn ? toProjectAssetSourceSvnDto(assets.iconsSvn) : undefined,
55
+ cutImageSvn: assets.cutImageSvn ? toProjectAssetSourceSvnDto(assets.cutImageSvn) : undefined,
56
+ };
57
+ }
58
+ function toProjectDto(project) {
59
+ return {
60
+ id: project.id,
61
+ name: project.name,
62
+ description: project.description,
63
+ root: project.root,
64
+ createdAt: project.createdAt,
65
+ updatedAt: project.updatedAt,
66
+ scripts: project.scripts,
67
+ packageManager: project.packageManager,
68
+ runtime: project.runtime,
69
+ nodeVersion: project.nodeVersion,
70
+ framework: project.framework,
71
+ env: project.env,
72
+ isFavorite: project.isFavorite,
73
+ lastOpened: project.lastOpened,
74
+ repoUrl: project.repoUrl,
75
+ repoPageUrl: project.repoPageUrl,
76
+ assets: toProjectAssetsDto(project.assets),
77
+ };
78
+ }
79
+ function toDetectResultDto(detect) {
80
+ if (!detect)
81
+ return undefined;
82
+ return {
83
+ framework: detect.framework,
84
+ hasPackageJson: detect.hasPackageJson,
85
+ scripts: detect.scripts,
86
+ scriptsCount: detect.scriptsCount,
87
+ recommendedScript: detect.recommendedScript,
88
+ lockFile: detect.lockFile,
89
+ hasGit: detect.hasGit,
90
+ hasMakefile: detect.hasMakefile,
91
+ hasDockerCompose: detect.hasDockerCompose,
92
+ };
93
+ }
94
+ function toImportCheckResultDto(result) {
95
+ return {
96
+ ok: result.ok,
97
+ root: result.root,
98
+ code: result.code,
99
+ reason: result.reason,
100
+ detect: toDetectResultDto(result.detect),
101
+ warnings: result.warnings,
102
+ };
103
+ }
104
+ function toCheckRootResultDto(result) {
105
+ return {
106
+ ok: result.ok,
107
+ root: result.root,
108
+ exists: result.exists,
109
+ isDir: result.isDir,
110
+ alreadyRegistered: result.alreadyRegistered,
111
+ message: result.message,
112
+ };
113
+ }
40
114
  async function projectRoutes(fastify) {
41
115
  fastify.get("/list", async () => {
42
116
  const projects = await fastify.core.project.list();
43
- return projects;
117
+ return projects.map(toProjectDto);
44
118
  });
45
119
  fastify.post("/update/:id", async (req, reply) => {
46
120
  const { id } = req.params;
@@ -54,8 +128,9 @@ async function projectRoutes(fastify) {
54
128
  ...(body.name !== undefined ? { name: body.name } : {}),
55
129
  ...(body.env !== undefined ? { env: body.env } : {}),
56
130
  ...(body.scripts !== undefined ? { scripts: body.scripts } : {}),
131
+ ...(body.runtime !== undefined ? { runtime: body.runtime } : {}),
57
132
  });
58
- return updated;
133
+ return toProjectDto(updated);
59
134
  }
60
135
  catch (err) {
61
136
  if (err instanceof Error) {
@@ -67,7 +142,31 @@ async function projectRoutes(fastify) {
67
142
  fastify.get("/getInfo/:id", async (req) => {
68
143
  const { id } = req.params;
69
144
  const project = await fastify.core.project.get(id);
70
- return project;
145
+ return toProjectDto(project);
146
+ });
147
+ async function updateProjectRuntime(projectId, body) {
148
+ const updated = await fastify.core.project.update(projectId, {
149
+ runtime: body.runtime,
150
+ });
151
+ return toProjectDto(updated);
152
+ }
153
+ fastify.patch("/:id/runtime", async (req) => {
154
+ const { id } = req.params;
155
+ const body = req.body;
156
+ return updateProjectRuntime(id, body);
157
+ });
158
+ fastify.post("/:id/runtime", async (req) => {
159
+ const { id } = req.params;
160
+ const body = req.body;
161
+ return updateProjectRuntime(id, body);
162
+ });
163
+ fastify.post("/:id/runtime/test", async (req) => {
164
+ const { id } = req.params;
165
+ const project = await fastify.core.project.get(id);
166
+ const runtimeConfig = project.runtime ?? (project.nodeVersion
167
+ ? { type: "managed", version: project.nodeVersion, packageManager: project.packageManager === "pnpm" || project.packageManager === "yarn" ? project.packageManager : "npm" }
168
+ : { type: "system", packageManager: project.packageManager === "pnpm" || project.packageManager === "yarn" ? project.packageManager : "npm" });
169
+ return await fastify.core.nodeRuntime.testRuntime(runtimeConfig);
71
170
  });
72
171
  fastify.delete("/delete/:id", async (req) => {
73
172
  const { id } = req.params;
@@ -76,7 +175,8 @@ async function projectRoutes(fastify) {
76
175
  });
77
176
  fastify.post("/check", async (req) => {
78
177
  const body = req.body;
79
- return fastify.core.project.checkRoot(body.rootPath);
178
+ const result = await fastify.core.project.checkRoot(body.rootPath);
179
+ return toCheckRootResultDto(result);
80
180
  });
81
181
  fastify.post("/detect", async (req) => {
82
182
  const body = req.body;
@@ -85,13 +185,16 @@ async function projectRoutes(fastify) {
85
185
  return {
86
186
  framework: meta.framework ?? "unknown",
87
187
  hasPackageJson: !!meta.scripts && Object.keys(meta.scripts).length > 0,
88
- scripts: meta.scripts ?? {},
188
+ scripts: Object.keys(meta.scripts ?? {}),
189
+ scriptsCount: Object.keys(meta.scripts ?? {}).length,
89
190
  recommendedScript: meta.scripts?.dev
90
191
  ? "dev"
91
192
  : meta.scripts?.start
92
193
  ? "start"
93
194
  : Object.keys(meta.scripts ?? {})[0],
94
195
  hasGit: meta.hasGit ?? false,
196
+ hasMakefile: meta.hasMakefile ?? false,
197
+ hasDockerCompose: meta.hasDockerCompose ?? false,
95
198
  };
96
199
  });
97
200
  fastify.post("/import", async (req) => {
@@ -109,7 +212,8 @@ async function projectRoutes(fastify) {
109
212
  });
110
213
  fastify.post("/checkImport", async (req) => {
111
214
  const body = req.body;
112
- return fastify.core.project.checkImport(body.root);
215
+ const result = await fastify.core.project.checkImport(body.root);
216
+ return toImportCheckResultDto(result);
113
217
  });
114
218
  fastify.post("/create", async (req) => {
115
219
  const body = req.body;
@@ -127,12 +231,12 @@ async function projectRoutes(fastify) {
127
231
  return { message: "isFavorite must be boolean" };
128
232
  }
129
233
  const updated = await fastify.core.project.setFavorite(id, body.isFavorite);
130
- return updated;
234
+ return toProjectDto(updated);
131
235
  });
132
236
  fastify.post("/favorite/:id/toggle", async (req) => {
133
237
  const { id } = req.params;
134
238
  const updated = await fastify.core.project.toggleFavorite(id);
135
- return updated;
239
+ return toProjectDto(updated);
136
240
  });
137
241
  fastify.post("/lastOpened/:id", async (req) => {
138
242
  const { id } = req.params;
@@ -141,7 +245,7 @@ async function projectRoutes(fastify) {
141
245
  throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.INVALID_TIMESTAMP, "timestamp must be a number");
142
246
  }
143
247
  const updated = await fastify.core.project.setLastOpened(id, body.timestamp);
144
- return updated;
248
+ return toProjectDto(updated);
145
249
  });
146
250
  fastify.post("/rename/:id", async (req) => {
147
251
  const { id } = req.params;
@@ -150,12 +254,12 @@ async function projectRoutes(fastify) {
150
254
  throw new errors_1.CoreError(errors_1.CoreErrorCodes.INVALID_NAME, "name must be a non-empty string");
151
255
  }
152
256
  const updated = await fastify.core.project.rename(id, body.name.trim());
153
- return updated;
257
+ return toProjectDto(updated);
154
258
  });
155
259
  fastify.post("/refreshScripts/:id", async (req) => {
156
260
  const { id } = req.params;
157
261
  const updated = await fastify.core.project.refreshScripts(id);
158
- return updated;
262
+ return toProjectDto(updated);
159
263
  });
160
264
  fastify.post("/edit/:id", async (req) => {
161
265
  const { id } = req.params;
@@ -168,7 +272,7 @@ async function projectRoutes(fastify) {
168
272
  description: body.description?.trim(),
169
273
  repoPageUrl: body.repoPageUrl?.trim(),
170
274
  });
171
- return updated;
275
+ return toProjectDto(updated);
172
276
  });
173
277
  fastify.post("/updateAssets/:id", async (req) => {
174
278
  const { id } = req.params;
@@ -178,7 +282,7 @@ async function projectRoutes(fastify) {
178
282
  throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "参数错误,assets.iconsSvn 是必需的");
179
283
  }
180
284
  const updated = await fastify.core.project.updateAssets(id, assets);
181
- return updated;
285
+ return toProjectDto(updated);
182
286
  });
183
287
  fastify.post("/openInEditor/:id", async (req) => {
184
288
  try {
@@ -0,0 +1,2 @@
1
+ import type { FastifyInstance } from "fastify";
2
+ export default function spriteBrowseRoutes(fastify: FastifyInstance): Promise<void>;
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = spriteBrowseRoutes;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const errors_1 = require("@yinuo-ngm/errors");
10
+ const sprite_quick_utils_1 = require("./sprite-quick.utils");
11
+ const SKIP = new Set([
12
+ ".svn",
13
+ ".git",
14
+ ".hg",
15
+ ".DS_Store",
16
+ "__MACOSX",
17
+ "Thumbs.db",
18
+ ]);
19
+ function safeJoin(root, sub) {
20
+ const resolved = node_path_1.default.resolve(root, sub);
21
+ const rootResolved = node_path_1.default.resolve(root);
22
+ if (!resolved.startsWith(rootResolved)) {
23
+ throw new errors_1.GlobalError(errors_1.GlobalErrorCodes.BAD_REQUEST, "INVALID_PATH");
24
+ }
25
+ return resolved;
26
+ }
27
+ function listDir(root) {
28
+ if (!node_fs_1.default.existsSync(root))
29
+ return [];
30
+ return node_fs_1.default
31
+ .readdirSync(root, { withFileTypes: true })
32
+ .filter(d => !SKIP.has(d.name) && !d.name.startsWith("."))
33
+ .map(d => ({
34
+ name: d.name,
35
+ kind: (d.isDirectory() ? "dir" : "file"),
36
+ ext: d.isDirectory() ? undefined : node_path_1.default.extname(d.name).toLowerCase(),
37
+ })).sort((a, b) => {
38
+ if (a.kind === b.kind) {
39
+ return a.name.localeCompare(b.name, "zh-Hans-CN", { numeric: true });
40
+ }
41
+ return a.kind === "dir" ? -1 : 1;
42
+ });
43
+ }
44
+ function countFiles(dir) {
45
+ if (!node_fs_1.default.existsSync(dir) || !node_fs_1.default.statSync(dir).isDirectory())
46
+ return 0;
47
+ return node_fs_1.default.readdirSync(dir, { withFileTypes: true }).filter(d => d.isFile()).length;
48
+ }
49
+ function toBrowseEntriesDto(root, entries) {
50
+ return { root, entries };
51
+ }
52
+ function toBrowseFilesDto(root, dir, entries) {
53
+ return { root, dir, entries };
54
+ }
55
+ async function spriteBrowseRoutes(fastify) {
56
+ fastify.get("/icons/groups/:projectId", async (req) => {
57
+ const { projectId } = req.params;
58
+ const project = await fastify.core.project.get(projectId);
59
+ const cfg = await fastify.core.sprite.getConfig(projectId);
60
+ const localRoot = String(cfg?.localImageRoot ?? "").trim();
61
+ const root = localRoot || project?.assets?.iconsSvn?.localDir;
62
+ if (!root) {
63
+ return toBrowseEntriesDto("", []);
64
+ }
65
+ const entries = listDir(root).filter(e => e.kind === "dir");
66
+ if (localRoot) {
67
+ const rootFiles = listDir(root).filter((e) => e.kind === "file" && (e.ext === ".png" || e.ext === ".svg"));
68
+ if (rootFiles.length > 0) {
69
+ entries.unshift({ name: "root", kind: "dir", ext: undefined });
70
+ }
71
+ }
72
+ return toBrowseEntriesDto(root, entries);
73
+ });
74
+ fastify.get("/icons/files/:projectId", async (req) => {
75
+ const { projectId } = req.params;
76
+ const group = req.query?.group;
77
+ const project = await fastify.core.project.get(projectId);
78
+ const cfg = await fastify.core.sprite.getConfig(projectId);
79
+ const localRoot = String(cfg?.localImageRoot ?? "").trim();
80
+ const root = localRoot || project?.assets?.iconsSvn?.localDir;
81
+ if (!root) {
82
+ return toBrowseEntriesDto("", []);
83
+ }
84
+ const isRootGroup = !!localRoot && (group === "root");
85
+ const groupDir = isRootGroup ? root : safeJoin(root, group || "");
86
+ const entries = listDir(groupDir)
87
+ .filter(e => e.kind === "file")
88
+ .map(e => ({
89
+ ...e,
90
+ url: localRoot
91
+ ? `/api/static/local/${projectId}/${isRootGroup ? e.name : `${group}/${e.name}`}`
92
+ : `/api/static/svn/${projectId}/icons/${group}/${e.name}`,
93
+ }));
94
+ return toBrowseEntriesDto(groupDir, entries);
95
+ });
96
+ fastify.get("/images/list/:projectId", async (req) => {
97
+ const { projectId } = req.params;
98
+ const quickProjectId = await (0, sprite_quick_utils_1.resolveEnabledRemoteProjectId)(fastify, projectId);
99
+ if (quickProjectId) {
100
+ const cfg = await fastify.core.sprite.getConfig(projectId);
101
+ const baseUrl = (0, sprite_quick_utils_1.getBaseUrl)(cfg);
102
+ const dir = String(req.query?.dir ?? "").trim();
103
+ const cache = await (0, sprite_quick_utils_1.fetchAndCacheRemoteMiscImages)(fastify, baseUrl, quickProjectId);
104
+ return (0, sprite_quick_utils_1.buildBrowseFromCache)(quickProjectId, cache, dir || undefined);
105
+ }
106
+ const project = await fastify.core.project.get(projectId);
107
+ const root = project?.assets?.cutImageSvn?.localDir;
108
+ if (!root) {
109
+ return toBrowseEntriesDto("", []);
110
+ }
111
+ const dir = String(req.query?.dir ?? "").trim();
112
+ if (dir.split(/[\\/]/g).some(seg => seg === "..")) {
113
+ return toBrowseFilesDto(root, "", []);
114
+ }
115
+ const absDir = dir ? safeJoin(root, dir) : root;
116
+ if (!node_fs_1.default.existsSync(absDir))
117
+ return toBrowseFilesDto(root, dir, []);
118
+ const entries = listDir(absDir).map(e => {
119
+ if (e.kind === "file") {
120
+ const rel = dir ? `${dir}/${e.name}` : e.name;
121
+ return {
122
+ ...e,
123
+ url: `/api/static/svn/${projectId}/images/${rel}`,
124
+ };
125
+ }
126
+ else if (e.kind === "dir") {
127
+ const rel = dir ? `${dir}/${e.name}` : e.name;
128
+ return {
129
+ ...e,
130
+ fileCount: countFiles(safeJoin(root, rel)),
131
+ };
132
+ }
133
+ return e;
134
+ });
135
+ return toBrowseFilesDto(root, dir, entries);
136
+ });
137
+ }
@@ -0,0 +1,19 @@
1
+ import type { FastifyInstance } from "fastify";
2
+ import type { QuickSpriteProjectDto, QuickGenerateResponseDto, QuickImagesResponseDto, SpriteSnapshotDto, SpriteGroupItemDto, BrowseFilesDto } from "@yinuo-ngm/protocol";
3
+ import type { SpriteConfig } from "@yinuo-ngm/sprite";
4
+ export declare function getBaseUrl(cfg?: {
5
+ quickSpriteBaseUrl?: string;
6
+ } | null): string;
7
+ export declare const QUICK_SPRITE_PROXY_PREFIX = "/api/sprite/proxy";
8
+ export declare function buildQuickPreviewUrl(localProjectId: string, group: string): string;
9
+ export declare function quickFetch<T>(fastify: FastifyInstance, baseUrl: string, path: string, init?: RequestInit): Promise<T>;
10
+ export declare function resolveEnabledRemoteProjectId(fastify: FastifyInstance, projectId: string): Promise<string | null>;
11
+ export declare function fetchRemoteProject(fastify: FastifyInstance, baseUrl: string, quickProjectId: string): Promise<QuickSpriteProjectDto | null>;
12
+ export declare function mapToGroup(result: QuickGenerateResponseDto, localProjectId: string, prefix: string, spriteUrlTemplate: string): SpriteGroupItemDto;
13
+ export declare function mapQuickGroupsToSnapshot(projectId: string, results: QuickGenerateResponseDto[], remoteProj: QuickSpriteProjectDto | null, localCfg: SpriteConfig | null): SpriteSnapshotDto;
14
+ export declare function copyRawResponseHeaders(response: Response, reply: any): void;
15
+ export declare function hasQuickSprite(fastify: FastifyInstance, projectId: string): Promise<boolean>;
16
+ export declare function fetchAndCacheRemoteMiscImages(fastify: FastifyInstance, baseUrl: string, quickProjectId: string, forceRefresh?: boolean): Promise<QuickImagesResponseDto>;
17
+ export declare function buildBrowseFromCache(quickProjectId: string, cache: QuickImagesResponseDto, dir?: string): BrowseFilesDto;
18
+ export declare const MISC_PROXY_PREFIX = "/api/sprite/misc-proxy";
19
+ export declare function buildRemoteMiscUrl(baseUrl: string, quickProjectId: string, filename: string): string;