From 2291bd449509aa952691f27d33daca352cf742cd Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Fri, 28 Oct 2022 16:21:08 -0700 Subject: [PATCH] Check null for current user + default state --- src/components/SelectionManager.vue | 2 +- src/components/modal/AlbumCollaborators.vue | 2 +- src/components/modal/AlbumDeleteModal.vue | 2 +- src/components/modal/AlbumForm.vue | 2 +- src/components/modal/FaceDeleteModal.vue | 2 +- src/components/modal/FaceEditModal.vue | 2 +- src/components/modal/FaceMergeModal.vue | 2 +- src/components/modal/FaceMoveModal.vue | 2 +- src/mixins/UserConfig.ts | 25 +++++++++++++++------ src/services/Utils.ts | 2 +- src/services/dav/albums.ts | 2 +- src/services/dav/base.ts | 4 ++-- src/services/dav/folders.ts | 2 +- 13 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/components/SelectionManager.vue b/src/components/SelectionManager.vue index a9564c49..081b9e27 100644 --- a/src/components/SelectionManager.vue +++ b/src/components/SelectionManager.vue @@ -472,7 +472,7 @@ export default class SelectionHandler extends Mixins(GlobalMixin, UserConfig) { } // Check photo ownership - if (this.$route.params.user !== getCurrentUser().uid) { + if (this.$route.params.user !== getCurrentUser()?.uid) { showError( this.t("memories", 'Only user "{user}" can update this person', { user, diff --git a/src/components/modal/AlbumCollaborators.vue b/src/components/modal/AlbumCollaborators.vue index 3db9e8f0..658bb24c 100644 --- a/src/components/modal/AlbumCollaborators.vue +++ b/src/components/modal/AlbumCollaborators.vue @@ -231,7 +231,7 @@ export default class AddToAlbumModal extends Mixins(GlobalMixin) { get searchResults(): string[] { return this.currentSearchResults - .filter(({ id }) => id !== getCurrentUser().uid) + .filter(({ id }) => id !== getCurrentUser()?.uid) .map(({ type, id }) => `${type}:${id}`) .filter( (collaboratorKey) => diff --git a/src/components/modal/AlbumDeleteModal.vue b/src/components/modal/AlbumDeleteModal.vue index 92b49343..2aa10a34 100644 --- a/src/components/modal/AlbumDeleteModal.vue +++ b/src/components/modal/AlbumDeleteModal.vue @@ -50,7 +50,7 @@ export default class AlbumDeleteModal extends Mixins(GlobalMixin) { public open() { const user = this.$route.params.user || ""; - if (this.$route.params.user !== getCurrentUser().uid) { + if (this.$route.params.user !== getCurrentUser()?.uid) { showError( this.t("memories", 'Only user "{user}" can delete this album', { user }) ); diff --git a/src/components/modal/AlbumForm.vue b/src/components/modal/AlbumForm.vue index 49672401..ca307cdd 100644 --- a/src/components/modal/AlbumForm.vue +++ b/src/components/modal/AlbumForm.vue @@ -195,7 +195,7 @@ export default class AlbumForm extends Mixins(GlobalMixin) { this.loading = true; let album = { basename: this.albumName, - filename: `/photos/${getCurrentUser().uid}/albums/${this.albumName}`, + filename: `/photos/${getCurrentUser()?.uid}/albums/${this.albumName}`, nbItems: 0, location: this.albumLocation, lastPhoto: -1, diff --git a/src/components/modal/FaceDeleteModal.vue b/src/components/modal/FaceDeleteModal.vue index 7d8e23cc..7812f8d9 100644 --- a/src/components/modal/FaceDeleteModal.vue +++ b/src/components/modal/FaceDeleteModal.vue @@ -44,7 +44,7 @@ export default class FaceDeleteModal extends Mixins(GlobalMixin) { public open() { const user = this.$route.params.user || ""; - if (this.$route.params.user !== getCurrentUser().uid) { + if (this.$route.params.user !== getCurrentUser()?.uid) { showError( this.t("memories", 'Only user "{user}" can delete this person', { user, diff --git a/src/components/modal/FaceEditModal.vue b/src/components/modal/FaceEditModal.vue index 53f97fc2..c6334d5f 100644 --- a/src/components/modal/FaceEditModal.vue +++ b/src/components/modal/FaceEditModal.vue @@ -52,7 +52,7 @@ export default class FaceEditModal extends Mixins(GlobalMixin) { public open() { const user = this.$route.params.user || ""; - if (this.$route.params.user !== getCurrentUser().uid) { + if (this.$route.params.user !== getCurrentUser()?.uid) { showError( this.t("memories", 'Only user "{user}" can update this person', { user, diff --git a/src/components/modal/FaceMergeModal.vue b/src/components/modal/FaceMergeModal.vue index d1d677f0..46e044e3 100644 --- a/src/components/modal/FaceMergeModal.vue +++ b/src/components/modal/FaceMergeModal.vue @@ -62,7 +62,7 @@ export default class FaceMergeModal extends Mixins(GlobalMixin) { public open() { const user = this.$route.params.user || ""; - if (this.$route.params.user !== getCurrentUser().uid) { + if (this.$route.params.user !== getCurrentUser()?.uid) { showError( this.t("memories", 'Only user "{user}" can update this person', { user, diff --git a/src/components/modal/FaceMoveModal.vue b/src/components/modal/FaceMoveModal.vue index dbe5d0a4..f20e48af 100644 --- a/src/components/modal/FaceMoveModal.vue +++ b/src/components/modal/FaceMoveModal.vue @@ -55,7 +55,7 @@ export default class FaceMoveModal extends Mixins(GlobalMixin) { // check ownership const user = this.$route.params.user || ""; - if (this.$route.params.user !== getCurrentUser().uid) { + if (this.$route.params.user !== getCurrentUser()?.uid) { showError( this.t("memories", 'Only user "{user}" can update this person', { user, diff --git a/src/mixins/UserConfig.ts b/src/mixins/UserConfig.ts index f920168d..7e406b21 100644 --- a/src/mixins/UserConfig.ts +++ b/src/mixins/UserConfig.ts @@ -31,14 +31,25 @@ const localSettings = ["squareThumbs", "showFaceRect"]; @Component export default class UserConfig extends Vue { - config_timelinePath: string = loadState("memories", "timelinePath") || ""; - config_foldersPath: string = loadState("memories", "foldersPath") || "/"; - config_showHidden = loadState("memories", "showHidden") === "true"; + config_timelinePath: string = loadState( + "memories", + "timelinePath", + "" + ); + config_foldersPath: string = loadState( + "memories", + "foldersPath", + "/" + ); + config_showHidden = + loadState("memories", "showHidden", "false") === "true"; - config_tagsEnabled = Boolean(loadState("memories", "systemtags")); - config_recognizeEnabled = Boolean(loadState("memories", "recognize")); - config_mapsEnabled = Boolean(loadState("memories", "maps")); - config_albumsEnabled = Boolean(loadState("memories", "albums")); + config_tagsEnabled = Boolean(loadState("memories", "systemtags", "")); + config_recognizeEnabled = Boolean( + loadState("memories", "recognize", "") + ); + config_mapsEnabled = Boolean(loadState("memories", "maps", "")); + config_albumsEnabled = Boolean(loadState("memories", "albums", "")); config_squareThumbs = localStorage.getItem("memories_squareThumbs") === "1"; config_showFaceRect = localStorage.getItem("memories_showFaceRect") === "1"; diff --git a/src/services/Utils.ts b/src/services/Utils.ts index c59a8c04..2a0d4116 100644 --- a/src/services/Utils.ts +++ b/src/services/Utils.ts @@ -217,7 +217,7 @@ export const constants = { /** Cache store */ let staticCache: Cache | null = null; const cacheName = `memories-${loadState("memories", "version")}-${ - getCurrentUser()!.uid + getCurrentUser()?.uid }`; openCache().then((cache) => { staticCache = cache; diff --git a/src/services/dav/albums.ts b/src/services/dav/albums.ts index bce140fc..e5c5257b 100644 --- a/src/services/dav/albums.ts +++ b/src/services/dav/albums.ts @@ -20,7 +20,7 @@ import client from "../DavClient"; */ export function getAlbumPath(user: string, name: string) { // Folder in the dav collection for user - const cuid = getCurrentUser().uid; + const cuid = getCurrentUser()?.uid; if (user === cuid) { return `/photos/${cuid}/albums/${name}`; } else { diff --git a/src/services/dav/base.ts b/src/services/dav/base.ts index ab55a26f..9f96777c 100644 --- a/src/services/dav/base.ts +++ b/src/services/dav/base.ts @@ -66,7 +66,7 @@ export async function getFiles(photos: IPhoto[]): Promise { * @returns list of file infos */ async function getFilesInternal(fileIds: number[]): Promise { - const prefixPath = `/files/${getCurrentUser()!.uid}`; + const prefixPath = `/files/${getCurrentUser()?.uid}`; // IMPORTANT: if this isn't there, then a blank // returns EVERYTHING on the server! @@ -158,7 +158,7 @@ export async function* runInParallel( * @param path path to the file */ export async function deleteFile(path: string) { - const prefixPath = `/files/${getCurrentUser()!.uid}`; + const prefixPath = `/files/${getCurrentUser()?.uid}`; return await client.deleteFile(`${prefixPath}${path}`); } diff --git a/src/services/dav/folders.ts b/src/services/dav/folders.ts index 1c954724..f08caa2c 100644 --- a/src/services/dav/folders.ts +++ b/src/services/dav/folders.ts @@ -13,7 +13,7 @@ export async function getFolderPreviewFileIds( folderPath: string, limit: number ): Promise { - const prefixPath = `/files/${getCurrentUser()!.uid}`; + const prefixPath = `/files/${getCurrentUser()?.uid}`; const filter = base.IMAGE_MIME_TYPES.map( (mime) => `