From b90b4aa2c6afd0f8c5267ae19bac2715f4f8225c Mon Sep 17 00:00:00 2001 From: Sergio Gutierrez Villalba Date: Wed, 22 Nov 2023 23:33:08 +0100 Subject: [PATCH] refactor(buckets): remove deprecated endpoints from old API --- lib/server/routes/buckets.js | 230 ----------------------------------- 1 file changed, 230 deletions(-) diff --git a/lib/server/routes/buckets.js b/lib/server/routes/buckets.js index 1be506f7..cab89e57 100644 --- a/lib/server/routes/buckets.js +++ b/lib/server/routes/buckets.js @@ -180,25 +180,6 @@ BucketsRouter.prototype.getBucketById = function (req, res, next) { }); }; -BucketsRouter.prototype.getBucketId = function (req, res, next) { - const Bucket = this.storage.models.Bucket; - - Bucket.findOne({ - userId: req.user.uuid, - name: req.params.name - }, '_id', { lean: true }, function (err, bucket) { - if (err) { - return next(new errors.InternalError(err.message)); - } - - if (!bucket) { - return next(new errors.NotFoundError('Bucket not found')); - } - - res.status(200).send({ id: bucket._id }); - }); -}; - /** * Creates a new bucket for the user * @param {http.IncomingMessage} req @@ -453,84 +434,6 @@ BucketsRouter.prototype.createBucketToken = function (req, res, next) { }); }; - -/** - * Creates a bucket entry from the given frame object - * @param {http.IncomingMessage} req - * @param {http.ServerResponse} res - * @param {Function} next - */ -BucketsRouter.prototype.createEntryFromFrame = function (req, res, next) { - const Frame = this.storage.models.Frame; - const Bucket = this.storage.models.Bucket; - const BucketEntry = this.storage.models.BucketEntry; - - if (req.body.filename && - req.body.filename.length > constants.MAX_BUCKETENTRYNAME) { - return next(new errors.BadRequestError('Maximum bucket entry name')); - } - - analytics.track(req.headers.dnt, { - userId: req.user.uuid, - event: 'File Upload Complete' - }); - - Bucket.findOne({ - userId: req.user.uuid, - _id: req.params.id - }, function (err, bucket) { - if (err) { - return next(new errors.InternalError(err.message)); - } - - if (!bucket) { - return next(new errors.NotFoundError('Bucket not found')); - } - - Frame.findOne({ - _id: req.body.frame, - user: req.user.email - }, function (err, frame) { - if (err) { - return next(new errors.InternalError(err.message)); - } - - if (!frame) { - return next(new errors.NotFoundError('Frame not found')); - } - - if (frame.locked) { - return next(new errors.BadRequestError('Frame is already locked')); - } - - BucketEntry.create({ - bucket: bucket._id, - frame: frame._id, - mimetype: req.body.mimetype, - name: req.body.filename, - hmac: req.body.hmac, - erasure: req.body.erasure, - index: req.body.index - }, function (err, entry) { - if (err) { - return next(new errors.InternalError(err.message)); - } - - frame.lock(function (err) { - if (err) { - return next(new errors.InternalError(err.message)); - } - - frame.bucketEntry = entry.id; - frame.save(); - - res.send(merge(entry.toObject(), { size: frame.size })); - }); - }); - }); - }); -}; - /** * Returns the bucket by ID * @param {String|ObjectId} bucketId - The unique _id for the bucket @@ -1100,53 +1003,6 @@ BucketsRouter.prototype.getFiles = async function (req, res, next) { } }; -/** - * Lists the file pointers stored in the given bucket - * @param {http.IncomingMessage} req - * @param {http.ServerResponse} res - * @param {Function} next - */ -BucketsRouter.prototype.listFilesInBucket = function (req, res, next) { - const { Bucket, BucketEntry } = this.storage.models; - - Bucket.findOne({ - _id: req.params.id, - userId: req.user.uuid - }, (err, bucket) => { - if (err) { - return next(new errors.InternalError(err.message)); - } - - if (!bucket) { - return next(new errors.NotFoundError('Bucket not found')); - } - - const startDate = utils.parseTimestamp(req.query.startDate); - const findQuery = { bucket: req.params.id }; - if (startDate) { - findQuery.created = { $gt: startDate }; - } - - const query = BucketEntry.find(findQuery).sort({ created: 1 }).limit(constants.DEFAULT_MAX_ENTRIES); - const stream = query.cursor(); - - stream.pipe(utils.createArrayFormatter(function (entry) { - return { - bucket: entry.bucket, - mimetype: entry.mimetype, - filename: entry.filename, - frame: entry.frame.id, - size: entry.frame.size, - id: entry._id, - created: entry.created, - hmac: entry.hmac, - erasure: entry.erasure, - index: entry.index - }; - })).pipe(res); - }); -}; - /** * Removes the file pointer from the bucket * @param {http.IncomingMessage} req @@ -1247,86 +1103,6 @@ BucketsRouter.prototype.deletePointers = async function (pointers) { } }; -BucketsRouter.prototype.renameFile = function (req, res, next) { - const { Bucket, BucketEntry } = this.storage.models; - - Bucket.findOne({ - _id: req.params.id, - userId: req.user.uuid - }, function (err, bucket) { - if (err) { - return next(new errors.InternalError(err.message)); - } - - if (!bucket) { - return next(new errors.NotFoundError('Bucket not found')); - } - - BucketEntry.findOne({ - bucket: bucket._id, - _id: req.params.file - }, function (err, entry) { - if (err) { - return next(err); - } - - if (!entry) { - return next(new errors.NotFoundError('File not found')); - } - - if (!entry.name) { - return next(new errors.BadRequestError('Invalid name')); - } - - entry.name = req.body.name; - - entry.save(function (err) { - if (err) { - return next(new errors.InternalError(err.message)); - } - - res.status(201).end(); - }); - - }); - - }); -}; - -BucketsRouter.prototype.getFileId = function (req, res, next) { - const Bucket = this.storage.models.Bucket; - const BucketEntry = this.storage.models.BucketEntry; - - Bucket.findOne({ - _id: req.params.id, - userId: req.user.uuid - }, '_id', { lean: true }, function (err, bucket) { - if (err) { - return next(new errors.InternalError(err.message)); - } - - if (!bucket) { - return next(new errors.NotFoundError('Bucket not found')); - } - - BucketEntry.findOne({ - bucket: bucket._id, - name: req.params.name - }, '_id', { lean: true }, function (err, entry) { - if (err) { - return next(new errors.InternalError(err.message)); - } - - if (!entry) { - return next(new errors.NotFoundError('File not found')); - } - res.status(200).send({ id: entry._id }); - }); - }); - -}; - - BucketsRouter.prototype.getFileInfo = function (req, res, next) { this._getBucketUnregistered(req, res, (err, bucket) => { if (err) { @@ -1556,21 +1332,15 @@ BucketsRouter.prototype._definitions = function () { /* jshint maxlen: 140 */ return [ ['GET', '/buckets', this.getLimiter(limiter(1000)), this._verify, this.getBuckets], - ['GET', '/buckets/:id', this.getLimiter(limiter(1000)), this._validate, this._verify, this.getBucketById], - ['GET', '/bucket-ids/:name', this.getLimiter(limiter(1000)), this._validate, this._verify, this.getBucketId], ['POST', '/buckets', this.getLimiter(limiter(1000)), this._verify, this.createBucket], ['DELETE', '/buckets/:id', this.getLimiter(limiter(1000)), this._validate, this._verify, this.destroyBucketById], ['PATCH', '/buckets/:id', this.getLimiter(limiter(1000)), this._validate, this._verify, this.updateBucketById], ['POST', '/buckets/:id/tokens', this.getLimiter(limiter(1000)), this._validate, this._verify, this.createBucketToken], - ['GET', '/buckets/:id/files', this.getLimiter(limiter(1000)), this._validate, this._verify, this.listFilesInBucket], - ['GET', '/buckets/:id/file-ids/:name', this.getLimiter(limiter(1000)), this._validate, this._verify, this.getFileId], ['GET', '/buckets/:id/files/:file', this.getLimiter(limiter(1000)), this._validate, this._usetokenOrVerify, this.getFile], ['GET', '/buckets/:id/bulk-files', this.getLimiter(limiter(1000)), this._validate, this._usetokenOrVerify, this.getFiles], ['DELETE', '/buckets/:id/files/:file', this.getLimiter(limiter(1000)), this._validate, this._verify, this.removeFile], ['GET', '/buckets/:id/files/:file/info', this.getLimiter(limiter(1000)), this._validate, this._usetokenOrVerify, this.getFileInfo], - ['POST', '/buckets/:id/files', this.getLimiter(limiter(1000)), this._validate, this._verify, this.createEntryFromFrame], ['GET', '/buckets/:id/files/:file/mirrors', this.getLimiter(limiter(1000)), this._validate, this._verify, this.listMirrorsForFile], - ['PATCH', '/buckets/:id/files/:file', this.getLimiter(limiter(1000)), this._validate, this._verify, this.renameFile], ['POST', '/v2/buckets/:id/files/start', this.getLimiter(limiter(1000)), this._validate, this._verify, this.startUpload], ['POST', '/v2/buckets/:id/files/finish', this.getLimiter(limiter(1000)), this._validate, this._verify, this.finishUpload], ['GET', '/v2/buckets/:id/files/:file/mirrors', this.getLimiter(limiter(1000)), this._validate, this._verify, this.getDownloadLinks],