Skip to content

Commit bbb1294

Browse files
authored
Support zero-byte file uploads (#5459)
1 parent a215f6d commit bbb1294

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

resources/scripts/components/server/files/UploadButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ export default ({ className }: WithClassname) => {
6464
const onFileSubmission = (files: FileList) => {
6565
clearAndAddHttpError();
6666
const list = Array.from(files);
67-
if (list.some((file) => !file.size || (!file.type && file.size === 4096))) {
68-
return addError('Folder uploads are not supported at this time.', 'Error');
67+
if (list.some((file) => !file.type && (!file.size || file.size === 4096))) {
68+
return addError('Folder uploads are not supported.', 'Error');
6969
}
7070

7171
const uploads = list.map((file) => {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Pterodactyl\Tests\Integration\Api\Client\Server\Files;
4+
5+
use Mockery\MockInterface;
6+
use Pterodactyl\Models\Permission;
7+
use Pterodactyl\Repositories\Wings\DaemonFileRepository;
8+
use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
9+
10+
class CompressFilesTest extends ClientApiIntegrationTestCase
11+
{
12+
public function testEndpointRequiresAuthorization(): void
13+
{
14+
[$user, $server] = $this->generateTestAccount([Permission::ACTION_CONTROL_CONSOLE]);
15+
16+
$this->postJson($this->link($server, '/files/compress'))->assertUnauthorized();
17+
18+
$this->actingAs($user)
19+
->postJson($this->link($server, '/files/compress'))
20+
->assertForbidden();
21+
}
22+
23+
public function testEndpointTriggersWingsCall(): void
24+
{
25+
[$user, $server] = $this->generateTestAccount([Permission::ACTION_FILE_ARCHIVE]);
26+
27+
$this->mock(DaemonFileRepository::class, function (MockInterface $mock) {
28+
$mock->expects('setServer->compressFiles')->with('/', ['test.txt'])->andReturn([
29+
'name' => 'test.tar.gz',
30+
'mime' => 'application/gzip',
31+
]);
32+
});
33+
34+
$this->actingAs($user)
35+
->postJson($endpoint = $this->link($server, '/files/compress'), [])
36+
->assertUnprocessable()
37+
->assertJsonPath('errors.0.meta', ['source_field' => 'files', 'rule' => 'required']);
38+
39+
$this->postJson($endpoint, ['root' => '/', 'files' => ['test.txt']])
40+
->assertOk()
41+
->assertJsonPath('object', 'file_object')
42+
->assertJsonPath('attributes.name', 'test.tar.gz')
43+
->assertJsonPath('attributes.mimetype', 'application/gzip');
44+
}
45+
}

0 commit comments

Comments
 (0)