Added gif size check
This commit is contained in:
parent
14c52e3ce4
commit
a3f2352bcd
@ -191,7 +191,9 @@
|
|||||||
"gchange23": "Your gif collection cannot contain two gifs with the same name!",
|
"gchange23": "Your gif collection cannot contain two gifs with the same name!",
|
||||||
"gchange24": "This collection name is already taken. Try another name!",
|
"gchange24": "This collection name is already taken. Try another name!",
|
||||||
"gchange25": "GIF (click to view)",
|
"gchange25": "GIF (click to view)",
|
||||||
"gchange26": "A name is needed to access and send GIF files"
|
"gchange26": "A name is needed to access and send GIF files",
|
||||||
|
"gchange27": "The gif collection size is over 25mb! Please try again!",
|
||||||
|
"gchange28": "Each gif in the collection cannot be over 0.7mb! Please try again!"
|
||||||
},
|
},
|
||||||
"startminting": {
|
"startminting": {
|
||||||
"smchange1": "Cannot fetch minting accounts",
|
"smchange1": "Cannot fetch minting accounts",
|
||||||
|
@ -7,6 +7,7 @@ import ShortUniqueId from 'short-unique-id';
|
|||||||
import {publishData} from '../../../utils/publish-image.js';
|
import {publishData} from '../../../utils/publish-image.js';
|
||||||
import {translate, get} from 'lit-translate';
|
import {translate, get} from 'lit-translate';
|
||||||
import {gifExplorerStyles} from './ChatGifs-css.js';
|
import {gifExplorerStyles} from './ChatGifs-css.js';
|
||||||
|
import { bytesToMegabytes } from '../../../utils/bytesToMegabytes.js';
|
||||||
import './ChatGifsExplore.js';
|
import './ChatGifsExplore.js';
|
||||||
import '../ImageComponent.js';
|
import '../ImageComponent.js';
|
||||||
import '@vaadin/tooltip';
|
import '@vaadin/tooltip';
|
||||||
@ -391,6 +392,7 @@ setOpenGifModal: { attribute: false }
|
|||||||
return {
|
return {
|
||||||
file,
|
file,
|
||||||
name: file.name,
|
name: file.name,
|
||||||
|
size: file.size
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
const removedExtensions = this.removeDotGIF(mapGifs);
|
const removedExtensions = this.removeDotGIF(mapGifs);
|
||||||
@ -398,6 +400,7 @@ setOpenGifModal: { attribute: false }
|
|||||||
}
|
}
|
||||||
|
|
||||||
async uploadGifCollection() {
|
async uploadGifCollection() {
|
||||||
|
console.log(this.gifsToBeAdded);
|
||||||
if (!this.newCollectionName) {
|
if (!this.newCollectionName) {
|
||||||
parentEpml.request('showSnackBar', get('gifs.gchange8'));
|
parentEpml.request('showSnackBar', get('gifs.gchange8'));
|
||||||
return;
|
return;
|
||||||
@ -424,6 +427,37 @@ setOpenGifModal: { attribute: false }
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function validateGifSizes(gifs) {
|
||||||
|
const maxSizeInMB = 0.7;
|
||||||
|
const invalidGifs = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < gifs.length; i++) {
|
||||||
|
const gif = gifs[i];
|
||||||
|
const gifSize = gif.size;
|
||||||
|
|
||||||
|
const gifSizeMB = bytesToMegabytes(gifSize);
|
||||||
|
|
||||||
|
if (gifSizeMB > maxSizeInMB) {
|
||||||
|
invalidGifs.push(gif);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (invalidGifs.length > 0) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let validatedSize = validateGifSizes(this.gifsToBeAdded);
|
||||||
|
|
||||||
|
if (!validatedSize) {
|
||||||
|
parentEpml.request('showSnackBar', get('gifs.gchange28'));
|
||||||
|
this.isLoading = false;
|
||||||
|
this.setGifsLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
function validateDuplicateGifNames(arr) {
|
function validateDuplicateGifNames(arr) {
|
||||||
let names = [];
|
let names = [];
|
||||||
for (let i = 0; i < arr.length; i++) {
|
for (let i = 0; i < arr.length; i++) {
|
||||||
@ -435,9 +469,9 @@ setOpenGifModal: { attribute: false }
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = validateDuplicateGifNames(this.gifsToBeAdded);
|
let validatedNames = validateDuplicateGifNames(this.gifsToBeAdded);
|
||||||
|
|
||||||
if (!result) {
|
if (!validatedNames) {
|
||||||
parentEpml.request('showSnackBar', get('gifs.gchange23'));
|
parentEpml.request('showSnackBar', get('gifs.gchange23'));
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
this.setGifsLoading(false);
|
this.setGifsLoading(false);
|
||||||
@ -470,8 +504,16 @@ setOpenGifModal: { attribute: false }
|
|||||||
|
|
||||||
const zipFileBlob = await zipFileWriter.getData();
|
const zipFileBlob = await zipFileWriter.getData();
|
||||||
|
|
||||||
const blobTobase = await blobToBase64(zipFileBlob);
|
const zipSize = bytesToMegabytes(zipFileBlob.size);
|
||||||
|
|
||||||
|
if (zipSize > 10) {
|
||||||
|
parentEpml.request('showSnackBar', get('gifs.gchange27'));
|
||||||
|
this.isLoading = false;
|
||||||
|
this.setGifsLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const blobTobase = await blobToBase64(zipFileBlob);
|
||||||
|
|
||||||
await publishData({
|
await publishData({
|
||||||
registeredName: userName,
|
registeredName: userName,
|
||||||
@ -562,6 +604,7 @@ setOpenGifModal: { attribute: false }
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
console.log(5, "chat gifs here");
|
||||||
return html`
|
return html`
|
||||||
<div class="gifs-container">
|
<div class="gifs-container">
|
||||||
<div class="gif-explorer-container">
|
<div class="gif-explorer-container">
|
||||||
|
3
qortal-ui-plugins/plugins/utils/bytesToMegabytes.js
Normal file
3
qortal-ui-plugins/plugins/utils/bytesToMegabytes.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export function bytesToMegabytes(bytes) {
|
||||||
|
return bytes / (1024 * 1024);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user