-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add clear images, so that Judges can clear the image storage
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
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
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")}`, | ||
}); | ||
} | ||
}; |