Skip to content

Commit 95d0c64

Browse files
committed
Require packs to be a tarball
1 parent 95730da commit 95d0c64

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

app/Repositories/ServiceRepository/Pack.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,8 @@ public function create(array $data)
6666
throw new DisplayException('The file provided does not appear to be valid.');
6767
}
6868

69-
if (! in_array($data['file_upload']->getMimeType(), [
70-
'application/zip',
71-
'application/gzip',
72-
])) {
73-
throw new DisplayException('The file provided does not meet the required filetypes of application/zip or application/gzip.');
69+
if ($data['file_upload']->getMimeType() !== 'application/gzip') {
70+
throw new DisplayException('The file provided does not meet the required filetype of application/gzip.');
7471
}
7572
}
7673

@@ -95,8 +92,7 @@ public function create(array $data)
9592

9693
Storage::makeDirectory('packs/' . $pack->uuid);
9794
if (isset($data['file_upload'])) {
98-
$filename = ($data['file_upload']->getMimeType() === 'application/zip') ? 'archive.zip' : 'archive.tar.gz';
99-
$data['file_upload']->storeAs('packs/' . $pack->uuid, $filename);
95+
$data['file_upload']->storeAs('packs/' . $pack->uuid, 'archive.tar.gz');
10096
}
10197

10298
DB::commit();
@@ -132,10 +128,9 @@ public function createWithTemplate(array $data)
132128
throw new DisplayException('The uploaded archive was unable to be opened.');
133129
}
134130

135-
$isZip = $zip->locateName('archive.zip');
136131
$isTar = $zip->locateName('archive.tar.gz');
137132

138-
if ($zip->locateName('import.json') === false || ($isZip === false && $isTar === false)) {
133+
if (! $zip->locateName('import.json') || ! $isTar) {
139134
throw new DisplayException('This contents of the provided archive were in an invalid format.');
140135
}
141136

@@ -156,7 +151,7 @@ public function createWithTemplate(array $data)
156151
]);
157152

158153
$pack = Models\ServicePack::findOrFail($id);
159-
if (! $zip->extractTo(storage_path('app/packs/' . $pack->uuid), ($isZip === false) ? 'archive.tar.gz' : 'archive.zip')) {
154+
if (! $zip->extractTo(storage_path('app/packs/' . $pack->uuid), 'archive.tar.gz')) {
160155
$pack->delete();
161156
throw new DisplayException('Unable to extract the archive file to the correct location.');
162157
}

resources/views/admin/services/packs/edit.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
@endforeach
176176
</tbody>
177177
</table>
178-
<p class="text-muted"><small>If you wish to modify or upload a new file it should be uploaded to <code>{{ storage_path('app/packs/' . $pack->uuid) }}</code> as either <code>archive.zip</code> or <code>archive.tar.gz</code>.</small></p>
178+
<p class="text-muted"><small>If you wish to modify or upload a new file it should be uploaded to <code>{{ storage_path('app/packs/' . $pack->uuid) }}</code> as <code>archive.tar.gz</code>.</small></p>
179179
</div>
180180
</div>
181181
</div>

resources/views/admin/services/packs/new.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@
150150
<div class="row">
151151
<div class="form-group col-md-12">
152152
<label class="control-label">Package Archive:</label>
153-
<input name="file_upload" type="file" accept=".zip,.tar.gz, application/zip, application/gzip" />
154-
<p class="text-muted"><small>This package file must either be a <code>.zip</code> or <code>.tar.gz</code> archive of files to use for either building or running this pack.<br /><br />If your file is larger than <code>20MB</code> we recommend uploading it using SFTP. Once you have added this pack to the system, a path will be provided where you should upload the file.
153+
<input name="file_upload" type="file" accept=".tar.gz, application/gzip" />
154+
<p class="text-muted"><small>This package file must be a <code>.tar.gz</code> archive of files to use for either building or running this pack.<br /><br />If your file is larger than <code>20MB</code> we recommend uploading it using SFTP. Once you have added this pack to the system, a path will be provided where you should upload the file.
155155
This server is currently configured with the following limits: <code>upload_max_filesize={{ ini_get('upload_max_filesize') }}</code> and <code>post_max_size={{ ini_get('post_max_size') }}</code>. If your file is larger than either of those values this request will fail.</small></p>
156156
</div>
157157
</div>

0 commit comments

Comments
 (0)