1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Helpers\GistBackupHandler; |
6
|
|
|
use App\Helpers\GistFinder; |
7
|
|
|
use Carbon\Carbon; |
8
|
|
|
|
9
|
|
|
class GistsController extends Controller |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Show gists list. |
13
|
|
|
* |
14
|
|
|
* @param GistFinder $gistFinder |
15
|
|
|
* |
16
|
|
|
* @return \Illuminate\View\View |
17
|
|
|
*/ |
18
|
|
|
public function index(GistFinder $gistFinder) |
19
|
|
|
{ |
20
|
|
|
$gistsAndTags = $gistFinder->getGistsAndTags(); |
21
|
|
|
|
22
|
|
|
$state = collect([ |
23
|
|
|
'user' => auth()->user(), |
|
|
|
|
24
|
|
|
'gists' => $gistsAndTags['gists'], |
25
|
|
|
'tags' => $gistsAndTags['tags'] |
26
|
|
|
]); |
27
|
|
|
|
28
|
|
|
return view('gists.index', compact('state')); |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Backup authorized user gists. |
33
|
|
|
* |
34
|
|
|
* @param GistBackupHandler $backupHandler |
35
|
|
|
* |
36
|
|
|
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse |
37
|
|
|
*/ |
38
|
|
|
public function backup(GistBackupHandler $backupHandler) |
39
|
|
|
{ |
40
|
|
|
if (auth()->user()->gists_backup_at) { |
41
|
|
|
$lastBackup = Carbon::createFromFormat('Y-m-d H:i:s', auth()->user()->gists_backup_at); |
|
|
|
|
42
|
|
|
if ($lastBackup->gt(Carbon::now()->subMinutes(5))) { |
43
|
|
|
return response('WAIT_A_MINUTE', 429); |
44
|
|
|
}; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$zipPath = $backupHandler->backup(); |
48
|
|
|
|
49
|
|
|
if ($zipPath === 0) { |
50
|
|
|
return response('NO_FILES', 404); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
auth()->user()->update(['gists_backup_at' => date('Y-m-d H:i:s')]); |
54
|
|
|
|
55
|
|
|
return response()->download($zipPath, null, [ |
56
|
|
|
'Set-Cookie' => 'fileDownload=true; path=/', |
57
|
|
|
'Content-Type' => 'application/zip' |
58
|
|
|
]); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: