Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 2 additions & 7 deletions src/components/File.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
data-test="media"
:class="{selected}">
<a class="file"
:href="davPath"
:href="file.source"
:aria-label="ariaLabel"
@click.stop.prevent="emitClick">

Expand Down Expand Up @@ -71,8 +71,7 @@
import Star from 'vue-material-design-icons/Star'
import VideoIcon from 'vue-material-design-icons/Video.vue'

import { generateRemoteUrl, generateUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'
import { generateUrl } from '@nextcloud/router'
import { NcCheckboxRadioSwitch } from '@nextcloud/vue'

import UserConfig from '../mixins/UserConfig.js'
Expand Down Expand Up @@ -121,10 +120,6 @@ export default {
},

computed: {
/** @return {string} */
davPath() {
return generateRemoteUrl(`dav/files/${getCurrentUser().uid}`) + this.file.filename
},
/** @return {string} */
ariaDescription() {
return `image-description-${this.file.fileid}`
Expand Down
8 changes: 2 additions & 6 deletions src/components/FileLegacy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
'file--cropped': croppedLayout,
}"
class="file"
:href="davPath"
:href="item.injected.source"
:aria-label="ariaLabel"
@click.prevent="openViewer">
<div v-if="item.injected.mime.includes('video') && item.injected.hasPreview" class="icon-video-white" />
Expand Down Expand Up @@ -57,8 +57,7 @@
</template>

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

import UserConfig from '../mixins/UserConfig.js'

Expand All @@ -81,9 +80,6 @@ export default {
},

computed: {
davPath() {
return generateRemoteUrl(`dav/files/${getCurrentUser().uid}`) + this.item.injected.filename
},
ariaUuid() {
return `image-${this.item.injected.fileid}`
},
Expand Down
4 changes: 3 additions & 1 deletion src/services/DavClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ import axios from '@nextcloud/axios'
import parseUrl from 'url-parse'
import { generateRemoteUrl } from '@nextcloud/router'

export const rootPath = 'dav'

// force our axios
const patcher = getPatcher()
patcher.patch('request', axios)

// init webdav client on default dav endpoint
const remote = generateRemoteUrl('dav')
const remote = generateRemoteUrl(rootPath)
const client = createClient(remote)

export const remotePath = parseUrl(remote).pathname
Expand Down
3 changes: 0 additions & 3 deletions src/services/PhotoSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { allMimes } from './AllowedMimes.js'
import client from './DavClient.js'
import { props } from './DavRequest.js'
import moment from '@nextcloud/moment'
import { generateRemoteUrl } from '@nextcloud/router'

/**
* List files from a folder and filter out unwanted mimes
Expand Down Expand Up @@ -147,6 +146,4 @@ export default async function(path = '', options = {}) {
const response = await client.getDirectoryContents('', options)

return response.data.map(data => genFileInfo(data))
.map(file => ({ ...file, source: generateRemoteUrl(`dav${file.filename}`) }))

}
13 changes: 11 additions & 2 deletions src/utils/fileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { generateRemoteUrl } from '@nextcloud/router'
import camelcase from 'camelcase'
import { isNumber } from './numberUtils'
import { rootPath } from '../services/DavClient.js'
import { isNumber } from './numberUtils.js'

/**
* Get an url encoded path
Expand Down Expand Up @@ -101,7 +103,7 @@ const sortCompare = function(fileInfo1, fileInfo2, key, asc = true) {
* @param {object} obj - object to flatten and format.
*/
function genFileInfo(obj) {
return Object.entries(obj).reduce((fileInfo, [key, data]) => {
const fileInfo = Object.entries(obj).reduce((fileInfo, [key, data]) => {
// flatten object if any
if (!!data && typeof data === 'object' && !Array.isArray(data)) {
return { ...fileInfo, ...genFileInfo(data) }
Expand All @@ -117,6 +119,13 @@ function genFileInfo(obj) {
return { ...fileInfo, [camelcase(key)]: isNumber(data) ? Number(data) : data }
}
}, {})

if (fileInfo.filename) {
// Adding context
fileInfo.source = generateRemoteUrl(rootPath) + '/' + fileInfo.filename
}

return fileInfo
}

export { encodeFilePath, extractFilePaths, sortCompare, genFileInfo }
3 changes: 0 additions & 3 deletions src/views/AlbumContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@
<script>
// eslint-disable-next-line node/no-extraneous-import
import { addNewFileMenuEntry } from '@nextcloud/files'
import { generateRemoteUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'
import { mapActions, mapGetters } from 'vuex'
import { NcActions, NcActionButton, NcButton, NcModal, NcEmptyContent, NcActionSeparator, NcLoadingIcon, isMobile } from '@nextcloud/vue'
Expand Down Expand Up @@ -340,8 +339,6 @@ export default {

const fetchedFiles = response.data
.map(file => genFileInfo(file))
// For the Viewer.
.map(file => ({ ...file, source: generateRemoteUrl(`dav${file.filename}`) }))

const fileIds = fetchedFiles
.map(file => file.fileid)
Expand Down
3 changes: 0 additions & 3 deletions src/views/SharedAlbumContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ import DownloadMultiple from 'vue-material-design-icons/DownloadMultiple'

import { NcActions, NcActionButton, NcButton, NcModal, NcEmptyContent, NcActionSeparator, isMobile } from '@nextcloud/vue'
import { getCurrentUser } from '@nextcloud/auth'
import { generateRemoteUrl } from '@nextcloud/router'

import FetchSharedAlbumsMixin from '../mixins/FetchSharedAlbumsMixin.js'
import FetchFilesMixin from '../mixins/FetchFilesMixin.js'
Expand Down Expand Up @@ -242,8 +241,6 @@ export default {

const fetchedFiles = response.data
.map(file => genFileInfo(file))
// For the Viewer.
.map(file => ({ ...file, source: generateRemoteUrl(`dav${file.filename}`) }))

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