memories/src/main.ts

120 lines
3.6 KiB
TypeScript
Raw Normal View History

import 'reflect-metadata';
import Vue from 'vue';
import VueVirtualScroller from 'vue-virtual-scroller';
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css';
import XImg from './components/frame/XImg.vue';
import GlobalMixin from './mixins/GlobalMixin';
import App from './App.vue';
import Admin from './components/admin/AdminMain.vue';
import router from './router';
import { generateFilePath } from '@nextcloud/router';
import { getRequestToken } from '@nextcloud/auth';
import type { Route } from 'vue-router';
import type { IPhoto } from './types';
import type PlyrType from 'plyr';
import type videojsType from 'video.js';
import './global.scss';
2022-12-11 04:01:57 +00:00
2022-10-28 22:46:13 +00:00
// Global exposed variables
declare global {
var mode: 'admin' | 'user';
2022-12-10 17:58:30 +00:00
var vueroute: () => Route;
2022-10-29 02:34:04 +00:00
var OC: Nextcloud.v24.OC;
var OCP: Nextcloud.v24.OCP;
2022-11-08 01:29:58 +00:00
2023-03-08 16:56:00 +00:00
var editMetadata: (photos: IPhoto[], sections?: number[]) => void;
var sharePhoto: (photo: IPhoto) => void;
2023-03-11 01:18:07 +00:00
var shareNodeLink: (path: string, immediate?: boolean) => Promise<void>;
2023-03-09 21:47:14 +00:00
var mSidebar: {
open: (fileid: number, filename?: string, forceNative?: boolean) => void;
2023-03-09 21:47:14 +00:00
close: () => void;
setTab: (tab: string) => void;
getWidth: () => number;
2023-03-09 21:47:14 +00:00
};
2022-11-08 01:29:58 +00:00
var currentViewerPhoto: IPhoto;
2022-11-23 11:03:06 +00:00
2022-11-23 11:16:45 +00:00
var windowInnerWidth: number; // cache
var windowInnerHeight: number; // cache
2022-11-24 19:36:41 +00:00
var __webpack_nonce__: string;
var __webpack_public_path__: string;
2022-11-27 20:49:04 +00:00
var vidjs: typeof videojsType;
var Plyr: typeof PlyrType;
var videoClientId: string;
var videoClientIdPersistent: string;
2022-10-28 22:46:13 +00:00
}
2022-11-23 11:16:45 +00:00
// Allow global access to the router
2022-12-10 17:58:30 +00:00
globalThis.vueroute = () => router.currentRoute;
2022-11-23 11:16:45 +00:00
// Cache these for better performance
2022-11-23 11:16:45 +00:00
globalThis.windowInnerWidth = window.innerWidth;
globalThis.windowInnerHeight = window.innerHeight;
2022-10-28 22:46:13 +00:00
2022-11-24 19:36:41 +00:00
// CSP config for webpack dynamic chunk loading
__webpack_nonce__ = window.btoa(getRequestToken() ?? '');
2022-11-24 19:36:41 +00:00
// Correct the root of the app for chunk loading
// OC.linkTo matches the apps folders
// OC.generateUrl ensure the index.php (or not)
// We do not want the index.php since we're loading files
__webpack_public_path__ = generateFilePath('memories', '', 'js/');
2022-11-24 19:36:41 +00:00
// Generate client id for this instance
// Does not need to be cryptographically secure
const getClientId = (): string => Math.random().toString(36).substring(2, 15).padEnd(12, '0');
globalThis.videoClientId = getClientId();
globalThis.videoClientIdPersistent = localStorage.getItem('videoClientIdPersistent') ?? getClientId();
localStorage.setItem('videoClientIdPersistent', globalThis.videoClientIdPersistent);
Vue.mixin(GlobalMixin as any);
Vue.use(VueVirtualScroller);
Vue.component('XImg', XImg);
2022-08-21 04:10:00 +00:00
// https://github.com/nextcloud/photos/blob/156f280c0476c483cb9ce81769ccb0c1c6500a4e/src/main.js
// TODO: remove when we have a proper fileinfo standalone library
// original scripts are loaded from
// https://github.com/nextcloud/server/blob/5bf3d1bb384da56adbf205752be8f840aac3b0c5/lib/private/legacy/template.php#L120-L122
window.addEventListener('DOMContentLoaded', () => {
2022-10-28 19:08:34 +00:00
if (!globalThis.OCA.Files) {
globalThis.OCA.Files = {};
}
// register unused client for the sidebar to have access to its parser methods
Object.assign(
globalThis.OCA.Files,
2022-10-29 02:36:01 +00:00
{
App: {
fileList: { filesClient: (<any>globalThis.OC.Files).getClient() },
},
},
2022-10-28 19:08:34 +00:00
globalThis.OCA.Files
);
});
2022-08-21 04:10:00 +00:00
let app = null;
const adminSection = document.getElementById('memories-admin-content');
if (adminSection) {
app = new Vue({
el: '#memories-admin-content',
render: (h) => h(Admin),
});
globalThis.mode = 'admin';
} else {
app = new Vue({
el: '#content',
router,
render: (h) => h(App),
});
globalThis.mode = 'user';
}
export default app;