From d79f0a7aad0f6a00aee5f148c11a20167568708c Mon Sep 17 00:00:00 2001 From: joan vicens Date: Mon, 2 Oct 2023 14:25:21 +0200 Subject: [PATCH 1/2] chore: accept folder uuid from clients --- src/app/routes/storage.ts | 11 +++++++++-- src/app/services/folder.js | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/app/routes/storage.ts b/src/app/routes/storage.ts index 58061197..69ed90cc 100644 --- a/src/app/routes/storage.ts +++ b/src/app/routes/storage.ts @@ -18,6 +18,7 @@ import { } from '../services/errors/FileWithNameAlreadyExistsError'; import { FolderAlreadyExistsError, FolderWithNameAlreadyExistsError } from '../services/errors/FolderWithNameAlreadyExistsError'; import * as resourceSharingMiddlewareBuilder from '../middleware/resource-sharing.middleware'; +import {validate } from 'uuid'; type AuthorizedRequest = Request & { user: UserAttributes }; interface Services { @@ -136,7 +137,8 @@ export class StorageController { } public async createFolder(req: Request, res: Response): Promise { - const { folderName, parentFolderId } = req.body; + this.logger.error(`A ${validate}`); + const { folderName, parentFolderId, uuid: clientCreatedUuuid } = req.body; const { behalfUser: user } = req as any; if (Validator.isInvalidString(folderName)) { @@ -147,6 +149,10 @@ export class StorageController { throw createHttpError(400, 'Invalid parent folder id'); } + if (clientCreatedUuuid && !validate(clientCreatedUuuid)) { + throw createHttpError(400, 'Invalid uuid'); + } + const clientId = String(req.headers['internxt-client-id']); const parentFolder = await this.services.Folder.getById(parentFolderId); @@ -158,8 +164,9 @@ export class StorageController { if (parentFolder.userId !== user.id) { throw createHttpError(403, 'Parent folder does not belong to user'); } + - return this.services.Folder.Create(user, folderName, parentFolderId) + return this.services.Folder.Create(user, folderName, parentFolderId, null, clientCreatedUuuid) .then(async (result: FolderAttributes) => { res.status(201).json(result); const workspaceMembers = await this.services.User.findWorkspaceMembers(user.bridgeUser); diff --git a/src/app/services/folder.js b/src/app/services/folder.js index 2f712670..cf80eda6 100644 --- a/src/app/services/folder.js +++ b/src/app/services/folder.js @@ -56,7 +56,7 @@ module.exports = (Model, App) => { }; // Create folder entry, for desktop - const Create = async (user, folderName, parentFolderId, teamId = null) => { + const Create = async (user, folderName, parentFolderId, teamId = null, uuid = null) => { if (parentFolderId >= 2147483648) { throw Error('Invalid parent folder'); } @@ -117,7 +117,7 @@ module.exports = (Model, App) => { const folder = await user.createFolder({ name: cryptoFolderName, plain_name: folderName, - uuid: v4(), + uuid: uuid || v4(), bucket: null, parentId: parentFolderId || null, parentUuid: parentFolder.uuid, From a1abd1acd5df0b9b21342cd794cc5c4591f9a35c Mon Sep 17 00:00:00 2001 From: joan vicens Date: Tue, 3 Oct 2023 10:46:13 +0200 Subject: [PATCH 2/2] fix: remove unnecessary log --- src/app/routes/storage.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/routes/storage.ts b/src/app/routes/storage.ts index 69ed90cc..9542e468 100644 --- a/src/app/routes/storage.ts +++ b/src/app/routes/storage.ts @@ -137,7 +137,6 @@ export class StorageController { } public async createFolder(req: Request, res: Response): Promise { - this.logger.error(`A ${validate}`); const { folderName, parentFolderId, uuid: clientCreatedUuuid } = req.body; const { behalfUser: user } = req as any;