mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-02-12 02:05:51 +00:00
Merge branch 'feature/gif-repos' into feature/gif-size-limits
This commit is contained in:
commit
66e751a95f
@ -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);
|
||||||
@ -424,6 +426,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 +468,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 +503,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,
|
||||||
|
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