You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.3 KiB

  1. <?php include "conf.php"; /* load a local configuration */ ?>
  2. <?php session_start(); ?>
  3. <?php require 'vendor/autoload.php'; /* composer includes */ ?>
  4. <?php include "modulekit/loader.php"; /* loads all php-includes */ ?>
  5. <?php include "node_modules/json-multiline-strings/src/json-multiline-strings.php"; ?>
  6. <?php call_hooks("init"); /* initialize submodules */ ?>
  7. <?php
  8. $allRepositories = getRepositories();
  9. if (!isset($_REQUEST['repo'])) {
  10. Header("Content-Type: application/json; charset=utf-8");
  11. print '{';
  12. $c = 0;
  13. foreach ($allRepositories as $repoId => $repoData) {
  14. $repo = getRepo($repoId, $repoData);
  15. print $c++ ? ',' : '';
  16. print json_encode($repoId, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES) . ':';
  17. $info = $repo->info();
  18. if (isset($repoData['repositoryUrl'])) {
  19. $info['repositoryUrl'] = $repoData['repositoryUrl'];
  20. }
  21. if (isset($repoData['categoryUrl'])) {
  22. $info['categoryUrl'] = $repoData['categoryUrl'];
  23. }
  24. print json_encode($info, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_FORCE_OBJECT);
  25. }
  26. print '}';
  27. exit(0);
  28. }
  29. $repoId = $_REQUEST['repo'];
  30. list($repoId, $branchId) = explode('/', $repoId);
  31. if (!array_key_exists($repoId, $allRepositories)) {
  32. Header("HTTP/1.1 404 Repository not found");
  33. exit(0);
  34. }
  35. $repoData = $allRepositories[$repoId];
  36. $repo = getRepo($repoId, $repoData);
  37. if ($branchId) {
  38. try {
  39. $repo->setBranch($branchId);
  40. }
  41. catch (Exception $e) {
  42. Header("HTTP/1.1 404 No such branch");
  43. exit(0);
  44. }
  45. }
  46. $cacheDir = null;
  47. $ts = $repo->timestamp($path);
  48. if (isset($config['cache'])) {
  49. $cacheDir = "{$config['cache']}/repo";
  50. @mkdir($cacheDir);
  51. $cacheTs = filemtime("{$cacheDir}/{$repoId}.json");
  52. if ($cacheTs === $ts) {
  53. Header("Content-Type: application/json; charset=utf-8");
  54. readfile("{$cacheDir}/{$repoId}.json");
  55. exit(0);
  56. }
  57. }
  58. $data = $repo->data();
  59. if (isset($repoData['repositoryUrl'])) {
  60. $data['repositoryUrl'] = $repoData['repositoryUrl'];
  61. }
  62. if (isset($repoData['categoryUrl'])) {
  63. $data['categoryUrl'] = $repoData['categoryUrl'];
  64. }
  65. $ret = json_encode($data, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
  66. Header("Content-Type: application/json; charset=utf-8");
  67. print $ret;
  68. file_put_contents("{$cacheDir}/{$repoId}.json", $ret);
  69. touch("{$cacheDir}/{$repoId}.json", $ts);