diff --git a/feishu-pages/package.json b/feishu-pages/package.json index 429fcbf..3a4d142 100644 --- a/feishu-pages/package.json +++ b/feishu-pages/package.json @@ -1,6 +1,6 @@ { "name": "feishu-pages", - "version": "0.7.4", + "version": "0.7.6", "description": "Generate Feishu Wiki into a Markdown for work with Static Page Generators.", "repository": { "url": "https://github.com/longbridgeapp/feishu-pages" diff --git a/feishu-pages/src/feishu.ts b/feishu-pages/src/feishu.ts index 816e351..83298b9 100644 --- a/feishu-pages/src/feishu.ts +++ b/feishu-pages/src/feishu.ts @@ -242,7 +242,12 @@ const isValidCacheExist = (cacheFilePath: string) => { * @param localPath * @returns */ -export const feishuDownload = async (fileToken: string, localPath: string, type: 'file' | 'image' | 'board') => { +export const feishuDownload = async ( + fileToken: string, + localPath: string, + type: 'file' | 'image' | 'board', + hasDocCache: boolean, +) => { const cacheFilePath = path.join(CACHE_DIR, fileToken); const cacheFileMetaPath = path.join(CACHE_DIR, `${fileToken}.headers.json`); fs.mkdirSync(CACHE_DIR, { recursive: true }); @@ -250,7 +255,7 @@ export const feishuDownload = async (fileToken: string, localPath: string, type: let res: { data?: fs.ReadStream; headers?: Record } = {}; let hasCache = false; // The board file can't be cached, because we can't get the content-length - let canCache = type != 'board'; + let canCache = type != 'board' || hasDocCache; let cacheFileHeaders = {}; try { diff --git a/feishu-pages/src/index.ts b/feishu-pages/src/index.ts index f7d4b6a..9649d0a 100644 --- a/feishu-pages/src/index.ts +++ b/feishu-pages/src/index.ts @@ -119,9 +119,7 @@ const fetchDocAndWriteFile = async ( let out = ''; out += metaInfo + '\n\n'; - if (!doc.hasCache) { - content = await downloadFiles(content, fileTokens, folder); - } + content = await downloadFiles(content, fileTokens, doc.hasCache); out += content; @@ -149,7 +147,7 @@ const fetchDocAndWriteFile = async ( const downloadFiles = async ( content: string, fileTokens: Record, - docFolder: string + hasDocCache: boolean, ) => { if (SKIP_ASSETS) { console.info('skip assets download.'); @@ -165,7 +163,8 @@ const downloadFiles = async ( const filePath = await feishuDownload( fileToken, path.join(path.join(DOCS_DIR, 'assets'), base_filename), - fileTokens[fileToken].type + fileTokens[fileToken].type, + hasDocCache, ); if (!filePath) { continue;