Skip to content

Commit b29c7fc

Browse files
committed
fix(excel-download): 修复Excel文件下载功能
1 parent b083c95 commit b29c7fc

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

Excel2Json.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ global.__dirname = UtilFile.getCurrentDirName(import.meta.url);
1414
(async function () {
1515
// 下载Excel
1616
ProcRmdir(__dirname, './resource')
17-
await ProcDownloadExcel(__dirname, ConfDownload.DocKey, './resource/excel.xlsx')
17+
await ProcDownloadExcel(__dirname, ConfDownload.DocBase, ConfDownload.DocPath, './resource/excel.xlsx')
1818

1919
// 解析Excel
2020
const tlConfs = []

config/download.mjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
const DocId = '121698938513'
2+
13
const DocKey = 'cv47wrxKiz7b'
24

5+
const DocBase = process.env.TMK_DOC_BASE
6+
7+
const DocPath = './kdocs/Translation-Unity.xlsx'
8+
39
export default {
4-
DocKey
10+
DocId,
11+
DocKey,
12+
DocBase,
13+
DocPath
514
}

pnpm-lock.yaml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proc/download-excel.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import _ from 'lodash'
2-
import Path from 'path'
1+
import Path from 'node:path'
2+
import URL from 'node:url'
33
import Axios from 'axios'
44
import FsExtra from 'fs-extra'
55

6-
export default async (base = process.cwd(), docKey = '', target = '') => {
7-
if (!docKey) { throw new Error('[DOWN-EXCEL] DocKey is empty') }
6+
export default async (base = process.cwd(), docBase = '', docPath = '', target = '') => {
7+
if (!docBase) { throw new Error('[DOWN-EXCEL] DocBase is empty') }
8+
if (!docPath) { throw new Error('[DOWN-EXCEL] DocPath is empty') }
89
if (!target) { throw new Error('[DOWN-EXCEL] Target is empty') }
910

10-
const downloadMeta = await Axios.get(`https://drive.kdocs.cn/api/v3/links/${docKey}/download?isblocks=false`).then(res => res.data).catch(() => ({}))
11-
const downloadUrl = _.get(downloadMeta, 'fileinfo.url', '')
11+
const downloadUrl = URL.resolve(docBase, docPath)
1212
const excelPath = Path.resolve(base, target)
1313

1414
return await Promise

0 commit comments

Comments
 (0)