RepoBrowseEntrypoint.vala 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using Invercargill;
  2. using Invercargill.DataStructures;
  3. using Statum;
  4. namespace UsmWeb {
  5. /**
  6. * Entrypoint for /repo/{name}: hydrates the
  7. * {@link PackagesState.SLOT_TYPE} PAGE slot scoped to one repository —
  8. * its overview card, add-repository instructions and package table.
  9. * Unknown repositories redirect to the overview; a load failure degrades
  10. * to an error card instead of a failed hydration.
  11. */
  12. public class RepoBrowseEntrypoint : StatumEntrypoint {
  13. protected RepositoryService repositories = Inversion.inject<RepositoryService>();
  14. protected UsmWebConfig config = Inversion.inject<UsmWebConfig>();
  15. protected Astralis.HttpContext http_context = Inversion.inject<Astralis.HttpContext>();
  16. public override async DirectiveBuilder handle() throws GLib.Error {
  17. var name = request.route("name") ?? "";
  18. var base_uri = DerivedBase.derive(http_context.request, config);
  19. State state;
  20. try {
  21. if (repositories.find(name) == null) {
  22. return directives().navigate("/");
  23. }
  24. state = PackagesState.build(repositories, config, action_registry, base_uri, "", name);
  25. } catch (Error e) {
  26. warning("[usm-web] Repository load failed: %s\n", e.message);
  27. var dict = new PropertyDictionary();
  28. dict.set_native<string>("load_error", e.message);
  29. state = new State() {
  30. type_name = PackagesState.SLOT_TYPE,
  31. public_data = dict,
  32. private_data = new PropertyDictionary()
  33. };
  34. }
  35. return directives().set(state_service.new_slot(Scope.PAGE, state));
  36. }
  37. }
  38. }