Hi there,
My code below searches for all images in one of my wix mediaManager files, and compares it with the name of an image in a database. For the code below I decided to put the name of an image in order to test the code. If I code for a limit of 1000 images, up to 3000 it works perfectly. But for a limit of 17,000 images it unfortunately does not work.
Maybe there would be a solution for me to filter the search in the image file with only the name of the image in order to have only the information of a single image rather than 17,000 a bit like for the .contains jquery collections
Cordially
Back-end code :
import { mediaManager } from 'wix-media-backend';
const filters = {
parentFolderId: "ab0f1603bc1744259d9044128973832f"
};
const sorting = {
order: "asc",
field: "originalFileName"
};
const paging1 = {
limit: 1000,
skip: 0
};
const paging2 = {
limit: 1000,
skip: 1000
};
const paging3 = {
limit: 1000,
skip: 2000
};
const paging4 = {
limit: 1000,
skip: 3000
};
const paging5 = {
limit: 1000,
skip: 4000
};
const paging6 = {
limit: 1000,
skip: 5000
};
const paging7 = {
limit: 1000,
skip: 6000
};
const paging8 = {
limit: 1000,
skip: 7000
};
const paging9 = {
limit: 1000,
skip: 8000
};
const paging10 = {
limit: 1000,
skip: 9000
};
const paging11 = {
limit: 1000,
skip: 10000
};
const paging12 = {
limit: 1000,
skip: 11000
};
const paging13 = {
limit: 1000,
skip: 12000
};
const paging14 = {
limit: 1000,
skip: 13000
};
const paging15 = {
limit: 1000,
skip: 14000
};
const paging16 = {
limit: 1000,
skip: 15000
};
const paging17 = {
limit: 1000,
skip: 1000
};
export function myListFilesFunction() {
return Promise.all([
mediaManager.listFiles(filters, sorting, paging1),
mediaManager.listFiles(filters, sorting, paging2),
mediaManager.listFiles(filters, sorting, paging3),
mediaManager.listFiles(filters, sorting, paging4),
mediaManager.listFiles(filters, sorting, paging5),
mediaManager.listFiles(filters, sorting, paging6),
mediaManager.listFiles(filters, sorting, paging7),
mediaManager.listFiles(filters, sorting, paging8),
mediaManager.listFiles(filters, sorting, paging9),
mediaManager.listFiles(filters, sorting, paging10),
mediaManager.listFiles(filters, sorting, paging11),
mediaManager.listFiles(filters, sorting, paging12),
mediaManager.listFiles(filters, sorting, paging13),
mediaManager.listFiles(filters, sorting, paging14),
mediaManager.listFiles(filters, sorting, paging15),
mediaManager.listFiles(filters, sorting, paging16),
mediaManager.listFiles(filters, sorting, paging17)
])
.then((myFiles) => {
const cachemyFiles = { items: [] }
for (const resultmyFiles of myFiles) {
cachemyFiles.items = cachemyFiles.items.concat(resultmyFiles);
console.log("cachemyFiles.items" + JSON.stringify(cachemyFiles.items))
}
return cachemyFiles.items;
})
.catch((error) => {
console.error(error);
});
}
Front end code:
import {fetch} from 'wix-fetch';
import {getJSON} from 'wix-fetch';
import {getUFvalue} from 'backend/Football.jsw';
import {multiply} from 'backend/Football.jsw';
import wixData from 'wix-data';
import wixwindow from 'wix-window';
import {myListFilesFunction} from 'backend/aModule-1.jsw'
$w.onReady(function () {
wixData.query("Media/Folders")
.limit(1000)
.find()
.then( (results) => {
console.log("results: " + JSON.stringify(results))
} );
});
$w.onReady(async function () {
var name = "257100" + ".png"
var arrName = []
const resultsmyListFilesFunction = await myListFilesFunction()
const xLen = resultsmyListFilesFunction.length
console.log("TEST LEN" + xLen);
for (let i=0; i < xLen; i++) {
const originalFileName = resultsmyListFilesFunction[i].originalFileName
if (name === String(originalFileName)) {
console.log("Name : " + name + "originalFileName : " + originalFileName)
arrName.push(originalFileName)
}
}
console.log("ResFinal : " + arrName)
})