Browse Source

Merge pull request #136 from JustinWesleyFerrari/feature/gif-size-limits

Feature/gif size limits
q-apps
AlphaX-Projects 2 years ago committed by GitHub
parent
commit
194b5070fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      qortal-ui-core/language/us.json
  2. 47
      qortal-ui-plugins/plugins/core/components/ChatGifs/ChatGifs.js
  3. 3
      qortal-ui-plugins/plugins/utils/bytesToMegabytes.js

4
qortal-ui-core/language/us.json

@ -191,7 +191,9 @@
"gchange23": "Your gif collection cannot contain two gifs with the same name!",
"gchange24": "This collection name is already taken. Try another name!",
"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": {
"smchange1": "Cannot fetch minting accounts",

47
qortal-ui-plugins/plugins/core/components/ChatGifs/ChatGifs.js

@ -7,6 +7,7 @@ import ShortUniqueId from 'short-unique-id';
import {publishData} from '../../../utils/publish-image.js';
import {translate, get} from 'lit-translate';
import {gifExplorerStyles} from './ChatGifs-css.js';
import { bytesToMegabytes } from '../../../utils/bytesToMegabytes.js';
import './ChatGifsExplore.js';
import '../ImageComponent.js';
import '@vaadin/tooltip';
@ -391,6 +392,7 @@ setOpenGifModal: { attribute: false }
return {
file,
name: file.name,
size: file.size
};
});
const removedExtensions = this.removeDotGIF(mapGifs);
@ -424,6 +426,37 @@ setOpenGifModal: { attribute: false }
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) {
let names = [];
for (let i = 0; i < arr.length; i++) {
@ -435,9 +468,9 @@ setOpenGifModal: { attribute: false }
return true;
}
let result = validateDuplicateGifNames(this.gifsToBeAdded);
let validatedNames = validateDuplicateGifNames(this.gifsToBeAdded);
if (!result) {
if (!validatedNames) {
parentEpml.request('showSnackBar', get('gifs.gchange23'));
this.isLoading = false;
this.setGifsLoading(false);
@ -470,8 +503,16 @@ setOpenGifModal: { attribute: false }
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({
registeredName: userName,

3
qortal-ui-plugins/plugins/utils/bytesToMegabytes.js

@ -0,0 +1,3 @@
export function bytesToMegabytes(bytes) {
return bytes / (1024 * 1024);
}
Loading…
Cancel
Save