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-759] Feat: allow to create empty files #409

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 10 additions & 11 deletions src/app/routes/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ export class StorageController {
file.fileId = file.file_id;
}

if (!file || !file.fileId || !file.bucket || file.size === undefined || file.size === null || !file.folder_id || !file.name) {
if (!file.fileId && file.size !== null && file.size !== 0) {
this.logger.error(
`Invalid metadata trying to create a file for user ${behalfUser.email}: ${JSON.stringify(file, null, 2)}`,
);
return res.status(400).json({ error: 'Invalid metadata for new file' });

This comment was marked as off-topic.

}

if (!file || !file.bucket || file.size === undefined || file.size === null || !file.folder_id || !file.name) {
this.logger.error(
`Invalid metadata trying to create a file for user ${behalfUser.email}: ${JSON.stringify(file, null, 2)}`,
);
Expand All @@ -76,9 +83,7 @@ export class StorageController {
);
} catch (err) {
this.logger.error(
`[FILE/CREATE] ERROR: ${(err as Error).message}, BODY ${JSON.stringify(
file,
)}, STACK: ${(err as Error).stack}`,
`[FILE/CREATE] ERROR: ${(err as Error).message}, BODY ${JSON.stringify(file)}, STACK: ${(err as Error).stack}`,
);
res.status(500).send({ error: 'Internal Server Error' });
}
Expand Down Expand Up @@ -293,13 +298,7 @@ export class StorageController {
}

await Promise.all([
this.services.Folder.getByIdAndUserIds(
id,
[
behalfUser.id,
(req as AuthorizedRequest).user.id
]
),
this.services.Folder.getByIdAndUserIds(id, [behalfUser.id, (req as AuthorizedRequest).user.id]),
this.services.Folder.getFolders(id, behalfUser.id, deleted),
this.services.Files.getByFolderAndUserId(id, behalfUser.id, deleted),
])
Expand Down
2 changes: 1 addition & 1 deletion src/app/services/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports = (Model, App) => {
bucket: file.bucket,
encrypt_version: file.encrypt_version,
userId: user.id,
uuid: v4(),
uuid: file.uuid || v4(),
folderUuid: folder.uuid,
modificationTime: file.modificationTime || new Date(),
};
Expand Down