@lark-apaas/devtool-kits 0.1.0-alpha.7 → 0.1.0-alpha.9

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/dist/index.js CHANGED
@@ -29203,7 +29203,15 @@ function collectLogsHandler(logDir, fileName) {
29203
29203
  return async (req, res) => {
29204
29204
  try {
29205
29205
  const logContent = req.body;
29206
- const logLine = JSON.stringify(logContent) + "\n";
29206
+ if (!logContent.message) {
29207
+ return res.status(400).json({
29208
+ message: "message is required"
29209
+ });
29210
+ }
29211
+ const logLine = JSON.stringify({
29212
+ ...logContent,
29213
+ server_time: (/* @__PURE__ */ new Date()).toISOString()
29214
+ }) + "\n";
29207
29215
  await fs8.promises.appendFile(filePath, logLine);
29208
29216
  res.json({
29209
29217
  success: true
@@ -29214,6 +29222,34 @@ function collectLogsHandler(logDir, fileName) {
29214
29222
  };
29215
29223
  }
29216
29224
  __name(collectLogsHandler, "collectLogsHandler");
29225
+ function collectLogsBatchHandler(logDir, fileName) {
29226
+ const filePath = join4(logDir, fileName);
29227
+ ensureDir(logDir);
29228
+ return async (req, res) => {
29229
+ try {
29230
+ const logContents = req.body;
29231
+ if (!Array.isArray(logContents)) {
29232
+ return res.status(400).json({
29233
+ message: "logContents must be an array"
29234
+ });
29235
+ }
29236
+ const logLines = [];
29237
+ for (const logContent of logContents) {
29238
+ logLines.push(JSON.stringify({
29239
+ ...logContent,
29240
+ server_time: (/* @__PURE__ */ new Date()).toISOString()
29241
+ }) + "\n");
29242
+ }
29243
+ await fs8.promises.appendFile(filePath, logLines.join(""));
29244
+ res.json({
29245
+ success: true
29246
+ });
29247
+ } catch (error) {
29248
+ handleError2(res, error, "Failed to collect logs");
29249
+ }
29250
+ };
29251
+ }
29252
+ __name(collectLogsBatchHandler, "collectLogsBatchHandler");
29217
29253
  function handleError2(res, error, message = "Failed to collect logs") {
29218
29254
  res.status(500).json({
29219
29255
  message,
@@ -29227,6 +29263,7 @@ function createDevLogRouter2(options = {}) {
29227
29263
  const logDir = resolveLogDir2(options.logDir);
29228
29264
  const router = import_express3.default.Router();
29229
29265
  router.post("/collect", import_express3.default.json(), collectLogsHandler(logDir, options.fileName || "client.log"));
29266
+ router.post("/collect-batch", import_express3.default.json(), collectLogsBatchHandler(logDir, options.fileName || "client.log"));
29230
29267
  return router;
29231
29268
  }
29232
29269
  __name(createDevLogRouter2, "createDevLogRouter");