Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/photos.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-11-14 19:25:39 +0300
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-11-14 19:25:42 +0300
commite6e6b217ded9ebcae3475eda0c00a7c82fd173e3 (patch)
treeddf147a44feac68c3d9463cab20a2b938618093e
parent2653815dbf99f18128de6325ba79eecaecaff46a (diff)
Use albums/shared endpoint
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
-rw-r--r--lib/Controller/AlbumsController.php27
-rw-r--r--src/components/Folder.vue10
-rw-r--r--src/router/index.js17
-rw-r--r--src/services/AlbumContent.js36
-rw-r--r--src/services/FileList.js2
-rw-r--r--src/store/folders.js2
-rw-r--r--src/utils/fileUtils.js4
-rw-r--r--src/views/Albums.vue21
8 files changed, 79 insertions, 40 deletions
diff --git a/lib/Controller/AlbumsController.php b/lib/Controller/AlbumsController.php
index 4493ec51..bedcd4c9 100644
--- a/lib/Controller/AlbumsController.php
+++ b/lib/Controller/AlbumsController.php
@@ -81,17 +81,27 @@ class AlbumsController extends Controller {
}
private function formatData(iterable $nodes): array {
+ $userFolder = $this->rootFolder->getUserFolder($this->userId);
+
$result = [];
/** @var Node $node */
foreach ($nodes as $node) {
+ // properly format full path and make sure
+ // we're relative to the user home folder
+ $isRoot = $node === $userFolder;
+ $path = $isRoot ? '/' : str_replace($userFolder->getPath(), '', $node->getPath());
+
$result[] = [
- 'id' => $node->getName(),
- 'basename' => $node->getName(),
- 'id' => $node->getName(),
- 'id' => $node->getName(),
- 'id' => $node->getName(),
- 'id' => $node->getName(),
- ]
+ 'basename' => $isRoot ? '' : $node->getName(),
+ 'etag' => $node->getEtag(),
+ 'fileid' => $node->getId(),
+ 'filename' => $path,
+ 'etag' => $node->getEtag(),
+ 'lastmod' => $node->getMTime(),
+ 'mime' => $node->getMimetype(),
+ 'size' => $node->getSize(),
+ 'type' => $node->getType()
+ ];
}
return $result;
@@ -100,6 +110,9 @@ class AlbumsController extends Controller {
private function scanCurrentFolder(Folder $folder, bool $shared): iterable {
$nodes = $folder->getDirectoryListing();
+ // add current folder to iterable set
+ yield $folder;
+
foreach ($nodes as $node) {
if ($node instanceof Folder) {
yield from $this->scanFolder($node, 0, $shared);
diff --git a/src/components/Folder.vue b/src/components/Folder.vue
index 53a11dd9..1ac705bc 100644
--- a/src/components/Folder.vue
+++ b/src/components/Folder.vue
@@ -54,7 +54,7 @@
import { generateUrl } from '@nextcloud/router'
import { mapGetters } from 'vuex'
-import getPictures from '../services/FileList'
+import getAlbumContent from '../services/AlbumContent'
import cancelableRequest from '../utils/CancelableRequest'
export default {
@@ -78,6 +78,10 @@ export default {
type: String,
default: 'icon-folder',
},
+ showShared: {
+ type: Boolean,
+ default: false,
+ },
},
data() {
@@ -137,12 +141,12 @@ export default {
async created() {
// init cancellable request
- const { request, cancel } = cancelableRequest(getPictures)
+ const { request, cancel } = cancelableRequest(getAlbumContent)
this.cancelRequest = cancel
try {
// get data
- const { folder, folders, files } = await request(this.filename)
+ const { folder, folders, files } = await request(this.filename, {shared: this.showShared})
console.info(folder, folders, files);
this.$store.dispatch('updateFolders', { fileid: folder.fileid, files, folders })
this.$store.dispatch('updateFiles', { folder, files, folders })
diff --git a/src/router/index.js b/src/router/index.js
index d4d9caa6..53ac5601 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -29,12 +29,6 @@ import Tags from '../views/Tags'
Vue.use(Router)
-// shortcut to properly format the path prop
-const props = route => ({
- // always lead current path with a slash
- path: `/${route.params.path ? route.params.path : ''}`,
-})
-
export default new Router({
mode: 'history',
// if index.php is in the url AND we got this far, then it's working:
@@ -51,7 +45,10 @@ export default new Router({
path: '/albums',
component: Albums,
name: 'albums',
- props,
+ props: route => ({
+ // always lead current path with a slash
+ path: `/${route.params.path ? route.params.path : ''}`,
+ }),
children: [
{
path: ':path*',
@@ -64,7 +61,11 @@ export default new Router({
path: '/shared',
component: Albums,
name: 'shared',
- props,
+ props: route => ({
+ // always lead current path with a slash
+ path: `/${route.params.path ? route.params.path : ''}`,
+ showShared: true,
+ }),
children: [
{
path: ':path*',
diff --git a/src/services/AlbumContent.js b/src/services/AlbumContent.js
index ea747ede..bfe7e193 100644
--- a/src/services/AlbumContent.js
+++ b/src/services/AlbumContent.js
@@ -20,6 +20,7 @@
*
*/
+import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import { genFileInfo } from '../utils/fileUtils'
@@ -27,19 +28,34 @@ import { genFileInfo } from '../utils/fileUtils'
* List files from a folder and filter out unwanted mimes
*
* @param {String} path the path relative to the user root
+ * @param {Object} [options] optional options for axios
+ * @param {boolean} [shared] fetch shared albums ?
* @returns {Array} the file list
*/
-export default async function(path) {
- // getDirectoryContents doesn't accept / for root
- const fixedPath = path === '/' ? '' : path
-
- const prefixPath = `/files/${getCurrentUser().uid}`
+export default async function(path = '/', options = {}) {
+ const prefixPath = generateUrl(`/apps/photos/api/v1/${options.shared ? 'shared' : 'albums'}`)
+ console.info(prefixPath);
// fetch listing
- const response = await client.stat(prefixPath + fixedPath, {
- data: request,
- details: true,
- })
+ const response = await axios.get(prefixPath + path, options)
+
+ const list = response.data.map(data => genFileInfo(data, prefixPath))
+
+ // filter all the files and folders
+ let folder = {}
+ const folders = []
+ const files = []
+ for (const entry of list) {
+ // is this the current provided path ?
+ if (entry.filename === path) {
+ folder = entry
+ } else if (entry.type !== 'file') {
+ folders.push(entry)
+ } else if (entry.mime === 'image/jpeg') {
+ files.push(entry)
+ }
+ }
- return genFileInfo(response.data, prefixPath)
+ // return current folder, subfolders and files
+ return { folder, folders, files }
}
diff --git a/src/services/FileList.js b/src/services/FileList.js
index 5f8d1750..bfe579db 100644
--- a/src/services/FileList.js
+++ b/src/services/FileList.js
@@ -80,7 +80,7 @@ export default async function(path, options) {
// is this the current provided path ?
if (entry.filename === path) {
folder = entry
- } else if (entry.type === 'directory') {
+ } else if (entry.type !== 'file') {
folders.push(entry)
} else if (entry.mime === 'image/jpeg') {
files.push(entry)
diff --git a/src/store/folders.js b/src/store/folders.js
index ab6d51fb..a4dd85d8 100644
--- a/src/store/folders.js
+++ b/src/store/folders.js
@@ -48,6 +48,8 @@ const mutations = {
Vue.set(state.folders, fileid, list.map(file => file.fileid))
const t1 = performance.now()
console.debug('perf: updateFolders', `${t1 - t0}ms`)
+ } else {
+ Vue.set(state.folders, fileid, [])
}
},
diff --git a/src/utils/fileUtils.js b/src/utils/fileUtils.js
index ddeb6e23..a04b9945 100644
--- a/src/utils/fileUtils.js
+++ b/src/utils/fileUtils.js
@@ -78,9 +78,9 @@ const sortCompare = function(fileInfo1, fileInfo2, key, asc = true) {
}
// else we sort by string, so let's sort directories first
- if (fileInfo1.type === 'directory' && fileInfo2.type !== 'directory') {
+ if (fileInfo1.type !== 'file' && fileInfo2.type === 'file') {
return asc ? -1 : 1
- } else if (fileInfo1.type !== 'directory' && fileInfo2.type === 'directory') {
+ } else if (fileInfo1.type === 'file' && fileInfo2.type !== 'file') {
return asc ? 1 : -1
}
diff --git a/src/views/Albums.vue b/src/views/Albums.vue
index 1aace973..0fa418e3 100644
--- a/src/views/Albums.vue
+++ b/src/views/Albums.vue
@@ -35,7 +35,7 @@
<!-- Folder content -->
<Grid v-else>
<Navigation v-if="folder" key="navigation" v-bind="folder" />
- <Folder v-for="dir in folderList" :key="dir.fileid" v-bind="dir" />
+ <Folder v-for="dir in folderList" :key="dir.fileid" v-bind="dir" :showShared="showShared" />
<File v-for="file in fileList" :key="file.fileid" v-bind="file" />
</Grid>
</template>
@@ -43,9 +43,7 @@
<script>
import { mapGetters } from 'vuex'
-// import getFolder from '../services/FolderInfo'
-import getPictures from '../services/FileList'
-// import searchPhotos from '../services/PhotoSearch'
+import getAlbumContent from '../services/AlbumContent'
import EmptyContent from './EmptyContent'
import Folder from '../components/Folder'
@@ -73,6 +71,10 @@ export default {
type: Boolean,
required: true,
},
+ showShared: {
+ type: Boolean,
+ default: false,
+ },
},
data() {
@@ -142,8 +144,10 @@ export default {
},
watch: {
- path(path) {
- console.debug('changed:', path)
+ path() {
+ this.fetchFolderContent()
+ },
+ showShared() {
this.fetchFolderContent()
},
},
@@ -169,13 +173,12 @@ export default {
this.error = null
// init cancellable request
- const { request, cancel } = cancelableRequest(getPictures)
+ const { request, cancel } = cancelableRequest(getAlbumContent)
this.cancelRequest = cancel
try {
// get content and current folder info
- const { folder, folders, files } = await request(this.path)
- console.debug(folder, folders, files)
+ const { folder, folders, files } = await request(this.path, {shared: this.showShared})
this.$store.dispatch('addPath', { path: this.path, fileid: folder.fileid })
this.$store.dispatch('updateFolders', { fileid: folder.fileid, files, folders })
this.$store.dispatch('updateFiles', { folder, files, folders })