Skip to content

Commit e736823

Browse files
suleymangunduzzSuleyman GUNDUZ
andauthored
Feature/support for sub folders (#46)
* Create sub folders by C(third) column. * Update read.me * Update version. Co-authored-by: Suleyman GUNDUZ <[email protected]>
1 parent 6585677 commit e736823

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ progress.
2424

2525
#### Sample Excel file structure
2626

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

3636
<br/>
3737

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "excel-parser-processor",
33
"productName": "Excel Parser Processor",
4-
"version": "1.1.0",
4+
"version": "1.2.0",
55
"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",
66
"main": "./dist/index.bundle.js",
77
"scripts": {

src/utils/processItems.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'path';
2-
import { createWriteStream } from 'fs';
2+
import { createWriteStream, mkdir } from 'fs';
33
import fetch from 'electron-fetch';
44
import { URL } from 'url';
55
import xlsx from 'node-xlsx';
@@ -19,17 +19,20 @@ const _resetProcessData = () => {
1919

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

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

2626
const response = await fetch(itemUrl);
2727

2828
if (response.ok) {
29+
if (subFolderName) {
30+
await mkdir(`${outputPath}/${subFolderName}`, { recursive: true }, () => {});
31+
}
2932

30-
const dest = createWriteStream(path.join(outputPath, itemName));
31-
response.body.pipe(dest);
33+
const dest = createWriteStream(path.join(outputPath, subFolderName ? subFolderName : '', itemName));
3234

35+
response.body.pipe(dest);
3336
} else {
3437
throw {
3538
status: response.status,
@@ -44,7 +47,7 @@ const processItems = async (rowItems, outputPath, win) => {
4447
const itemsLength = rowItems.length;
4548

4649
for (let i = 0; i < itemsLength; i += 20) {
47-
const requests = rowItems.slice(i, i + 20).map((item) => {
50+
const requests = rowItems.slice(i, i + 20).map(item => {
4851
return processItem(item, outputPath)
4952
.then(() => {
5053
const unprocessedItems = erroneousItems.length + incompatibleItems.length;

0 commit comments

Comments
 (0)