Skip to content

Commit

Permalink
refactor: improve upload logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sinedied committed May 24, 2024
1 parent bbf6b42 commit 1f8acb1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions scripts/upload-documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import path from 'node:path';
// ```
async function uploadDocuments(apiUrl, dataFolder) {
try {
const uploadUrl = `${apiUrl}/api/documents`;
const files = await fs.readdir(dataFolder);
console.log(`Uploading documents to: ${uploadUrl}`);

/* eslint-disable no-await-in-loop */
for (const file of files) {
Expand All @@ -20,14 +22,14 @@ async function uploadDocuments(apiUrl, dataFolder) {
const formData = new FormData();
formData.append('file', new File(blobParts, file));

const response = await fetch(`${apiUrl}/api/documents`, {
const response = await fetch(uploadUrl, {
method: 'post',
body: formData,
});

const responseData = await response.json();
if (response.ok) {
console.log(responseData);
console.log(`${file}: ${responseData.message}`);
} else {
throw new Error(responseData.error);
}
Expand Down

0 comments on commit 1f8acb1

Please sign in to comment.