Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Revert "Display album's name instead of token"
This reverts commit 2de383f.

Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge committed Oct 20, 2022
commit 57b02f1c105cbec0ee64472a80b32dc7253f1302
4 changes: 2 additions & 2 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
'path' => '',
]
],
[ 'name' => 'publicAlbum#get', 'url' => '/public/{ownerId}/{path}', 'verb' => 'GET',
[ 'name' => 'publicAlbum#get', 'url' => '/public/{ownerId}/{token}', 'verb' => 'GET',
'requirements' => [
'ownerId' => '.*',
],
'requirements' => [
'path' => '.*',
'token' => '.*',
],
],
['name' => 'page#index', 'url' => '/folders/{path}', 'verb' => 'GET', 'postfix' => 'folders',
Expand Down
1 change: 1 addition & 0 deletions lib/Album/AlbumMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ public function getCollaborators(int $albumId): array {
break;
case self::TYPE_LINK:
$displayName = $this->l->t('Public link');
;
break;
default:
throw new \Exception('Invalid collaborator type: ' . $row['collaborator_type']);
Expand Down
2 changes: 2 additions & 0 deletions lib/Sabre/Album/PropFindPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCP\Files\NotFoundException;

class PropFindPlugin extends ServerPlugin {
public const ORIGINAL_NAME_PROPERTYNAME = '{http://nextcloud.org/ns}original-name';
public const FILE_NAME_PROPERTYNAME = '{http://nextcloud.org/ns}file-name';
public const FAVORITE_PROPERTYNAME = '{http://owncloud.org/ns}favorite';
public const DATE_RANGE_PROPERTYNAME = '{http://nextcloud.org/ns}dateRange';
Expand Down Expand Up @@ -110,6 +111,7 @@ public function propFind(PropFind $propFind, INode $node): void {
}

if ($node instanceof AlbumRoot) {
$propFind->handle(self::ORIGINAL_NAME_PROPERTYNAME, fn () => $node->getAlbum()->getAlbum()->getTitle());
$propFind->handle(self::LAST_PHOTO_PROPERTYNAME, fn () => $node->getAlbum()->getAlbum()->getLastAddedPhoto());
$propFind->handle(self::NBITEMS_PROPERTYNAME, fn () => count($node->getChildren()));
$propFind->handle(self::LOCATION_PROPERTYNAME, fn () => $node->getAlbum()->getAlbum()->getLocation());
Expand Down
2 changes: 1 addition & 1 deletion lib/Sabre/Album/PublicAlbumRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function setName($name) {
}

public function copyInto($targetName, $sourcePath, INode $sourceNode): bool {
throw new Forbidden('Not allowed to copy into a public album');
throw new Forbidden('Not allowed to copy into a public album');
}

/**
Expand Down
30 changes: 1 addition & 29 deletions lib/Sabre/Album/PublicAlbumsHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,9 @@

use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\Server;
use OCP\Files\IRootFolder;
use OCP\IUser;
use OCA\Photos\Service\UserConfigService;
use OCA\Photos\Album\AlbumMapper;

class PublicAlbumsHome extends AlbumsHome {
private Server $server;

public function __construct(
array $principalInfo,
AlbumMapper $albumMapper,
IUser $user,
IRootFolder $rootFolder,
UserConfigService $userConfigService,
Server $server
) {
parent::__construct(
$principalInfo,
$albumMapper,
$user,
$rootFolder,
$userConfigService,
);

$this->server = $server;
}

public function getName(): string {
return 'public';
}
Expand All @@ -65,10 +40,7 @@ public function createDirectory($name) {
}

public function getChild($name) {
$basicAuth = $this->server->httpRequest->getHeader('Authorization') ?? 'Basic ';
[, $base64Token] = explode('Basic ', $basicAuth);
$token = \base64_decode($base64Token);
$albums = $this->albumMapper->getSharedAlbumsForCollaboratorWithFiles($token, AlbumMapper::TYPE_LINK);
$albums = $this->albumMapper->getSharedAlbumsForCollaboratorWithFiles($name, AlbumMapper::TYPE_LINK);

$albums = array_filter($albums, fn ($album) => $album->getAlbum()->getUserId() === $this->user->getUid());

Expand Down
8 changes: 2 additions & 6 deletions lib/Sabre/PhotosHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\ICollection;
use Sabre\DAV\Server;

class PhotosHome implements ICollection {
private AlbumMapper $albumMapper;
Expand All @@ -43,24 +42,21 @@ class PhotosHome implements ICollection {
private IRootFolder $rootFolder;
private IGroupManager $groupManager;
private UserConfigService $userConfigService;
private Server $server;

public function __construct(
array $principalInfo,
AlbumMapper $albumMapper,
IUser $user,
IRootFolder $rootFolder,
IGroupManager $groupManager,
UserConfigService $userConfigService,
Server $server
UserConfigService $userConfigService
) {
$this->principalInfo = $principalInfo;
$this->albumMapper = $albumMapper;
$this->user = $user;
$this->rootFolder = $rootFolder;
$this->groupManager = $groupManager;
$this->userConfigService = $userConfigService;
$this->server = $server;
}

/**
Expand Down Expand Up @@ -99,7 +95,7 @@ public function getChild($name) {
} elseif ($name === 'sharedalbums') {
return new SharedAlbumsHome($this->principalInfo, $this->albumMapper, $this->user, $this->rootFolder, $this->groupManager, $this->userConfigService);
} elseif ($name === 'public') {
return new PublicAlbumsHome($this->principalInfo, $this->albumMapper, $this->user, $this->rootFolder, $this->userConfigService, $this->server);
return new PublicAlbumsHome($this->principalInfo, $this->albumMapper, $this->user, $this->rootFolder, $this->userConfigService);
}

throw new NotFound();
Expand Down
8 changes: 2 additions & 6 deletions lib/Sabre/RootCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use OCP\IUserSession;
use Sabre\DAVACL\AbstractPrincipalCollection;
use Sabre\DAVACL\PrincipalBackend;
use Sabre\DAV\Server;
use OCP\IGroupManager;

class RootCollection extends AbstractPrincipalCollection {
Expand All @@ -38,16 +37,14 @@ class RootCollection extends AbstractPrincipalCollection {
private IRootFolder $rootFolder;
private IGroupManager $groupManager;
private UserConfigService $userConfigService;
private Server $server;

public function __construct(
AlbumMapper $folderMapper,
IUserSession $userSession,
IRootFolder $rootFolder,
PrincipalBackend\BackendInterface $principalBackend,
IGroupManager $groupManager,
UserConfigService $userConfigService,
Server $server
UserConfigService $userConfigService
) {
parent::__construct($principalBackend, 'principals/users');

Expand All @@ -56,7 +53,6 @@ public function __construct(
$this->rootFolder = $rootFolder;
$this->groupManager = $groupManager;
$this->userConfigService = $userConfigService;
$this->server = $server;
}

/**
Expand All @@ -74,7 +70,7 @@ public function getChildForPrincipal(array $principalInfo): PhotosHome {
if (is_null($user) || $name !== $user->getUID()) {
throw new \Sabre\DAV\Exception\Forbidden();
}
return new PhotosHome($principalInfo, $this->folderMapper, $user, $this->rootFolder, $this->groupManager, $this->userConfigService, $this->server);
return new PhotosHome($principalInfo, $this->folderMapper, $user, $this->rootFolder, $this->groupManager, $this->userConfigService);
}

public function getName(): string {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Albums/CollaboratorsSelectionForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ export default {
},

async copyPublicLink() {
await navigator.clipboard.writeText(`${window.location.protocol}//${window.location.host}${generateUrl(`apps/photos/public/${getCurrentUser().uid}/${this.albumName}?token=${this.publicLink.id}`)}`)
await navigator.clipboard.writeText(`${window.location.protocol}//${window.location.host}${generateUrl(`apps/photos/public/${getCurrentUser().uid}/${this.publicLink.id}`)}`)
this.publicLinkCopied = true
setTimeout(() => {
this.publicLinkCopied = false
Expand Down
5 changes: 2 additions & 3 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,12 @@ const router = new Router({
}),
},
{
path: '/public/:userId/:path*',
path: '/public/:userId/:token',
component: PublicAlbumContent,
name: 'publicAlbums',
props: route => ({
userId: route.params.userId,
albumName: route.params.path,
token: route.query.token,
token: route.params.token,
}),
},
{
Expand Down
3 changes: 2 additions & 1 deletion src/services/Albums.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { genFileInfo } from '../utils/fileUtils.js'
* @param {import('webdav').StatOptions} options - Options to forward to the webdav client.
* @return {Promise<Album|null>}
*/
export async function fetchAlbum(path, options) {
export async function fetchAlbum(path, options, extraProps = '') {
try {
const response = await client.stat(path, {
data: `<?xml version="1.0"?>
Expand All @@ -59,6 +59,7 @@ export async function fetchAlbum(path, options) {
<nc:location />
<nc:dateRange />
<nc:collaborators />
${extraProps}
</d:prop>
</d:propfind>`,
details: true,
Expand Down
48 changes: 24 additions & 24 deletions src/views/PublicAlbumContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@
-->
<template>
<div>
<CollectionContent v-if="true"
ref="collectionContent"
<CollectionContent ref="collectionContent"
:collection="album"
:collection-file-ids="albumFileIds"
:semaphore="semaphore"
:loading="loadingAlbum || loadingFiles"
:error="errorFetchingAlbum || errorFetchingFiles">
<!-- Header -->
<HeaderNavigation key="navigation"
<HeaderNavigation v-if="albumOriginalName !== ''"
key="navigation"
slot="header"
slot-scope="{selectedFileIds}"
:loading="loadingAlbum || loadingFiles"
:params="{ albumName }"
:params="{ userId, token }"
path="/"
:root-title="albumName"
:title="albumName"
:root-title="albumOriginalName"
:title="albumOriginalName"
@refresh="fetchAlbumContent">
<!-- TODO: enable upload on public albums -->
<!-- <UploadPicker :accept="allowedMimes"
Expand Down Expand Up @@ -104,7 +104,6 @@

<script>
import { mapActions, mapGetters } from 'vuex'

import MapMarker from 'vue-material-design-icons/MapMarker'
import Plus from 'vue-material-design-icons/Plus'
import ImagePlus from 'vue-material-design-icons/ImagePlus'
Expand Down Expand Up @@ -156,10 +155,6 @@ export default {
type: String,
required: true,
},
albumName: {
type: String,
required: true,
},
token: {
type: String,
required: true,
Expand All @@ -173,7 +168,7 @@ export default {
errorFetchingAlbum: null,
loadingCount: 0,
loadingAddFilesToAlbum: false,
publicClient: null,
albumOriginalName: '',
}
},

Expand All @@ -191,6 +186,13 @@ export default {
return this.publicAlbums[this.albumName] || {}
},

/**
* @return {string} The album's name is the token.
*/
albumName() {
return this.token
},

/**
* @return {string[]} The list of files for the current albumName.
*/
Expand Down Expand Up @@ -221,13 +223,13 @@ export default {
this.loadingAlbum = true
this.errorFetchingAlbum = null

const album = await fetchAlbum(`/photos/${this.userId}/public/${this.albumName}`, {
signal: this.abortController.signal,
headers: {
Authorization: `Basic ${btoa(this.token)}`,
},
})
const album = await fetchAlbum(
`/photos/${this.userId}/public/${this.token}`,
this.abortController.signal,
'<nc:original-name />',
)
this.addPublicAlbums({ collections: [album] })
this.albumOriginalName = album.originalName
} catch (error) {
if (error.response?.status === 404) {
this.errorFetchingAlbum = 404
Expand Down Expand Up @@ -255,12 +257,10 @@ export default {
this.loadingFiles = true
this.semaphoreSymbol = semaphoreSymbol

const fetchedFiles = await fetchAlbumContent(`/photos/${this.userId}/public/${this.albumName}`, {
signal: this.abortController.signal,
headers: {
Authorization: `Basic ${btoa(this.token)}`,
},
})
const fetchedFiles = await fetchAlbumContent(
`/photos/${this.userId}/public/${this.token}`,
this.abortController.signal,
)

const fileIds = fetchedFiles
.map(file => file.fileid.toString())
Expand Down