|
@@ -6,7 +6,7 @@ import store from "./store";
|
|
import App from "./App.vue";
|
|
import App from "./App.vue";
|
|
import ws from "./ws";
|
|
import ws from "./ws";
|
|
|
|
|
|
-const REQUIRED_CONFIG_VERSION = 1;
|
|
|
|
|
|
+const REQUIRED_CONFIG_VERSION = 2;
|
|
|
|
|
|
const handleMetadata = attrs => {
|
|
const handleMetadata = attrs => {
|
|
document.title = `Musare | ${attrs.title}`;
|
|
document.title = `Musare | ${attrs.title}`;
|
|
@@ -137,106 +137,123 @@ const router = new VueRouter({
|
|
]
|
|
]
|
|
});
|
|
});
|
|
|
|
|
|
-// const { serverDomain } = config;
|
|
|
|
-ws.init({ url: "ws://localhost:8080/ws" });
|
|
|
|
-
|
|
|
|
-ws.socket.on("ready", (loggedIn, role, username, userId) =>
|
|
|
|
- store.dispatch("user/auth/authData", {
|
|
|
|
- loggedIn,
|
|
|
|
- role,
|
|
|
|
- username,
|
|
|
|
- userId
|
|
|
|
- })
|
|
|
|
-);
|
|
|
|
-
|
|
|
|
-ws.socket.on("keep.event:banned", ban =>
|
|
|
|
- store.dispatch("user/auth/banUser", ban)
|
|
|
|
-);
|
|
|
|
-
|
|
|
|
-ws.socket.on("event:user.username.changed", username =>
|
|
|
|
- store.dispatch("user/auth/updateUsername", username)
|
|
|
|
-);
|
|
|
|
-
|
|
|
|
-ws.socket.on("keep.event:user.preferences.changed", preferences => {
|
|
|
|
- store.dispatch(
|
|
|
|
- "user/preferences/changeAutoSkipDisliked",
|
|
|
|
- preferences.autoSkipDisliked
|
|
|
|
- );
|
|
|
|
|
|
+lofig.folder = "../config/default.json";
|
|
|
|
|
|
- store.dispatch("user/preferences/changeNightmode", preferences.nightmode);
|
|
|
|
|
|
+(async () => {
|
|
|
|
+ const websocketsDomain = await lofig.get("websocketsDomain");
|
|
|
|
+ ws.init(websocketsDomain);
|
|
|
|
|
|
- store.dispatch(
|
|
|
|
- "user/preferences/changeActivityLogPublic",
|
|
|
|
- preferences.activityLogPublic
|
|
|
|
|
|
+ ws.socket.on("ready", (loggedIn, role, username, userId) =>
|
|
|
|
+ store.dispatch("user/auth/authData", {
|
|
|
|
+ loggedIn,
|
|
|
|
+ role,
|
|
|
|
+ username,
|
|
|
|
+ userId
|
|
|
|
+ })
|
|
);
|
|
);
|
|
-});
|
|
|
|
|
|
|
|
-lofig.folder = "../config/default.json";
|
|
|
|
-lofig.fetchConfig().then(config => {
|
|
|
|
- const { configVersion, skipConfigVersionCheck } = config;
|
|
|
|
- if (configVersion !== REQUIRED_CONFIG_VERSION && !skipConfigVersionCheck) {
|
|
|
|
- // eslint-disable-next-line no-alert
|
|
|
|
- alert(
|
|
|
|
- "CONFIG VERSION IS WRONG. PLEASE UPDATE YOUR CONFIG WITH THE HELP OF THE TEMPLATE FILE AND THE README FILE."
|
|
|
|
- );
|
|
|
|
- window.stop();
|
|
|
|
- }
|
|
|
|
-});
|
|
|
|
|
|
+ ws.socket.on("keep.event:banned", ban =>
|
|
|
|
+ store.dispatch("user/auth/banUser", ban)
|
|
|
|
+ );
|
|
|
|
|
|
-router.beforeEach((to, from, next) => {
|
|
|
|
- if (window.stationInterval) {
|
|
|
|
- clearInterval(window.stationInterval);
|
|
|
|
- window.stationInterval = 0;
|
|
|
|
- }
|
|
|
|
|
|
+ ws.socket.on("event:user.username.changed", username =>
|
|
|
|
+ store.dispatch("user/auth/updateUsername", username)
|
|
|
|
+ );
|
|
|
|
|
|
- if (window.socket) ws.removeAllListeners();
|
|
|
|
|
|
+ ws.socket.on("keep.event:user.preferences.changed", preferences => {
|
|
|
|
+ store.dispatch(
|
|
|
|
+ "user/preferences/changeAutoSkipDisliked",
|
|
|
|
+ preferences.autoSkipDisliked
|
|
|
|
+ );
|
|
|
|
|
|
- ws.clear();
|
|
|
|
|
|
+ store.dispatch(
|
|
|
|
+ "user/preferences/changeNightmode",
|
|
|
|
+ preferences.nightmode
|
|
|
|
+ );
|
|
|
|
|
|
- if (to.meta.loginRequired || to.meta.adminRequired) {
|
|
|
|
- const gotData = () => {
|
|
|
|
- if (to.meta.loginRequired && !store.state.user.auth.loggedIn)
|
|
|
|
- next({ path: "/login" });
|
|
|
|
- else if (
|
|
|
|
- to.meta.adminRequired &&
|
|
|
|
- store.state.user.auth.role !== "admin"
|
|
|
|
- )
|
|
|
|
- next({ path: "/" });
|
|
|
|
- else next();
|
|
|
|
- };
|
|
|
|
|
|
+ store.dispatch(
|
|
|
|
+ "user/preferences/changeActivityLogPublic",
|
|
|
|
+ preferences.activityLogPublic
|
|
|
|
+ );
|
|
|
|
+ });
|
|
|
|
|
|
- if (store.state.user.auth.gotData) gotData();
|
|
|
|
- else {
|
|
|
|
- const watcher = store.watch(
|
|
|
|
- state => state.user.auth.gotData,
|
|
|
|
- () => {
|
|
|
|
- watcher();
|
|
|
|
- gotData();
|
|
|
|
- }
|
|
|
|
|
|
+ lofig.fetchConfig().then(config => {
|
|
|
|
+ const { configVersion, skipConfigVersionCheck } = config;
|
|
|
|
+ if (
|
|
|
|
+ configVersion !== REQUIRED_CONFIG_VERSION &&
|
|
|
|
+ !skipConfigVersionCheck
|
|
|
|
+ ) {
|
|
|
|
+ // eslint-disable-next-line no-alert
|
|
|
|
+ alert(
|
|
|
|
+ "CONFIG VERSION IS WRONG. PLEASE UPDATE YOUR CONFIG WITH THE HELP OF THE TEMPLATE FILE AND THE README FILE."
|
|
);
|
|
);
|
|
|
|
+ window.stop();
|
|
}
|
|
}
|
|
- } else next();
|
|
|
|
-});
|
|
|
|
|
|
+ });
|
|
|
|
|
|
-Vue.directive("click-outside", {
|
|
|
|
- bind(element, binding) {
|
|
|
|
- window.handleOutsideClick = event => {
|
|
|
|
- if (!(element === event.target || element.contains(event.target))) {
|
|
|
|
- binding.value();
|
|
|
|
|
|
+ router.beforeEach((to, from, next) => {
|
|
|
|
+ if (window.stationInterval) {
|
|
|
|
+ clearInterval(window.stationInterval);
|
|
|
|
+ window.stationInterval = 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (window.socket) ws.removeAllListeners();
|
|
|
|
+
|
|
|
|
+ ws.clear();
|
|
|
|
+
|
|
|
|
+ if (to.meta.loginRequired || to.meta.adminRequired) {
|
|
|
|
+ const gotData = () => {
|
|
|
|
+ if (to.meta.loginRequired && !store.state.user.auth.loggedIn)
|
|
|
|
+ next({ path: "/login" });
|
|
|
|
+ else if (
|
|
|
|
+ to.meta.adminRequired &&
|
|
|
|
+ store.state.user.auth.role !== "admin"
|
|
|
|
+ )
|
|
|
|
+ next({ path: "/" });
|
|
|
|
+ else next();
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ if (store.state.user.auth.gotData) gotData();
|
|
|
|
+ else {
|
|
|
|
+ const watcher = store.watch(
|
|
|
|
+ state => state.user.auth.gotData,
|
|
|
|
+ () => {
|
|
|
|
+ watcher();
|
|
|
|
+ gotData();
|
|
|
|
+ }
|
|
|
|
+ );
|
|
}
|
|
}
|
|
- };
|
|
|
|
|
|
+ } else next();
|
|
|
|
+ });
|
|
|
|
|
|
- document.body.addEventListener("click", window.handleOutsideClick);
|
|
|
|
- },
|
|
|
|
- unbind() {
|
|
|
|
- document.body.removeEventListener("click", window.handleOutsideClick);
|
|
|
|
- }
|
|
|
|
-});
|
|
|
|
|
|
+ Vue.directive("click-outside", {
|
|
|
|
+ bind(element, binding) {
|
|
|
|
+ window.handleOutsideClick = event => {
|
|
|
|
+ if (
|
|
|
|
+ !(
|
|
|
|
+ element === event.target ||
|
|
|
|
+ element.contains(event.target)
|
|
|
|
+ )
|
|
|
|
+ ) {
|
|
|
|
+ binding.value();
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
|
|
-// eslint-disable-next-line no-new
|
|
|
|
-new Vue({
|
|
|
|
- router,
|
|
|
|
- store,
|
|
|
|
- el: "#root",
|
|
|
|
- render: wrapper => wrapper(App)
|
|
|
|
-});
|
|
|
|
|
|
+ document.body.addEventListener("click", window.handleOutsideClick);
|
|
|
|
+ },
|
|
|
|
+ unbind() {
|
|
|
|
+ document.body.removeEventListener(
|
|
|
|
+ "click",
|
|
|
|
+ window.handleOutsideClick
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // eslint-disable-next-line no-new
|
|
|
|
+ new Vue({
|
|
|
|
+ router,
|
|
|
|
+ store,
|
|
|
|
+ el: "#root",
|
|
|
|
+ render: wrapper => wrapper(App)
|
|
|
|
+ });
|
|
|
|
+})();
|