yuanjiajun commited on
Commit ·
63409a4
1
Parent(s): b3d0047
测试
Browse files- Dockerfile +2 -2
- package.json +0 -2
- src/utils/file-utils.ts +6 -10
Dockerfile
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# 使用官方 Node 镜像作为基础镜像
|
| 2 |
-
FROM node:
|
| 3 |
|
| 4 |
# 设置工作目录
|
| 5 |
WORKDIR /usr/src/app
|
|
@@ -11,7 +11,7 @@ RUN mkdir -p /usr/src/app/uploads && chown -R node:node /usr/src/app/uploads
|
|
| 11 |
COPY package*.json ./
|
| 12 |
|
| 13 |
# 安装项目依赖
|
| 14 |
-
RUN npm install --registry=https://registry.npmmirror.com
|
| 15 |
|
| 16 |
# 复制项目文件到工作目录
|
| 17 |
COPY . .
|
|
|
|
| 1 |
# 使用官方 Node 镜像作为基础镜像
|
| 2 |
+
FROM node:14
|
| 3 |
|
| 4 |
# 设置工作目录
|
| 5 |
WORKDIR /usr/src/app
|
|
|
|
| 11 |
COPY package*.json ./
|
| 12 |
|
| 13 |
# 安装项目依赖
|
| 14 |
+
RUN npm install --registry=https://registry.npmmirror.com
|
| 15 |
|
| 16 |
# 复制项目文件到工作目录
|
| 17 |
COPY . .
|
package.json
CHANGED
|
@@ -19,7 +19,6 @@
|
|
| 19 |
"axios": "^1.7.7",
|
| 20 |
"chardet": "^2.0.0",
|
| 21 |
"encoding": "^0.1.13",
|
| 22 |
-
"fetch": "^1.1.0",
|
| 23 |
"fs": "0.0.1-security",
|
| 24 |
"html-docx-js": "^0.3.1",
|
| 25 |
"koa": "^2.15.3",
|
|
@@ -27,7 +26,6 @@
|
|
| 27 |
"koa-bodyparser": "^4.4.1",
|
| 28 |
"koa-router": "^13.0.1",
|
| 29 |
"koa-static": "^5.0.0",
|
| 30 |
-
"node-fetch": "^3.3.2",
|
| 31 |
"nodemon": "^3.1.7",
|
| 32 |
"sharp": "^0.33.5",
|
| 33 |
"tsc-alias": "^1.8.10",
|
|
|
|
| 19 |
"axios": "^1.7.7",
|
| 20 |
"chardet": "^2.0.0",
|
| 21 |
"encoding": "^0.1.13",
|
|
|
|
| 22 |
"fs": "0.0.1-security",
|
| 23 |
"html-docx-js": "^0.3.1",
|
| 24 |
"koa": "^2.15.3",
|
|
|
|
| 26 |
"koa-bodyparser": "^4.4.1",
|
| 27 |
"koa-router": "^13.0.1",
|
| 28 |
"koa-static": "^5.0.0",
|
|
|
|
| 29 |
"nodemon": "^3.1.7",
|
| 30 |
"sharp": "^0.33.5",
|
| 31 |
"tsc-alias": "^1.8.10",
|
src/utils/file-utils.ts
CHANGED
|
@@ -40,21 +40,17 @@ export function bufferToBase64ImageSrc(buffer: Buffer, mimeType: string): string
|
|
| 40 |
export async function downloadDocx(url: string, fileName: string) {
|
| 41 |
try {
|
| 42 |
// 发起 GET 请求下载文件
|
| 43 |
-
const response = await
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
// 确保响应头中的 Content-Type 为 DOCX 文件
|
| 48 |
-
const contentType = response.headers
|
| 49 |
if (contentType !== 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') {
|
| 50 |
throw new Error(`Unexpected content type: ${contentType}`);
|
| 51 |
}
|
| 52 |
|
| 53 |
-
|
| 54 |
-
const blob = await response.blob();
|
| 55 |
-
// 将 Blob 转换为 ArrayBuffer
|
| 56 |
-
const arrayBuffer = await blob.arrayBuffer();
|
| 57 |
-
// 将 ArrayBuffer 转换为 Buffer
|
| 58 |
const buffer = Buffer.from(arrayBuffer);
|
| 59 |
// 获取用户的桌面路径
|
| 60 |
const desktopPath = path.join(os.homedir(), 'Desktop');
|
|
|
|
| 40 |
export async function downloadDocx(url: string, fileName: string) {
|
| 41 |
try {
|
| 42 |
// 发起 GET 请求下载文件
|
| 43 |
+
const response = await axios.get(url, {
|
| 44 |
+
responseType: 'arraybuffer', // 设置响应类型为 blob
|
| 45 |
+
});
|
| 46 |
+
|
| 47 |
// 确保响应头中的 Content-Type 为 DOCX 文件
|
| 48 |
+
const contentType = response.headers['content-type'];
|
| 49 |
if (contentType !== 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') {
|
| 50 |
throw new Error(`Unexpected content type: ${contentType}`);
|
| 51 |
}
|
| 52 |
|
| 53 |
+
const arrayBuffer = response.data as ArrayBuffer;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
const buffer = Buffer.from(arrayBuffer);
|
| 55 |
// 获取用户的桌面路径
|
| 56 |
const desktopPath = path.join(os.homedir(), 'Desktop');
|