mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
Attempt a download via API
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
1debdc47cf
commit
b590f29f33
|
@ -2,7 +2,9 @@
|
|||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Transformers\BackupsTransformer;
|
||||
use App\Helpers\Helper;
|
||||
use App\Helpers\StorageHelper;
|
||||
use App\Http\Transformers\DatatablesTransformer;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Ldap;
|
||||
|
@ -298,13 +300,20 @@ class SettingsController extends Controller
|
|||
}
|
||||
|
||||
$files = array_reverse($files_raw);
|
||||
return (new BackupsTransformer())->transformBackups($files, $count);
|
||||
return (new DatatablesTransformer)->transformDatatables($files, $count);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function downloadBackup($file) {
|
||||
$path = '';
|
||||
return response()->download($path, $file->name, $headers);
|
||||
|
||||
$path = 'app/backups';
|
||||
if (Storage::exists($path.'/'.$file)) {
|
||||
$headers = ['ContentType' => 'application/zip'];
|
||||
return Storage::download($path.'/'.$file, $file, $headers);
|
||||
} else {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'File not found'));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Transformers;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use Gate;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class BackupsTransformer
|
||||
{
|
||||
public function transformBackups(Array $files, $total)
|
||||
{
|
||||
$array = [];
|
||||
foreach ($files as $file) {
|
||||
$array[] = self::transformCategory($file);
|
||||
}
|
||||
|
||||
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
||||
}
|
||||
|
||||
public function transformCategory(Array $file = null)
|
||||
{
|
||||
if ($file) {
|
||||
$array = [
|
||||
'id' => (int) $file->id,
|
||||
'name' => e($category->name),
|
||||
'image' => ($category->image) ? Storage::disk('public')->url('categories/'.e($category->image)) : null,
|
||||
'category_type' => ucwords(e($category->category_type)),
|
||||
'has_eula' => ($category->getEula() ? true : false),
|
||||
'use_default_eula' => ($category->use_default_eula=='1' ? true : false),
|
||||
'eula' => ($category->getEula()),
|
||||
'checkin_email' => ($category->checkin_email == '1'),
|
||||
'require_acceptance' => ($category->require_acceptance == '1'),
|
||||
'item_count' => (int) $category->itemCount(),
|
||||
'assets_count' => (int) $category->assets_count,
|
||||
'accessories_count' => (int) $category->accessories_count,
|
||||
'consumables_count' => (int) $category->consumables_count,
|
||||
'components_count' => (int) $category->components_count,
|
||||
'licenses_count' => (int) $category->licenses_count,
|
||||
'created_at' => Helper::getFormattedDateObject($category->created_at, 'datetime'),
|
||||
'updated_at' => Helper::getFormattedDateObject($category->updated_at, 'datetime'),
|
||||
];
|
||||
|
||||
$permissions_array['available_actions'] = [
|
||||
'update' => Gate::allows('update', Category::class),
|
||||
'delete' => $category->isDeletable(),
|
||||
];
|
||||
|
||||
$array += $permissions_array;
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue