Skip to content

Commit

Permalink
feat: validation of file size #3
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiomrebelo committed Jun 19, 2023
1 parent 74d0d14 commit cbcde28
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 11 deletions.
27 changes: 22 additions & 5 deletions src/rollup-project/build/bundle.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,15 @@ const resultsContainer = () => {
lexiconResultsContainer.appendChild(lexiconGlobalResult);
mainSection.appendChild(lexiconResultsContainer);


const inputImagesLabel = headline("h3", "Input Images", ["d-none"], "input-images-headline");
mainSection.appendChild(inputImagesLabel);

const inputImagesContainer = container("div", ["mt-4", "d-none"], "input-images");




mainSection.appendChild(inputImagesContainer);

containerOuter.appendChild(mainSection);
Expand Down Expand Up @@ -281,6 +289,8 @@ class App {
this.text = null;
this.screen = 0;

this.IMAGE_SIZE = 1024; // in kb

this.init();
}

Expand Down Expand Up @@ -383,13 +393,13 @@ class App {
for (let i = 0; i<files.length; i++) {
const img = new Image();
img.src = files[i];
img.classList.add('d-inline-block');
if (i > 0) img.classList.add(`mx-2`);
img.classList.add('d-inline-block', `mb-2`, `mr-2`);
img.style.height = `100px`;
img.style.width = `auto`;
imgContainer.appendChild(img);
}
imgContainer.classList.replace('d-none', 'd-block');
document.getElementById("input-images-headline").classList.replace('d-none', 'd-block');
}

_readImages = async (files) => {
Expand All @@ -405,10 +415,17 @@ class App {
});
};
for (let i = 0; i < files.length; i++) {
if (files[i].type.includes('image')) {
res.push(getBase64(files[i]));
console.log (`size size: ${Math.round(files[i].size/1024)}`);
if (files[i].size/1024 < this.IMAGE_SIZE) {
// if (files[i].size)
if (files[i].type.includes('image')) {
res.push(getBase64(files[i]));
} else {
err.push(files[i].name);
}
} else {
err.push (files[i].name);
// handler
console.error (`size bigger than ${this.IMAGE_SIZE}`);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/rollup-project/build/bundle.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/rollup-project/build/bundle.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/rollup-project/build/bundle.min.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/rollup-project/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ export const resultsContainer = () => {
lexiconResultsContainer.appendChild(lexiconGlobalResult);
mainSection.appendChild(lexiconResultsContainer);


const inputImagesLabel = headline("h3", "Input Images", ["d-none"], "input-images-headline");
mainSection.appendChild(inputImagesLabel);

const inputImagesContainer = container("div", ["mt-4", "d-none"], "input-images");




mainSection.appendChild(inputImagesContainer);

containerOuter.appendChild(mainSection);
Expand Down
4 changes: 4 additions & 0 deletions src/rollup-project/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
html {
background-color: var(--main-bg-color);
font-family: monospace;
}

.mr-2 {
margin-right: .5rem!important;
}
19 changes: 14 additions & 5 deletions src/rollup-project/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export default class App {
this.text = null;
this.screen = 0;

this.IMAGE_SIZE = 1024; // in kb

this.init();
}

Expand Down Expand Up @@ -121,13 +123,13 @@ export default class App {
for (let i = 0; i<files.length; i++) {
const img = new Image();
img.src = files[i];
img.classList.add('d-inline-block');
if (i > 0) img.classList.add(`mx-2`);
img.classList.add('d-inline-block', `mb-2`, `mr-2`);
img.style.height = `100px`;
img.style.width = `auto`;
imgContainer.appendChild(img);
}
imgContainer.classList.replace('d-none', 'd-block');
document.getElementById("input-images-headline").classList.replace('d-none', 'd-block');
}

_readImages = async (files) => {
Expand All @@ -143,10 +145,17 @@ export default class App {
});
};
for (let i = 0; i < files.length; i++) {
if (files[i].type.includes('image')) {
res.push(getBase64(files[i]));
console.log (`size size: ${Math.round(files[i].size/1024)}`)
if (files[i].size/1024 < this.IMAGE_SIZE) {
// if (files[i].size)
if (files[i].type.includes('image')) {
res.push(getBase64(files[i]));
} else {
err.push(files[i].name);
}
} else {
err.push (files[i].name);
// handler
console.error (`size bigger than ${this.IMAGE_SIZE}`);
}
}

Expand Down

0 comments on commit cbcde28

Please sign in to comment.