2020-06-23 11:44:14 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright (c) 2018 - 2020 Michael Mayer <hello@photoprism.org>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2020-06-23 11:53:11 +00:00
|
|
|
PhotoPrism™ is a registered trademark of Michael Mayer. You may use it as required
|
|
|
|
to describe our software, run your own server, for educational purposes, but not for
|
|
|
|
offering commercial goods, products, or services without prior written permission.
|
|
|
|
In other words, please ask.
|
2020-06-23 11:44:14 +00:00
|
|
|
|
|
|
|
Feel free to send an e-mail to hello@photoprism.org if you have questions,
|
|
|
|
want to support our work, or just want to say hello.
|
|
|
|
|
|
|
|
Additional information can be found in our Developer Guide:
|
|
|
|
https://docs.photoprism.org/developer-guide/
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2019-12-05 02:13:42 +00:00
|
|
|
import "core-js/stable";
|
|
|
|
import "regenerator-runtime/runtime";
|
2019-05-09 04:48:10 +00:00
|
|
|
import Api from "common/api";
|
2019-11-16 22:55:56 +00:00
|
|
|
import Notify from "common/notify";
|
2019-05-21 09:54:39 +00:00
|
|
|
import Clipboard from "common/clipboard";
|
2019-05-28 00:50:22 +00:00
|
|
|
import Components from "component/components";
|
2019-06-30 00:52:12 +00:00
|
|
|
import Dialogs from "dialog/dialogs";
|
2019-11-16 21:41:14 +00:00
|
|
|
import Event from "pubsub-js";
|
|
|
|
import GetTextPlugin from "vue-gettext";
|
2019-12-02 01:43:41 +00:00
|
|
|
import Log from "common/log";
|
2020-06-22 18:15:08 +00:00
|
|
|
import PhotoPrism from "app.vue";
|
2019-11-16 21:41:14 +00:00
|
|
|
import Router from "vue-router";
|
|
|
|
import Routes from "routes";
|
2020-04-23 12:30:28 +00:00
|
|
|
import {config, session} from "session";
|
2019-11-17 13:24:48 +00:00
|
|
|
import {Settings} from "luxon";
|
2019-11-16 21:41:14 +00:00
|
|
|
import Socket from "common/websocket";
|
|
|
|
import Viewer from "common/viewer";
|
|
|
|
import Vue from "vue";
|
|
|
|
import Vuetify from "vuetify";
|
2019-09-19 21:23:39 +00:00
|
|
|
import VueLuxon from "vue-luxon";
|
2019-06-09 02:37:02 +00:00
|
|
|
import VueFilters from "vue2-filters";
|
2019-11-16 21:41:14 +00:00
|
|
|
import VueFullscreen from "vue-fullscreen";
|
|
|
|
import VueInfiniteScroll from "vue-infinite-scroll";
|
2020-05-20 08:42:48 +00:00
|
|
|
import VueModal from "vue-js-modal";
|
2020-05-13 13:36:42 +00:00
|
|
|
import Hls from "hls.js";
|
2020-07-03 14:27:26 +00:00
|
|
|
import {$gettext, Mount} from "common/vm";
|
2018-07-27 15:31:39 +00:00
|
|
|
|
2019-05-21 09:54:39 +00:00
|
|
|
// Initialize helpers
|
|
|
|
const viewer = new Viewer();
|
|
|
|
const clipboard = new Clipboard(window.localStorage, "photo_clipboard");
|
2020-04-26 12:31:33 +00:00
|
|
|
const isPublic = config.get("public");
|
2020-07-02 07:10:29 +00:00
|
|
|
const isMobile = (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
|
2018-07-27 15:31:39 +00:00
|
|
|
|
2020-05-13 13:36:42 +00:00
|
|
|
// HTTP Live Streaming (video support)
|
|
|
|
window.Hls = Hls;
|
|
|
|
|
2019-05-21 09:54:39 +00:00
|
|
|
// Assign helpers to VueJS prototype
|
2018-07-27 15:31:39 +00:00
|
|
|
Vue.prototype.$event = Event;
|
2019-11-16 22:55:56 +00:00
|
|
|
Vue.prototype.$notify = Notify;
|
2019-05-21 09:54:39 +00:00
|
|
|
Vue.prototype.$viewer = viewer;
|
2020-01-23 06:39:04 +00:00
|
|
|
Vue.prototype.$session = session;
|
2018-07-27 15:31:39 +00:00
|
|
|
Vue.prototype.$api = Api;
|
2019-12-02 01:43:41 +00:00
|
|
|
Vue.prototype.$log = Log;
|
2019-11-16 15:06:34 +00:00
|
|
|
Vue.prototype.$socket = Socket;
|
2018-09-13 08:23:06 +00:00
|
|
|
Vue.prototype.$config = config;
|
2019-05-21 09:54:39 +00:00
|
|
|
Vue.prototype.$clipboard = clipboard;
|
2020-07-02 07:10:29 +00:00
|
|
|
Vue.prototype.$isMobile = isMobile;
|
2018-07-27 15:31:39 +00:00
|
|
|
|
2019-05-07 00:05:01 +00:00
|
|
|
// Register Vuetify
|
2020-01-20 11:20:54 +00:00
|
|
|
Vue.use(Vuetify, {"theme": config.theme});
|
2018-09-06 21:58:16 +00:00
|
|
|
|
2019-12-02 18:03:41 +00:00
|
|
|
Vue.config.language = config.values.settings.language;
|
|
|
|
Settings.defaultLocale = config.values.settings.language;
|
2019-09-19 21:23:39 +00:00
|
|
|
|
2019-05-07 00:05:01 +00:00
|
|
|
// Register other VueJS plugins
|
2020-01-20 11:20:54 +00:00
|
|
|
Vue.use(GetTextPlugin, {
|
|
|
|
translations: config.translations,
|
2020-01-31 14:29:06 +00:00
|
|
|
silent: true, // !config.values.debug,
|
2020-01-20 11:20:54 +00:00
|
|
|
defaultLanguage: Vue.config.language,
|
2020-06-16 11:19:51 +00:00
|
|
|
autoAddKeyAttributes: true,
|
2020-01-20 11:20:54 +00:00
|
|
|
});
|
|
|
|
|
2019-09-19 21:23:39 +00:00
|
|
|
Vue.use(VueLuxon);
|
2019-06-09 02:37:02 +00:00
|
|
|
Vue.use(VueInfiniteScroll);
|
2018-09-25 07:45:06 +00:00
|
|
|
Vue.use(VueFullscreen);
|
2020-07-02 12:09:02 +00:00
|
|
|
Vue.use(VueModal, {dynamic: true, dynamicDefaults: {clickToClose: true}});
|
2019-06-09 02:37:02 +00:00
|
|
|
Vue.use(VueFilters);
|
2019-05-07 00:05:01 +00:00
|
|
|
Vue.use(Components);
|
2019-06-30 00:52:12 +00:00
|
|
|
Vue.use(Dialogs);
|
2018-07-27 15:31:39 +00:00
|
|
|
Vue.use(Router);
|
|
|
|
|
2019-05-07 00:05:01 +00:00
|
|
|
// Configure client-side routing
|
2018-07-27 15:31:39 +00:00
|
|
|
const router = new Router({
|
2019-05-19 16:58:30 +00:00
|
|
|
routes: Routes,
|
2019-05-09 04:48:10 +00:00
|
|
|
mode: "history",
|
2018-07-27 15:31:39 +00:00
|
|
|
saveScrollPosition: true,
|
|
|
|
});
|
|
|
|
|
2019-11-08 05:53:40 +00:00
|
|
|
router.beforeEach((to, from, next) => {
|
2019-11-17 13:24:48 +00:00
|
|
|
if (to.matched.some(record => record.meta.admin)) {
|
2020-01-23 06:39:04 +00:00
|
|
|
if (isPublic || session.isAdmin()) {
|
2019-11-08 05:53:40 +00:00
|
|
|
next();
|
|
|
|
} else {
|
|
|
|
next({
|
|
|
|
name: "login",
|
2019-11-17 13:24:48 +00:00
|
|
|
params: {nextUrl: to.fullPath},
|
2019-11-08 05:53:40 +00:00
|
|
|
});
|
|
|
|
}
|
2019-11-17 13:24:48 +00:00
|
|
|
} else if (to.matched.some(record => record.meta.auth)) {
|
2020-01-23 06:39:04 +00:00
|
|
|
if (isPublic || session.isUser()) {
|
2019-11-08 05:53:40 +00:00
|
|
|
next();
|
|
|
|
} else {
|
|
|
|
next({
|
|
|
|
name: "login",
|
2019-11-17 13:24:48 +00:00
|
|
|
params: {nextUrl: to.fullPath},
|
2019-11-08 05:53:40 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-01-20 11:20:54 +00:00
|
|
|
router.afterEach((to) => {
|
2020-07-03 14:27:26 +00:00
|
|
|
if (to.meta.title && config.values.siteTitle !== to.meta.title) {
|
|
|
|
config.page.title = $gettext(to.meta.title);
|
|
|
|
window.document.title = config.values.siteTitle + ": " + config.page.title;
|
2020-01-20 11:20:54 +00:00
|
|
|
} else {
|
2020-07-03 14:27:26 +00:00
|
|
|
config.page.title = config.values.siteTitle;
|
2020-05-31 10:52:41 +00:00
|
|
|
window.document.title = config.values.siteTitle + ": " + config.values.siteCaption;
|
2020-01-20 11:20:54 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-02 07:10:29 +00:00
|
|
|
// Pull client config every 10 minutes in case push fails (except on mobile to save battery).
|
2020-07-02 12:09:02 +00:00
|
|
|
if (isMobile) {
|
2020-07-02 07:10:29 +00:00
|
|
|
document.body.classList.add("mobile");
|
|
|
|
} else {
|
|
|
|
setInterval(() => config.update(), 600000);
|
|
|
|
}
|
|
|
|
|
2020-07-02 12:09:02 +00:00
|
|
|
// Start application.
|
|
|
|
Mount(Vue, PhotoPrism, router);
|