Skip to content

Commit

Permalink
Merge branch 'use-oc-table' of github.com:owncloud/web into use-oc-table
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasHirt committed Mar 2, 2021
2 parents 0b04440 + 313b98c commit c87ff14
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 63 deletions.
88 changes: 33 additions & 55 deletions packages/web-app-files/src/helpers/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import moment from 'moment'

import fileIconMappings from '../fileTypeIconMappings.json'
import { getIndicators } from './statusIndicators'
import { checkPermission, bitmaskToRole, permissionsBitmask } from '../helpers/collaborators'
import { shareTypes, userShareTypes } from '../helpers/shareTypes'
import { bitmaskToRole, checkPermission, permissionsBitmask } from './collaborators'
import { shareTypes, userShareTypes } from './shareTypes'
import { $gettext } from '../gettext'
import { getAvatarSrc } from './user'

Expand Down Expand Up @@ -43,28 +43,28 @@ export function getFileIcon(extension) {
return 'file'
}

export function getFileExtension(name) {
const dotIndex = name.lastIndexOf('.')

return name.substring(dotIndex + 1).toLowerCase()
function _getFileExtension(name) {
const extension = path.extname(name)
if (!extension) {
return ''
}
return extension.replace(/^(.)/, '').toLowerCase()
}

export function buildResource(resource) {
const builtResource = {
const isFolder = resource.type === 'dir'
const extension = _getFileExtension(resource.name)
return {
id: resource.fileInfo['{http://owncloud.org/ns}fileid'],
icon: resource.type === 'dir' ? 'folder' : getFileIcon(getFileExtension(resource.name)),
name: (() => {
const name = resource.name

return name.includes('/') ? name.substring(name.lastIndexOf('/') + 1) : name
})(),
icon: isFolder ? 'folder' : getFileIcon(extension),
name: path.basename(resource.name),
extension: isFolder ? '' : extension,
path: resource.name,
type: resource.type === 'dir' ? 'folder' : resource.type,
type: isFolder ? 'folder' : resource.type,
mdate: resource.fileInfo['{DAV:}getlastmodified'],
size:
resource.type === 'dir'
? resource.fileInfo['{http://owncloud.org/ns}size']
: resource.fileInfo['{DAV:}getcontentlength'],
size: isFolder
? resource.fileInfo['{http://owncloud.org/ns}size']
: resource.fileInfo['{DAV:}getcontentlength'],
indicators: [],
permissions: resource.fileInfo['{http://owncloud.org/ns}permissions'] || '',
starred: resource.fileInfo['{http://owncloud.org/ns}favorite'] !== '0',
Expand All @@ -86,12 +86,12 @@ export function buildResource(resource) {
return shareTypes || []
})(),
privateLink: resource.fileInfo['{http://owncloud.org/ns}privatelink'],
extension: getFileExtension(resource.name),
canUpload: function() {
return this.permissions.indexOf('C') >= 0
},
canDownload: function() {
return this.type !== 'folder'
// TODO: as soon as we allow folder downloads as archive we want to return `true` here without exceptions
return !isFolder
},
canBeDeleted: function() {
return this.permissions.indexOf('D') >= 0
Expand All @@ -112,11 +112,9 @@ export function buildResource(resource) {
return this.permissions.indexOf('S') >= 0
}
}

return builtResource
}

export function attatchIndicators(resource, sharesTree) {
export function attachIndicators(resource, sharesTree) {
return (resource.indicators = getIndicators(resource, sharesTree))
}

Expand Down Expand Up @@ -207,6 +205,7 @@ async function buildSharedResource(share, incomingShares = false, allowSharePerm
id: share.item_source,
type: share.item_type
}
const isFolder = resource.type === 'folder'

if (incomingShares) {
resource.resourceOwner = {
Expand All @@ -221,21 +220,19 @@ async function buildSharedResource(share, incomingShares = false, allowSharePerm
}
]
resource.status = share.state
resource.name = share.file_target.includes('/')
? share.file_target.substring(share.file_target.lastIndexOf('/') + 1)
: share.file_target
resource.name = path.basename(share.file_target)
resource.path = share.file_target
resource.isReceivedShare = () => true
} else {
resource.sharedWith = share.sharedWith
resource.shareOwner = share.uid_owner
resource.shareOwnerDisplayname = share.displayname_owner
resource.name = path.basename(share.path)
resource.basename = path.basename(share.path, resource.extension)
resource.path = share.path
// permissions irrelevant here
resource.isReceivedShare = () => false
}
resource.extension = isFolder ? '' : _getFileExtension(resource.name)
// FIXME: add actual permission parsing
resource.canUpload = () => true
resource.canBeDeleted = () => true
Expand All @@ -244,18 +241,10 @@ async function buildSharedResource(share, incomingShares = false, allowSharePerm
return checkPermission(share.permissions, 'share')
}
resource.isMounted = () => false
resource.canDownload = () => resource.type !== 'folder'
if (resource.extension) {
// remove extension from basename like _buildFile does
resource.basename = resource.basename.substring(
0,
resource.basename.length - resource.extension.length - 1
)
}
resource.canDownload = () => !isFolder
resource.share = buildShare(share, resource, allowSharePerm)
resource.indicators = []
resource.icon =
resource.type === 'folder' ? 'folder' : getFileIcon(getFileExtension(resource.name))
resource.icon = isFolder ? 'folder' : getFileIcon(resource.extension)
resource.sdate = share.stime * 1000

return resource
Expand Down Expand Up @@ -367,27 +356,16 @@ export function buildCollaboratorShare(s, file, allowSharePerm) {
}

export function buildDeletedResource(resource) {
const isFolder = resource.type === 'dir'
const fullName = resource.fileInfo['{http://owncloud.org/ns}trashbin-original-filename']
return {
type: resource.type === 'dir' ? 'folder' : resource.type,
type: isFolder ? 'folder' : resource.type,
ddate: resource.fileInfo['{http://owncloud.org/ns}trashbin-delete-datetime'],
name: (function() {
const fullName = resource.fileInfo['{http://owncloud.org/ns}trashbin-original-filename']
const pathList = fullName.split('/').filter(e => e !== '')
return pathList.length === 0 ? '' : pathList[pathList.length - 1]
})(),
name: path.basename(fullName),
extension: isFolder ? '' : _getFileExtension(fullName),
path: resource.fileInfo['{http://owncloud.org/ns}trashbin-original-location'],
id: (function() {
const pathList = resource.name.split('/').filter(e => e !== '')
return pathList.length === 0 ? '' : pathList[pathList.length - 1]
})(),
icon:
resource.type === 'dir'
? 'folder'
: getFileIcon(
getFileExtension(
resource.fileInfo['{http://owncloud.org/ns}trashbin-original-filename']
)
),
id: path.basename(resource.name),
icon: isFolder ? 'folder' : getFileIcon(this.extension),
indicators: []
}
}
3 changes: 1 addition & 2 deletions packages/web-app-files/src/mixins/fileActions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { mapGetters, mapActions, mapState } from 'vuex'

import { checkRoute } from '../helpers/route'
import { getFileExtension } from '../helpers/resources'
import Copy from './actions/copy'
import Delete from './actions/delete'
import Download from './actions/download'
Expand Down Expand Up @@ -54,7 +53,7 @@ export default {
return false
}

return getFileExtension(resource.name) === editor.extension
return resource.extension === editor.extension
},
canBeDefault: true
}
Expand Down
9 changes: 5 additions & 4 deletions packages/web-app-files/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,10 @@ export default {
}

for (const resource of resources) {
if (!resource.extension) {
continue
}

const etag = resource.etag

if (etag) {
Expand All @@ -532,13 +536,10 @@ export default {

try {
resource.preview = await mediaSource(previewUrl, 'url')
commit('UPDATE_RESOURCE', resource)
} catch (error) {
console.error(error)
}
}

for (const resource of resources) {
commit('UPDATE_RESOURCE', resource)
}
}
}
4 changes: 2 additions & 2 deletions packages/web-app-files/src/store/mutations.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Vue from 'vue'
import pickBy from 'lodash-es/pickBy'
import moment from 'moment'
import { attatchIndicators } from '../helpers/resources'
import { attachIndicators } from '../helpers/resources'

/**
* @param {Array.<Object>} shares array of shares
Expand Down Expand Up @@ -286,7 +286,7 @@ export default {
},

LOAD_INDICATORS(state) {
state.files.forEach(resource => attatchIndicators(resource, state.sharesTree))
state.files.forEach(resource => attachIndicators(resource, state.sharesTree))
},

PUSH_NEW_RESOURCE(state, resource) {
Expand Down

0 comments on commit c87ff14

Please sign in to comment.