Skip to content

Commit

Permalink
Add clear images, so that Judges can clear the image storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic-R committed Aug 16, 2024
1 parent 403fed1 commit 5868222
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions commands/clear_images.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require("dotenv").config();

const blobServiceClient = BlobServiceClient.fromConnectionString(
process.env.AZURE_STORAGE_CONNECTION_STRING
);
const containerClient = blobServiceClient.getContainerClient(
process.env.CONTAINER_NAME
);

module.exports = {
command: {
name: "cleardatabase",
description: "Löscht PERMANENT den Inhalt des Bild-Speichers",
options: [
{
name: "sure",
description: "Bist du sicher, dass du den Speicher löschen willst?",
type: 5,
required: true,
},
{
name: "reason",
description: "Grund für die Löschung des Speichers.",
type: 3,
required: true,
}
],
},
run: async (client, interaction, prisma) => {
if (interaction.options.getBoolean("sure") === false) {
return interaction.reply({
content: "Du musst sicherstellen, dass du die Datenbank wirklich löschen möchtest.",
ephemeral: true,
});
}

const blobs = containerClient.listBlobsFlat();
console.log(blobs)
for await (const blob of blobs) {
if(blob.name.startsWith("wichtig/")) return;
console.log(`Blob ${i++}: ${blob.name}`);
await containerClient.deleteBlob(blob.name, {deleteSnapshots: "include"});
}

return interaction.reply({
content: `Die Gesamtheit von https://${process.env.CDN_URL}/${process.env.CONTAINER_NAME}/ wurde geleert. Grund: ${interaction.options.getString("reason")}`,
});
}
};

0 comments on commit 5868222

Please sign in to comment.