Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PB-1030] chore: accept folder uuid from clients #418

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/app/routes/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
FileAlreadyExistsError,
FileWithNameAlreadyExistsError
} 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

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

View workflow job for this annotation

GitHub Actions / run-tests (14.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 @@ -93,7 +94,7 @@
return res.status(409).send({ error: err.message });
}
this.logger.error(
`[FILE/CREATE] ERROR: ${(err as Error).message}, BODY ${JSON.stringify(file)}, STACK: ${(err as Error).stack} USER: ${behalfUser.email}`,

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

View workflow job for this annotation

GitHub Actions / build (16.x)

This line has a length of 145. Maximum allowed is 120

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

View workflow job for this annotation

GitHub Actions / run-tests (14.x)

This line has a length of 145. Maximum allowed is 120
);
res.status(500).send({ error: 'Internal Server Error' });
}
Expand Down Expand Up @@ -136,7 +137,7 @@
}

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 @@
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 @@
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
Loading