douyin-downloader 0.1.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.
- package/README.md +114 -0
- package/dist/bin/dydl.d.ts +2 -0
- package/dist/bin/dydl.js +17 -0
- package/dist/bin/dydl.js.map +1 -0
- package/dist/src/cli/commands/check.d.ts +10 -0
- package/dist/src/cli/commands/check.js +102 -0
- package/dist/src/cli/commands/check.js.map +1 -0
- package/dist/src/cli/commands/info.d.ts +10 -0
- package/dist/src/cli/commands/info.js +106 -0
- package/dist/src/cli/commands/info.js.map +1 -0
- package/dist/src/cli/commands/list.d.ts +10 -0
- package/dist/src/cli/commands/list.js +85 -0
- package/dist/src/cli/commands/list.js.map +1 -0
- package/dist/src/cli/commands/login.d.ts +10 -0
- package/dist/src/cli/commands/login.js +158 -0
- package/dist/src/cli/commands/login.js.map +1 -0
- package/dist/src/cli/commands/open.d.ts +10 -0
- package/dist/src/cli/commands/open.js +141 -0
- package/dist/src/cli/commands/open.js.map +1 -0
- package/dist/src/cli/commands/video.d.ts +10 -0
- package/dist/src/cli/commands/video.js +209 -0
- package/dist/src/cli/commands/video.js.map +1 -0
- package/dist/src/cli/index.d.ts +15 -0
- package/dist/src/cli/index.js +134 -0
- package/dist/src/cli/index.js.map +1 -0
- package/dist/src/cli/progress-display.d.ts +80 -0
- package/dist/src/cli/progress-display.js +225 -0
- package/dist/src/cli/progress-display.js.map +1 -0
- package/dist/src/cli/utils.d.ts +31 -0
- package/dist/src/cli/utils.js +171 -0
- package/dist/src/cli/utils.js.map +1 -0
- package/dist/src/douyin/auth/cookie-path.d.ts +22 -0
- package/dist/src/douyin/auth/cookie-path.js +72 -0
- package/dist/src/douyin/auth/cookie-path.js.map +1 -0
- package/dist/src/douyin/auth/cookie-storage.d.ts +19 -0
- package/dist/src/douyin/auth/cookie-storage.js +65 -0
- package/dist/src/douyin/auth/cookie-storage.js.map +1 -0
- package/dist/src/douyin/auth/errors.d.ts +28 -0
- package/dist/src/douyin/auth/errors.js +49 -0
- package/dist/src/douyin/auth/errors.js.map +1 -0
- package/dist/src/douyin/auth/getDefaultCookiePath.d.ts +24 -0
- package/dist/src/douyin/auth/getDefaultCookiePath.js +90 -0
- package/dist/src/douyin/auth/getDefaultCookiePath.js.map +1 -0
- package/dist/src/douyin/auth/index.d.ts +16 -0
- package/dist/src/douyin/auth/index.js +68 -0
- package/dist/src/douyin/auth/index.js.map +1 -0
- package/dist/src/douyin/auth/isValidCookie.d.ts +18 -0
- package/dist/src/douyin/auth/isValidCookie.js +60 -0
- package/dist/src/douyin/auth/isValidCookie.js.map +1 -0
- package/dist/src/douyin/auth/loadAndValidateCookie.d.ts +17 -0
- package/dist/src/douyin/auth/loadAndValidateCookie.js +45 -0
- package/dist/src/douyin/auth/loadAndValidateCookie.js.map +1 -0
- package/dist/src/douyin/auth/loadCookie.d.ts +17 -0
- package/dist/src/douyin/auth/loadCookie.js +79 -0
- package/dist/src/douyin/auth/loadCookie.js.map +1 -0
- package/dist/src/douyin/auth/login.d.ts +33 -0
- package/dist/src/douyin/auth/login.js +157 -0
- package/dist/src/douyin/auth/login.js.map +1 -0
- package/dist/src/douyin/auth/saveCookie.d.ts +17 -0
- package/dist/src/douyin/auth/saveCookie.js +89 -0
- package/dist/src/douyin/auth/saveCookie.js.map +1 -0
- package/dist/src/douyin/auth/validate.d.ts +11 -0
- package/dist/src/douyin/auth/validate.js +104 -0
- package/dist/src/douyin/auth/validate.js.map +1 -0
- package/dist/src/douyin/browser/manager.d.ts +54 -0
- package/dist/src/douyin/browser/manager.js +344 -0
- package/dist/src/douyin/browser/manager.js.map +1 -0
- package/dist/src/douyin/download/download-manager.d.ts +25 -0
- package/dist/src/douyin/download/download-manager.js +107 -0
- package/dist/src/douyin/download/download-manager.js.map +1 -0
- package/dist/src/douyin/download/error-handler.d.ts +49 -0
- package/dist/src/douyin/download/error-handler.js +160 -0
- package/dist/src/douyin/download/error-handler.js.map +1 -0
- package/dist/src/douyin/download/index.d.ts +39 -0
- package/dist/src/douyin/download/index.js +156 -0
- package/dist/src/douyin/download/index.js.map +1 -0
- package/dist/src/douyin/download/path-formatter.d.ts +42 -0
- package/dist/src/douyin/download/path-formatter.js +107 -0
- package/dist/src/douyin/download/path-formatter.js.map +1 -0
- package/dist/src/douyin/download/video-downloader.d.ts +35 -0
- package/dist/src/douyin/download/video-downloader.js +223 -0
- package/dist/src/douyin/download/video-downloader.js.map +1 -0
- package/dist/src/douyin/index.d.ts +19 -0
- package/dist/src/douyin/index.js +52 -0
- package/dist/src/douyin/index.js.map +1 -0
- package/dist/src/douyin/info/batch-processor.d.ts +15 -0
- package/dist/src/douyin/info/batch-processor.js +65 -0
- package/dist/src/douyin/info/batch-processor.js.map +1 -0
- package/dist/src/douyin/info/browser-manager.d.ts +56 -0
- package/dist/src/douyin/info/browser-manager.js +225 -0
- package/dist/src/douyin/info/browser-manager.js.map +1 -0
- package/dist/src/douyin/info/error-handler.d.ts +36 -0
- package/dist/src/douyin/info/error-handler.js +172 -0
- package/dist/src/douyin/info/error-handler.js.map +1 -0
- package/dist/src/douyin/info/fetch-video-detail.d.ts +14 -0
- package/dist/src/douyin/info/fetch-video-detail.js +247 -0
- package/dist/src/douyin/info/fetch-video-detail.js.map +1 -0
- package/dist/src/douyin/info/index.d.ts +29 -0
- package/dist/src/douyin/info/index.js +85 -0
- package/dist/src/douyin/info/index.js.map +1 -0
- package/dist/src/douyin/info/text-processor.d.ts +15 -0
- package/dist/src/douyin/info/text-processor.js +47 -0
- package/dist/src/douyin/info/text-processor.js.map +1 -0
- package/dist/src/douyin/info/user.d.ts +26 -0
- package/dist/src/douyin/info/user.js +237 -0
- package/dist/src/douyin/info/user.js.map +1 -0
- package/dist/src/douyin/parser/containsDouyinLink.d.ts +18 -0
- package/dist/src/douyin/parser/containsDouyinLink.js +27 -0
- package/dist/src/douyin/parser/containsDouyinLink.js.map +1 -0
- package/dist/src/douyin/parser/extract-links.d.ts +23 -0
- package/dist/src/douyin/parser/extract-links.js +79 -0
- package/dist/src/douyin/parser/extract-links.js.map +1 -0
- package/dist/src/douyin/parser/extractDouyinLinks.d.ts +18 -0
- package/dist/src/douyin/parser/extractDouyinLinks.js +58 -0
- package/dist/src/douyin/parser/extractDouyinLinks.js.map +1 -0
- package/dist/src/douyin/parser/index.d.ts +35 -0
- package/dist/src/douyin/parser/index.js +70 -0
- package/dist/src/douyin/parser/index.js.map +1 -0
- package/dist/src/douyin/parser/link-patterns.d.ts +34 -0
- package/dist/src/douyin/parser/link-patterns.js +121 -0
- package/dist/src/douyin/parser/link-patterns.js.map +1 -0
- package/dist/src/douyin/parser/parse-batch.d.ts +26 -0
- package/dist/src/douyin/parser/parse-batch.js +67 -0
- package/dist/src/douyin/parser/parse-batch.js.map +1 -0
- package/dist/src/douyin/parser/parseDouyinLinks.d.ts +30 -0
- package/dist/src/douyin/parser/parseDouyinLinks.js +164 -0
- package/dist/src/douyin/parser/parseDouyinLinks.js.map +1 -0
- package/dist/src/douyin/parser/resolve-links.d.ts +25 -0
- package/dist/src/douyin/parser/resolve-links.js +131 -0
- package/dist/src/douyin/parser/resolve-links.js.map +1 -0
- package/dist/src/index.d.ts +16 -0
- package/dist/src/index.js +72 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/types.d.ts +217 -0
- package/dist/src/types.js +6 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils/browser.d.ts +73 -0
- package/dist/src/utils/browser.js +96 -0
- package/dist/src/utils/browser.js.map +1 -0
- package/dist/src/utils/error.d.ts +160 -0
- package/dist/src/utils/error.js +334 -0
- package/dist/src/utils/error.js.map +1 -0
- package/dist/src/utils/fetch.d.ts +41 -0
- package/dist/src/utils/fetch.js +155 -0
- package/dist/src/utils/fetch.js.map +1 -0
- package/dist/src/utils/file.d.ts +46 -0
- package/dist/src/utils/file.js +189 -0
- package/dist/src/utils/file.js.map +1 -0
- package/dist/src/utils/index.d.ts +11 -0
- package/dist/src/utils/index.js +29 -0
- package/dist/src/utils/index.js.map +1 -0
- package/dist/src/utils/logger.d.ts +161 -0
- package/dist/src/utils/logger.js +286 -0
- package/dist/src/utils/logger.js.map +1 -0
- package/dist/src/utils/performance.d.ts +98 -0
- package/dist/src/utils/performance.js +292 -0
- package/dist/src/utils/performance.js.map +1 -0
- package/dist/src/utils/retry.d.ts +56 -0
- package/dist/src/utils/retry.js +127 -0
- package/dist/src/utils/retry.js.map +1 -0
- package/package.json +61 -0
@@ -0,0 +1,72 @@
|
|
1
|
+
"use strict";
|
2
|
+
/**
|
3
|
+
* 抖音影片解析與下載套件
|
4
|
+
*
|
5
|
+
* @packageDocumentation
|
6
|
+
*
|
7
|
+
* @remarks
|
8
|
+
* 免責聲明:本套件僅供學習和個人使用。請遵守抖音平台的服務條款和相關法規。
|
9
|
+
* 用戶須對使用本套件的行為負責,開發者不對任何濫用行為或因此產生的後果負責。
|
10
|
+
* 請尊重原創作者的著作權,不要未經授權分發下載的內容。
|
11
|
+
*/
|
12
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
13
|
+
if (k2 === undefined) k2 = k;
|
14
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
15
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
16
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
17
|
+
}
|
18
|
+
Object.defineProperty(o, k2, desc);
|
19
|
+
}) : (function(o, m, k, k2) {
|
20
|
+
if (k2 === undefined) k2 = k;
|
21
|
+
o[k2] = m[k];
|
22
|
+
}));
|
23
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
24
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
25
|
+
}) : function(o, v) {
|
26
|
+
o["default"] = v;
|
27
|
+
});
|
28
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
29
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
30
|
+
};
|
31
|
+
var __importStar = (this && this.__importStar) || (function () {
|
32
|
+
var ownKeys = function(o) {
|
33
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
34
|
+
var ar = [];
|
35
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
36
|
+
return ar;
|
37
|
+
};
|
38
|
+
return ownKeys(o);
|
39
|
+
};
|
40
|
+
return function (mod) {
|
41
|
+
if (mod && mod.__esModule) return mod;
|
42
|
+
var result = {};
|
43
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
44
|
+
__setModuleDefault(result, mod);
|
45
|
+
return result;
|
46
|
+
};
|
47
|
+
})();
|
48
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
49
|
+
exports.cleanupBrowser = exports.browserManager = exports.time = exports.timeAsync = exports.PerformanceMonitor = exports.LogLevel = exports.Logger = exports.douyin = exports.ErrorCode = exports.AppError = void 0;
|
50
|
+
// 導出類型定義
|
51
|
+
__exportStar(require("./types"), exports);
|
52
|
+
// 導出錯誤處理
|
53
|
+
var error_1 = require("./utils/error"); // Export the actual error class and enum
|
54
|
+
Object.defineProperty(exports, "AppError", { enumerable: true, get: function () { return error_1.AppError; } });
|
55
|
+
Object.defineProperty(exports, "ErrorCode", { enumerable: true, get: function () { return error_1.ErrorCode; } });
|
56
|
+
exports.douyin = __importStar(require("./douyin"));
|
57
|
+
// ======================== 通用工具 ========================
|
58
|
+
// 導出日誌和性能工具
|
59
|
+
var logger_1 = require("./utils/logger"); // Corrected path
|
60
|
+
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
|
61
|
+
Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return logger_1.LogLevel; } });
|
62
|
+
var performance_1 = require("./utils/performance"); // Corrected path
|
63
|
+
Object.defineProperty(exports, "PerformanceMonitor", { enumerable: true, get: function () { return performance_1.PerformanceMonitor; } });
|
64
|
+
Object.defineProperty(exports, "timeAsync", { enumerable: true, get: function () { return performance_1.timeAsync; } });
|
65
|
+
Object.defineProperty(exports, "time", { enumerable: true, get: function () { return performance_1.time; } });
|
66
|
+
// 導出瀏覽器管理工具
|
67
|
+
var browser_1 = require("./utils/browser"); // Corrected path
|
68
|
+
Object.defineProperty(exports, "browserManager", { enumerable: true, get: function () { return browser_1.browserManager; } });
|
69
|
+
Object.defineProperty(exports, "cleanupBrowser", { enumerable: true, get: function () { return browser_1.cleanupBrowser; } });
|
70
|
+
// 導出其他通用工具 (如果有的話)
|
71
|
+
// export * from './utils/index'; // Example if utils/index.ts exports common utilities
|
72
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,SAAS;AACT,0CAAwB;AAExB,SAAS;AACT,uCAAoD,CAAC,yCAAyC;AAArF,iGAAA,QAAQ,OAAA;AAAE,kGAAA,SAAS,OAAA;AAE5B,mDAAmC;AAEnC,yDAAyD;AAEzD,YAAY;AACZ,yCAGwB,CAAC,iBAAiB;AAFxC,gGAAA,MAAM,OAAA;AACN,kGAAA,QAAQ,OAAA;AAGV,mDAI6B,CAAC,iBAAiB;AAH7C,iHAAA,kBAAkB,OAAA;AAClB,wGAAA,SAAS,OAAA;AACT,mGAAA,IAAI,OAAA;AAGN,YAAY;AACZ,2CAAiE,CAAC,iBAAiB;AAA1E,yGAAA,cAAc,OAAA;AAAE,yGAAA,cAAc,OAAA;AAEvC,mBAAmB;AACnB,uFAAuF"}
|
@@ -0,0 +1,217 @@
|
|
1
|
+
/**
|
2
|
+
* 基礎選項接口,包含通用配置如並行數、重試次數、超時和進度回調
|
3
|
+
*/
|
4
|
+
export interface BaseOptions {
|
5
|
+
/** 並行處理請求的數量 */
|
6
|
+
concurrency?: number;
|
7
|
+
/** 網路請求失敗時的重試次數 */
|
8
|
+
retries?: number;
|
9
|
+
/** 請求超時時間(毫秒) */
|
10
|
+
timeout?: number;
|
11
|
+
/**
|
12
|
+
* 進度回調函數
|
13
|
+
* @param current 當前處理的項目數
|
14
|
+
* @param total 總項目數
|
15
|
+
* @param overallProgress 可選的總體進度百分比 (0-100)
|
16
|
+
*/
|
17
|
+
onProgress?: (current: number, total: number, overallProgress?: number) => void;
|
18
|
+
}
|
19
|
+
/**
|
20
|
+
* 登入選項
|
21
|
+
*/
|
22
|
+
export interface LoginOptions extends BaseOptions {
|
23
|
+
/** Cookie 檔案的儲存路徑 */
|
24
|
+
cookiePath?: string;
|
25
|
+
/** 是否在登入成功或失敗後自動清理瀏覽器資源 */
|
26
|
+
autoCleanup?: boolean;
|
27
|
+
}
|
28
|
+
/**
|
29
|
+
* 連結解析選項
|
30
|
+
*/
|
31
|
+
export interface ParseOptions extends BaseOptions {
|
32
|
+
/** 自訂請求時使用的 User-Agent */
|
33
|
+
userAgent?: string;
|
34
|
+
}
|
35
|
+
/**
|
36
|
+
* 影片資訊獲取選項
|
37
|
+
*/
|
38
|
+
export interface FetchVideoOptions extends BaseOptions {
|
39
|
+
}
|
40
|
+
/**
|
41
|
+
* 用戶影片獲取選項
|
42
|
+
*/
|
43
|
+
export interface UserVideosOptions extends BaseOptions {
|
44
|
+
/** 限制獲取的影片數量,0 表示獲取全部 */
|
45
|
+
limit?: number;
|
46
|
+
/** 用於分頁的游標 (平台特定) */
|
47
|
+
cursor?: string | number;
|
48
|
+
/**
|
49
|
+
* 進度回調函數 (特定於用戶影片獲取)
|
50
|
+
* @param fetchedCount 已獲取的影片數量
|
51
|
+
* @param totalEstimated 預估的總影片數量 (如果可用)
|
52
|
+
*/
|
53
|
+
onProgress?: (fetchedCount: number, totalEstimated?: number) => void;
|
54
|
+
}
|
55
|
+
/**
|
56
|
+
* 影片下載選項
|
57
|
+
*/
|
58
|
+
export interface DownloadOptions extends BaseOptions {
|
59
|
+
/** 是否覆蓋已存在的檔案,預設 false */
|
60
|
+
overwrite?: boolean;
|
61
|
+
/** 是否按用戶名創建子文件夾,預設 true */
|
62
|
+
useSubfolders?: boolean;
|
63
|
+
/** 檔名模板,預設 "{date}-{title}" */
|
64
|
+
filenameTemplate?: string;
|
65
|
+
/**
|
66
|
+
* 單個文件下載進度回調函數
|
67
|
+
* @param progress 當前文件的下載進度百分比 (0-100)
|
68
|
+
*/
|
69
|
+
onFileProgress?: (progress: number) => void;
|
70
|
+
/** 自定義請求頭 */
|
71
|
+
headers?: Record<string, string>;
|
72
|
+
}
|
73
|
+
/**
|
74
|
+
* 登入結果
|
75
|
+
*/
|
76
|
+
export interface LoginResult {
|
77
|
+
/** 獲取到的 Cookie 字串 */
|
78
|
+
cookie: string;
|
79
|
+
/** 用於清理登入過程中創建的資源(如瀏覽器實例)的函數 */
|
80
|
+
cleanup: () => Promise<void>;
|
81
|
+
}
|
82
|
+
/**
|
83
|
+
* 連結解析結果
|
84
|
+
*/
|
85
|
+
export interface ParseResult {
|
86
|
+
/** 在原始文本中找到的URL */
|
87
|
+
originalUrl: string;
|
88
|
+
/** 標準化後的影片或用戶主頁 URL */
|
89
|
+
standardUrl: string;
|
90
|
+
/** 提取到的 ID (影片 ID 或用戶 ID) */
|
91
|
+
id: string;
|
92
|
+
/** 連結類型 */
|
93
|
+
type: 'video' | 'user' | 'unknown';
|
94
|
+
}
|
95
|
+
/**
|
96
|
+
* 通用影片資訊結構
|
97
|
+
*/
|
98
|
+
export interface VideoInfo {
|
99
|
+
/** 平台特定的影片 ID */
|
100
|
+
id: string;
|
101
|
+
/** 影片標題 */
|
102
|
+
title: string;
|
103
|
+
/** 影片描述 */
|
104
|
+
description?: string;
|
105
|
+
/** 用於播放或下載的影片 URL */
|
106
|
+
videoPlayUrl: string;
|
107
|
+
cdnPlayUrls: string[];
|
108
|
+
/** 影片封面圖片 URL */
|
109
|
+
coverUrl?: string;
|
110
|
+
/** 作者暱稱 */
|
111
|
+
userName: string;
|
112
|
+
/** 作者主頁 URL */
|
113
|
+
userUrl: string;
|
114
|
+
/** 平台特定的作者 ID */
|
115
|
+
userId?: string;
|
116
|
+
/** 影片發布日期 (建議 ISO 8601 格式) */
|
117
|
+
releaseDate?: string;
|
118
|
+
/** 影片時長 (秒) */
|
119
|
+
duration?: number;
|
120
|
+
/** 影片統計數據 */
|
121
|
+
stats?: {
|
122
|
+
playCount?: number;
|
123
|
+
likeCount?: number;
|
124
|
+
commentCount?: number;
|
125
|
+
shareCount?: number;
|
126
|
+
};
|
127
|
+
}
|
128
|
+
/**
|
129
|
+
* 通用用戶影片列表項結構
|
130
|
+
*/
|
131
|
+
export interface UserVideoItem {
|
132
|
+
/** 平台特定的影片 ID */
|
133
|
+
vid: string;
|
134
|
+
/** 影片描述/標題 */
|
135
|
+
description: string;
|
136
|
+
/** 影片創建時間戳 (秒) */
|
137
|
+
createTime: number;
|
138
|
+
/** 可選的影片播放/下載 URL */
|
139
|
+
videoPlayUrl?: string;
|
140
|
+
/** 作者資訊 */
|
141
|
+
author: {
|
142
|
+
/** 平台特定的作者 ID */
|
143
|
+
id: string;
|
144
|
+
/** 作者暱稱 */
|
145
|
+
nickname: string;
|
146
|
+
};
|
147
|
+
/** 影片統計數據 */
|
148
|
+
stats?: {
|
149
|
+
playCount?: number;
|
150
|
+
likeCount?: number;
|
151
|
+
commentCount?: number;
|
152
|
+
shareCount?: number;
|
153
|
+
};
|
154
|
+
}
|
155
|
+
/**
|
156
|
+
* 下載結果
|
157
|
+
*/
|
158
|
+
export interface DownloadResult {
|
159
|
+
/** 原始影片資訊 */
|
160
|
+
videoInfo: VideoInfo;
|
161
|
+
/** 是否下載成功 */
|
162
|
+
success: boolean;
|
163
|
+
/** 下載成功時的檔案路徑 */
|
164
|
+
filePath?: string;
|
165
|
+
/** 下載失敗時的錯誤資訊 */
|
166
|
+
error?: Error;
|
167
|
+
}
|
168
|
+
/**
|
169
|
+
* 認證服務介面
|
170
|
+
*/
|
171
|
+
export interface AuthService {
|
172
|
+
login(options?: LoginOptions): Promise<LoginResult>;
|
173
|
+
isValidCookie(cookie: string): Promise<boolean>;
|
174
|
+
loadCookie(cookiePath?: string): Promise<string | null>;
|
175
|
+
saveCookie(cookie: string, cookiePath?: string): Promise<void>;
|
176
|
+
loadAndValidateCookie(cookiePath?: string): Promise<string | null>;
|
177
|
+
getDefaultCookiePath(): string;
|
178
|
+
}
|
179
|
+
/**
|
180
|
+
* 資訊獲取服務介面
|
181
|
+
*/
|
182
|
+
export interface InfoService {
|
183
|
+
fetchVideoDetail(url: string, cookie: string, options?: FetchVideoOptions): Promise<VideoInfo | null>;
|
184
|
+
fetchVideosInfoUrls(urls: string[], cookie: string, options?: FetchVideoOptions): Promise<VideoInfo[]>;
|
185
|
+
fetchVideosInfoText(text: string, cookie: string, options?: FetchVideoOptions): Promise<VideoInfo[]>;
|
186
|
+
fetchUserVideos(userUrl: string, cookie: string, limit?: number, options?: UserVideosOptions): Promise<UserVideoItem[]>;
|
187
|
+
}
|
188
|
+
/**
|
189
|
+
* 下載服務介面
|
190
|
+
*/
|
191
|
+
export interface DownloadService {
|
192
|
+
downloadVideo(videoInfo: VideoInfo, outputPath: string, options?: DownloadOptions): Promise<DownloadResult>;
|
193
|
+
downloadVideos(videoInfos: VideoInfo[], outputPath: string, options?: DownloadOptions): Promise<DownloadResult[]>;
|
194
|
+
downloadVideosFromUrls(videoUrls: string[], outputPath: string, cookie: string, options?: DownloadOptions): Promise<DownloadResult[]>;
|
195
|
+
downloadVideosFromText(text: string, outputPath: string, cookie: string, options?: DownloadOptions): Promise<DownloadResult[]>;
|
196
|
+
}
|
197
|
+
/**
|
198
|
+
* 解析器服務介面
|
199
|
+
*/
|
200
|
+
export interface ParserService {
|
201
|
+
extractLinks(text: string): string[];
|
202
|
+
parseLinks(urls: string[], options?: ParseOptions): Promise<ParseResult[]>;
|
203
|
+
containsLink(text: string): boolean;
|
204
|
+
}
|
205
|
+
/**
|
206
|
+
* 支持的平台類型
|
207
|
+
*/
|
208
|
+
export type Platform = 'douyin' | 'tiktok';
|
209
|
+
/**
|
210
|
+
* 特定平台的服務集合
|
211
|
+
*/
|
212
|
+
export interface PlatformServices {
|
213
|
+
auth: AuthService;
|
214
|
+
info: InfoService;
|
215
|
+
download: DownloadService;
|
216
|
+
parser: ParserService;
|
217
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA,eAAe;;AAsPf,mBAAmB;AACnB,iFAAiF"}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
/**
|
2
|
+
* @deprecated 通用瀏覽器工具 - 已棄用。請改用 src/douyin/browser/manager.ts 中的函式。
|
3
|
+
* 提供 Puppeteer 瀏覽器管理功能
|
4
|
+
*/
|
5
|
+
import { Browser, Page } from 'puppeteer';
|
6
|
+
/**
|
7
|
+
* @deprecated 瀏覽器管理器選項 - 已棄用。
|
8
|
+
*/
|
9
|
+
export interface BrowserManagerOptions {
|
10
|
+
headless?: boolean | 'new' | 'shell' | undefined;
|
11
|
+
timeout?: number;
|
12
|
+
userAgent?: string;
|
13
|
+
executablePath?: string;
|
14
|
+
userDataDir?: string;
|
15
|
+
}
|
16
|
+
/**
|
17
|
+
* @deprecated 登入專用瀏覽器處理結果 - 已棄用。
|
18
|
+
*/
|
19
|
+
export interface LoginBrowserResult {
|
20
|
+
page: Page;
|
21
|
+
browser: Browser;
|
22
|
+
cleanup: () => Promise<void>;
|
23
|
+
}
|
24
|
+
/**
|
25
|
+
* @deprecated 瀏覽器管理器 - 已棄用。請改用 src/douyin/browser/manager.ts 中的函式。
|
26
|
+
* 使用單例模式管理 Puppeteer 瀏覽器實例
|
27
|
+
*/
|
28
|
+
export declare class BrowserManager {
|
29
|
+
private static instance;
|
30
|
+
/**
|
31
|
+
* @deprecated 獲取 BrowserManager 單例 - 已棄用。
|
32
|
+
* @param options 瀏覽器選項
|
33
|
+
* @returns BrowserManager 實例
|
34
|
+
*/
|
35
|
+
static getInstance(options?: BrowserManagerOptions): BrowserManager;
|
36
|
+
/**
|
37
|
+
* @deprecated 私有構造函數 - 已棄用。
|
38
|
+
* @param options 瀏覽器選項
|
39
|
+
*/
|
40
|
+
private constructor();
|
41
|
+
/**
|
42
|
+
* @deprecated 獲取瀏覽器實例 - 已棄用。
|
43
|
+
* @returns Promise<Browser>
|
44
|
+
*/
|
45
|
+
getBrowser(): Promise<Browser>;
|
46
|
+
/**
|
47
|
+
* @deprecated 創建新的頁面 - 已棄用。
|
48
|
+
* @returns Promise<Page>
|
49
|
+
*/
|
50
|
+
newPage(targetUrl?: string, cookies?: string, blockResources?: boolean): Promise<Page>;
|
51
|
+
/**
|
52
|
+
* @deprecated 創建用於登入的獨立瀏覽器實例 - 已棄用。
|
53
|
+
* @returns Promise<LoginBrowserResult>
|
54
|
+
*/
|
55
|
+
newLoginBrowser(options?: {
|
56
|
+
timeout?: number;
|
57
|
+
userAgent?: string;
|
58
|
+
executablePath?: string;
|
59
|
+
userDataDir?: string;
|
60
|
+
}): Promise<LoginBrowserResult>;
|
61
|
+
/**
|
62
|
+
* @deprecated 設置頁面的 Cookie - 已棄用。
|
63
|
+
*/
|
64
|
+
setCookies(page: Page, cookieString: string | undefined, domain?: string): Promise<void>;
|
65
|
+
/**
|
66
|
+
* @deprecated 關閉瀏覽器實例 - 已棄用。
|
67
|
+
*/
|
68
|
+
close(): Promise<void>;
|
69
|
+
}
|
70
|
+
/** @deprecated Use functions from src/douyin/browser/manager.ts instead. */
|
71
|
+
export declare const browserManager: BrowserManager;
|
72
|
+
/** @deprecated Browser lifecycle should be managed explicitly using closeBrowser from src/douyin/browser/manager.ts. */
|
73
|
+
export declare function cleanupBrowser(): Promise<void>;
|
@@ -0,0 +1,96 @@
|
|
1
|
+
"use strict";
|
2
|
+
/**
|
3
|
+
* @deprecated 通用瀏覽器工具 - 已棄用。請改用 src/douyin/browser/manager.ts 中的函式。
|
4
|
+
* 提供 Puppeteer 瀏覽器管理功能
|
5
|
+
*/
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
7
|
+
exports.browserManager = exports.BrowserManager = void 0;
|
8
|
+
exports.cleanupBrowser = cleanupBrowser;
|
9
|
+
const logger_1 = require("./logger"); // Use the utils logger
|
10
|
+
/**
|
11
|
+
* @deprecated 瀏覽器管理器 - 已棄用。請改用 src/douyin/browser/manager.ts 中的函式。
|
12
|
+
* 使用單例模式管理 Puppeteer 瀏覽器實例
|
13
|
+
*/
|
14
|
+
class BrowserManager {
|
15
|
+
// Keep static instance for basic compatibility, but make it unusable
|
16
|
+
static instance;
|
17
|
+
// Remove internal state
|
18
|
+
// private browser: Browser | null = null;
|
19
|
+
// private browserInitPromise: Promise<Browser> | null = null;
|
20
|
+
// private options: BrowserManagerOptions;
|
21
|
+
/**
|
22
|
+
* @deprecated 獲取 BrowserManager 單例 - 已棄用。
|
23
|
+
* @param options 瀏覽器選項
|
24
|
+
* @returns BrowserManager 實例
|
25
|
+
*/
|
26
|
+
static getInstance(options = {}) {
|
27
|
+
logger_1.utilsLogger.error('DEPRECATED: BrowserManager.getInstance is deprecated. Use functions from src/douyin/browser/manager.ts instead.');
|
28
|
+
if (!BrowserManager.instance) {
|
29
|
+
// Still create instance to avoid breaking existing getInstance calls immediately, but log error.
|
30
|
+
BrowserManager.instance = new BrowserManager(options);
|
31
|
+
}
|
32
|
+
return BrowserManager.instance;
|
33
|
+
}
|
34
|
+
/**
|
35
|
+
* @deprecated 私有構造函數 - 已棄用。
|
36
|
+
* @param options 瀏覽器選項
|
37
|
+
*/
|
38
|
+
constructor(options) {
|
39
|
+
// Log error only once during construction if instance didn't exist
|
40
|
+
if (!BrowserManager.instance) {
|
41
|
+
logger_1.utilsLogger.error('DEPRECATED: BrowserManager constructor is deprecated and should not be used.');
|
42
|
+
}
|
43
|
+
// this.options = options; // Don't store options
|
44
|
+
}
|
45
|
+
/**
|
46
|
+
* @deprecated 獲取瀏覽器實例 - 已棄用。
|
47
|
+
* @returns Promise<Browser>
|
48
|
+
*/
|
49
|
+
async getBrowser() {
|
50
|
+
logger_1.utilsLogger.error('DEPRECATED: BrowserManager.getBrowser is deprecated. Use launchBrowser from src/douyin/browser/manager.ts.');
|
51
|
+
throw new Error('BrowserManager.getBrowser is deprecated.');
|
52
|
+
}
|
53
|
+
/**
|
54
|
+
* @deprecated 創建新的頁面 - 已棄用。
|
55
|
+
* @returns Promise<Page>
|
56
|
+
*/
|
57
|
+
async newPage(targetUrl, cookies, blockResources = true) {
|
58
|
+
logger_1.utilsLogger.error('DEPRECATED: BrowserManager.newPage is deprecated. Use newPage from src/douyin/browser/manager.ts.');
|
59
|
+
throw new Error('BrowserManager.newPage is deprecated.');
|
60
|
+
}
|
61
|
+
/**
|
62
|
+
* @deprecated 創建用於登入的獨立瀏覽器實例 - 已棄用。
|
63
|
+
* @returns Promise<LoginBrowserResult>
|
64
|
+
*/
|
65
|
+
async newLoginBrowser(options = {}) {
|
66
|
+
logger_1.utilsLogger.error('DEPRECATED: BrowserManager.newLoginBrowser is deprecated. Use launchLoginBrowser from src/douyin/browser/manager.ts.');
|
67
|
+
throw new Error('BrowserManager.newLoginBrowser is deprecated.');
|
68
|
+
}
|
69
|
+
/**
|
70
|
+
* @deprecated 設置頁面的 Cookie - 已棄用。
|
71
|
+
*/
|
72
|
+
async setCookies(page, cookieString, domain) {
|
73
|
+
logger_1.utilsLogger.error('DEPRECATED: BrowserManager.setCookies is deprecated. Use setCookiesOnPage from src/douyin/browser/manager.ts.');
|
74
|
+
throw new Error('BrowserManager.setCookies is deprecated.');
|
75
|
+
}
|
76
|
+
/**
|
77
|
+
* @deprecated 關閉瀏覽器實例 - 已棄用。
|
78
|
+
*/
|
79
|
+
async close() {
|
80
|
+
logger_1.utilsLogger.warn('DEPRECATED: BrowserManager.close is deprecated and does nothing. Browser lifecycle should be managed explicitly using closeBrowser from src/douyin/browser/manager.ts.');
|
81
|
+
// No operation
|
82
|
+
}
|
83
|
+
}
|
84
|
+
exports.BrowserManager = BrowserManager;
|
85
|
+
// 導出默認的瀏覽器管理器實例
|
86
|
+
/** @deprecated Use functions from src/douyin/browser/manager.ts instead. */
|
87
|
+
exports.browserManager = BrowserManager.getInstance();
|
88
|
+
// 清理函數,用於在進程退出時關閉瀏覽器
|
89
|
+
/** @deprecated Browser lifecycle should be managed explicitly using closeBrowser from src/douyin/browser/manager.ts. */
|
90
|
+
async function cleanupBrowser() {
|
91
|
+
logger_1.utilsLogger.warn('DEPRECATED: cleanupBrowser is deprecated and does nothing. Ensure browsers are closed explicitly using closeBrowser from src/douyin/browser/manager.ts.');
|
92
|
+
// Do nothing
|
93
|
+
}
|
94
|
+
// --- Process Exit Handling ---
|
95
|
+
// Removed all process exit handling as the singleton is deprecated
|
96
|
+
//# sourceMappingURL=browser.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../../src/utils/browser.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA4HH,wCAGC;AAzHD,qCAAiD,CAAC,uBAAuB;AAyBzE;;;GAGG;AACH,MAAa,cAAc;IACzB,qEAAqE;IAC7D,MAAM,CAAC,QAAQ,CAAiB;IACxC,wBAAwB;IACxB,0CAA0C;IAC1C,8DAA8D;IAC9D,0CAA0C;IAE1C;;;;OAIG;IACI,MAAM,CAAC,WAAW,CAAC,UAAiC,EAAE;QAC3D,oBAAM,CAAC,KAAK,CAAC,iHAAiH,CAAC,CAAC;QAChI,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;YAC7B,iGAAiG;YACjG,cAAc,CAAC,QAAQ,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;QACxD,CAAC;QACD,OAAO,cAAc,CAAC,QAAQ,CAAC;IACjC,CAAC;IAED;;;OAGG;IACH,YAAoB,OAA8B;QAChD,mEAAmE;QACnE,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;YAC3B,oBAAM,CAAC,KAAK,CAAC,8EAA8E,CAAC,CAAC;QACjG,CAAC;QACD,iDAAiD;IACnD,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU;QACd,oBAAM,CAAC,KAAK,CAAC,4GAA4G,CAAC,CAAC;QAC3H,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,OAAO,CAAC,SAAkB,EAAE,OAAgB,EAAE,iBAA0B,IAAI;QAChF,oBAAM,CAAC,KAAK,CAAC,mGAAmG,CAAC,CAAC;QAClH,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,eAAe,CAAC,UAKlB,EAAE;QACJ,oBAAM,CAAC,KAAK,CAAC,sHAAsH,CAAC,CAAC;QACrI,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU,CAAC,IAAU,EAAE,YAAgC,EAAE,MAAe;QAC5E,oBAAM,CAAC,KAAK,CAAC,+GAA+G,CAAC,CAAC;QAC9H,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,oBAAM,CAAC,IAAI,CAAC,wKAAwK,CAAC,CAAC;QACtL,eAAe;IACjB,CAAC;CACF;AAjFD,wCAiFC;AAED,gBAAgB;AAChB,4EAA4E;AAC/D,QAAA,cAAc,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC;AAE3D,qBAAqB;AACrB,wHAAwH;AACjH,KAAK,UAAU,cAAc;IAClC,oBAAM,CAAC,IAAI,CAAC,yJAAyJ,CAAC,CAAC;IACvK,aAAa;AACf,CAAC;AAED,gCAAgC;AAChC,mEAAmE"}
|
@@ -0,0 +1,160 @@
|
|
1
|
+
/**
|
2
|
+
* 通用錯誤處理系統
|
3
|
+
* 提供統一的錯誤類型和處理機制
|
4
|
+
*/
|
5
|
+
/**
|
6
|
+
* 錯誤碼枚舉
|
7
|
+
* 用於標識不同類型的錯誤
|
8
|
+
*/
|
9
|
+
export declare enum ErrorCode {
|
10
|
+
UNKNOWN_ERROR = "UNKNOWN_ERROR",
|
11
|
+
INVALID_ARGUMENT = "INVALID_ARGUMENT",
|
12
|
+
NETWORK_ERROR = "NETWORK_ERROR",
|
13
|
+
TIMEOUT_ERROR = "TIMEOUT_ERROR",
|
14
|
+
RATE_LIMIT_ERROR = "RATE_LIMIT_ERROR",
|
15
|
+
AUTHENTICATION_ERROR = "AUTHENTICATION_ERROR",
|
16
|
+
COOKIE_INVALID = "COOKIE_INVALID",
|
17
|
+
COOKIE_EXPIRED = "COOKIE_EXPIRED",
|
18
|
+
CAPTCHA_REQUIRED = "CAPTCHA_REQUIRED",
|
19
|
+
PARSING_ERROR = "PARSING_ERROR",
|
20
|
+
INVALID_URL = "INVALID_URL",
|
21
|
+
RESOURCE_ERROR = "RESOURCE_ERROR",
|
22
|
+
VIDEO_NOT_FOUND = "VIDEO_NOT_FOUND",
|
23
|
+
USER_NOT_FOUND = "USER_NOT_FOUND",
|
24
|
+
CONTENT_RESTRICTED = "CONTENT_RESTRICTED",
|
25
|
+
DOWNLOAD_ERROR = "DOWNLOAD_ERROR",
|
26
|
+
DOWNLOAD_INTERRUPTED = "DOWNLOAD_INTERRUPTED",
|
27
|
+
FILE_SYSTEM_ERROR = "FILE_SYSTEM_ERROR",
|
28
|
+
PERMISSION_DENIED = "PERMISSION_DENIED",
|
29
|
+
BROWSER_ERROR = "BROWSER_ERROR",
|
30
|
+
BROWSER_LAUNCH_FAILED = "BROWSER_LAUNCH_FAILED",
|
31
|
+
API_ERROR = "API_ERROR"
|
32
|
+
}
|
33
|
+
/**
|
34
|
+
* 應用程序錯誤類
|
35
|
+
* 統一的錯誤類,包含錯誤碼、原因和其他信息
|
36
|
+
*/
|
37
|
+
export declare class AppError extends Error {
|
38
|
+
readonly code: ErrorCode;
|
39
|
+
readonly cause?: (Error | unknown) | undefined;
|
40
|
+
readonly details?: Record<string, any> | undefined;
|
41
|
+
/**
|
42
|
+
* 創建應用程序錯誤
|
43
|
+
* @param message 錯誤消息
|
44
|
+
* @param code 錯誤碼,默認為 UNKNOWN_ERROR
|
45
|
+
* @param cause 原始錯誤,用於錯誤鏈
|
46
|
+
* @param details 錯誤詳情,可包含任何額外信息
|
47
|
+
*/
|
48
|
+
constructor(message: string, code?: ErrorCode, cause?: (Error | unknown) | undefined, // Allow unknown cause
|
49
|
+
details?: Record<string, any> | undefined);
|
50
|
+
/**
|
51
|
+
* 獲取完整的錯誤消息,包括錯誤碼和詳情
|
52
|
+
*/
|
53
|
+
get fullMessage(): string;
|
54
|
+
/**
|
55
|
+
* 判斷錯誤是否可重試
|
56
|
+
* @returns 是否可重試
|
57
|
+
*/
|
58
|
+
isRetryable(): boolean;
|
59
|
+
/**
|
60
|
+
* 從通用錯誤創建 AppError
|
61
|
+
* @param error 通用錯誤
|
62
|
+
* @param code 錯誤碼,默認為 UNKNOWN_ERROR
|
63
|
+
* @param defaultMessage 默認錯誤消息,如果原錯誤沒有消息
|
64
|
+
* @returns AppError 實例
|
65
|
+
*/
|
66
|
+
static from(error: unknown, code?: ErrorCode, defaultMessage?: string): AppError;
|
67
|
+
/**
|
68
|
+
* 創建網絡錯誤
|
69
|
+
* @param message 錯誤消息
|
70
|
+
* @param cause 原始錯誤
|
71
|
+
* @returns AppError 實例
|
72
|
+
*/
|
73
|
+
static network(message: string, cause?: Error | unknown): AppError;
|
74
|
+
/**
|
75
|
+
* 創建認證錯誤
|
76
|
+
* @param message 錯誤消息
|
77
|
+
* @param cause 原始錯誤
|
78
|
+
* @returns AppError 實例
|
79
|
+
*/
|
80
|
+
static authentication(message: string, cause?: Error | unknown): AppError;
|
81
|
+
/**
|
82
|
+
* 創建解析錯誤
|
83
|
+
* @param message 錯誤消息
|
84
|
+
* @param cause 原始錯誤
|
85
|
+
* @returns AppError 實例
|
86
|
+
*/
|
87
|
+
static parsing(message: string, cause?: Error | unknown): AppError;
|
88
|
+
/**
|
89
|
+
* 創建視頻未找到錯誤
|
90
|
+
* @param message 錯誤消息
|
91
|
+
* @param videoId 視頻ID
|
92
|
+
* @returns AppError 實例
|
93
|
+
*/
|
94
|
+
static videoNotFound(message: string, videoId?: string): AppError;
|
95
|
+
/**
|
96
|
+
* 創建用戶未找到錯誤
|
97
|
+
* @param message 錯誤消息
|
98
|
+
* @param userId 用戶ID
|
99
|
+
* @returns AppError 實例
|
100
|
+
*/
|
101
|
+
static userNotFound(message: string, userId?: string): AppError;
|
102
|
+
/**
|
103
|
+
* 創建下載錯誤
|
104
|
+
* @param message 錯誤消息
|
105
|
+
* @param cause 原始錯誤
|
106
|
+
* @param url 下載URL
|
107
|
+
* @returns AppError 實例
|
108
|
+
*/
|
109
|
+
static download(message: string, cause?: Error | unknown, url?: string): AppError;
|
110
|
+
/**
|
111
|
+
* 創建文件系統錯誤
|
112
|
+
* @param message 錯誤消息
|
113
|
+
* @param cause 原始錯誤
|
114
|
+
* @param path 文件路徑
|
115
|
+
* @returns AppError 實例
|
116
|
+
*/
|
117
|
+
static fileSystem(message: string, cause?: Error | unknown, path?: string): AppError;
|
118
|
+
/**
|
119
|
+
* 創建權限錯誤
|
120
|
+
* @param message 錯誤消息
|
121
|
+
* @param cause 原始錯誤
|
122
|
+
* @param path 文件路徑
|
123
|
+
* @returns AppError 實例
|
124
|
+
*/
|
125
|
+
static permissionDenied(message: string, cause?: Error | unknown, path?: string): AppError;
|
126
|
+
/**
|
127
|
+
* 創建瀏覽器錯誤
|
128
|
+
* @param message 錯誤消息
|
129
|
+
* @param cause 原始錯誤
|
130
|
+
* @returns AppError 實例
|
131
|
+
*/
|
132
|
+
static browser(message: string, cause?: Error | unknown): AppError;
|
133
|
+
/**
|
134
|
+
* 創建API錯誤
|
135
|
+
* @param message 錯誤消息
|
136
|
+
* @param cause 原始錯誤
|
137
|
+
* @param statusCode HTTP狀態碼
|
138
|
+
* @returns AppError 實例
|
139
|
+
*/
|
140
|
+
static api(message: string, cause?: Error | unknown, statusCode?: number): AppError;
|
141
|
+
/**
|
142
|
+
* 處理平台API特定錯誤 (需要平台特定實現來覆蓋或擴展)
|
143
|
+
* @param apiResponse API響應
|
144
|
+
* @param platform 平台標識 ('douyin', 'tiktok', etc.)
|
145
|
+
* @returns AppError 實例
|
146
|
+
*/
|
147
|
+
static fromApiResponse(apiResponse: any, platform?: string): AppError;
|
148
|
+
}
|
149
|
+
/**
|
150
|
+
* 解析錯誤消息中的HTTP狀態碼
|
151
|
+
* @param error 錯誤對象
|
152
|
+
* @returns 狀態碼或undefined
|
153
|
+
*/
|
154
|
+
export declare function parseHttpStatusFromError(error: Error | AppError): number | undefined;
|
155
|
+
/**
|
156
|
+
* 解析常見的網絡錯誤
|
157
|
+
* @param error 錯誤對象
|
158
|
+
* @returns 標準化的AppError
|
159
|
+
*/
|
160
|
+
export declare function parseNetworkError(error: Error | AppError): AppError;
|