Skip to content

Commit

Permalink
Apply suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Oct 10, 2022
1 parent 57373f3 commit fb218a1
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 86 deletions.
7 changes: 3 additions & 4 deletions lib/Controller/PublicAlbumController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ public function __construct(
* @NoCSRFRequired
*/
public function get(): TemplateResponse {
$this->eventDispatcher->dispatch(LoadSidebar::class, new LoadSidebar());
$this->eventDispatcher->dispatch(LoadViewer::class, new LoadViewer());

$this->initialState->provideInitialState('image-mimes', Application::IMAGE_MIMES);
$this->initialState->provideInitialState('video-mimes', Application::VIDEO_MIMES);
$this->initialState->provideInitialState('maps', $this->appManager->isEnabledForUser('maps') === true);
$this->initialState->provideInitialState('recognize', $this->appManager->isEnabledForUser('recognize') === true);
$this->initialState->provideInitialState('systemtags', $this->appManager->isEnabledForUser('systemtags') === true);
$this->initialState->provideInitialState('maps', false);
$this->initialState->provideInitialState('recognize', false);
$this->initialState->provideInitialState('systemtags', false);

// Provide user config
foreach (array_keys(UserConfigService::DEFAULT_CONFIGS) as $key) {
Expand Down
6 changes: 2 additions & 4 deletions lib/Sabre/Album/AlbumPhoto.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,9 @@ public function setFavoriteState($favoriteState): bool {

switch ($favoriteState) {
case "0":
$tagger->removeFromFavorites($this->albumFile->getFileId());
return "0";
return $tagger->removeFromFavorites($this->albumFile->getFileId());
case "1":
$tagger->addToFavorites($this->albumFile->getFileId());
return "1";
return $tagger->addToFavorites($this->albumFile->getFileId());
default:
new \Exception('Favorite state is invalide, should be 0 or 1.');
}
Expand Down
4 changes: 3 additions & 1 deletion lib/Sabre/Album/AlbumsHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class AlbumsHome implements ICollection {
protected Folder $userFolder;
protected UserConfigService $userConfigService;

public const NAME = 'albums';

/**
* @var AlbumRoot[]
*/
Expand Down Expand Up @@ -70,7 +72,7 @@ public function delete() {
}

public function getName(): string {
return 'albums';
return self::NAME;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions lib/Sabre/Album/PublicAlbumsHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
use OCA\Photos\Album\AlbumMapper;

class PublicAlbumsHome extends AlbumsHome {
public function getName(): string {
return 'public';
}
public const NAME = 'public';

/**
* @return never
Expand Down
6 changes: 2 additions & 4 deletions lib/Sabre/Album/SharedAlbumsHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
class SharedAlbumsHome extends AlbumsHome {
private IGroupManager $groupManager;

public const NAME = 'sharedalbums';

public function __construct(
array $principalInfo,
AlbumMapper $albumMapper,
Expand All @@ -53,10 +55,6 @@ public function __construct(
$this->groupManager = $groupManager;
}

public function getName(): string {
return 'sharedalbums';
}

/**
* @return never
*/
Expand Down
8 changes: 4 additions & 4 deletions lib/Sabre/PhotosHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ public function createDirectory($name) {

public function getChild($name) {
switch ($name) {
case 'albums':
case AlbumsHome::NAME:
return new AlbumsHome($this->principalInfo, $this->albumMapper, $this->user, $this->rootFolder, $this->userConfigService);
case 'sharedalbums':
case SharedAlbumsHome::NAME:
return new SharedAlbumsHome($this->principalInfo, $this->albumMapper, $this->user, $this->rootFolder, $this->groupManager, $this->userConfigService);
case 'public':
case PublicAlbumsHome::NAME:
return new PublicAlbumsHome($this->principalInfo, $this->albumMapper, $this->user, $this->rootFolder, $this->userConfigService);
}

Expand All @@ -114,7 +114,7 @@ public function getChildren(): array {
}

public function childExists($name): bool {
return $name === 'albums' || $name === 'sharedalbums' || $name === 'public';
return $name === AlbumsHome::NAME || $name === SharedAlbumsHome::NAME || $name === PublicAlbumsHome::NAME;
}

public function getLastModified(): int {
Expand Down
4 changes: 2 additions & 2 deletions src/Photos.vue
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ export default {
}), {
scope: generateUrl('/apps/photos'),
}).then(registration => {
logger.debug('SW registered: ', registration)
logger.debug('SW registered: ', { registration })
}).catch(registrationError => {
logger.error('SW registration failed: ', registrationError)
logger.error('SW registration failed: ', { registrationError })
})

})
Expand Down
4 changes: 2 additions & 2 deletions src/PhotosPublic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ export default {
try {
const url = generateUrl('/apps/photos/service-worker.js', {}, { noRewrite: true })
const registration = await navigator.serviceWorker.register(url, { scope: generateUrl('/apps/photos') })
logger.debug('SW registered: ', registration)
logger.debug('SW registered: ', { registration })
} catch (error) {
logger.error('SW registration failed: ', error)
logger.error('SW registration failed: ', { error })
}
})
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Albums/CollaboratorsSelectionForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ export default {
this.errorFetchingAlbum = error
}

logger.error('[PublicAlbumContent] Error fetching album', error)
logger.error('[PublicAlbumContent] Error fetching album', {error})
showError(this.t('photos', 'Failed to fetch album.'))
} finally {
this.loadingAlbum = false
Expand All @@ -385,7 +385,7 @@ export default {
},
})
} catch (error) {
logger.error('[PublicAlbumContent] Error updating album', error)
logger.error('[PublicAlbumContent] Error updating album', {error})
showError(this.t('photos', 'Failed to update album.'))
} finally {
this.loadingAlbum = false
Expand Down
2 changes: 1 addition & 1 deletion src/components/TiledLayout/TiledLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default {
computed: {
/** @return {import('../services/TiledLayout.js').TiledRow[]} */
rows() {
logger.debug('[TiledLayout] Computing rows', this.items)
logger.debug('[TiledLayout] Computing rows', { items: this.items })

return splitItemsInRows(this.items, this.containerWidth, this.baseHeight)
},
Expand Down
4 changes: 2 additions & 2 deletions src/mixins/FetchFacesMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default {
this.errorFetchingFaces = error
}
}
logger.error(t('photos', 'Failed to fetch faces list.'), error)
logger.error(t('photos', 'Failed to fetch faces list.'), { error })
showError(t('photos', 'Failed to fetch faces list.'))
} finally {
this.loadingFaces = false
Expand Down Expand Up @@ -140,7 +140,7 @@ export default {
}

// cancelled request, moving on...
logger.error('Error fetching face files', error)
logger.error('Error fetching face files', { error })
} finally {
this.loadingFiles = false
}
Expand Down
2 changes: 1 addition & 1 deletion src/mixins/FetchFilesMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default {
}

// cancelled request, moving on...
logger.error('Error fetching files', error)
logger.error('Error fetching files', { error })
console.error(error)
} finally {
this.loadingFiles = false
Expand Down
57 changes: 27 additions & 30 deletions src/services/Albums.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,43 @@ import { genFileInfo } from '../utils/fileUtils.js'
* @property {number} cover - The cover of the album.
*/

/**
* @param {string} extraProps - Extra properties to add to the DAV request.
* @return {string}
*/
function getDavRequest(extraProps = '') {
return `<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:"
xmlns:oc="http://owncloud.org/ns"
xmlns:nc="http://nextcloud.org/ns"
xmlns:ocs="http://open-collaboration-services.org/ns">
<d:prop>
<nc:last-photo />
<nc:nbItems />
<nc:location />
<nc:dateRange />
<nc:collaborators />
${extraProps}
</d:prop>
</d:propfind>`
}

/**
*
* @param {string} path - Albums' root path.
* @param {import('webdav').StatOptions} options - Options to forward to the webdav client.
* @param {string} extraProps - Extra properties to add to the DAV request.
* @return {Promise<Album|null>}
*/
export async function fetchAlbum(path, options, extraProps = '') {
try {
const response = await client.stat(path, {
data: `<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:"
xmlns:oc="http://owncloud.org/ns"
xmlns:nc="http://nextcloud.org/ns"
xmlns:ocs="http://open-collaboration-services.org/ns">
<d:prop>
<nc:last-photo />
<nc:nbItems />
<nc:location />
<nc:dateRange />
<nc:collaborators />
${extraProps}
</d:prop>
</d:propfind>`,
data: getDavRequest(extraProps),
details: true,
...options,
})

logger.debug('[Albums] Fetched an album: ', response.data)
logger.debug('[Albums] Fetched an album: ', { data: response.data })

return formatAlbum(response.data)
} catch (error) {
Expand All @@ -87,24 +96,12 @@ export async function fetchAlbum(path, options, extraProps = '') {
export async function fetchAlbums(path, options) {
try {
const response = await client.getDirectoryContents(path, {
data: `<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:"
xmlns:oc="http://owncloud.org/ns"
xmlns:nc="http://nextcloud.org/ns"
xmlns:ocs="http://open-collaboration-services.org/ns">
<d:prop>
<nc:last-photo />
<nc:nbItems />
<nc:location />
<nc:dateRange />
<nc:collaborators />
</d:prop>
</d:propfind>`,
data: getDavRequest(),
details: true,
...options,
})

logger.debug(`[Albums] Fetched ${response.data.length} albums: `, response.data)
logger.debug(`[Albums] Fetched ${response.data.length} albums: `, { data: response.data })

return response.data
.filter(album => album.filename !== path)
Expand Down Expand Up @@ -183,7 +180,7 @@ export async function fetchAlbumContent(path, options) {
return []
}

logger.error('Error fetching album files', error)
logger.error('Error fetching album files', { error })
console.error(error)

throw error
Expand Down
12 changes: 6 additions & 6 deletions src/store/albums.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const actions = {
if (error.response.status !== 409) { // Already in the album.
context.commit('removeFilesFromAlbum', { albumName, fileIdsToRemove: [fileId] })

logger.error(t('photos', 'Failed to add {fileBaseName} to album {albumName}.', { fileBaseName: file.basename, albumName }), error)
logger.error(t('photos', 'Failed to add {fileBaseName} to album {albumName}.', { fileBaseName: file.basename, albumName }), { error })
showError(t('photos', 'Failed to add {fileBaseName} to album {albumName}.', { fileBaseName: file.basename, albumName }))
}
} finally {
Expand Down Expand Up @@ -193,7 +193,7 @@ const actions = {
} catch (error) {
context.commit('addFilesToAlbum', { albumName, fileIdsToAdd: [fileId] })

logger.error(t('photos', 'Failed to delete {fileBaseName}.', { fileBaseName: file.basename }), error)
logger.error(t('photos', 'Failed to delete {fileBaseName}.', { fileBaseName: file.basename }), { error })
showError(t('photos', 'Failed to delete {fileBaseName}.', { fileBaseName: file.basename }))
} finally {
semaphore.release(symbol)
Expand All @@ -216,7 +216,7 @@ const actions = {
context.commit('addAlbums', { albums: [album] })
return album
} catch (error) {
logger.error(t('photos', 'Failed to create {albumName}.', { albumName: album.basename }), error)
logger.error(t('photos', 'Failed to create {albumName}.', { albumName: album.basename }), { error })
showError(t('photos', 'Failed to create {albumName}.', { albumName: album.basename }))
}
},
Expand Down Expand Up @@ -244,7 +244,7 @@ const actions = {
return newAlbum
} catch (error) {
context.commit('removeAlbums', { albumNames: [newAlbumName] })
logger.error(t('photos', 'Failed to rename {currentAlbumName} to {newAlbumName}.', { currentAlbumName, newAlbumName }), error)
logger.error(t('photos', 'Failed to rename {currentAlbumName} to {newAlbumName}.', { currentAlbumName, newAlbumName }), { error })
showError(t('photos', 'Failed to rename {currentAlbumName} to {newAlbumName}.', { currentAlbumName, newAlbumName }))
return album
}
Expand Down Expand Up @@ -301,7 +301,7 @@ const actions = {
return updatedAlbum
} catch (error) {
context.commit('updateAlbum', { album })
logger.error(t('photos', 'Failed to update properties of {albumName} with {properties}.', { albumName, properties: JSON.stringify(properties) }), error)
logger.error(t('photos', 'Failed to update properties of {albumName} with {properties}.', { albumName, properties: JSON.stringify(properties) }), { error })
showError(t('photos', 'Failed to update properties of {albumName} with {properties}.', { albumName, properties: JSON.stringify(properties) }))
return album
}
Expand All @@ -320,7 +320,7 @@ const actions = {
await client.deleteFile(album.filename)
context.commit('removeAlbums', { albumNames: [albumName] })
} catch (error) {
logger.error(t('photos', 'Failed to delete {albumName}.', { albumName }), error)
logger.error(t('photos', 'Failed to delete {albumName}.', { albumName }), { error })
showError(t('photos', 'Failed to delete {albumName}.', { albumName }))
}
},
Expand Down
11 changes: 4 additions & 7 deletions src/store/collectionStoreFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ export default function collectionStoreFactory(collectionName) {
const collectionFiles = state[`${collectionName}sFiles`][collectionId] || []
state[`${collectionName}sFiles`] = {
...state[`${collectionName}sFiles`],
[collectionId]: [
...collectionFiles,
...fileIdsToAdd.filter(fileId => !collectionFiles.includes(fileId)), // Filter to prevent duplicate fileId.
],
[collectionId]: [...new Set([...collectionFiles, ...fileIdsToAdd])],
}
state[`${collectionName}s`][collectionId].nbItems += fileIdsToAdd.length
},
Expand Down Expand Up @@ -147,7 +144,7 @@ export default function collectionStoreFactory(collectionName) {
if (error.response.status !== 409) { // Already in the collection.
context.commit(`removeFilesFrom${capitalizedCollectionName}`, { collectionId, fileIdsToRemove: [fileId] })

logger.error(translate('photos', 'Failed to add {fileBaseName} to {collectionId}.', { fileBaseName: file.basename, collectionId }), error)
logger.error(translate('photos', 'Failed to add {fileBaseName} to {collectionId}.', { fileBaseName: file.basename, collectionId }), { error })
showError(translate('photos', 'Failed to add {fileBaseName} to {collectionId}.', { fileBaseName: file.basename, collectionId }))
}
} finally {
Expand Down Expand Up @@ -181,7 +178,7 @@ export default function collectionStoreFactory(collectionName) {
} catch (error) {
context.commit(`addFilesTo${capitalizedCollectionName}`, { collectionId, fileIdsToAdd: [fileId] })

logger.error(translate('photos', 'Failed to delete {fileBaseName}.', { fileBaseName: file.basename }), error)
logger.error(translate('photos', 'Failed to delete {fileBaseName}.', { fileBaseName: file.basename }), { error })
showError(translate('photos', 'Failed to delete {fileBaseName}.', { fileBaseName: file.basename }))
} finally {
semaphore.release(symbol)
Expand All @@ -204,7 +201,7 @@ export default function collectionStoreFactory(collectionName) {
await client.deleteFile(collection.filename)
context.commit(`remove${capitalizedCollectionName}s`, { collectionIds: [collectionId] })
} catch (error) {
logger.error(translate('photos', 'Failed to delete {collectionId}.', { collectionId }), error)
logger.error(translate('photos', 'Failed to delete {collectionId}.', { collectionId }), { error })
showError(translate('photos', 'Failed to delete {collectionId}.', { collectionId }))
}
},
Expand Down
Loading

0 comments on commit fb218a1

Please sign in to comment.