Skip to content

Commit

Permalink
Fix large collections upload (#26)
Browse files Browse the repository at this point in the history
* Add chunk length limit (#25)

* Fix create collection loading on zero cooldown
  • Loading branch information
nikitayutanov authored Mar 4, 2024
1 parent 210bcfa commit b11996f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function CreateSimpleCollectionModal({ close }: Pick<ModalProps, 'close'>) {

const getNftsPayload = async (nfts: NFT[]) => {
const images = nfts.map(({ file }) => file);
const chunks = getFileChunks(images, getBytes(MAX.SIZE_MB.NFTS_CHUNK));
const chunks = getFileChunks(images, getBytes(MAX.SIZE_MB.NFTS_CHUNK), MAX.FILES_PER_CHUNK);
const urls: string[] = [];

for (const chunk of chunks) {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/features/create-simple-collection/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const IMAGE_TYPES_ACCEPT = IMAGE_TYPES.join(', ');

const MAX = {
NFTS_COUNT: 10000,
FILES_PER_CHUNK: 50,

SIZE_MB: {
IMAGE: 5,
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/features/create-simple-collection/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ function getBytes(mb: number) {

const getFileUrl = (file: File) => URL.createObjectURL(file);

const getFileChunks = (files: File[], chunkSizeBytes: number) => {
const getFileChunks = (files: File[], chunkSizeBytes: number, maxFilesPerChunk: number) => {
const chunks: File[][] = [];
let chunk: File[] = [];
let chunkSize = 0;

files.forEach((file) => {
const potentialChunkSize = chunkSize + file.size;

if (potentialChunkSize > chunkSizeBytes) {
if (chunk.length === maxFilesPerChunk || potentialChunkSize > chunkSizeBytes) {
chunks.push(chunk);
chunk = [];
chunkSize = 0;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/create-collection/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ function useLastCollection() {
function useCreateCountdown() {
const { marketplace } = useMarketplace();
const { config, admins } = marketplace || {};
const isConfigReady = Boolean(config);
const msBetweenCollections = Number(config?.timeBetweenCreateCollections || '0');
const isConfigReady = Boolean(msBetweenCollections);

const { account } = useAccount();
const isAdmin = admins?.includes(account?.decodedAddress || '');
Expand Down

0 comments on commit b11996f

Please sign in to comment.