| Total Complexity | 14 |
| Total Lines | 143 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 1 | <?php |
||
| 24 | class GuestLinksController extends Controller |
||
| 25 | { |
||
| 26 | // Landing page if no link is sent |
||
| 27 | public function index() |
||
| 28 | { |
||
| 29 | Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.\Request::ip()); |
||
| 30 | return view('links.userIndex'); |
||
| 31 | } |
||
| 32 | |||
| 33 | // Show the link details for the user |
||
| 34 | public function show($id) |
||
| 35 | { |
||
| 36 | $details = FileLinks::where('link_hash', $id)->first(); |
||
| 37 | |||
| 38 | // Verify that the link is valid |
||
| 39 | if(empty($details)) |
||
| 40 | { |
||
| 41 | Log::warning('Visitor '.\Request::ip().' visited bad link Hash - '.$id); |
||
| 42 | return view('links.guestBadLink'); |
||
| 43 | } |
||
| 44 | // Verify that the link has not expired |
||
| 45 | else if($details->expire <= date('Y-m-d')) |
||
|
1 ignored issue
–
show
|
|||
| 46 | { |
||
| 47 | Log::warning('Visitor '.\Request::ip().' visited expired link Hash - '.$id); |
||
| 48 | return view('links.guestExpiredLink'); |
||
| 49 | } |
||
| 50 | |||
| 51 | // Link is valid - determine if the link has files that can be downloaded |
||
| 52 | $files = FileLinkFiles::where('link_id', $details->link_id) |
||
|
1 ignored issue
–
show
|
|||
| 53 | ->where('upload', false) |
||
| 54 | ->count(); |
||
| 55 | |||
| 56 | if($files == 0 && $details->allow_upload === 'No') |
||
| 57 | { |
||
| 58 | Log::warning('Visitor ' . \Request::ip() . ' visited a link that they cannot do anything with. Hash - ' . $id); |
||
| 59 | return view('links.guestDeadLink'); |
||
| 60 | } |
||
| 61 | |||
| 62 | Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.\Request::ip()); |
||
| 63 | Log::debug('Link Hash-'.$id); |
||
| 64 | return view('links.guestDetails', [ |
||
| 65 | 'hash' => $id, |
||
| 66 | 'details' => $details, |
||
| 67 | 'hasFiles' => $files > 0 ? true : false, |
||
| 68 | 'allowUp' => $details->allow_upload === 'Yes' ? true : false, |
||
| 69 | ]); |
||
| 70 | } |
||
| 71 | |||
| 72 | // Get the guest available files for the link |
||
| 73 | public function getFiles($id) |
||
| 86 | } |
||
| 87 | |||
| 88 | // Upload new file |
||
| 89 | public function update(Request $request, $id) |
||
| 90 | { |
||
| 91 | $request->validate(['name' => 'required', 'file' => 'required']); |
||
| 92 | |||
| 93 | $receiver = new FileReceiver('file', $request, HandlerFactory::classFromRequest($request)); |
||
| 94 | |||
| 95 | // Verify that the upload is valid and being processed |
||
| 96 | if($receiver->isUploaded() === false) |
||
| 97 | { |
||
| 98 | Log::error('Upload File Missing - '.$request->toArray()); |
||
| 99 | throw new UploadMissingFileException(); |
||
| 100 | } |
||
| 101 | |||
| 102 | // Recieve and process the file |
||
| 103 | $save = $receiver->receive(); |
||
| 104 | |||
| 105 | // See if the uploade has finished |
||
| 106 | if($save->isFinished()) |
||
| 107 | { |
||
| 108 | $this->saveFile($save->getFile(), $id, $request); |
||
| 109 | |||
| 110 | return 'uploaded successfully'; |
||
| 111 | } |
||
| 112 | |||
| 113 | // Get the current progress |
||
| 114 | $handler = $save->handler(); |
||
| 115 | |||
| 116 | Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.\Request::ip()); |
||
| 117 | Log::debug('File being uploaded. Percentage done - '.$handler->getPercentageDone()); |
||
| 118 | return response()->json([ |
||
| 119 | 'done' => $handler->getPercentageDone(), |
||
| 120 | 'status' => true |
||
| 121 | ]); |
||
| 122 | } |
||
| 123 | |||
| 124 | // Save the file in the database |
||
| 125 | private function saveFile(UploadedFile $file, $id, $request) |
||
| 126 | { |
||
| 127 | $details = FileLinks::where('link_hash', $id)->first(); |
||
| 128 | $filePath = config('filesystems.paths.links').DIRECTORY_SEPARATOR.$details->link_id; |
||
|
1 ignored issue
–
show
|
|||
| 129 | |||
| 130 | $fileName = Files::cleanFilename($filePath, $file->getClientOriginalName()); |
||
| 131 | $file->storeAs($filePath, $fileName); |
||
| 132 | |||
| 133 | // Place file in Files table of DB |
||
| 134 | $newFile = Files::create([ |
||
| 135 | 'file_name' => $fileName, |
||
| 136 | 'file_link' => $filePath.DIRECTORY_SEPARATOR |
||
| 137 | ]); |
||
| 138 | $fileID = $newFile->file_id; |
||
|
1 ignored issue
–
show
|
|||
| 139 | |||
| 140 | // Place the file in the file link files table of DB |
||
| 141 | FileLinkFiles::create([ |
||
| 142 | 'link_id' => $details->link_id, |
||
| 143 | 'file_id' => $fileID, |
||
| 144 | 'added_by' => $request->name, |
||
| 145 | 'upload' => 1, |
||
| 146 | 'note' => $request->note |
||
| 147 | ]); |
||
| 148 | |||
| 149 | Log::info('File uploaded by guest '.\Request::ip().' for file link -'.$details->link_id); |
||
| 150 | Log::debug('File Data -', $request->toArray()); |
||
| 151 | |||
| 152 | return response()->json(['success' => true]); |
||
| 153 | } |
||
| 154 | |||
| 155 | // Notify the owner of the link that files were uploaded |
||
| 156 | public function notify(Request $request, $id) |
||
| 167 | } |
||
| 168 | } |
||
| 169 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths