| Conditions | 8 |
| Paths | 32 |
| Total Lines | 47 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | public function get(Request $request) |
||
| 11 | { |
||
| 12 | try { |
||
| 13 | $file = Models\File::retrieve($request->get('id')); |
||
| 14 | } catch (\Exception $e) { |
||
| 15 | abort(404); |
||
| 16 | } |
||
| 17 | |||
| 18 | $useThumbnail = false; |
||
| 19 | $disposition = 'attachment'; |
||
| 20 | switch ($request->get('action')) { |
||
| 21 | case 'preview': |
||
| 22 | $useThumbnail = true; |
||
| 23 | // intended fallthrough |
||
| 24 | case 'inline': |
||
| 25 | $disposition = 'inline'; |
||
| 26 | break; |
||
| 27 | |||
| 28 | default: |
||
| 29 | break; |
||
| 30 | } |
||
| 31 | |||
| 32 | if ($useThumbnail && $request->get('thumbnail', 1) && ($thumbnail = $file['thumbnail'])) { |
||
| 33 | $mime = $thumbnail['mime']; |
||
| 34 | $filename = $thumbnail['name']; |
||
| 35 | $contents = $thumbnail['contents']; |
||
| 36 | } |
||
| 37 | else { |
||
| 38 | $content = $file->ref('content'); |
||
| 39 | |||
| 40 | $mime = $content['type']; |
||
| 41 | $filename = $file['name']; |
||
| 42 | $contents = $content['data']; |
||
| 43 | } |
||
| 44 | |||
| 45 | $headers = [ |
||
| 46 | 'Content-Type' => $mime, |
||
| 47 | 'Content-Length' => strlen($contents), |
||
| 48 | 'Content-Disposition' => "$disposition; filename=\"$filename\"", |
||
| 49 | ]; |
||
| 50 | |||
| 51 | if ($request->get('nocache')) { |
||
| 52 | $headers['Pragma'] = 'no-cache'; |
||
| 53 | $headers['Expires'] = '0'; |
||
| 54 | } |
||
| 55 | |||
| 56 | return response($contents, 200, $headers); |
||
| 57 | } |
||
| 59 |