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.

56 lines
1.6 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. print json_encode($repo->info(), JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_FORCE_OBJECT);
  18. }
  19. print '}';
  20. exit(0);
  21. }
  22. $repoId = $_REQUEST['repo'];
  23. if (!array_key_exists($repoId, $allRepositories)) {
  24. Header("HTTP/1.1 404 Repository not found");
  25. exit(0);
  26. }
  27. $repo = getRepo($repoId, $allRepositories[$repoId]);
  28. $cacheDir = null;
  29. $ts = $repo->timestamp($path);
  30. if (isset($config['cache'])) {
  31. $cacheDir = "{$config['cache']}/repo";
  32. @mkdir($cacheDir);
  33. $cacheTs = filemtime("{$cacheDir}/{$repoId}.json");
  34. if ($cacheTs === $ts) {
  35. Header("Content-Type: application/json; charset=utf-8");
  36. readfile("{$cacheDir}/{$repoId}.json");
  37. exit(0);
  38. }
  39. }
  40. $data = $repo->data();
  41. $ret = json_encode($data, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
  42. Header("Content-Type: application/json; charset=utf-8");
  43. print $ret;
  44. file_put_contents("{$cacheDir}/{$repoId}.json", $ret);
  45. touch("{$cacheDir}/{$repoId}.json", $ts);