Skip to content

Commit

Permalink
Merge pull request #1660 from nextcloud/backport/1648/stable25
Browse files Browse the repository at this point in the history
[stable25] Use full filenames in folder view
  • Loading branch information
artonge authored Feb 27, 2023
2 parents d4fbd9f + 0bbc7d5 commit 08ed5d5
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 18 deletions.
4 changes: 2 additions & 2 deletions js/photos-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/photos-main.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/photos-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/photos-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/photos-src_views_Folders_vue.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/photos-src_views_Folders_vue.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/components/FileLegacy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default {
methods: {
openViewer() {
OCA.Viewer.open({
path: this.item.injected.filename,
fileInfo: this.item.injected,
list: this.item.injected.list,
loadMore: this.item.injected.loadMore ? async () => await this.item.injected.loadMore(true) : () => [],
canLoop: this.item.injected.canLoop,
Expand Down
8 changes: 7 additions & 1 deletion src/components/Folder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
<script>
import { mapGetters } from 'vuex'

import { getCurrentUser } from '@nextcloud/auth'

import FolderTagPreview from './FolderTagPreview.vue'
import getAlbumContent from '../services/AlbumContent.js'
import AbortControllerMixin from '../mixins/AbortControllerMixin.js'
Expand Down Expand Up @@ -107,8 +109,12 @@ export default {
methods: {
async getFolderData(filename) {
try {
// Remove leading /file/{userId}
const prefix = `/files/${getCurrentUser()?.uid}`
const unPrefixedFileName = filename.replace(new RegExp(`^${prefix}`), '')

// get data
const { folder, folders, files } = await getAlbumContent(filename, {
const { folder, folders, files } = await getAlbumContent(unPrefixedFileName, {
shared: this.item.injected.showShared,
signal: this.abortController.signal,
})
Expand Down
8 changes: 7 additions & 1 deletion src/components/FolderTagPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

<script>
import { generateUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'

export default {
name: 'FolderTagPreview',
Expand Down Expand Up @@ -129,10 +130,15 @@ export default {
if (this.to) {
return this.to
}

// Remove leading /file/{userId}
const prefix = `/files/${getCurrentUser()?.uid}`
let path = this.path.replace(new RegExp(`^${prefix}`), '')

// always remove first slash, the router
// manage it automatically
const regex = /^\/?(.+)/i
const path = regex.exec(this.path)[1]
path = regex.exec(path)[1]

// apply to current route
return Object.assign({}, this.$route, {
Expand Down
12 changes: 8 additions & 4 deletions src/services/AlbumContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import { genFileInfo, encodeFilePath } from '../utils/fileUtils.js'
import allowedMimes from './AllowedMimes.js'
import { getCurrentUser } from '@nextcloud/auth'

/**
* List files from a folder and filter out unwanted mimes
Expand All @@ -34,11 +35,14 @@ import allowedMimes from './AllowedMimes.js'
* @return {Promise<object[]>} the file list
*/
export default async function(path = '/', options = {}) {
const prefixPath = generateUrl(`/apps/photos/api/v1/${options.shared ? 'shared' : 'albums'}`)
const endpoint = generateUrl(`/apps/photos/api/v1/${options.shared ? 'shared' : 'albums'}`)
const prefix = `/files/${getCurrentUser()?.uid}`

// fetch listing
const response = await axios.get(prefixPath + encodeFilePath(path), options)
const list = response.data.map(data => genFileInfo(data))
const response = await axios.get(endpoint + encodeFilePath(path), options)
const list = response.data
.map(data => ({ ...data, filename: `${prefix}${data.filename}` }))
.map(data => genFileInfo(data))

// filter all the files and folders
let folder = {}
Expand All @@ -47,7 +51,7 @@ export default async function(path = '/', options = {}) {

for (const entry of list) {
// is this the current provided path ?
if (entry.filename === path) {
if (entry.filename === `${prefix}${path}`) {
folder = entry
} else if (entry.type !== 'file') {
folders.push(entry)
Expand Down
4 changes: 2 additions & 2 deletions src/views/Folders.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
<div v-else-if="!initializing">
<HeaderNavigation key="navigation"
:loading="loading"
:path="folder.filename"
:path="path"
:title="folder.basename"
:root-title="rootTitle"
@refresh="onRefresh">
<UploadPicker :accept="allowedMimes"
:destination="folder.filename"
:destination="path"
:multiple="true"
@uploaded="onUpload" />
</HeaderNavigation>
Expand Down

0 comments on commit 08ed5d5

Please sign in to comment.