config.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { defineStore } from "pinia";
  2. export const useConfigStore = defineStore("config", {
  3. state: (): {
  4. cookie: string;
  5. sitename: string;
  6. recaptcha: {
  7. enabled: boolean;
  8. key: string;
  9. };
  10. githubAuthentication: boolean;
  11. messages: Record<string, string>;
  12. christmas: boolean;
  13. footerLinks: Record<string, string | boolean>;
  14. primaryColor: string;
  15. shortcutOverrides: Record<string, any>;
  16. registrationDisabled: boolean;
  17. mailEnabled: boolean;
  18. discogsEnabled: boolean;
  19. experimental: {
  20. changable_listen_mode: string[] | boolean;
  21. media_session: boolean;
  22. disable_youtube_search: boolean;
  23. station_history: boolean;
  24. soundcloud: boolean;
  25. spotify: boolean;
  26. };
  27. } => ({
  28. cookie: "musareSID",
  29. sitename: MUSARE_SITENAME,
  30. recaptcha: {
  31. enabled: false,
  32. key: ""
  33. },
  34. githubAuthentication: false,
  35. messages: {
  36. accountRemoval:
  37. "Your account will be deactivated instantly and your data will shortly be deleted by an admin."
  38. },
  39. christmas: false,
  40. footerLinks: {},
  41. primaryColor: MUSARE_PRIMARY_COLOR,
  42. shortcutOverrides: {},
  43. registrationDisabled: false,
  44. mailEnabled: true,
  45. discogsEnabled: true,
  46. experimental: {
  47. changable_listen_mode: [],
  48. media_session: false,
  49. disable_youtube_search: false,
  50. station_history: false,
  51. soundcloud: false,
  52. spotify: false
  53. }
  54. }),
  55. actions: {
  56. get(query: string) {
  57. let config = JSON.parse(JSON.stringify(this.$state));
  58. query.split(".").forEach(property => {
  59. config = config[property];
  60. });
  61. return config;
  62. }
  63. },
  64. getters: {
  65. urls() {
  66. const { protocol, host } = document.location;
  67. const secure = protocol !== "http:";
  68. const client = `${protocol}//${host}`;
  69. const api = `${client}/backend`;
  70. const ws = `${secure ? "wss" : "ws"}://${host}/backend/ws`;
  71. return { client, api, ws, host, secure };
  72. }
  73. }
  74. });