config.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { defineStore } from "pinia";
  2. export const useConfigStore = defineStore("config", {
  3. state: (): {
  4. config: {
  5. cookie: string;
  6. sitename: string;
  7. recaptcha: {
  8. enabled: boolean;
  9. key: string;
  10. };
  11. githubAuthentication: boolean;
  12. messages: Record<string, string>;
  13. christmas: boolean;
  14. footerLinks: Record<string, string | boolean>;
  15. shortcutOverrides: Record<string, any>;
  16. registrationDisabled: boolean;
  17. experimental: {
  18. changable_listen_mode: string[];
  19. media_session: boolean;
  20. disable_youtube_search: boolean;
  21. station_history: boolean;
  22. soundcloud: boolean;
  23. spotify: boolean;
  24. };
  25. };
  26. } => ({
  27. config: {
  28. cookie: "musareSID",
  29. sitename: "Musare",
  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. shortcutOverrides: {},
  42. registrationDisabled: false,
  43. experimental: {
  44. changable_listen_mode: [],
  45. media_session: false,
  46. disable_youtube_search: false,
  47. station_history: false,
  48. soundcloud: false,
  49. spotify: false
  50. }
  51. }
  52. }),
  53. actions: {
  54. setConfig(config) {
  55. this.config = config;
  56. },
  57. get(query: string) {
  58. let { config } = this;
  59. query.split(".").forEach(property => {
  60. config = config[property];
  61. });
  62. return config;
  63. }
  64. },
  65. getters: {
  66. urls() {
  67. const { protocol, host } = document.location;
  68. const secure = protocol !== "http:";
  69. const client = `${protocol}//${host}`;
  70. const api = `${client}/backend`;
  71. const ws = `${secure ? "wss" : "ws"}://${host}/backend/ws`;
  72. return { client, api, ws, host, secure };
  73. }
  74. }
  75. });