Skip to content

Instantly share code, notes, and snippets.

@optlsnd
Created August 30, 2023 16:55
Show Gist options
  • Save optlsnd/e364fc7e2f491bbfe38388176db7ef5a to your computer and use it in GitHub Desktop.
Save optlsnd/e364fc7e2f491bbfe38388176db7ef5a to your computer and use it in GitHub Desktop.
import {
listOfFiles,
deleteFile,
UploadcareSimpleAuthSchema,
paginate,
} from "@uploadcare/rest-client";
// Replace demo API keys with yours
const uploadcareSimpleAuthSchema = new UploadcareSimpleAuthSchema({
publicKey: "demopublickey",
secretKey: "demosecretkey",
});
const paginatedListOfFiles = paginate(listOfFiles);
const pages = paginatedListOfFiles(
{
limit: 1000,
},
{ authSchema: uploadcareSimpleAuthSchema }
);
const USER_ID = 12345; // User ID to delete
for await (const page of pages) {
page.results.forEach(async (file) => {
if (file.metadata?.userId === USER_ID) {
try {
const res = await deleteFile(
{
uuid,
},
{
authSchema: uploadcareSimpleAuthSchema,
}
);
console.log("File deleted: ", res.uuid);
} catch (err) {
throw new Error(err);
}
}
if (Object.keys(file.metadata).length) {
console.log(file.metadata);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment