Require packs to be a tarball

This commit is contained in:
Dane Everitt 2017-01-25 18:20:41 -05:00
parent 95730da419
commit 95d0c646f9
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 8 additions and 13 deletions

View file

@ -66,11 +66,8 @@ class Pack
throw new DisplayException('The file provided does not appear to be valid.'); throw new DisplayException('The file provided does not appear to be valid.');
} }
if (! in_array($data['file_upload']->getMimeType(), [ if ($data['file_upload']->getMimeType() !== 'application/gzip') {
'application/zip', throw new DisplayException('The file provided does not meet the required filetype of application/gzip.');
'application/gzip',
])) {
throw new DisplayException('The file provided does not meet the required filetypes of application/zip or application/gzip.');
} }
} }
@ -95,8 +92,7 @@ class Pack
Storage::makeDirectory('packs/' . $pack->uuid); Storage::makeDirectory('packs/' . $pack->uuid);
if (isset($data['file_upload'])) { if (isset($data['file_upload'])) {
$filename = ($data['file_upload']->getMimeType() === 'application/zip') ? 'archive.zip' : 'archive.tar.gz'; $data['file_upload']->storeAs('packs/' . $pack->uuid, 'archive.tar.gz');
$data['file_upload']->storeAs('packs/' . $pack->uuid, $filename);
} }
DB::commit(); DB::commit();
@ -132,10 +128,9 @@ class Pack
throw new DisplayException('The uploaded archive was unable to be opened.'); throw new DisplayException('The uploaded archive was unable to be opened.');
} }
$isZip = $zip->locateName('archive.zip');
$isTar = $zip->locateName('archive.tar.gz'); $isTar = $zip->locateName('archive.tar.gz');
if ($zip->locateName('import.json') === false || ($isZip === false && $isTar === false)) { if (! $zip->locateName('import.json') || ! $isTar) {
throw new DisplayException('This contents of the provided archive were in an invalid format.'); throw new DisplayException('This contents of the provided archive were in an invalid format.');
} }
@ -156,7 +151,7 @@ class Pack
]); ]);
$pack = Models\ServicePack::findOrFail($id); $pack = Models\ServicePack::findOrFail($id);
if (! $zip->extractTo(storage_path('app/packs/' . $pack->uuid), ($isZip === false) ? 'archive.tar.gz' : 'archive.zip')) { if (! $zip->extractTo(storage_path('app/packs/' . $pack->uuid), 'archive.tar.gz')) {
$pack->delete(); $pack->delete();
throw new DisplayException('Unable to extract the archive file to the correct location.'); throw new DisplayException('Unable to extract the archive file to the correct location.');
} }

View file

@ -175,7 +175,7 @@
@endforeach @endforeach
</tbody> </tbody>
</table> </table>
<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> <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>
</div> </div>
</div> </div>
</div> </div>

View file

@ -150,8 +150,8 @@
<div class="row"> <div class="row">
<div class="form-group col-md-12"> <div class="form-group col-md-12">
<label class="control-label">Package Archive:</label> <label class="control-label">Package Archive:</label>
<input name="file_upload" type="file" accept=".zip,.tar.gz, application/zip, application/gzip" /> <input name="file_upload" type="file" accept=".tar.gz, application/gzip" />
<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. <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.
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> 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>
</div> </div>
</div> </div>