Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ progress.

#### Sample Excel file structure

| | A | B |
| ------------- | :---------------------------------------------------------------- | :-------------------------|
| 1 | https://www.buraktargac.com/sample_image.gif | optional-sample-file-name |
| 2 | https://www.buraktargac.com/sample_image.png | optional-sample-file-name |
| 3 | https://www.buraktargac.com/sample_image.jpg | |
| . | ... | |
| . | ... | |
| n | Asset URL ( can be any type of file jpg, jpeg, png, txt, doc, etc)| |
| | A | B | C |
| ------------- | :---------------------------------------------------------------- | :-------------------------| :-------------------------|
| 1 | https://www.buraktargac.com/sample_image.gif | optional-sample-file-name | optional-sub-folder-name |
| 2 | https://www.buraktargac.com/sample_image.png | optional-sample-file-name | optional-sub-folder-name |
| 3 | https://www.buraktargac.com/sample_image.jpg | | |
| . | ... | | |
| . | ... | | |
| n | Asset URL ( can be any type of file jpg, jpeg, png, txt, doc, etc)| | |

<br/>

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "excel-parser-processor",
"productName": "Excel Parser Processor",
"version": "1.1.0",
"version": "1.2.0",
"description": "Does the tedious processing over all items of a given excel file by converting the rows to an array and process all items of that array recursively",
"main": "./dist/index.bundle.js",
"scripts": {
Expand Down
13 changes: 8 additions & 5 deletions src/utils/processItems.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import { createWriteStream } from 'fs';
import { createWriteStream, mkdir } from 'fs';
import fetch from 'electron-fetch';
import { URL } from 'url';
import xlsx from 'node-xlsx';
Expand All @@ -19,17 +19,20 @@ const _resetProcessData = () => {

const processItem = async (item, outputPath) => {

const [ itemUrl, newName ] = item;
const [ itemUrl, newName, subFolderName ] = item;
const url = new URL(itemUrl);
const itemName = newName ? `${newName}${path.extname(url.pathname)}` : path.basename(url.pathname);

const response = await fetch(itemUrl);

if (response.ok) {
if (subFolderName) {
await mkdir(`${outputPath}/${subFolderName}`, { recursive: true }, () => {});
}

const dest = createWriteStream(path.join(outputPath, itemName));
response.body.pipe(dest);
const dest = createWriteStream(path.join(outputPath, subFolderName ? subFolderName : '', itemName));

response.body.pipe(dest);
} else {
throw {
status: response.status,
Expand All @@ -44,7 +47,7 @@ const processItems = async (rowItems, outputPath, win) => {
const itemsLength = rowItems.length;

for (let i = 0; i < itemsLength; i += 20) {
const requests = rowItems.slice(i, i + 20).map((item) => {
const requests = rowItems.slice(i, i + 20).map(item => {
return processItem(item, outputPath)
.then(() => {
const unprocessedItems = erroneousItems.length + incompatibleItems.length;
Expand Down