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
|
|
|
$authUser = auth()->user(); |
|
|
|
|
23
|
|
|
$state = collect([ |
24
|
|
|
'user' => [ |
25
|
|
|
'name' => $authUser->name, |
26
|
|
|
'nickname' => $authUser->nickname, |
27
|
|
|
'avatar' => $authUser->avatar |
28
|
|
|
], |
29
|
|
|
'gists' => $gistsAndTags['gists'], |
30
|
|
|
'tags' => $gistsAndTags['tags'] |
31
|
|
|
]); |
32
|
|
|
|
33
|
|
|
return view('gists.index', compact('state')); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Backup authorized user gists. |
38
|
|
|
* |
39
|
|
|
* @param GistBackupHandler $backupHandler |
40
|
|
|
* |
41
|
|
|
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse |
42
|
|
|
*/ |
43
|
|
|
public function backup(GistBackupHandler $backupHandler) |
44
|
|
|
{ |
45
|
|
|
if (auth()->user()->gists_backup_at) { |
46
|
|
|
$lastBackup = Carbon::createFromFormat('Y-m-d H:i:s', auth()->user()->gists_backup_at); |
|
|
|
|
47
|
|
|
if ($lastBackup->gt(Carbon::now()->subMinutes(5))) { |
48
|
|
|
return response('WAIT_A_MINUTE', 429); |
49
|
|
|
}; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$zipPath = $backupHandler->backup(); |
53
|
|
|
|
54
|
|
|
if ($zipPath === 0) { |
55
|
|
|
return response('NO_FILES', 404); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
auth()->user()->update(['gists_backup_at' => date('Y-m-d H:i:s')]); |
59
|
|
|
|
60
|
|
|
return response()->download($zipPath, null, [ |
61
|
|
|
'Set-Cookie' => 'fileDownload=true; path=/', |
62
|
|
|
'Content-Type' => 'application/zip' |
63
|
|
|
])->deleteFileAfterSend(true); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
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: