mirror of https://github.com/nextcloud/photos
Make sure we have a valid source for each file
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
This commit is contained in:
parent
0299bbd4cb
commit
775aec519d
|
@ -25,7 +25,7 @@
|
|||
data-test="media"
|
||||
:class="{selected}">
|
||||
<a class="file"
|
||||
:href="davPath"
|
||||
:href="file.source"
|
||||
:aria-label="ariaLabel"
|
||||
@click.stop.prevent="emitClick">
|
||||
|
||||
|
@ -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'
|
||||
|
@ -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}`
|
||||
|
|
|
@ -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" />
|
||||
|
@ -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'
|
||||
|
||||
|
@ -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}`
|
||||
},
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
@ -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}`) }))
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -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) }
|
||||
|
@ -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 }
|
||||
|
|
|
@ -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'
|
||||
|
@ -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)
|
||||
|
|
|
@ -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'
|
||||
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue