Debian Codegraph @

docpages/dl.dpp.dev/index.php

raw symbols SCIP
1 <?php
2 // Force no caching of the download
3 header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
4 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
5 header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
6 header("Cache-Control: post-check=0, pre-check=0", false);
7 header("Pragma: no-cache");
8 header("Status: 200 OK");
9
10 // Split up url and set defaults
11 list($_, $version, $arch, $type) = explode('/', preg_replace('/https:\/\/dl\.dpp\.dev\//', '', $_SERVER['REDIRECT_URL'] ?? ''), 4);
12 $version = !empty($version) ? $version : 'latest';
13 $arch = !empty($arch) ? $arch : 'linux-x64';
14 $type = !empty($type) ? $type : 'deb';
15 $urls = [];
16
17 // All windows downloads are of type 'zip', if not specified, it is defaulted
18 if (preg_match('/^win/i', $arch) && $type === 'deb') {
19 $type = 'zip';
20 }
21 // the short word 'win' is a shorthand for the vs2019 release build
22 if ($arch === 'win') {
23 $arch = 'win32-release-vs2019';
24 }
25
26 // A crontab keeps this updated so we only perform one github api request per 5 minutes
27 $json = json_decode(file_get_contents('release.json'));
28
29 // If the user asked for 'latest', we find out what the latest release tag name is
30 if ($version === 'latest') {
31 $version = $json[0]->tag_name;
32 }
33
34 // Build search filename
35 $searchName = 'libdpp-' . preg_replace('/^v/', '', $version) . '-' . $arch . '.' . $type;
36
37 // Iterate list of release artifacts across all releases
38 foreach ($json as $index => $release) {
39 foreach ($release->assets as $index2 => $asset) {
40 $url = $asset->browser_download_url;
41 $name = $asset->name;
42 $thisVersion = $release->tag_name;
43 // We found a matching file, stream it to the user
44 if (strtoupper($searchName) == strtoupper($name)) {
45 header('Content-Type: application/octet-stream');
46 header('Content-Disposition: attachment; filename="' . $name . '"');
47 readfile($url);
48 exit;
49 }
50 $urls[] = [
51 'name' => $name,
52 'url' => $url,
53 'version' => $thisVersion,
54 ];
55 }
56 }
57
58
59 if ($version === 'json') {
60 header('Content-Type: application/json');
61 echo json_encode($urls);
62 } else {
63 // Nothing found, offer up some useful info
64 foreach ($urls as $thisUrl) {
65 printf("%s - <a href='%s' target='_blank'>%s</a><br />", $thisUrl['version'], $thisUrl['url'], $thisUrl['name']);
66 }
67 }
68