-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.php
49 lines (35 loc) · 1.41 KB
/
index.php
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
<?php
require('vendor/autoload.php');
$configFile = file_get_contents('config.json');
$config = json_decode($configFile);
$app = new Slim\App();
$app->get('/{platform}/RELEASES', function($request, $response, $args) use ($config) {
$platform = $request->getAttribute('platform');
$pkgs = scandir(dirname(__FILE__) . '/releases/' . $platform);
if(isset($_GET['localVersion'])){
$localVersion = Naneau\SemVer\Parser::parse($_GET['localVersion']);
}else{
$localVersion = Naneau\SemVer\Parser::parse('0.0.0');
}
foreach ($pkgs as $pkg) {
if($pkg[0] != '.'){
$re = '/-(.*?)-/';
preg_match($re, $pkg, $matches);
if (!empty($matches)){
$version = Naneau\SemVer\Parser::parse($matches[1]);
if(Naneau\SemVer\Compare::greaterThan($version, $localVersion) || Naneau\SemVer\Compare::equals($version, $localVersion)){
$hash = sha1_file(dirname(__FILE__) . '/releases/' . $platform . '/' .$pkg);
$filesize = filesize(dirname(__FILE__) . '/releases/' . $platform . '/' .$pkg);
$response->getBody()->write($hash . ' ' . $config->baseurl . '/releases/' . $platform . '/' . $pkg . ' ' . $filesize . "\r\n");
}
}
}
}
return $response;
});
$app->get('/{platform}/notes/{version}', function($request, $response, $args){
$response->getBody()->write('Release ' . $request->getAttribute('version'));
return $response;
});
$app->run();
?>