Created
August 30, 2023 16:55
-
-
Save optlsnd/e364fc7e2f491bbfe38388176db7ef5a to your computer and use it in GitHub Desktop.
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, | |
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