Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/Sabre/PropFindPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OCA\Photos\Sabre\Place\PlacePhoto;
use OCA\Photos\Sabre\Place\PlaceRoot;
use OCP\Files\DavUtil;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\FilesMetadata\IFilesMetadataManager;
use OCP\IPreview;
Expand All @@ -42,13 +43,15 @@ class PropFindPlugin extends ServerPlugin {
public const FILTERS_PROPERTYNAME = '{http://nextcloud.org/ns}filters';
public const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions';
public const PHOTOS_ALBUM_FILE_ORIGIN_PROPERTYNAME = '{http://nextcloud.org/ns}photos-album-file-origin';
public const PHOTOS_COLLECTION_FILE_ORIGINAL_FILENAME_PROPERTYNAME = '{http://nextcloud.org/ns}photos-collection-file-original-filename';

private ?Tree $tree = null;

public function __construct(
private readonly IPreview $previewManager,
private readonly IFilesMetadataManager $filesMetadataManager,
private readonly IUserSession $userSession,
private readonly IRootFolder $rootFolder,
) {
}

Expand Down Expand Up @@ -117,6 +120,19 @@ public function propFind(PropFind $propFind, INode $node): void {
return null;
}
});

$propFind->handle(self::PHOTOS_COLLECTION_FILE_ORIGINAL_FILENAME_PROPERTYNAME, function () use ($node) {
if (!($node instanceof AlbumPhoto)) {
return;
}

$currentUser = $this->userSession->getUser();
$fileOwner = $node->getFileInfo()->getOwner();
if ($currentUser !== null && $currentUser === $fileOwner) {
$userFolder = $this->rootFolder->getUserFolder($currentUser->getUID());
return $userFolder->getRelativePath($node->getFileInfo()->getPath());
}
});
}

if ($node instanceof ICollection) {
Expand Down
18 changes: 16 additions & 2 deletions src/components/Collection/CollectionContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@
</template>

<script lang='ts'>
import type { File } from '@nextcloud/files'
import type { PropType } from 'vue'
import type { PublicAlbum } from '../../store/publicAlbums.js'
import type { Collection } from '../../services/collectionFetcher.js'

import { subscribe, unsubscribe } from '@nextcloud/event-bus'
import { translate } from '@nextcloud/l10n'
import { useIsMobile } from '@nextcloud/vue/composables/useIsMobile'
import { defineComponent } from 'vue'
Expand All @@ -75,7 +77,7 @@

props: {
collection: {
type: Object as PropType<PublicAlbum>,
type: Object as PropType<Collection>,
default: () => undefined,
},

Expand All @@ -91,7 +93,7 @@

allowSelection: {
type: Boolean,
default: true,

Check warning on line 96 in src/components/Collection/CollectionContent.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Boolean prop should only be defaulted to false
},

error: {
Expand Down Expand Up @@ -122,6 +124,14 @@
},
},

mounted() {
subscribe('files:node:deleted', this.handleFileDeleted)
},

destroyed() {
unsubscribe('files:node:deleted', this.handleFileDeleted)
},

methods: {
openViewer(fileId: string) {
window.OCA.Viewer.open({
Expand All @@ -130,6 +140,10 @@
})
},

handleFileDeleted({ fileid }: File) {
this.$store.commit('removeFilesFromCollection', { collectionFileName: this.collection.root + this.collection.path, fileIdsToRemove: [fileid?.toString()] })
},

t: translate,
},
})
Expand Down
6 changes: 6 additions & 0 deletions src/components/FilesListViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,12 @@ export default {

mounted() {
subscribe('files:node:updated', this.handleFileUpdated)
subscribe('files:node:deleted', this.handleFileDeleted)
},

destroyed() {
unsubscribe('files:node:updated', this.handleFileUpdated)
unsubscribe('files:node:deleted', this.handleFileDeleted)
},

methods: {
Expand All @@ -250,6 +252,10 @@ export default {
const fetchedFile = await fetchFile(this.files[fileid as number].path)
this.$store.dispatch('appendFiles', [fetchedFile])
},

handleFileDeleted({ fileid }: File) {
this.$store.commit('deleteFile', fileid)
},
},
}
</script>
Expand Down
1 change: 1 addition & 0 deletions src/components/PhotosPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
*/
open: {
type: Boolean,
default: true,

Check warning on line 158 in src/components/PhotosPicker.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Boolean prop should only be defaulted to false
},

/**
Expand Down Expand Up @@ -244,6 +244,7 @@

emitPickedEvent() {
this.$emit('files-picked', this.selectedFileIds)
this.resetSelection()
},

/**
Expand Down
5 changes: 4 additions & 1 deletion src/mixins/FetchCollectionContentMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
fetchCollection, fetchCollectionFiles,
} from '../services/collectionFetcher.js'
import logger from '../services/logger.js'
import { collectionFilesExtraProps } from '../store/collections.js'
import SemaphoreWithPriority from '../utils/semaphoreWithPriority.js'
import AbortControllerMixin from './AbortControllerMixin.js'

Expand Down Expand Up @@ -62,11 +63,13 @@ export default defineComponent({
return null
},

async fetchCollectionFiles(collectionFileName: string, extraProps?: string[], client?: WebDAVClient): Promise<File[]> {
async fetchCollectionFiles(collectionFileName: string, extraProps: string[] = [], client?: WebDAVClient): Promise<File[]> {
if (this.loadingCollectionFiles) {
return []
}

extraProps = [...extraProps, ...collectionFilesExtraProps]

const fetchSemaphoreSymbol = await this.fetchSemaphore.acquire()

try {
Expand Down
3 changes: 2 additions & 1 deletion src/services/collectionFetcher.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @stylistic/no-tabs */
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand Down Expand Up @@ -68,7 +69,7 @@ function getCollectionFilesDavRequest(extraProps: string[] = []): string {
<oc:favorite />
<oc:fileid />
<oc:permissions />
${extraProps.join('')}
${extraProps.join('\n ')}
</d:prop>
</d:propfind>`
}
Expand Down
2 changes: 2 additions & 0 deletions src/store/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { davClient } from '../services/DavClient.ts'
import logger from '../services/logger.js'
import Semaphore from '../utils/semaphoreWithPriority.js'

export const collectionFilesExtraProps = ['<nc:photos-collection-file-original-filename />']

/**
* Collections are indexed by their `filename`.
*/
Expand Down
22 changes: 16 additions & 6 deletions src/utils/fileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {

FileType, Permission,
} from '@nextcloud/files'
import { getRemoteURL, getRootPath } from '@nextcloud/files/dav'
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand Down Expand Up @@ -93,12 +94,12 @@ export function sortCompareFileInfo(fileInfo1: FoldersNode, fileInfo2: FoldersNo
}

export type ViewerFileInfo = {
fileid: number
fileid?: number
basename: string
filename: string
mime: string
mtime: Date
ownerId: string
mime?: string
mtime?: Date
ownerId: string | null
source: string
hasPreview: boolean
previewUrl: string
Expand Down Expand Up @@ -129,14 +130,23 @@ export function toViewerFileInfo(file: Node): ViewerFileInfo {
permissions += 'R'
}

let filename = file.root + file.path
let source = file.source
// Override the filename and source to allow deleting a file from the viewer.
// This is needed when the filename and source are related to the albums.
if (file.attributes['photos-collection-file-original-filename'] !== undefined) {
filename = file.attributes['photos-collection-file-original-filename']
source = getRemoteURL() + getRootPath() + filename
}

return {
fileid: file.fileid,
basename: file.basename,
filename: file.root + file.path,
filename,
mime: file.mime,
mtime: file.mtime,
ownerId: file.owner,
source: file.source,
source,
hasPreview: file.attributes.hasPreview,
previewUrl: file.attributes.previewUrl ?? generateUrl(`/apps/photos/api/v1/preview/${file.fileid}?x=2048&y=2048`),
etag: file.attributes.etag,
Expand Down
Loading