Use albums/shared endpoint

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2019-11-14 17:25:39 +01:00
parent 2653815dbf
commit e6e6b217de
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF
8 changed files with 79 additions and 40 deletions

View File

@ -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);

View File

@ -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 })

View File

@ -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*',

View File

@ -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)
return genFileInfo(response.data, prefixPath)
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 current folder, subfolders and files
return { folder, folders, files }
}

View File

@ -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)

View File

@ -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, [])
}
},

View File

@ -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
}

View File

@ -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 })