From 5868222618a57d104dfb2a8e3a9784a495a35551 Mon Sep 17 00:00:00 2001 From: "Michael R." Date: Fri, 16 Aug 2024 19:46:30 +0000 Subject: [PATCH] Add clear images, so that Judges can clear the image storage --- commands/clear_images.js | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 commands/clear_images.js diff --git a/commands/clear_images.js b/commands/clear_images.js new file mode 100644 index 0000000..c4d99d5 --- /dev/null +++ b/commands/clear_images.js @@ -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")}`, + }); + } +};