Attempt a download via API

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe
2022-06-28 23:59:13 -07:00
parent 1debdc47cf
commit b590f29f33
2 changed files with 13 additions and 59 deletions
@@ -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'));
}
}
}