tt-help-cli-ycl 1.3.94 → 1.3.95

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tt-help-cli-ycl",
3
- "version": "1.3.94",
3
+ "version": "1.3.95",
4
4
  "description": "TikTok user & video data scraper - extract ttSeller, verified, locationCreated from HTML source",
5
5
  "type": "module",
6
6
  "bin": {
@@ -208,10 +208,11 @@ export { killEdgeProcesses };
208
208
 
209
209
  export async function ensureBrowserReady(options = {}) {
210
210
  const port = options.port || DEFAULT_CDP_PORT;
211
- const baseDir = options.userDataDir || DEFAULT_USER_DATA_DIR;
212
- // 非默认端口时,userDataDir 加上 _p{port} 后缀
213
211
  const userDataDir =
214
- port !== DEFAULT_CDP_PORT ? `${baseDir}_p${port}` : baseDir;
212
+ options.userDataDir ||
213
+ (port !== DEFAULT_CDP_PORT
214
+ ? `${DEFAULT_USER_DATA_DIR}_p${port}`
215
+ : DEFAULT_USER_DATA_DIR);
215
216
  const proxyServer = options.proxyServer || null;
216
217
  const isCustom = port !== DEFAULT_CDP_PORT || !!options.userDataDir;
217
218
 
@@ -715,10 +715,9 @@ export function createStore(filePath, options = {}) {
715
715
 
716
716
  console.error(`[data-store] 正在备份数据库: ${backupName}`);
717
717
 
718
- // 使用 better-sqlite3 backup API(原子性备份,安全可靠)
719
- const backupDb = new Database(backupPath);
720
- getDb().backup("main", backupDb, "main");
721
- backupDb.close();
718
+ // WAL checkpoint 确保所有数据落盘,再同步复制文件
719
+ getDb().exec("PRAGMA wal_checkpoint(TRUNCATE)");
720
+ fs.copyFileSync(getDbPath(), backupPath);
722
721
 
723
722
  // 验证备份文件大小
724
723
  const stat = fs.statSync(backupPath);
@@ -2551,12 +2550,12 @@ export function createStore(filePath, options = {}) {
2551
2550
  sqlParams.push(...targetCountries);
2552
2551
  }
2553
2552
 
2554
- // 优先级:tt_seller=1 的商家重处理任务优先 > tag 来源 > 其余
2553
+ // 优先级:tt_seller=1 的商家重处理任务优先 > tag 来源 > 其余(最新任务优先)
2555
2554
  sql += ` ORDER BY
2556
2555
  CASE WHEN tt_seller = 1 THEN 0 ELSE 1 END,
2557
2556
  CASE WHEN sources LIKE '%tag%' THEN 0 ELSE 1 END,
2558
- created_at ASC,
2559
- unique_id ASC
2557
+ created_at DESC,
2558
+ unique_id DESC
2560
2559
  LIMIT ?`;
2561
2560
  sqlParams.push(l);
2562
2561
 
@@ -1269,14 +1269,23 @@ export function startWatchServer(
1269
1269
  _resolve({ server, port });
1270
1270
  });
1271
1271
 
1272
+ // 标记是否正在关闭,避免重复处理
1273
+ let isShuttingDown = false;
1274
+
1272
1275
  async function gracefulShutdown(signal) {
1276
+ if (isShuttingDown) {
1277
+ console.error("[server] 正在关闭中,请稍候...");
1278
+ return;
1279
+ }
1280
+ isShuttingDown = true;
1281
+
1273
1282
  console.error(`\n[server] 收到 ${signal},正在保存数据...`);
1274
1283
  server.close(() => {
1275
1284
  console.error("[server] HTTP 服务已关闭");
1276
1285
  });
1277
1286
  await store.flushSave();
1278
1287
  console.error("[server] 数据已保存");
1279
- // 备份数据库
1288
+ // 备份数据库(同步操作,不会被 SIGINT 中断)
1280
1289
  store.stopBackup();
1281
1290
  console.error("[server] 退出");
1282
1291
  process.exit(0);