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.

73 lines
2.1 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. if (!array_key_exists($repoId, $allRepositories)) {
  31. Header("HTTP/1.1 404 Repository not found");
  32. exit(0);
  33. }
  34. $repoData = $allRepositories[$repoId];
  35. $repo = getRepo($repoId, $repoData);
  36. $cacheDir = null;
  37. $ts = $repo->timestamp($path);
  38. if (isset($config['cache'])) {
  39. $cacheDir = "{$config['cache']}/repo";
  40. @mkdir($cacheDir);
  41. $cacheTs = filemtime("{$cacheDir}/{$repoId}.json");
  42. if ($cacheTs === $ts) {
  43. Header("Content-Type: application/json; charset=utf-8");
  44. readfile("{$cacheDir}/{$repoId}.json");
  45. exit(0);
  46. }
  47. }
  48. $data = $repo->data();
  49. if (isset($repoData['repositoryUrl'])) {
  50. $data['repositoryUrl'] = $repoData['repositoryUrl'];
  51. }
  52. if (isset($repoData['categoryUrl'])) {
  53. $data['categoryUrl'] = $repoData['categoryUrl'];
  54. }
  55. $ret = json_encode($data, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
  56. Header("Content-Type: application/json; charset=utf-8");
  57. print $ret;
  58. file_put_contents("{$cacheDir}/{$repoId}.json", $ret);
  59. touch("{$cacheDir}/{$repoId}.json", $ts);