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,49 @@
|
|
1
|
+
"use strict";
|
2
|
+
// Copied from src/auth/errors.ts
|
3
|
+
// Original file path: src/auth/errors.ts
|
4
|
+
/**
|
5
|
+
* 錯誤類型定義
|
6
|
+
* 提供認證與登入模組相關的特定錯誤類型
|
7
|
+
*/
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
9
|
+
exports.CookieStorageError = exports.CookieValidationError = exports.LoginError = void 0;
|
10
|
+
/**
|
11
|
+
* 登入錯誤
|
12
|
+
* 用於表示登入過程中發生的錯誤
|
13
|
+
*/
|
14
|
+
class LoginError extends Error {
|
15
|
+
cause;
|
16
|
+
constructor(message, cause) {
|
17
|
+
super(`登入錯誤: ${message}`);
|
18
|
+
this.name = 'LoginError';
|
19
|
+
this.cause = cause;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
exports.LoginError = LoginError;
|
23
|
+
/**
|
24
|
+
* Cookie 驗證錯誤
|
25
|
+
* 用於表示 Cookie 驗證過程中發生的錯誤
|
26
|
+
*/
|
27
|
+
class CookieValidationError extends Error {
|
28
|
+
cause;
|
29
|
+
constructor(message, cause) {
|
30
|
+
super(`Cookie 驗證錯誤: ${message}`);
|
31
|
+
this.name = 'CookieValidationError';
|
32
|
+
this.cause = cause;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
exports.CookieValidationError = CookieValidationError;
|
36
|
+
/**
|
37
|
+
* Cookie 存儲錯誤
|
38
|
+
* 用於表示 Cookie 儲存或讀取過程中發生的錯誤
|
39
|
+
*/
|
40
|
+
class CookieStorageError extends Error {
|
41
|
+
cause;
|
42
|
+
constructor(message, cause) {
|
43
|
+
super(`Cookie 儲存錯誤: ${message}`);
|
44
|
+
this.name = 'CookieStorageError';
|
45
|
+
this.cause = cause;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
exports.CookieStorageError = CookieStorageError;
|
49
|
+
//# sourceMappingURL=errors.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/douyin/auth/errors.ts"],"names":[],"mappings":";AAAA,iCAAiC;AACjC,yCAAyC;AACzC;;;GAGG;;;AAEH;;;GAGG;AACH,MAAa,UAAW,SAAQ,KAAK;IACnC,KAAK,CAAO;IAEZ,YAAY,OAAe,EAAE,KAAW;QACtC,KAAK,CAAC,SAAS,OAAO,EAAE,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AARD,gCAQC;AAED;;;GAGG;AACH,MAAa,qBAAsB,SAAQ,KAAK;IAC9C,KAAK,CAAO;IAEZ,YAAY,OAAe,EAAE,KAAW;QACtC,KAAK,CAAC,gBAAgB,OAAO,EAAE,CAAC,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AARD,sDAQC;AAED;;;GAGG;AACH,MAAa,kBAAmB,SAAQ,KAAK;IAC3C,KAAK,CAAO;IAEZ,YAAY,OAAe,EAAE,KAAW;QACtC,KAAK,CAAC,gBAAgB,OAAO,EAAE,CAAC,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AARD,gDAQC"}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
/**
|
2
|
+
* 抖音 Cookie 路徑模組
|
3
|
+
* 獲取默認的 Cookie 存儲路徑
|
4
|
+
*
|
5
|
+
* @remarks
|
6
|
+
* 參考來源:此功能改寫自原本存放於 src/auth/cookie-path.ts 的功能
|
7
|
+
* 需要驗證:標準路徑設置是否符合應用規範
|
8
|
+
*/
|
9
|
+
/**
|
10
|
+
* 獲取應用數據目錄
|
11
|
+
* @returns 資料目錄路徑
|
12
|
+
*
|
13
|
+
* @remarks
|
14
|
+
* 此功能與 getDefaultCookiePath 配合使用
|
15
|
+
*/
|
16
|
+
export declare function getAppDataDir(): string;
|
17
|
+
/**
|
18
|
+
* 獲取默認的 Cookie 存儲路徑
|
19
|
+
* @returns 根據作業系統返回默認的 Cookie 文件路徑
|
20
|
+
*
|
21
|
+
* @remarks
|
22
|
+
* 改寫自原本存放於 src/auth/cookie-path.ts 的功能
|
23
|
+
*/
|
24
|
+
export declare function getDefaultCookiePath(): string;
|
@@ -0,0 +1,90 @@
|
|
1
|
+
"use strict";
|
2
|
+
/**
|
3
|
+
* 抖音 Cookie 路徑模組
|
4
|
+
* 獲取默認的 Cookie 存儲路徑
|
5
|
+
*
|
6
|
+
* @remarks
|
7
|
+
* 參考來源:此功能改寫自原本存放於 src/auth/cookie-path.ts 的功能
|
8
|
+
* 需要驗證:標準路徑設置是否符合應用規範
|
9
|
+
*/
|
10
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
11
|
+
if (k2 === undefined) k2 = k;
|
12
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
13
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
14
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
15
|
+
}
|
16
|
+
Object.defineProperty(o, k2, desc);
|
17
|
+
}) : (function(o, m, k, k2) {
|
18
|
+
if (k2 === undefined) k2 = k;
|
19
|
+
o[k2] = m[k];
|
20
|
+
}));
|
21
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
22
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
23
|
+
}) : function(o, v) {
|
24
|
+
o["default"] = v;
|
25
|
+
});
|
26
|
+
var __importStar = (this && this.__importStar) || (function () {
|
27
|
+
var ownKeys = function(o) {
|
28
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
29
|
+
var ar = [];
|
30
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
31
|
+
return ar;
|
32
|
+
};
|
33
|
+
return ownKeys(o);
|
34
|
+
};
|
35
|
+
return function (mod) {
|
36
|
+
if (mod && mod.__esModule) return mod;
|
37
|
+
var result = {};
|
38
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
39
|
+
__setModuleDefault(result, mod);
|
40
|
+
return result;
|
41
|
+
};
|
42
|
+
})();
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
44
|
+
exports.getAppDataDir = getAppDataDir;
|
45
|
+
exports.getDefaultCookiePath = getDefaultCookiePath;
|
46
|
+
const os = __importStar(require("os"));
|
47
|
+
const path = __importStar(require("path"));
|
48
|
+
/**
|
49
|
+
* 獲取應用數據目錄
|
50
|
+
* @returns 資料目錄路徑
|
51
|
+
*
|
52
|
+
* @remarks
|
53
|
+
* 此功能與 getDefaultCookiePath 配合使用
|
54
|
+
*/
|
55
|
+
function getAppDataDir() {
|
56
|
+
// 應用名稱
|
57
|
+
const appName = 'douyin-downloader';
|
58
|
+
// 獲取用戶家目錄
|
59
|
+
const homedir = os.homedir();
|
60
|
+
// 根據作業系統決定應用數據目錄位置
|
61
|
+
const platform = os.platform();
|
62
|
+
let appDataDir;
|
63
|
+
if (platform === 'win32') {
|
64
|
+
// Windows: %APPDATA%\[appName]
|
65
|
+
appDataDir = path.join(process.env.APPDATA || path.join(homedir, 'AppData', 'Roaming'), appName);
|
66
|
+
}
|
67
|
+
else if (platform === 'darwin') {
|
68
|
+
// macOS: ~/Library/Application Support/[appName]
|
69
|
+
appDataDir = path.join(homedir, 'Library', 'Application Support', appName);
|
70
|
+
}
|
71
|
+
else {
|
72
|
+
// Linux 和其他系統
|
73
|
+
appDataDir = path.join(homedir, '.config', appName);
|
74
|
+
}
|
75
|
+
return appDataDir;
|
76
|
+
}
|
77
|
+
/**
|
78
|
+
* 獲取默認的 Cookie 存儲路徑
|
79
|
+
* @returns 根據作業系統返回默認的 Cookie 文件路徑
|
80
|
+
*
|
81
|
+
* @remarks
|
82
|
+
* 改寫自原本存放於 src/auth/cookie-path.ts 的功能
|
83
|
+
*/
|
84
|
+
function getDefaultCookiePath() {
|
85
|
+
// 應用數據目錄名稱
|
86
|
+
const cookieFileName = 'douyin-cookie.txt';
|
87
|
+
// 組合完整的 Cookie 檔案路徑
|
88
|
+
return path.join(getAppDataDir(), cookieFileName);
|
89
|
+
}
|
90
|
+
//# sourceMappingURL=getDefaultCookiePath.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"getDefaultCookiePath.js","sourceRoot":"","sources":["../../../../src/douyin/auth/getDefaultCookiePath.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYH,sCAwBC;AASD,oDAMC;AAjDD,uCAAyB;AACzB,2CAA6B;AAE7B;;;;;;GAMG;AACH,SAAgB,aAAa;IAC3B,OAAO;IACP,MAAM,OAAO,GAAG,mBAAmB,CAAC;IAEpC,UAAU;IACV,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;IAE7B,mBAAmB;IACnB,MAAM,QAAQ,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;IAE/B,IAAI,UAAkB,CAAC;IAEvB,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QACzB,+BAA+B;QAC/B,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,OAAO,CAAC,CAAC;IACnG,CAAC;SAAM,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjC,iDAAiD;QACjD,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAC;IAC7E,CAAC;SAAM,CAAC;QACN,cAAc;QACd,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,oBAAoB;IAClC,WAAW;IACX,MAAM,cAAc,GAAG,mBAAmB,CAAC;IAE3C,oBAAoB;IACpB,OAAO,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,cAAc,CAAC,CAAC;AACpD,CAAC"}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/**
|
2
|
+
* 認證模組
|
3
|
+
* 提供抖音登入和 Cookie 管理功能
|
4
|
+
*/
|
5
|
+
export * from './errors';
|
6
|
+
export { getDefaultCookiePath, ensureCookieDirectory, getAppDataDir } from './cookie-path';
|
7
|
+
export { saveCookie, loadCookie } from './cookie-storage';
|
8
|
+
export { login } from './login';
|
9
|
+
export type { LoginOptions, LoginResult } from './login';
|
10
|
+
export { isValidCookie } from './validate';
|
11
|
+
/**
|
12
|
+
* 從檔案讀取 Cookie 並驗證有效性
|
13
|
+
* @param cookiePath 可選的 Cookie 檔案路徑
|
14
|
+
* @returns Promise<string> 有效的 Cookie 字串,如無效則返回空字串
|
15
|
+
*/
|
16
|
+
export declare function loadAndValidateCookie(cookiePath?: string): Promise<string>;
|
@@ -0,0 +1,68 @@
|
|
1
|
+
"use strict";
|
2
|
+
// Copied from src/auth/index.ts
|
3
|
+
// Original file path: src/auth/index.ts
|
4
|
+
/**
|
5
|
+
* 認證模組
|
6
|
+
* 提供抖音登入和 Cookie 管理功能
|
7
|
+
*/
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
9
|
+
if (k2 === undefined) k2 = k;
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
13
|
+
}
|
14
|
+
Object.defineProperty(o, k2, desc);
|
15
|
+
}) : (function(o, m, k, k2) {
|
16
|
+
if (k2 === undefined) k2 = k;
|
17
|
+
o[k2] = m[k];
|
18
|
+
}));
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
21
|
+
};
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
23
|
+
exports.isValidCookie = exports.login = exports.loadCookie = exports.saveCookie = exports.getAppDataDir = exports.ensureCookieDirectory = exports.getDefaultCookiePath = void 0;
|
24
|
+
exports.loadAndValidateCookie = loadAndValidateCookie;
|
25
|
+
const validate_1 = require("./validate");
|
26
|
+
const cookie_storage_1 = require("./cookie-storage");
|
27
|
+
const logger_1 = require("../../utils/logger"); // Updated path to shared utils
|
28
|
+
__exportStar(require("./errors"), exports);
|
29
|
+
var cookie_path_1 = require("./cookie-path");
|
30
|
+
Object.defineProperty(exports, "getDefaultCookiePath", { enumerable: true, get: function () { return cookie_path_1.getDefaultCookiePath; } });
|
31
|
+
Object.defineProperty(exports, "ensureCookieDirectory", { enumerable: true, get: function () { return cookie_path_1.ensureCookieDirectory; } });
|
32
|
+
Object.defineProperty(exports, "getAppDataDir", { enumerable: true, get: function () { return cookie_path_1.getAppDataDir; } });
|
33
|
+
var cookie_storage_2 = require("./cookie-storage");
|
34
|
+
Object.defineProperty(exports, "saveCookie", { enumerable: true, get: function () { return cookie_storage_2.saveCookie; } });
|
35
|
+
Object.defineProperty(exports, "loadCookie", { enumerable: true, get: function () { return cookie_storage_2.loadCookie; } });
|
36
|
+
var login_1 = require("./login");
|
37
|
+
Object.defineProperty(exports, "login", { enumerable: true, get: function () { return login_1.login; } });
|
38
|
+
var validate_2 = require("./validate");
|
39
|
+
Object.defineProperty(exports, "isValidCookie", { enumerable: true, get: function () { return validate_2.isValidCookie; } });
|
40
|
+
/**
|
41
|
+
* 從檔案讀取 Cookie 並驗證有效性
|
42
|
+
* @param cookiePath 可選的 Cookie 檔案路徑
|
43
|
+
* @returns Promise<string> 有效的 Cookie 字串,如無效則返回空字串
|
44
|
+
*/
|
45
|
+
async function loadAndValidateCookie(cookiePath) {
|
46
|
+
// 加載 Cookie
|
47
|
+
const cookie = await (0, cookie_storage_1.loadCookie)(cookiePath);
|
48
|
+
if (!cookie) {
|
49
|
+
logger_1.authLogger.warn('未找到 Cookie 檔案或檔案為空');
|
50
|
+
return '';
|
51
|
+
}
|
52
|
+
// 驗證 Cookie
|
53
|
+
try {
|
54
|
+
const isValid = await (0, validate_1.isValidCookie)(cookie);
|
55
|
+
if (!isValid) {
|
56
|
+
logger_1.authLogger.warn('Cookie 已失效,需要重新登入');
|
57
|
+
return '';
|
58
|
+
}
|
59
|
+
logger_1.authLogger.info('已載入有效的 Cookie');
|
60
|
+
return cookie;
|
61
|
+
}
|
62
|
+
catch (error) {
|
63
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
64
|
+
logger_1.authLogger.error('驗證 Cookie 時發生錯誤:', err);
|
65
|
+
return '';
|
66
|
+
}
|
67
|
+
}
|
68
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/douyin/auth/index.ts"],"names":[],"mappings":";AAAA,gCAAgC;AAChC,wCAAwC;AACxC;;;GAGG;;;;;;;;;;;;;;;;;AAoBH,sDAyBC;AA1CD,yCAA2C;AAE3C,qDAA0D;AAC1D,+CAA0D,CAAC,+BAA+B;AAE1F,2CAAyB;AACzB,6CAA2F;AAAlF,mHAAA,oBAAoB,OAAA;AAAE,oHAAA,qBAAqB,OAAA;AAAE,4GAAA,aAAa,OAAA;AACnE,mDAA0D;AAAjD,4GAAA,UAAU,OAAA;AAAE,4GAAA,UAAU,OAAA;AAC/B,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AAEd,uCAA2C;AAAlC,yGAAA,aAAa,OAAA;AAEtB;;;;GAIG;AACI,KAAK,UAAU,qBAAqB,CAAC,UAAmB;IAC7D,YAAY;IACZ,MAAM,MAAM,GAAG,MAAM,IAAA,2BAAU,EAAC,UAAU,CAAC,CAAC;IAE5C,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,mBAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAClC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,YAAY;IACZ,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,IAAA,wBAAa,EAAC,MAAM,CAAC,CAAC;QAE5C,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,mBAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACjC,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,mBAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAC7B,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,GAAG,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACtE,mBAAM,CAAC,KAAK,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC;QACtC,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/**
|
2
|
+
* 抖音 Cookie 驗證模組
|
3
|
+
* 檢查提供的 Cookie 字串是否有效
|
4
|
+
*
|
5
|
+
* @remarks
|
6
|
+
* 參考來源:此功能改寫自原本存放於 src/auth/validate.ts 的功能
|
7
|
+
* 需要驗證:此模組是否符合抖音最新 API 規範
|
8
|
+
*/
|
9
|
+
/**
|
10
|
+
* 檢查提供的 Cookie 字串是否仍然有效
|
11
|
+
* @param cookie 要驗證的 Cookie 字串
|
12
|
+
* @returns 布林值,true 表示有效,false 表示無效
|
13
|
+
*
|
14
|
+
* @remarks
|
15
|
+
* 改寫自原本存放於 src/auth/validate.ts 的功能
|
16
|
+
* 但簡化了實現,更類似於 TikTok 的驗證流程
|
17
|
+
*/
|
18
|
+
export declare function isValidCookie(cookie: string): Promise<boolean>;
|
@@ -0,0 +1,60 @@
|
|
1
|
+
"use strict";
|
2
|
+
/**
|
3
|
+
* 抖音 Cookie 驗證模組
|
4
|
+
* 檢查提供的 Cookie 字串是否有效
|
5
|
+
*
|
6
|
+
* @remarks
|
7
|
+
* 參考來源:此功能改寫自原本存放於 src/auth/validate.ts 的功能
|
8
|
+
* 需要驗證:此模組是否符合抖音最新 API 規範
|
9
|
+
*/
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
11
|
+
exports.isValidCookie = isValidCookie;
|
12
|
+
/**
|
13
|
+
* 檢查提供的 Cookie 字串是否仍然有效
|
14
|
+
* @param cookie 要驗證的 Cookie 字串
|
15
|
+
* @returns 布林值,true 表示有效,false 表示無效
|
16
|
+
*
|
17
|
+
* @remarks
|
18
|
+
* 改寫自原本存放於 src/auth/validate.ts 的功能
|
19
|
+
* 但簡化了實現,更類似於 TikTok 的驗證流程
|
20
|
+
*/
|
21
|
+
async function isValidCookie(cookie) {
|
22
|
+
return true;
|
23
|
+
if (!cookie || cookie.trim() === '') {
|
24
|
+
console.warn('提供的 Cookie 為空');
|
25
|
+
return false;
|
26
|
+
}
|
27
|
+
try {
|
28
|
+
// 嘗試請求需要登入才能訪問的 API
|
29
|
+
const response = await fetch('https://www.douyin.com/aweme/v1/web/user/profile/self/', {
|
30
|
+
method: 'GET',
|
31
|
+
headers: {
|
32
|
+
'Cookie': cookie,
|
33
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36',
|
34
|
+
'Referer': 'https://www.douyin.com/'
|
35
|
+
}
|
36
|
+
});
|
37
|
+
if (!response.ok) {
|
38
|
+
console.warn(`Cookie 驗證請求失敗,狀態碼: ${response.status}`);
|
39
|
+
return false;
|
40
|
+
}
|
41
|
+
const data = await response.json();
|
42
|
+
// 檢查返回數據是否表示未登入
|
43
|
+
if (data.status_code === 2455 || data.message === '用户未登录') {
|
44
|
+
console.warn('Cookie 已過期或無效');
|
45
|
+
return false;
|
46
|
+
}
|
47
|
+
// 檢查是否有用戶數據
|
48
|
+
if (data.user) {
|
49
|
+
console.log('Cookie 有效');
|
50
|
+
return true;
|
51
|
+
}
|
52
|
+
console.warn('無法確認 Cookie 是否有效,未檢測到用戶數據');
|
53
|
+
return false;
|
54
|
+
}
|
55
|
+
catch (error) {
|
56
|
+
console.error('驗證 Cookie 時發生錯誤:', error);
|
57
|
+
return false;
|
58
|
+
}
|
59
|
+
}
|
60
|
+
//# sourceMappingURL=isValidCookie.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"isValidCookie.js","sourceRoot":"","sources":["../../../../src/douyin/auth/isValidCookie.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AAWH,sCA2CC;AApDD;;;;;;;;GAQG;AACI,KAAK,UAAU,aAAa,CAAC,MAAc;IAChD,OAAO,IAAI,CAAC;IACZ,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACpC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC;QACH,oBAAoB;QACpB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,wDAAwD,EAAE;YACrF,MAAM,EAAE,KAAK;YACb,OAAO,EAAE;gBACP,QAAQ,EAAE,MAAM;gBAChB,YAAY,EAAE,iHAAiH;gBAC/H,SAAS,EAAE,yBAAyB;aACrC;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,OAAO,CAAC,IAAI,CAAC,sBAAsB,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;YACtD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAEnC,gBAAgB;QAChB,IAAI,IAAI,CAAC,WAAW,KAAK,IAAI,IAAI,IAAI,CAAC,OAAO,KAAK,OAAO,EAAE,CAAC;YAC1D,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;YAC9B,OAAO,KAAK,CAAC;QACf,CAAC;QAED,YAAY;QACZ,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;YACzB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;QAC1C,OAAO,KAAK,CAAC;IACf,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;QACzC,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
/**
|
2
|
+
* 抖音 Cookie 讀取與驗證模組
|
3
|
+
* 從檔案讀取 Cookie 並驗證有效性
|
4
|
+
*
|
5
|
+
* @remarks
|
6
|
+
* 參考來源:此功能改寫自原本存放於 src/auth/index.ts 的 loadAndValidateCookie 功能
|
7
|
+
* 需要驗證:驗證流程是否符合抖音最新要求
|
8
|
+
*/
|
9
|
+
/**
|
10
|
+
* 從檔案讀取 Cookie 並驗證有效性
|
11
|
+
* @param cookiePath 可選的 Cookie 檔案路徑
|
12
|
+
* @returns 有效的 Cookie 字串,如無效則返回空字串
|
13
|
+
*
|
14
|
+
* @remarks
|
15
|
+
* 整合了 Cookie 讀取和驗證功能
|
16
|
+
*/
|
17
|
+
export declare function loadAndValidateCookie(cookiePath?: string): Promise<string>;
|
@@ -0,0 +1,45 @@
|
|
1
|
+
"use strict";
|
2
|
+
/**
|
3
|
+
* 抖音 Cookie 讀取與驗證模組
|
4
|
+
* 從檔案讀取 Cookie 並驗證有效性
|
5
|
+
*
|
6
|
+
* @remarks
|
7
|
+
* 參考來源:此功能改寫自原本存放於 src/auth/index.ts 的 loadAndValidateCookie 功能
|
8
|
+
* 需要驗證:驗證流程是否符合抖音最新要求
|
9
|
+
*/
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
11
|
+
exports.loadAndValidateCookie = loadAndValidateCookie;
|
12
|
+
const isValidCookie_1 = require("./isValidCookie");
|
13
|
+
const loadCookie_1 = require("./loadCookie");
|
14
|
+
/**
|
15
|
+
* 從檔案讀取 Cookie 並驗證有效性
|
16
|
+
* @param cookiePath 可選的 Cookie 檔案路徑
|
17
|
+
* @returns 有效的 Cookie 字串,如無效則返回空字串
|
18
|
+
*
|
19
|
+
* @remarks
|
20
|
+
* 整合了 Cookie 讀取和驗證功能
|
21
|
+
*/
|
22
|
+
async function loadAndValidateCookie(cookiePath) {
|
23
|
+
try {
|
24
|
+
// 從檔案讀取 Cookie
|
25
|
+
const cookie = await (0, loadCookie_1.loadCookie)(cookiePath);
|
26
|
+
if (!cookie) {
|
27
|
+
console.warn('未找到 Cookie 檔案或檔案為空');
|
28
|
+
return '';
|
29
|
+
}
|
30
|
+
// 驗證 Cookie 是否有效
|
31
|
+
const isValid = await (0, isValidCookie_1.isValidCookie)(cookie);
|
32
|
+
if (!isValid) {
|
33
|
+
console.warn('Cookie 已失效,需要重新登入');
|
34
|
+
return '';
|
35
|
+
}
|
36
|
+
console.log('已載入有效的 Cookie');
|
37
|
+
return cookie;
|
38
|
+
}
|
39
|
+
catch (error) {
|
40
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
41
|
+
console.error('驗證 Cookie 時發生錯誤:', errorMessage);
|
42
|
+
return '';
|
43
|
+
}
|
44
|
+
}
|
45
|
+
//# sourceMappingURL=loadAndValidateCookie.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"loadAndValidateCookie.js","sourceRoot":"","sources":["../../../../src/douyin/auth/loadAndValidateCookie.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AAaH,sDAyBC;AApCD,mDAAgD;AAChD,6CAA0C;AAE1C;;;;;;;GAOG;AACI,KAAK,UAAU,qBAAqB,CAAC,UAAmB;IAC7D,IAAI,CAAC;QACH,eAAe;QACf,MAAM,MAAM,GAAG,MAAM,IAAA,uBAAU,EAAC,UAAU,CAAC,CAAC;QAE5C,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;YACnC,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,iBAAiB;QACjB,MAAM,OAAO,GAAG,MAAM,IAAA,6BAAa,EAAC,MAAM,CAAC,CAAC;QAE5C,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YAClC,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QAC7B,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5E,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,YAAY,CAAC,CAAC;QAChD,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
/**
|
2
|
+
* 抖音 Cookie 讀取模組
|
3
|
+
* 從檔案讀取 Cookie
|
4
|
+
*
|
5
|
+
* @remarks
|
6
|
+
* 參考來源:此功能改寫自原本存放於 src/auth/cookie-storage.ts 的功能
|
7
|
+
* 需要驗證:文件操作是否符合不同平台標準
|
8
|
+
*/
|
9
|
+
/**
|
10
|
+
* 從檔案讀取 Cookie
|
11
|
+
* @param cookiePath 可選的 Cookie 檔案路徑
|
12
|
+
* @returns Cookie 字串,如檔案不存在則返回空字串
|
13
|
+
*
|
14
|
+
* @remarks
|
15
|
+
* 基本的文件系統操作
|
16
|
+
*/
|
17
|
+
export declare function loadCookie(cookiePath?: string): Promise<string>;
|
@@ -0,0 +1,79 @@
|
|
1
|
+
"use strict";
|
2
|
+
/**
|
3
|
+
* 抖音 Cookie 讀取模組
|
4
|
+
* 從檔案讀取 Cookie
|
5
|
+
*
|
6
|
+
* @remarks
|
7
|
+
* 參考來源:此功能改寫自原本存放於 src/auth/cookie-storage.ts 的功能
|
8
|
+
* 需要驗證:文件操作是否符合不同平台標準
|
9
|
+
*/
|
10
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
11
|
+
if (k2 === undefined) k2 = k;
|
12
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
13
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
14
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
15
|
+
}
|
16
|
+
Object.defineProperty(o, k2, desc);
|
17
|
+
}) : (function(o, m, k, k2) {
|
18
|
+
if (k2 === undefined) k2 = k;
|
19
|
+
o[k2] = m[k];
|
20
|
+
}));
|
21
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
22
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
23
|
+
}) : function(o, v) {
|
24
|
+
o["default"] = v;
|
25
|
+
});
|
26
|
+
var __importStar = (this && this.__importStar) || (function () {
|
27
|
+
var ownKeys = function(o) {
|
28
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
29
|
+
var ar = [];
|
30
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
31
|
+
return ar;
|
32
|
+
};
|
33
|
+
return ownKeys(o);
|
34
|
+
};
|
35
|
+
return function (mod) {
|
36
|
+
if (mod && mod.__esModule) return mod;
|
37
|
+
var result = {};
|
38
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
39
|
+
__setModuleDefault(result, mod);
|
40
|
+
return result;
|
41
|
+
};
|
42
|
+
})();
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
44
|
+
exports.loadCookie = loadCookie;
|
45
|
+
const fs = __importStar(require("fs"));
|
46
|
+
const getDefaultCookiePath_1 = require("./getDefaultCookiePath");
|
47
|
+
/**
|
48
|
+
* 從檔案讀取 Cookie
|
49
|
+
* @param cookiePath 可選的 Cookie 檔案路徑
|
50
|
+
* @returns Cookie 字串,如檔案不存在則返回空字串
|
51
|
+
*
|
52
|
+
* @remarks
|
53
|
+
* 基本的文件系統操作
|
54
|
+
*/
|
55
|
+
async function loadCookie(cookiePath) {
|
56
|
+
try {
|
57
|
+
// 如果未提供路徑,使用默認路徑
|
58
|
+
const filePath = cookiePath || (0, getDefaultCookiePath_1.getDefaultCookiePath)();
|
59
|
+
// 嘗試讀取檔案
|
60
|
+
const cookieString = await fs.promises.readFile(filePath, 'utf-8');
|
61
|
+
if (!cookieString || cookieString.trim() === '') {
|
62
|
+
console.warn(`Cookie 檔案 ${filePath} 存在但為空`);
|
63
|
+
return '';
|
64
|
+
}
|
65
|
+
console.log(`已從 ${filePath} 讀取 Cookie`);
|
66
|
+
return cookieString.trim();
|
67
|
+
}
|
68
|
+
catch (error) {
|
69
|
+
// 如果檔案不存在,返回空字串
|
70
|
+
if (error.code === 'ENOENT') {
|
71
|
+
console.warn(`Cookie 檔案不存在: ${cookiePath || (0, getDefaultCookiePath_1.getDefaultCookiePath)()}`);
|
72
|
+
return '';
|
73
|
+
}
|
74
|
+
// 其他錯誤
|
75
|
+
console.error('讀取 Cookie 時發生錯誤:', error);
|
76
|
+
return '';
|
77
|
+
}
|
78
|
+
}
|
79
|
+
//# sourceMappingURL=loadCookie.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"loadCookie.js","sourceRoot":"","sources":["../../../../src/douyin/auth/loadCookie.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaH,gCA0BC;AArCD,uCAAyB;AACzB,iEAA8D;AAE9D;;;;;;;GAOG;AACI,KAAK,UAAU,UAAU,CAAC,UAAmB;IAClD,IAAI,CAAC;QACH,iBAAiB;QACjB,MAAM,QAAQ,GAAG,UAAU,IAAI,IAAA,2CAAoB,GAAE,CAAC;QAEtD,SAAS;QACT,MAAM,YAAY,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAEnE,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YAChD,OAAO,CAAC,IAAI,CAAC,aAAa,QAAQ,QAAQ,CAAC,CAAC;YAC5C,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,MAAM,QAAQ,YAAY,CAAC,CAAC;QACxC,OAAO,YAAY,CAAC,IAAI,EAAE,CAAC;IAC7B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,gBAAgB;QAChB,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACvD,OAAO,CAAC,IAAI,CAAC,iBAAiB,UAAU,IAAI,IAAA,2CAAoB,GAAE,EAAE,CAAC,CAAC;YACtE,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,OAAO;QACP,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;QACzC,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/**
|
2
|
+
* 瀏覽器自動化登入
|
3
|
+
* 提供抖音自動化登入功能
|
4
|
+
*/
|
5
|
+
/**
|
6
|
+
* 登入選項
|
7
|
+
*/
|
8
|
+
export interface LoginOptions {
|
9
|
+
timeout?: number;
|
10
|
+
headless?: boolean;
|
11
|
+
browserType?: 'chromium' | 'firefox' | 'webkit';
|
12
|
+
userAgent?: string;
|
13
|
+
autoCleanup?: boolean;
|
14
|
+
initialCookie?: string;
|
15
|
+
executablePath?: string;
|
16
|
+
userDataDir?: string;
|
17
|
+
}
|
18
|
+
/**
|
19
|
+
* 登入結果 (保持與舊版兼容)
|
20
|
+
*/
|
21
|
+
export interface LoginResult {
|
22
|
+
cookie: string;
|
23
|
+
cleanup: () => Promise<void>;
|
24
|
+
}
|
25
|
+
/**
|
26
|
+
* 登入抖音並獲取 Cookie
|
27
|
+
* 打開瀏覽器進行登入操作,獲取有效的 cookie 字串。
|
28
|
+
* @param savePath 可選的 Cookie 儲存路徑
|
29
|
+
* @param options 登入選項
|
30
|
+
* @returns Promise<string | LoginResult> 如果 autoCleanup 為 true,則只返回 cookie 字串;否則返回包含 cookie 和 cleanup 函數的對象
|
31
|
+
* @throws {LoginError} 如果登入過程中出現錯誤
|
32
|
+
*/
|
33
|
+
export declare function login(savePath?: string, options?: LoginOptions): Promise<string | LoginResult>;
|