From 193f824429f600f3ffee41d67c458b4ee930c873 Mon Sep 17 00:00:00 2001 From: "@wwwjim" Date: Sun, 27 Sep 2020 11:57:51 -0700 Subject: [PATCH] max bucket count on archive to prevent things from getting out of hand --- pages/api/data/archive.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pages/api/data/archive.js b/pages/api/data/archive.js index dc9b1ae8..91775988 100644 --- a/pages/api/data/archive.js +++ b/pages/api/data/archive.js @@ -4,6 +4,8 @@ import * as Social from "~/node_common/social"; import { v4 as uuid } from "uuid"; +const MAX_BUCKET_COUNT = 10; + export default async (req, res) => { const id = Utilities.getIdFromCookie(req); if (!id) { @@ -103,6 +105,37 @@ export default async (req, res) => { console.log( `[ encrypted ] making an ${encryptedBucketName} for this archive deal.` ); + + let userBuckets = []; + try { + userBuckets = await buckets.list(); + } catch (e) { + Social.sendTextileSlackMessage({ + file: "/pages/api/data/archive.js", + user: user, + message: e.message, + code: e.code, + functionName: `buckets.list (encrypted)`, + }); + + return res.status(500).send({ + decorator: "BUCKET_SPAWN_VERIFICATION_FAILED_FOR_BUCKET_COUNT", + error: true, + }); + } + + console.log( + `[ encrypted ] user has ${ + userBuckets.length + } out of ${MAX_BUCKET_COUNT} used.` + ); + if (userBuckets.length >= MAX_BUCKET_COUNT) { + return res.status(500).send({ + decorator: "TOO_MANY_BUCKETS", + error: true, + }); + } + try { const newBucket = await buckets.create( encryptedBucketName,