Skip to content

Commit

Permalink
Allow uploading empty files (#333)
Browse files Browse the repository at this point in the history
* chore: bump runtime

* fix: remove additional download check

* test: update empty file upload test
  • Loading branch information
jkoenig134 authored Dec 19, 2024
1 parent e425dbb commit da9dc8e
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 60 deletions.
102 changes: 56 additions & 46 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"@js-soft/docdb-access-mongo": "1.1.9",
"@js-soft/node-logger": "1.2.0",
"@js-soft/ts-utils": "^2.3.3",
"@nmshd/runtime": "6.16.0",
"@nmshd/runtime": "6.20.0",
"@nmshd/typescript-ioc": "^3.2.4",
"@nmshd/typescript-rest": "^3.0.5",
"agentkeepalive": "4.5.0",
Expand All @@ -92,7 +92,7 @@
"compression": "1.7.5",
"correlation-id": "^5.2.0",
"cors": "2.8.5",
"eventsource": "^3.0.1",
"eventsource": "3.0.1",
"express": "4.21.2",
"helmet": "8.0.0",
"json-stringify-safe": "5.0.1",
Expand All @@ -104,7 +104,7 @@
"redis": "^4.7.0",
"reflect-metadata": "0.2.2",
"swagger-ui-express": "5.0.1",
"undici": "^7.1.0",
"undici": "^7.2.0",
"yamljs": "0.3.0",
"yargs": "^17.7.2"
},
Expand All @@ -113,8 +113,8 @@
"@js-soft/eslint-config-ts": "1.6.13",
"@js-soft/license-check": "1.0.9",
"@nmshd/connector-sdk": "*",
"@nmshd/content": "6.16.0",
"@nmshd/core-types": "6.16.0",
"@nmshd/content": "6.20.0",
"@nmshd/core-types": "6.20.0",
"@nmshd/typescript-rest-swagger": "^1.4.1",
"@types/amqplib": "^0.10.6",
"@types/compression": "^1.7.5",
Expand All @@ -127,18 +127,18 @@
"@types/lodash": "^4.17.13",
"@types/luxon": "^3.4.2",
"@types/nconf": "^0.10.7",
"@types/node": "^22.10.1",
"@types/node": "^22.10.2",
"@types/on-headers": "^1.0.3",
"@types/swagger-ui-express": "^4.1.7",
"@types/yamljs": "^0.2.34",
"c8": "^10.1.2",
"c8": "^10.1.3",
"cpx2": "^8.0.0",
"eslint": "^8.57.1",
"jest": "^29.7.0",
"jest-expect-message": "^1.1.3",
"jest-json-schema": "^6.1.0",
"lodash": "^4.17.21",
"nodemon": "^3.1.7",
"nodemon": "^3.1.9",
"npm-run-all": "^4.1.5",
"openapi-types": "^12.1.3",
"prettier": "^3.4.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"build:schemas:watch": "npx nodemon -e ts -w 'src/types' --exec 'npm run build:schemas'"
},
"dependencies": {
"@nmshd/content": "6.16.0",
"@nmshd/content": "6.20.0",
"axios": "^1.7.9",
"form-data": "^4.0.1",
"qs": "^6.13.1"
Expand Down
4 changes: 1 addition & 3 deletions src/modules/coreHttpApi/common/BaseController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ export abstract class BaseController {
const filename = filenamePredicate(result);
const mimetype = mimetypePredicate(result);

if (!content || content.length <= 0) {
throw new Error("'content' cannot be empty or undefined");
}
if (!content) throw new Error("'content' cannot be undefined");

let buffer: Buffer;
if (content instanceof Buffer) {
Expand Down
8 changes: 6 additions & 2 deletions test/files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ describe("File Upload", () => {
expect(response.result.byteLength).toBe(4);
});

test("cannot upload an empty file", async () => {
test("can upload an empty file", async () => {
const response = await client1.files.uploadOwnFile(await makeUploadRequest({ file: Buffer.of() }));
expect(response).toBeAnError("'content' is empty", "error.runtime.validation.invalidPropertyValue");
expect(response).toBeSuccessful(ValidationSchema.File);

const downloadResponse = await client1.files.downloadFile(response.result.id);
expect(downloadResponse.isSuccess).toBeTruthy();
expect(downloadResponse.result.byteLength).toBe(0);
});

test("cannot upload a file that is null", async () => {
Expand Down

0 comments on commit da9dc8e

Please sign in to comment.