diff --git a/apps/files_versions/src/services/FileVersion.js b/apps/files_versions/src/services/FileVersion.js new file mode 100644 index 0000000000..b9d5e4f98c --- /dev/null +++ b/apps/files_versions/src/services/FileVersion.js @@ -0,0 +1,85 @@ +/** + * @copyright Copyright (c) 2019 John Molakvoæ + * @author Enoch + * @author John Molakvoæ + * @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 . + * + */ + +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: ` + + + + + + + + + + + + + + + + + + + + + + `, + details: true, + }, options)) + + return response.data.map(FileVersion) +} diff --git a/apps/files_versions/src/views/VersionTab.vue b/apps/files_versions/src/views/VersionTab.vue index 8614825dc4..c6f13b4cdf 100644 --- a/apps/files_versions/src/views/VersionTab.vue +++ b/apps/files_versions/src/views/VersionTab.vue @@ -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() },