-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathTrainingRoadmapPdfController.php
More file actions
51 lines (43 loc) · 1.49 KB
/
TrainingRoadmapPdfController.php
File metadata and controls
51 lines (43 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
class TrainingRoadmapPdfController extends Controller
{
/**
* Public roadmap PDF used by the Discover Digital Programme embed.
* Kept allowlisted here so the proxy cannot be abused as an open redirect.
*/
private const ROADMAP_SOURCE = 'https://codeweek-resources.s3.eu-west-1.amazonaws.com/+discover-digital-toolkit/DDP_toolkit_roadmap.pdf';
/**
* Same-origin PDF bytes for PDF.js (avoids cross-origin fetch issues).
*/
public function proxyPdf()
{
$bytes = Cache::remember(
'training_embedded_roadmap_pdf_v1',
3600,
function () {
$response = Http::timeout(120)->get(self::ROADMAP_SOURCE);
if (! $response->successful()) {
abort(502, 'Unable to load roadmap PDF.');
}
return $response->body();
}
);
return response($bytes, 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="DDP_toolkit_roadmap.pdf"',
'Cache-Control' => 'public, max-age=3600',
]);
}
/**
* Minimal PDF.js viewer (no site chrome) for iframe embedding on training pages.
*/
public function viewer()
{
return response()
->view('training.roadmap-pdfjs')
->header('X-Frame-Options', 'SAMEORIGIN');
}
}