@bililive-tools/manager 1.6.1 → 1.9.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.
@@ -70,13 +70,16 @@ export function createRecordExtraDataController(savePath) {
70
70
  initializeFile().catch(console.error);
71
71
  scheduleWrite();
72
72
  };
73
- const setMeta = (meta) => {
73
+ const setMeta = async (meta) => {
74
74
  if (hasCompleted)
75
75
  return;
76
76
  data.meta = {
77
77
  ...data.meta,
78
78
  ...meta,
79
79
  };
80
+ // 确保文件已初始化,然后立即更新文件中的metadata
81
+ await initializeFile().catch(console.error);
82
+ await updateMetadataInFile(savePath, data.meta).catch(console.error);
80
83
  };
81
84
  const flush = async () => {
82
85
  if (hasCompleted)
@@ -89,7 +92,7 @@ export function createRecordExtraDataController(savePath) {
89
92
  await writeToFile();
90
93
  }
91
94
  // 完成XML文件(添加结束标签等)
92
- await finalizeXmlFile(savePath, data.meta);
95
+ await finalizeXmlFile(savePath);
93
96
  // 清理内存
94
97
  data.pendingMessages = [];
95
98
  };
@@ -206,9 +209,9 @@ async function appendToXmlFile(filePath, content) {
206
209
  }
207
210
  }
208
211
  /**
209
- * 完成XML文件写入
212
+ * 更新XML文件中的metadata
210
213
  */
211
- async function finalizeXmlFile(filePath, metadata) {
214
+ async function updateMetadataInFile(filePath, metadata) {
212
215
  try {
213
216
  const builder = new XMLBuilder({
214
217
  ignoreAttributes: false,
@@ -228,8 +231,25 @@ async function finalizeXmlFile(filePath, metadata) {
228
231
  });
229
232
  // 读取文件内容
230
233
  const content = await fs.promises.readFile(filePath, "utf-8");
231
- // 替换占位符为实际的metadata,并添加结束标签
232
- const finalContent = content.replace("<!--METADATA_PLACEHOLDER-->", metadataXml) + "</i>";
234
+ // 替换占位符为实际的metadata
235
+ const updatedContent = content.replace("<!--METADATA_PLACEHOLDER-->", metadataXml);
236
+ // 写回文件
237
+ await fs.promises.writeFile(filePath, updatedContent);
238
+ }
239
+ catch (error) {
240
+ console.error(`更新XML文件metadata失败: ${filePath}`, error);
241
+ throw error;
242
+ }
243
+ }
244
+ /**
245
+ * 完成XML文件写入
246
+ */
247
+ async function finalizeXmlFile(filePath) {
248
+ try {
249
+ // 读取文件内容
250
+ const content = await fs.promises.readFile(filePath, "utf-8");
251
+ // 添加结束标签
252
+ const finalContent = content + "</i>";
233
253
  // 写回文件
234
254
  await fs.promises.writeFile(filePath, finalContent);
235
255
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bililive-tools/manager",
3
- "version": "1.6.1",
3
+ "version": "1.9.0",
4
4
  "description": "Batch scheduling recorders",
5
5
  "main": "./lib/index.js",
6
6
  "type": "module",