Skip to content

Commit e3aabb4

Browse files
committed
refactor: update XLSX import to use named imports and add API key authentication option
1 parent 539999d commit e3aabb4

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

examples/test-document-to-markdown-endpoints.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ async function testDocxToMarkdown() {
6565
method: 'POST',
6666
headers: {
6767
'Content-Type': 'application/json',
68-
'Authorization': 'Bearer YOUR_AUTH_TOKEN' // Replace with actual token
68+
// Use one of the following authentication methods:
69+
// 1. For JWT tokens:
70+
// 'Authorization': 'Bearer YOUR_JWT_TOKEN', // Replace with actual JWT token
71+
// 2. For API keys (comment out the Authorization header above and use this instead):
72+
'X-API-Key': 'YOUR_API_KEY' // Replace with actual API key (starts with pfs_)
6973
},
7074
body: JSON.stringify({
7175
file: testDocxBase64,
@@ -99,7 +103,11 @@ async function testDocToMarkdown() {
99103
method: 'POST',
100104
headers: {
101105
'Content-Type': 'application/json',
102-
'Authorization': 'Bearer YOUR_AUTH_TOKEN' // Replace with actual token
106+
// Use one of the following authentication methods:
107+
// 1. For JWT tokens:
108+
// 'Authorization': 'Bearer YOUR_JWT_TOKEN', // Replace with actual JWT token
109+
// 2. For API keys (comment out the Authorization header above and use this instead):
110+
'X-API-Key': 'YOUR_API_KEY' // Replace with actual API key (starts with pfs_)
103111
},
104112
body: JSON.stringify({
105113
file: testDocBase64,
@@ -133,7 +141,11 @@ async function testEpubToMarkdown() {
133141
method: 'POST',
134142
headers: {
135143
'Content-Type': 'application/json',
136-
'Authorization': 'Bearer YOUR_AUTH_TOKEN' // Replace with actual token
144+
// Use one of the following authentication methods:
145+
// 1. For JWT tokens:
146+
// 'Authorization': 'Bearer YOUR_JWT_TOKEN', // Replace with actual JWT token
147+
// 2. For API keys (comment out the Authorization header above and use this instead):
148+
'X-API-Key': 'YOUR_API_KEY' // Replace with actual API key (starts with pfs_)
137149
},
138150
body: JSON.stringify({
139151
file: testEpubBase64,
@@ -167,7 +179,11 @@ async function testTextToMarkdown() {
167179
method: 'POST',
168180
headers: {
169181
'Content-Type': 'application/json',
170-
'Authorization': 'Bearer YOUR_AUTH_TOKEN' // Replace with actual token
182+
// Use one of the following authentication methods:
183+
// 1. For JWT tokens:
184+
// 'Authorization': 'Bearer YOUR_JWT_TOKEN', // Replace with actual JWT token
185+
// 2. For API keys (comment out the Authorization header above and use this instead):
186+
'X-API-Key': 'YOUR_API_KEY' // Replace with actual API key (starts with pfs_)
171187
},
172188
body: JSON.stringify({
173189
file: testTextBase64,
@@ -201,7 +217,11 @@ async function testPptxToMarkdown() {
201217
method: 'POST',
202218
headers: {
203219
'Content-Type': 'application/json',
204-
'Authorization': 'Bearer YOUR_AUTH_TOKEN' // Replace with actual token
220+
// Use one of the following authentication methods:
221+
// 1. For JWT tokens:
222+
// 'Authorization': 'Bearer YOUR_JWT_TOKEN', // Replace with actual JWT token
223+
// 2. For API keys (comment out the Authorization header above and use this instead):
224+
'X-API-Key': 'YOUR_API_KEY' // Replace with actual API key (starts with pfs_)
205225
},
206226
body: JSON.stringify({
207227
file: testPptxBase64,
@@ -235,7 +255,11 @@ async function testXlsxToMarkdown() {
235255
method: 'POST',
236256
headers: {
237257
'Content-Type': 'application/json',
238-
'Authorization': 'Bearer YOUR_AUTH_TOKEN' // Replace with actual token
258+
// Use one of the following authentication methods:
259+
// 1. For JWT tokens:
260+
// 'Authorization': 'Bearer YOUR_JWT_TOKEN', // Replace with actual JWT token
261+
// 2. For API keys (comment out the Authorization header above and use this instead):
262+
'X-API-Key': 'YOUR_API_KEY' // Replace with actual API key (starts with pfs_)
239263
},
240264
body: JSON.stringify({
241265
file: testXlsxBase64,

src/services/xlsx-to-markdown-service.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import path from 'path';
44
import { promisify } from 'util';
55
import { v4 as uuidv4 } from 'uuid';
66
import os from 'os';
7-
import * as XLSX from 'xlsx';
7+
import { read, utils } from 'xlsx/xlsx.mjs';
88

99
const execPromise = promisify(exec);
1010

@@ -29,7 +29,8 @@ export const xlsxToMarkdownService = {
2929
await fs.promises.writeFile(inputPath, xlsxBuffer);
3030

3131
// Read the workbook using xlsx package
32-
const workbook = XLSX.readFile(inputPath);
32+
const buffer = await fs.promises.readFile(inputPath);
33+
const workbook = read(buffer);
3334

3435
// Array to store markdown content from each sheet
3536
const markdownParts = [];
@@ -42,7 +43,7 @@ export const xlsxToMarkdownService = {
4243
const worksheet = workbook.Sheets[sheetName];
4344

4445
// Convert worksheet to CSV
45-
const csvContent = XLSX.utils.sheet_to_csv(worksheet);
46+
const csvContent = utils.sheet_to_csv(worksheet);
4647

4748
// Create temporary files for CSV and Markdown
4849
const csvId = uuidv4();

0 commit comments

Comments
 (0)