Skip to content

Commit 46153e4

Browse files
committed
feat: increase file size limits to 100 GB in NetworkFacade and related error handling
1 parent d3b770b commit 46153e4

4 files changed

Lines changed: 43 additions & 14 deletions

File tree

src/services/network/network-facade.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { RangeOptions } from '../../utils/network.utils';
1313
import { UsageService } from '../usage.service';
1414
import { FormatUtils } from '../../utils/format.utils';
1515

16-
const FORTY_GIGABYTES = 40 * 1024 * 1024 * 1024;
16+
const HUNDRED_GIGABYTES = 100 * 1024 * 1024 * 1024;
1717

1818
export class NetworkFacade {
1919
private readonly cryptoLib: Network.Crypto;
@@ -145,8 +145,8 @@ export class NetworkFacade {
145145
throw new Error(`File is too big (${formattedSize} exceeds account upload limit of ${formattedLimit})`);
146146
}
147147

148-
if (size > FORTY_GIGABYTES) {
149-
throw new Error('File is too big (more than 40 GB)');
148+
if (size >= HUNDRED_GIGABYTES) {
149+
throw new Error('File is too big (more than 100 GB)');
150150
}
151151

152152
return this.environment.upload(bucketId, {

src/webdav/handlers/PUT.handler.ts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { WebDavFolderService } from '../../services/webdav/webdav-folder.service
1313
import { ThumbnailUtils } from '../../utils/thumbnail.utils';
1414
import { ThumbnailService } from '../../services/thumbnail.service';
1515
import { FormatUtils } from '../../utils/format.utils';
16+
import { XMLUtils } from '../../utils/xml.utils';
1617

1718
export class PUTRequestHandler implements WebDavMethodHandler {
1819
handle = async (req: Request, res: Response) => {
@@ -84,13 +85,39 @@ export class PUTRequestHandler implements WebDavMethodHandler {
8485
const networkUploadTimer = CLIUtils.timer();
8586
const abortable = new AbortController();
8687

87-
fileId = await networkFacade.uploadFile({
88-
from: fileStream,
89-
size: contentLength,
90-
bucketId: bucket,
91-
progressCallback,
92-
abortSignal: abortable.signal,
93-
});
88+
try {
89+
fileId = await networkFacade.uploadFile({
90+
from: fileStream,
91+
size: contentLength,
92+
bucketId: bucket,
93+
progressCallback,
94+
abortSignal: abortable.signal,
95+
});
96+
} catch (e) {
97+
aborted = true;
98+
abortable.abort();
99+
const error = e as Error;
100+
if (bufferStream) {
101+
req.unpipe(bufferStream);
102+
bufferStream.destroy();
103+
}
104+
if (error.message.toLowerCase().includes('file is too big')) {
105+
webdavLogger.error('[PUT] ❌ File is too big (' + FormatUtils.humanFileSize(contentLength) + ')');
106+
const errorBodyXML = XMLUtils.toWebDavXML(
107+
{
108+
[XMLUtils.addDefaultNamespace('responsedescription')]: error.message,
109+
},
110+
{},
111+
'error',
112+
);
113+
res.set('Content-Type', 'application/xml; charset="utf-8"');
114+
res.status(413).send(errorBodyXML);
115+
req.destroy();
116+
return;
117+
}
118+
119+
throw e;
120+
}
94121

95122
res.on('close', async () => {
96123
aborted = true;

src/webdav/middewares/errors.middleware.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ export const ErrorHandlingMiddleware: ErrorRequestHandler = (err, req, res, _) =
2626
statusCode = err.statusCode;
2727
}
2828

29+
res.set('Content-Type', 'application/xml; charset="utf-8"');
2930
res.status(statusCode).send(errorBodyXML);
31+
req.destroy();
3032
};

test/services/network/network-facade.service.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe('Network Facade Service', () => {
8787
expect(mockEnvironment.upload).not.toHaveBeenCalled();
8888
});
8989

90-
it('Should throw an error when a file exceeds 40 GB', async () => {
90+
it('Should throw an error when a file exceeds 100 GB', async () => {
9191
const mockEnvironment = {
9292
upload: vi.fn(),
9393
};
@@ -106,16 +106,16 @@ describe('Network Facade Service', () => {
106106
await expect(() =>
107107
sut.uploadFile({
108108
from: readStream,
109-
size: 41 * 1024 * 1024 * 1024,
109+
size: 101 * 1024 * 1024 * 1024,
110110
bucketId: 'bucket-id',
111111
progressCallback: vi.fn(),
112112
}),
113-
).rejects.toThrow('File is too big (more than 40 GB)');
113+
).rejects.toThrow('File is too big (more than 100 GB)');
114114

115115
expect(mockEnvironment.upload).not.toHaveBeenCalled();
116116
});
117117

118-
it('Should enforce API limit over 40 GB hard cap when maxUploadFileSize is smaller', async () => {
118+
it('Should enforce API limit over 100 GB hard cap when maxUploadFileSize is smaller', async () => {
119119
const mockEnvironment = {
120120
upload: vi.fn(),
121121
};

0 commit comments

Comments
 (0)