Created
October 5, 2023 16:48
-
-
Save optlsnd/47407258ab54fc9d31bd5e884bbf11e7 to your computer and use it in GitHub Desktop.
Store not nstored files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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