refactor: use cached uid and isAdmin
Signed-off-by: Varun Patil <radialapps@gmail.com>pull/803/head
parent
78de9601ef
commit
bca08f7eb2
|
@ -51,7 +51,6 @@ import NcContent from '@nextcloud/vue/dist/Components/NcContent';
|
||||||
import NcAppContent from '@nextcloud/vue/dist/Components/NcAppContent';
|
import NcAppContent from '@nextcloud/vue/dist/Components/NcAppContent';
|
||||||
import NcButton from '@nextcloud/vue/dist/Components/NcButton';
|
import NcButton from '@nextcloud/vue/dist/Components/NcButton';
|
||||||
|
|
||||||
import { getCurrentUser } from '@nextcloud/auth';
|
|
||||||
import axios from '@nextcloud/axios';
|
import axios from '@nextcloud/axios';
|
||||||
|
|
||||||
import banner from '../assets/banner.svg';
|
import banner from '../assets/banner.svg';
|
||||||
|
@ -85,7 +84,7 @@ export default defineComponent({
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
isAdmin(): boolean {
|
isAdmin(): boolean {
|
||||||
return Boolean(getCurrentUser()?.isAdmin);
|
return utils.isAdmin;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,6 @@ import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton';
|
||||||
|
|
||||||
import { translate as t, translatePlural as n } from '@nextcloud/l10n';
|
import { translate as t, translatePlural as n } from '@nextcloud/l10n';
|
||||||
import { subscribe, unsubscribe } from '@nextcloud/event-bus';
|
import { subscribe, unsubscribe } from '@nextcloud/event-bus';
|
||||||
import { getCurrentUser } from '@nextcloud/auth';
|
|
||||||
|
|
||||||
import * as dav from '../services/dav';
|
import * as dav from '../services/dav';
|
||||||
import * as utils from '../services/utils';
|
import * as utils from '../services/utils';
|
||||||
|
@ -899,7 +898,7 @@ export default defineComponent({
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check photo ownership
|
// Check photo ownership
|
||||||
if (this.$route.params.user !== getCurrentUser()?.uid) {
|
if (this.$route.params.user !== utils.uid) {
|
||||||
showError(this.t('memories', 'Only user "{user}" can update this person', { user }));
|
showError(this.t('memories', 'Only user "{user}" can update this person', { user }));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,8 +145,6 @@ input[type='text'] {
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
|
|
||||||
import { getCurrentUser } from '@nextcloud/auth';
|
|
||||||
|
|
||||||
import UserConfig from '../mixins/UserConfig';
|
import UserConfig from '../mixins/UserConfig';
|
||||||
import * as utils from '../services/utils';
|
import * as utils from '../services/utils';
|
||||||
import * as nativex from '../native';
|
import * as nativex from '../native';
|
||||||
|
@ -192,7 +190,7 @@ export default defineComponent({
|
||||||
},
|
},
|
||||||
|
|
||||||
user(): string {
|
user(): string {
|
||||||
return getCurrentUser()?.uid.toString() ?? '';
|
return utils.uid ?? String();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, PropType } from 'vue';
|
import { defineComponent, PropType } from 'vue';
|
||||||
|
|
||||||
import { getCurrentUser } from '@nextcloud/auth';
|
|
||||||
import NcCounterBubble from '@nextcloud/vue/dist/Components/NcCounterBubble';
|
import NcCounterBubble from '@nextcloud/vue/dist/Components/NcCounterBubble';
|
||||||
|
|
||||||
import type { IAlbum, ICluster, IFace, IPhoto } from '../../types';
|
import type { IAlbum, ICluster, IFace, IPhoto } from '../../types';
|
||||||
|
@ -36,6 +35,7 @@ import { getPreviewUrl } from '../../services/utils/helpers';
|
||||||
import errorsvg from '../../assets/error.svg';
|
import errorsvg from '../../assets/error.svg';
|
||||||
import plussvg from '../../assets/plus.svg';
|
import plussvg from '../../assets/plus.svg';
|
||||||
|
|
||||||
|
import * as utils from '../../services/utils';
|
||||||
import { API } from '../../services/API';
|
import { API } from '../../services/API';
|
||||||
|
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
|
@ -95,7 +95,7 @@ export default defineComponent({
|
||||||
text = this.n('memories', '{n} item', '{n} items', this.album.count, { n: this.album.count });
|
text = this.n('memories', '{n} item', '{n} items', this.album.count, { n: this.album.count });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.album.user !== getCurrentUser()?.uid) {
|
if (this.album.user !== utils.uid) {
|
||||||
text +=
|
text +=
|
||||||
' / ' +
|
' / ' +
|
||||||
this.t('memories', 'Shared by {user}', {
|
this.t('memories', 'Shared by {user}', {
|
||||||
|
|
|
@ -138,7 +138,6 @@ import Earth from 'vue-material-design-icons/Earth.vue';
|
||||||
|
|
||||||
import axios from '@nextcloud/axios';
|
import axios from '@nextcloud/axios';
|
||||||
import { showError } from '@nextcloud/dialogs';
|
import { showError } from '@nextcloud/dialogs';
|
||||||
import { getCurrentUser } from '@nextcloud/auth';
|
|
||||||
import { generateOcsUrl, generateUrl } from '@nextcloud/router';
|
import { generateOcsUrl, generateUrl } from '@nextcloud/router';
|
||||||
|
|
||||||
import NcButton from '@nextcloud/vue/dist/Components/NcButton';
|
import NcButton from '@nextcloud/vue/dist/Components/NcButton';
|
||||||
|
@ -148,6 +147,7 @@ const NcTextField = () => import('@nextcloud/vue/dist/Components/NcTextField');
|
||||||
const NcListItemIcon = () => import('@nextcloud/vue/dist/Components/NcListItemIcon');
|
const NcListItemIcon = () => import('@nextcloud/vue/dist/Components/NcListItemIcon');
|
||||||
|
|
||||||
import * as dav from '../../services/dav';
|
import * as dav from '../../services/dav';
|
||||||
|
import * as utils from '../../services/utils';
|
||||||
import * as nativex from '../../native';
|
import * as nativex from '../../native';
|
||||||
|
|
||||||
import { Type } from '@nextcloud/sharing';
|
import { Type } from '@nextcloud/sharing';
|
||||||
|
@ -208,7 +208,7 @@ export default defineComponent({
|
||||||
computed: {
|
computed: {
|
||||||
searchResults(): string[] {
|
searchResults(): string[] {
|
||||||
return this.currentSearchResults
|
return this.currentSearchResults
|
||||||
.filter(({ id }) => id !== getCurrentUser()?.uid)
|
.filter(({ id }) => id !== utils.uid)
|
||||||
.map(({ type, id }) => `${type}:${id}`)
|
.map(({ type, id }) => `${type}:${id}`)
|
||||||
.filter((collaboratorKey) => !this.selectedCollaboratorsKeys.includes(collaboratorKey));
|
.filter((collaboratorKey) => !this.selectedCollaboratorsKeys.includes(collaboratorKey));
|
||||||
},
|
},
|
||||||
|
@ -333,9 +333,8 @@ export default defineComponent({
|
||||||
this.loadingAlbum = true;
|
this.loadingAlbum = true;
|
||||||
this.errorFetchingAlbum = null;
|
this.errorFetchingAlbum = null;
|
||||||
|
|
||||||
const uid = getCurrentUser()?.uid.toString();
|
if (!utils.uid) return;
|
||||||
if (!uid) return;
|
const album = await dav.getAlbum(utils.uid, this.albumName);
|
||||||
const album = await dav.getAlbum(uid, this.albumName);
|
|
||||||
this.populateCollaborators(album.collaborators);
|
this.populateCollaborators(album.collaborators);
|
||||||
|
|
||||||
// Direct share if native share is available
|
// Direct share if native share is available
|
||||||
|
@ -366,9 +365,8 @@ export default defineComponent({
|
||||||
|
|
||||||
async updateAlbumCollaborators() {
|
async updateAlbumCollaborators() {
|
||||||
try {
|
try {
|
||||||
const uid = getCurrentUser()?.uid?.toString();
|
if (!utils.uid) return;
|
||||||
if (!uid) return;
|
const album = await dav.getAlbum(utils.uid, this.albumName);
|
||||||
const album = await dav.getAlbum(uid, this.albumName);
|
|
||||||
await dav.updateAlbum(album, {
|
await dav.updateAlbum(album, {
|
||||||
albumName: this.albumName,
|
albumName: this.albumName,
|
||||||
properties: {
|
properties: {
|
||||||
|
|
|
@ -58,7 +58,7 @@ export default defineComponent({
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
owned() {
|
owned() {
|
||||||
return this.user === utils.uid();
|
return this.user === utils.uid;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -89,12 +89,12 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, PropType } from 'vue';
|
import { defineComponent, PropType } from 'vue';
|
||||||
|
|
||||||
import { getCurrentUser } from '@nextcloud/auth';
|
|
||||||
import { showError } from '@nextcloud/dialogs';
|
import { showError } from '@nextcloud/dialogs';
|
||||||
import NcButton from '@nextcloud/vue/dist/Components/NcButton';
|
import NcButton from '@nextcloud/vue/dist/Components/NcButton';
|
||||||
const NcTextField = () => import('@nextcloud/vue/dist/Components/NcTextField');
|
const NcTextField = () => import('@nextcloud/vue/dist/Components/NcTextField');
|
||||||
|
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
|
import * as utils from '../../services/utils';
|
||||||
import * as dav from '../../services/dav';
|
import * as dav from '../../services/dav';
|
||||||
|
|
||||||
import AlbumCollaborators from './AlbumCollaborators.vue';
|
import AlbumCollaborators from './AlbumCollaborators.vue';
|
||||||
|
@ -186,7 +186,7 @@ export default defineComponent({
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
let album = {
|
let album = {
|
||||||
basename: this.albumName,
|
basename: this.albumName,
|
||||||
filename: `/photos/${getCurrentUser()?.uid}/albums/${this.albumName}`,
|
filename: `/photos/${utils.uid}/albums/${this.albumName}`,
|
||||||
nbItems: 0,
|
nbItems: 0,
|
||||||
location: this.albumLocation,
|
location: this.albumLocation,
|
||||||
lastPhoto: -1,
|
lastPhoto: -1,
|
||||||
|
|
|
@ -34,11 +34,11 @@
|
||||||
import { defineComponent, PropType } from 'vue';
|
import { defineComponent, PropType } from 'vue';
|
||||||
import { getPreviewUrl } from '../../services/utils/helpers';
|
import { getPreviewUrl } from '../../services/utils/helpers';
|
||||||
|
|
||||||
import { getCurrentUser } from '@nextcloud/auth';
|
|
||||||
|
|
||||||
import NcButton from '@nextcloud/vue/dist/Components/NcButton';
|
import NcButton from '@nextcloud/vue/dist/Components/NcButton';
|
||||||
const NcListItem = () => import('@nextcloud/vue/dist/Components/NcListItem');
|
const NcListItem = () => import('@nextcloud/vue/dist/Components/NcListItem');
|
||||||
|
|
||||||
|
import * as utils from '../../services/utils';
|
||||||
|
|
||||||
import type { IAlbum, IPhoto } from '../../types';
|
import type { IAlbum, IPhoto } from '../../types';
|
||||||
|
|
||||||
import ImageMultipleIcon from 'vue-material-design-icons/ImageMultiple.vue';
|
import ImageMultipleIcon from 'vue-material-design-icons/ImageMultiple.vue';
|
||||||
|
@ -93,7 +93,7 @@ export default defineComponent({
|
||||||
getSubtitle(album: IAlbum) {
|
getSubtitle(album: IAlbum) {
|
||||||
let text = this.n('memories', '%n item', '%n items', album.count);
|
let text = this.n('memories', '%n item', '%n items', album.count);
|
||||||
|
|
||||||
if (album.user !== getCurrentUser()?.uid) {
|
if (album.user !== utils.uid) {
|
||||||
text +=
|
text +=
|
||||||
' / ' +
|
' / ' +
|
||||||
this.t('memories', 'shared by {owner}', {
|
this.t('memories', 'shared by {owner}', {
|
||||||
|
|
|
@ -21,8 +21,10 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton';
|
||||||
const NcTextField = () => import('@nextcloud/vue/dist/Components/NcTextField');
|
const NcTextField = () => import('@nextcloud/vue/dist/Components/NcTextField');
|
||||||
|
|
||||||
import { showError } from '@nextcloud/dialogs';
|
import { showError } from '@nextcloud/dialogs';
|
||||||
import { getCurrentUser } from '@nextcloud/auth';
|
|
||||||
import Modal from './Modal.vue';
|
import Modal from './Modal.vue';
|
||||||
|
|
||||||
|
import * as utils from '../../services/utils';
|
||||||
import * as dav from '../../services/dav';
|
import * as dav from '../../services/dav';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
|
@ -57,7 +59,7 @@ export default defineComponent({
|
||||||
|
|
||||||
open() {
|
open() {
|
||||||
const user = this.$route.params.user || '';
|
const user = this.$route.params.user || '';
|
||||||
if (this.$route.params.user !== getCurrentUser()?.uid) {
|
if (this.$route.params.user !== utils.uid) {
|
||||||
showError(
|
showError(
|
||||||
this.t('memories', 'Only user "{user}" can delete this person', {
|
this.t('memories', 'Only user "{user}" can delete this person', {
|
||||||
user,
|
user,
|
||||||
|
|
|
@ -31,8 +31,10 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton';
|
||||||
const NcTextField = () => import('@nextcloud/vue/dist/Components/NcTextField');
|
const NcTextField = () => import('@nextcloud/vue/dist/Components/NcTextField');
|
||||||
|
|
||||||
import { showError } from '@nextcloud/dialogs';
|
import { showError } from '@nextcloud/dialogs';
|
||||||
import { getCurrentUser } from '@nextcloud/auth';
|
|
||||||
import Modal from './Modal.vue';
|
import Modal from './Modal.vue';
|
||||||
|
|
||||||
|
import * as utils from '../../services/utils';
|
||||||
import * as dav from '../../services/dav';
|
import * as dav from '../../services/dav';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
|
@ -74,7 +76,7 @@ export default defineComponent({
|
||||||
|
|
||||||
open() {
|
open() {
|
||||||
const user = this.$route.params.user || '';
|
const user = this.$route.params.user || '';
|
||||||
if (this.$route.params.user !== getCurrentUser()?.uid) {
|
if (this.$route.params.user !== utils.uid) {
|
||||||
showError(
|
showError(
|
||||||
this.t('memories', 'Only user "{user}" can update this person', {
|
this.t('memories', 'Only user "{user}" can update this person', {
|
||||||
user,
|
user,
|
||||||
|
|
|
@ -28,7 +28,6 @@ const NcTextField = () => import('@nextcloud/vue/dist/Components/NcTextField');
|
||||||
const NcProgressBar = () => import('@nextcloud/vue/dist/Components/NcProgressBar');
|
const NcProgressBar = () => import('@nextcloud/vue/dist/Components/NcProgressBar');
|
||||||
|
|
||||||
import { showError } from '@nextcloud/dialogs';
|
import { showError } from '@nextcloud/dialogs';
|
||||||
import { getCurrentUser } from '@nextcloud/auth';
|
|
||||||
import { IFileInfo, IFace } from '../../types';
|
import { IFileInfo, IFace } from '../../types';
|
||||||
import Cluster from '../frame/Cluster.vue';
|
import Cluster from '../frame/Cluster.vue';
|
||||||
import FaceList from './FaceList.vue';
|
import FaceList from './FaceList.vue';
|
||||||
|
@ -63,7 +62,7 @@ export default defineComponent({
|
||||||
|
|
||||||
open() {
|
open() {
|
||||||
const user = this.$route.params.user || '';
|
const user = this.$route.params.user || '';
|
||||||
if (this.$route.params.user !== getCurrentUser()?.uid) {
|
if (this.$route.params.user !== utils.uid) {
|
||||||
showError(
|
showError(
|
||||||
this.t('memories', 'Only user "{user}" can update this person', {
|
this.t('memories', 'Only user "{user}" can update this person', {
|
||||||
user,
|
user,
|
||||||
|
|
|
@ -23,7 +23,6 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton';
|
||||||
const NcTextField = () => import('@nextcloud/vue/dist/Components/NcTextField');
|
const NcTextField = () => import('@nextcloud/vue/dist/Components/NcTextField');
|
||||||
|
|
||||||
import { showError } from '@nextcloud/dialogs';
|
import { showError } from '@nextcloud/dialogs';
|
||||||
import { getCurrentUser } from '@nextcloud/auth';
|
|
||||||
import { IPhoto, IFace } from '../../types';
|
import { IPhoto, IFace } from '../../types';
|
||||||
import Cluster from '../frame/Cluster.vue';
|
import Cluster from '../frame/Cluster.vue';
|
||||||
import FaceList from './FaceList.vue';
|
import FaceList from './FaceList.vue';
|
||||||
|
@ -63,7 +62,7 @@ export default defineComponent({
|
||||||
|
|
||||||
// check ownership
|
// check ownership
|
||||||
const user = this.$route.params.user || '';
|
const user = this.$route.params.user || '';
|
||||||
if (this.$route.params.user !== getCurrentUser()?.uid) {
|
if (this.$route.params.user !== utils.uid) {
|
||||||
showError(
|
showError(
|
||||||
this.t('memories', 'Only user "{user}" can update this person', {
|
this.t('memories', 'Only user "{user}" can update this person', {
|
||||||
user,
|
user,
|
||||||
|
|
|
@ -102,7 +102,6 @@ import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton';
|
||||||
import NcActionCheckbox from '@nextcloud/vue/dist/Components/NcActionCheckbox';
|
import NcActionCheckbox from '@nextcloud/vue/dist/Components/NcActionCheckbox';
|
||||||
import NcActionRadio from '@nextcloud/vue/dist/Components/NcActionRadio';
|
import NcActionRadio from '@nextcloud/vue/dist/Components/NcActionRadio';
|
||||||
|
|
||||||
import { getCurrentUser } from '@nextcloud/auth';
|
|
||||||
import axios from '@nextcloud/axios';
|
import axios from '@nextcloud/axios';
|
||||||
|
|
||||||
import AlbumCreateModal from '../modal/AlbumCreateModal.vue';
|
import AlbumCreateModal from '../modal/AlbumCreateModal.vue';
|
||||||
|
@ -154,7 +153,7 @@ export default defineComponent({
|
||||||
},
|
},
|
||||||
|
|
||||||
canEditAlbum(): boolean {
|
canEditAlbum(): boolean {
|
||||||
return !this.isAlbumList && this.$route.params.user === getCurrentUser()?.uid;
|
return !this.isAlbumList && this.$route.params.user === utils.uid;
|
||||||
},
|
},
|
||||||
|
|
||||||
name(): string {
|
name(): string {
|
||||||
|
|
|
@ -67,7 +67,6 @@ import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton';
|
||||||
import NcActionCheckbox from '@nextcloud/vue/dist/Components/NcActionCheckbox';
|
import NcActionCheckbox from '@nextcloud/vue/dist/Components/NcActionCheckbox';
|
||||||
|
|
||||||
import { emit } from '@nextcloud/event-bus';
|
import { emit } from '@nextcloud/event-bus';
|
||||||
import { getCurrentUser } from '@nextcloud/auth';
|
|
||||||
|
|
||||||
import FaceEditModal from '../modal/FaceEditModal.vue';
|
import FaceEditModal from '../modal/FaceEditModal.vue';
|
||||||
import FaceDeleteModal from '../modal/FaceDeleteModal.vue';
|
import FaceDeleteModal from '../modal/FaceDeleteModal.vue';
|
||||||
|
@ -132,7 +131,7 @@ export default defineComponent({
|
||||||
this.$router.push({
|
this.$router.push({
|
||||||
name: this.$route.name as string,
|
name: this.$route.name as string,
|
||||||
params: {
|
params: {
|
||||||
user: String(getCurrentUser()?.uid),
|
user: utils.uid as string,
|
||||||
name: utils.constants.FACE_NULL,
|
name: utils.constants.FACE_NULL,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,7 +5,6 @@ import * as utils from '../../services/utils';
|
||||||
|
|
||||||
import { showError } from '@nextcloud/dialogs';
|
import { showError } from '@nextcloud/dialogs';
|
||||||
import { translate as t } from '@nextcloud/l10n';
|
import { translate as t } from '@nextcloud/l10n';
|
||||||
import { getCurrentUser } from '@nextcloud/auth';
|
|
||||||
|
|
||||||
import { API } from '../../services/API';
|
import { API } from '../../services/API';
|
||||||
import type { PsContent, PsEvent } from './types';
|
import type { PsContent, PsEvent } from './types';
|
||||||
|
@ -203,7 +202,7 @@ class VideoContentSetup {
|
||||||
hlsFailed = true;
|
hlsFailed = true;
|
||||||
console.warn('PsVideo: HLS stream could not be opened.');
|
console.warn('PsVideo: HLS stream could not be opened.');
|
||||||
|
|
||||||
if (getCurrentUser()?.isAdmin) {
|
if (utils.isAdmin) {
|
||||||
showError(t('memories', 'Transcoding failed, check Nextcloud logs.'));
|
showError(t('memories', 'Transcoding failed, check Nextcloud logs.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,24 @@
|
||||||
import * as base from './base';
|
import * as base from './base';
|
||||||
import { getCurrentUser } from '@nextcloud/auth';
|
|
||||||
|
import axios from '@nextcloud/axios';
|
||||||
import { showError } from '@nextcloud/dialogs';
|
import { showError } from '@nextcloud/dialogs';
|
||||||
import { translate as t } from '@nextcloud/l10n';
|
import { translate as t } from '@nextcloud/l10n';
|
||||||
|
|
||||||
import { IAlbum, IFileInfo, IPhoto } from '../../types';
|
import { IAlbum, IFileInfo, IPhoto } from '../../types';
|
||||||
|
|
||||||
import { API } from '../API';
|
import { API } from '../API';
|
||||||
import axios from '@nextcloud/axios';
|
|
||||||
import client from './client';
|
import client from './client';
|
||||||
|
import * as utils from '../utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get DAV path for album
|
* Get DAV path for album
|
||||||
*/
|
*/
|
||||||
export function getAlbumPath(user: string, name: string) {
|
export function getAlbumPath(user: string, name: string) {
|
||||||
// Folder in the dav collection for user
|
// Folder in the dav collection for user
|
||||||
const cuid = getCurrentUser()?.uid;
|
if (user === utils.uid) {
|
||||||
if (user === cuid) {
|
return `/photos/${utils.uid}/albums/${name}`;
|
||||||
return `/photos/${cuid}/albums/${name}`;
|
|
||||||
} else {
|
} else {
|
||||||
return `/photos/${cuid}/sharedalbums/${name} (${user})`;
|
return `/photos/${utils.uid}/sharedalbums/${name} (${user})`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +118,7 @@ export async function* removeFromAlbum(user: string, name: string, photos: IPhot
|
||||||
*/
|
*/
|
||||||
export async function createAlbum(albumName: string) {
|
export async function createAlbum(albumName: string) {
|
||||||
try {
|
try {
|
||||||
await client.createDirectory(`/photos/${getCurrentUser()?.uid}/albums/${albumName}`);
|
await client.createDirectory(`/photos/${utils.uid}/albums/${albumName}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
showError(t('photos', 'Failed to create {albumName}.', { albumName }));
|
showError(t('photos', 'Failed to create {albumName}.', { albumName }));
|
||||||
|
@ -214,8 +216,8 @@ export async function renameAlbum(album: any, { currentAlbumName, newAlbumName }
|
||||||
const newAlbum = { ...album, basename: newAlbumName };
|
const newAlbum = { ...album, basename: newAlbumName };
|
||||||
try {
|
try {
|
||||||
await client.moveFile(
|
await client.moveFile(
|
||||||
`/photos/${getCurrentUser()?.uid}/albums/${currentAlbumName}`,
|
`/photos/${utils.uid}/albums/${currentAlbumName}`,
|
||||||
`/photos/${getCurrentUser()?.uid}/albums/${newAlbumName}`
|
`/photos/${utils.uid}/albums/${newAlbumName}`
|
||||||
);
|
);
|
||||||
return newAlbum;
|
return newAlbum;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -232,11 +234,10 @@ export async function renameAlbum(album: any, { currentAlbumName, newAlbumName }
|
||||||
|
|
||||||
/** Get fileinfo objects from album photos */
|
/** Get fileinfo objects from album photos */
|
||||||
export function getAlbumFileInfos(photos: IPhoto[], albumUser: string, albumName: string): IFileInfo[] {
|
export function getAlbumFileInfos(photos: IPhoto[], albumUser: string, albumName: string): IFileInfo[] {
|
||||||
const uid = getCurrentUser()?.uid;
|
|
||||||
const collection =
|
const collection =
|
||||||
albumUser === uid
|
albumUser === utils.uid
|
||||||
? `/photos/${uid}/albums/${albumName}`
|
? `/photos/${utils.uid}/albums/${albumName}`
|
||||||
: `/photos/${uid}/sharedalbums/${albumName} (${albumUser})`;
|
: `/photos/${utils.uid}/sharedalbums/${albumName} (${albumUser})`;
|
||||||
|
|
||||||
return photos.map((photo) => {
|
return photos.map((photo) => {
|
||||||
const basename = `${photo.fileid}-${photo.basename}`;
|
const basename = `${photo.fileid}-${photo.basename}`;
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import { getCurrentUser } from '@nextcloud/auth';
|
|
||||||
import { showError } from '@nextcloud/dialogs';
|
import { showError } from '@nextcloud/dialogs';
|
||||||
import { translate as t } from '@nextcloud/l10n';
|
import { translate as t } from '@nextcloud/l10n';
|
||||||
import axios from '@nextcloud/axios';
|
import axios from '@nextcloud/axios';
|
||||||
|
@ -60,8 +59,7 @@ export async function getFiles(photos: IPhoto[]): Promise<IFileInfo[]> {
|
||||||
const rest: IPhoto[] = [];
|
const rest: IPhoto[] = [];
|
||||||
|
|
||||||
// Partition photos with and without cache
|
// Partition photos with and without cache
|
||||||
const uid = getCurrentUser()?.uid;
|
if (utils.uid) {
|
||||||
if (uid) {
|
|
||||||
for (const photo of photos) {
|
for (const photo of photos) {
|
||||||
const filename = photo.imageInfo?.filename;
|
const filename = photo.imageInfo?.filename;
|
||||||
if (filename) {
|
if (filename) {
|
||||||
|
@ -69,7 +67,7 @@ export async function getFiles(photos: IPhoto[]): Promise<IFileInfo[]> {
|
||||||
id: photo.fileid,
|
id: photo.fileid,
|
||||||
fileid: photo.fileid,
|
fileid: photo.fileid,
|
||||||
basename: photo.basename ?? filename.split('/').pop() ?? '',
|
basename: photo.basename ?? filename.split('/').pop() ?? '',
|
||||||
originalFilename: `/files/${uid}${filename}`,
|
originalFilename: `/files/${utils.uid}${filename}`,
|
||||||
filename: filename,
|
filename: filename,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -97,7 +95,7 @@ async function getFilesInternal1(photos: IPhoto[]): Promise<IFileInfo[]> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getFilesInternal2(fileIds: number[]): Promise<IFileInfo[]> {
|
async function getFilesInternal2(fileIds: number[]): Promise<IFileInfo[]> {
|
||||||
const prefixPath = `/files/${getCurrentUser()?.uid}`;
|
const prefixPath = `/files/${utils.uid}`;
|
||||||
|
|
||||||
// IMPORTANT: if this isn't there, then a blank
|
// IMPORTANT: if this isn't there, then a blank
|
||||||
// returns EVERYTHING on the server!
|
// returns EVERYTHING on the server!
|
||||||
|
@ -311,7 +309,7 @@ export async function* movePhotos(photos: IPhoto[], destination: string, overwri
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set absolute target path
|
// Set absolute target path
|
||||||
const prefixPath = `files/${getCurrentUser()?.uid}`;
|
const prefixPath = `files/${utils.uid}`;
|
||||||
let targetPath = prefixPath + destination;
|
let targetPath = prefixPath + destination;
|
||||||
if (!targetPath.endsWith('/')) {
|
if (!targetPath.endsWith('/')) {
|
||||||
targetPath += '/';
|
targetPath += '/';
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
import { getCurrentUser } from '@nextcloud/auth';
|
|
||||||
import config from '../static-config';
|
import config from '../static-config';
|
||||||
|
import { uid } from './helpers';
|
||||||
|
|
||||||
/** Cache keys */
|
/** Cache keys */
|
||||||
const uid = getCurrentUser()?.uid || 'guest';
|
|
||||||
|
|
||||||
async function getCacheName() {
|
async function getCacheName() {
|
||||||
const ver = await config.get('version');
|
const ver = await config.get('version');
|
||||||
return `memories-data-${ver}-${uid}`;
|
return `memories-data-${ver}-${uid}`;
|
||||||
|
@ -11,7 +9,7 @@ async function getCacheName() {
|
||||||
|
|
||||||
// Clear all caches except the current one
|
// Clear all caches except the current one
|
||||||
(async function clearCaches() {
|
(async function clearCaches() {
|
||||||
if (uid === 'guest') return;
|
if (!uid) return;
|
||||||
|
|
||||||
const keys = await window.caches?.keys();
|
const keys = await window.caches?.keys();
|
||||||
if (!keys?.length) return;
|
if (!keys?.length) return;
|
||||||
|
|
|
@ -8,9 +8,12 @@ import * as nativex from '../../native';
|
||||||
/**
|
/**
|
||||||
* Get the current user UID
|
* Get the current user UID
|
||||||
*/
|
*/
|
||||||
export function uid() {
|
export const uid = String(getCurrentUser()?.uid || String()) || null;
|
||||||
return String(getCurrentUser()?.uid || String()) || null;
|
|
||||||
}
|
/**
|
||||||
|
* Check if the current user is an admin
|
||||||
|
*/
|
||||||
|
export const isAdmin = Boolean(getCurrentUser()?.isAdmin);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if width <= 768px
|
* Check if width <= 768px
|
||||||
|
|
Loading…
Reference in New Issue