Skip to content

Instantly share code, notes, and snippets.

@optlsnd
Created October 5, 2023 16:48
Show Gist options
  • Save optlsnd/47407258ab54fc9d31bd5e884bbf11e7 to your computer and use it in GitHub Desktop.
Save optlsnd/47407258ab54fc9d31bd5e884bbf11e7 to your computer and use it in GitHub Desktop.
Store not nstored files
import {
listOfFiles,
storeFiles,
UploadcareSimpleAuthSchema,
paginate,
} from "@uploadcare/rest-client";
const uploadcareSimpleAuthSchema = new UploadcareSimpleAuthSchema({
publicKey: "YOUR_PUBLIC_KEY",
secretKey: "YOUR_SECRET_KEY",
});
const startDate = "2023-10-04"; // List files starting this date, YYYY-MM-DD
const paginatedListOfFiles = paginate(listOfFiles);
const pages = paginatedListOfFiles(
{
removed: false, // Don't list removed files
stored: false, // List only not stored files
limit: 100,
from: new Date(startDate).toISOString(),
},
{ authSchema: uploadcareSimpleAuthSchema }
);
let storedTotal = 0;
for await (const page of pages) {
const uuids = page.results.map((file) => file.uuid);
try {
const result = await storeFiles(
{
uuids,
},
{ authSchema: uploadcareSimpleAuthSchema }
);
storedTotal += result.result.length;
console.clear();
console.log("Stored total: ", storedTotal);
} catch (e) {
throw new Error(e);
}
}
{
"name": "store-files",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@uploadcare/rest-client": "^6.6.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment