FileVersion service

This commit is contained in:
Terry 2021-04-23 13:48:19 +02:00
parent 27ce9abd68
commit 6368672eec
2 changed files with 92 additions and 42 deletions

View File

@ -0,0 +1,85 @@
/**
* @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com>
* @author Enoch <enoch@nextcloud.com>
* @author John Molakvoæ <skjnldsv@protonmail.com>
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import client from './DavClient'
import { genFileInfo } from '../utils/fileUtils'
import axios from "@nextcloud/axios";
import {generateRemoteUrl} from "@nextcloud/router";
import { getCurrentUser } from '@nextcloud/auth';
/**
* Retrieve the files list
*
* @param {String} path the path relative to the user root
* @param {Object} [options] optional options for axios
* @returns {Array} the file list
*/
export default async function(client) {
// getDirectoryContents doesn't accept / for root
getCurrentUser(){
return this._currentUser || getCurrentUser().uid
}
// init params
const shareUrl = generateRemoteUrl('dav') + this.getCurrentUser() + '/versions/' + this._fileInfo.get('id')
const format = 'json'
// TODO: replace with proper getFUllpath implementation of our own FileInfo model
const path = (this.fileInfo.path + '/' + this.fileInfo.name).replace('//', '/')
// Fetch Version
const fetchVersion = await axios.get(shareUrl, {
params: {
format,
path,
},
})
// wait for data
const response = await client.getDirectoryContents(fixedPath, Object.assign({
data: `<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:"
xmlns:oc="http://owncloud.org/ns"
xmlns:nc="http://nextcloud.org/ns"
xmlns:ocs="http://open-collaboration-services.org/ns">
<d:prop>
<d:getlastmodified />
<d:getetag />
<d:getcontenttype />
<d:resourcetype />
<oc:fileid />
<oc:permissions />
<oc:size />
<d:getcontentlength />
<nc:has-preview />
<nc:mount-type />
<nc:is-encrypted />
<ocs:share-permissions />
<oc:tags />
<oc:favorite />
<oc:comments-unread />
<oc:owner-id />
<oc:owner-display-name />
<oc:share-types />
</d:prop>
</d:propfind>`,
details: true,
}, options))
return response.data.map(FileVersion)
}

View File

@ -39,9 +39,8 @@
import axios from '@nextcloud/axios'
import { generateRemoteUrl } from '@nextcloud/router'
import { ListItemIcon } from '@nextcloud/vue'
import { getCurrentUser } from '@nextcloud/auth'
import VersionEntry from '../components/VersionEntry'
import FileVersion from "../services/FileVersion";
export default {
name: 'VersionTab',
@ -83,11 +82,6 @@ export default {
setCurrentUser(user) {
this._currentUser = user
},
getCurrentUser() {
return this._currentUser || getCurrentUser().uid
},
setClient(client) {
this._client = client
},
@ -110,42 +104,13 @@ export default {
async getVersions() {
try {
this.loading = true
// init params
const shareUrl = generateRemoteUrl('dav') + this.getCurrentUser() + '/versions/' + this._fileInfo.get('id')
const format = 'json'
console.log('Shareurl:', shareUrl)
// TODO: replace with proper getFUllpath implementation of our own FileInfo model
const path = (this.fileInfo.path + '/' + this.fileInfo.name).replace('//', '/')
console.log(path)
// fetch version
const fetchVersion = await axios.get(shareUrl, {
params: {
format,
path,
},
})
// wait for data
this.loading = false
// process results
this.versionList = fetchVersion.data
console.log(versionList)
this.version.fullPath = fullPath
this.version.fileId = fileId
this.version.name = name
this.version.timestamp = parseInt(moment(new Date(version.timestamp)).format('X'), 10)
this.version.id = OC.basename(version.href)
this.version.size = parseInt(version.size, 10)
this.version.user = user
this.version.client = client
return version
} catch (error) {
this.error = t('files_version', 'Unable to load the version list')
this.loading = false
console.error('Error loading the version list', error)
const fetchVersion = FileVersion(Client);
fetchVersion();
}
},
catch(e){
console.log(error);
}
}
mounted() {
this.getVersions()
},