Skip to content

Commit

Permalink
Merge pull request #418 from internxt/chore/accept-folder-uuid-from-c…
Browse files Browse the repository at this point in the history
…lients

[PB-1030] chore: accept folder uuid from clients
  • Loading branch information
JoanVicens authored Oct 3, 2023
2 parents 66c579e + a1abd1a commit bd6b05c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/app/routes/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '../services/errors/FileWithNameAlreadyExistsError';
import { FolderAlreadyExistsError, FolderWithNameAlreadyExistsError } from '../services/errors/FolderWithNameAlreadyExistsError';

Check failure on line 19 in src/app/routes/storage.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

This line has a length of 129. Maximum allowed is 120
import * as resourceSharingMiddlewareBuilder from '../middleware/resource-sharing.middleware';
import {validate } from 'uuid';

type AuthorizedRequest = Request & { user: UserAttributes };
interface Services {
Expand Down Expand Up @@ -136,7 +137,7 @@ export class StorageController {
}

public async createFolder(req: Request, res: Response): Promise<void> {
const { folderName, parentFolderId } = req.body;
const { folderName, parentFolderId, uuid: clientCreatedUuuid } = req.body;
const { behalfUser: user } = req as any;

if (Validator.isInvalidString(folderName)) {
Expand All @@ -147,6 +148,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);
Expand All @@ -158,8 +163,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);
Expand Down
4 changes: 2 additions & 2 deletions src/app/services/folder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit bd6b05c

Please sign in to comment.