Skip to content

Commit

Permalink
Merge pull request #10192 from owncloud/fix-stable-7.1-for-release
Browse files Browse the repository at this point in the history
Fix stable 7.1 for release
  • Loading branch information
JammingBen authored Dec 19, 2023
2 parents d2bdf10 + 852d06a commit 7a929ea
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 286 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "7.1.2",
"version": "7.1.3",
"private": true,
"homepage": "https://github.com/owncloud/web",
"license": "AGPL-3.0",
Expand Down
101 changes: 56 additions & 45 deletions packages/web-app-files/src/HandleUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ export interface HandleUploadOptions {
* 5. start upload
*/
export class HandleUpload extends BasePlugin {
id: string
type: string
uppy: Uppy

clientService: ClientService
hasSpaces: Ref<boolean>
language: Language
Expand All @@ -58,10 +54,8 @@ export class HandleUpload extends BasePlugin {

constructor(uppy: Uppy, opts: HandleUploadOptions) {
super(uppy, opts)
this.id = opts.id || 'HandleUpload'
this.type = 'modifier'
this.uppy = uppy

;(this as any).id = opts.id || 'HandleUpload'
;(this as any).type = 'modifier'
this.clientService = opts.clientService
this.hasSpaces = opts.hasSpaces
this.language = opts.language
Expand All @@ -77,6 +71,10 @@ export class HandleUpload extends BasePlugin {
this.handleUpload = this.handleUpload.bind(this)
}

get _uppy(): Uppy {
return (this as any).uppy
}

get currentFolder(): Resource {
return this.store.getters['Files/currentFolder']
}
Expand All @@ -91,53 +89,57 @@ export class HandleUpload extends BasePlugin {

removeFilesFromUpload(filesToUpload: UppyResource[]) {
for (const file of filesToUpload) {
this.uppy.removeFile(file.id)
this._uppy.removeFile(file.id)
}
}

getUploadPluginName() {
return this.uppy.getPlugin('Tus') ? 'tus' : 'xhrUpload'
/**
* Sets the endpoint url for a given file.
*/
setEndpointUrl(fileId: string, endpoint: string) {
if (this._uppy.getPlugin('Tus')) {
this._uppy.setFileState(fileId, { tus: { endpoint } })
return
}
this._uppy.setFileState(fileId, { xhrUpload: { endpoint } })
}

/**
* Converts the input files type UppyResources and updates the uppy upload queue
*/
prepareFiles(files: UppyFile[]): UppyResource[] {
const filesToUpload: Record<string, UppyResource> = {}
const filesToUpload = []

if (!this.currentFolder && unref(this.route)?.params?.token) {
// public file drop
const publicLinkToken = unref(this.route).params.token
let endpoint = this.clientService.owncloudSdk.publicFiles.getFileUrl(publicLinkToken) + '/'
for (const file of files) {
if (!this.uppy.getPlugin('Tus')) {
if (!this._uppy.getPlugin('Tus')) {
endpoint = urlJoin(endpoint, encodeURIComponent(file.name))
}

file[this.getUploadPluginName()] = { endpoint }
file.meta = {
...file.meta,
this.setEndpointUrl(file.id, endpoint)
this._uppy.setFileMeta(file.id, {
tusEndpoint: endpoint,
uploadId: uuid.v4()
}
})

filesToUpload[file.id] = file as unknown as UppyResource
filesToUpload.push(this._uppy.getFile(file.id))
}
this.uppy.setState({ files: { ...this.uppy.getState().files, ...filesToUpload } })
return Object.values(filesToUpload)
return filesToUpload
}
const { id: currentFolderId, path: currentFolderPath } = this.currentFolder

const { name, params, query } = unref(this.route)
const topLevelFolderIds: Record<string, string> = {}
const topLevelFolderIds = {}

for (const file of files) {
const relativeFilePath = file.meta.relativePath as string
// Directory without filename
const directory =
!relativeFilePath || dirname(relativeFilePath) === '.' ? '' : dirname(relativeFilePath)

let topLevelFolderId: string
let topLevelFolderId
if (relativeFilePath) {
const topLevelDirectory = relativeFilePath.split('/').filter(Boolean)[0]
if (!topLevelFolderIds[topLevelDirectory]) {
Expand All @@ -151,13 +153,12 @@ export class HandleUpload extends BasePlugin {
})

let endpoint = urlJoin(webDavUrl, directory.split('/').map(encodeURIComponent).join('/'))
if (!this.uppy.getPlugin('Tus')) {
if (!this._uppy.getPlugin('Tus')) {
endpoint = urlJoin(endpoint, encodeURIComponent(file.name))
}

file[this.getUploadPluginName()] = { endpoint }
file.meta = {
...file.meta,
this.setEndpointUrl(file.id, endpoint)
this._uppy.setFileMeta(file.id, {
// file data
name: file.name,
mtime: (file.data as any).lastModified / 1000,
Expand All @@ -178,20 +179,19 @@ export class HandleUpload extends BasePlugin {
routeName: name as string,
routeDriveAliasAndItem: (params as any)?.driveAliasAndItem || '',
routeShareId: (query as any)?.shareId || ''
}
})

filesToUpload[file.id] = file as unknown as UppyResource
filesToUpload.push(this._uppy.getFile(file.id))
}

this.uppy.setState({ files: { ...this.uppy.getState().files, ...filesToUpload } })
return Object.values(filesToUpload)
return filesToUpload
}

checkQuotaExceeded(filesToUpload: UppyResource[]): boolean {
let quotaExceeded = false

const uploadSizeSpaceMapping = filesToUpload.reduce((acc, uppyResource) => {
let targetUploadSpace: SpaceResource
let targetUploadSpace

if (uppyResource.meta.routeName === locationPublicLink.name) {
return acc
Expand Down Expand Up @@ -338,14 +338,14 @@ export class HandleUpload extends BasePlugin {
}
}

let filesToRemove: string[] = []
let filesToRemove = []
if (failedFolders.length) {
// remove files of folders that could not be created
// remove file of folders that could not be created
filesToRemove = filesToUpload
.filter((f) => failedFolders.some((r) => f.meta.relativeFolder.startsWith(r)))
.map(({ id }) => id)
for (const fileId of filesToRemove) {
this.uppy.removeFile(fileId)
this._uppy.removeFile(fileId)
}
}

Expand All @@ -370,26 +370,37 @@ export class HandleUpload extends BasePlugin {

// name conflict handling
if (this.conflictHandlingEnabled) {
const conflictHandler = new ResourceConflict(this.store, this.language)
const conflicts = conflictHandler.getConflicts(filesToUpload)
const confictHandler = new ResourceConflict(this.store, this.language)
const conflicts = confictHandler.getConflicts(filesToUpload)
if (conflicts.length) {
const dashboard = document.getElementsByClassName('uppy-Dashboard')
if (dashboard.length) {
;(dashboard[0] as HTMLElement).style.display = 'none'
}

const result = await conflictHandler.displayOverwriteDialog(filesToUpload, conflicts)
const result = await confictHandler.displayOverwriteDialog(filesToUpload, conflicts)
if (result.length === 0) {
this.removeFilesFromUpload(filesToUpload)
return this.uppyService.clearInputs()
}

for (const file of filesToUpload) {
const conflictResult = result.find(({ id }) => id === file.id)
if (!conflictResult) {
this._uppy.removeFile(file.id)
continue
}
this._uppy.setFileMeta(file.id, conflictResult.meta)
this._uppy.setFileState(file.id, { name: conflictResult.name })
this.setEndpointUrl(
file.id,
!!this._uppy.getPlugin('Tus')
? conflictResult.meta.tusEndpoint
: conflictResult.xhrUpload.endpoint
)
}

filesToUpload = result
const conflictMap = result.reduce<Record<string, UppyResource>>((acc, file) => {
acc[file.id] = file
return acc
}, {})
this.uppy.setState({ files: { ...this.uppy.getState().files, ...conflictMap } })
}
}

Expand All @@ -408,10 +419,10 @@ export class HandleUpload extends BasePlugin {
}

install() {
this.uppy.on('files-added', this.handleUpload)
this._uppy.on('files-added', this.handleUpload)
}

uninstall() {
this.uppy.off('files-added', this.handleUpload)
this._uppy.off('files-added', this.handleUpload)
}
}
6 changes: 0 additions & 6 deletions packages/web-app-files/src/helpers/resource/actions/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,6 @@ export class ResourceConflict extends ConflictDialog {
`/${encodeURIComponent(newFolderName)}`
)
}
if (file.tus?.endpoint) {
file.tus.endpoint = file.tus.endpoint.replace(
new RegExp(`/${encodeURIComponent(folder)}`),
`/${encodeURIComponent(newFolderName)}`
)
}
}
}
return files
Expand Down
7 changes: 6 additions & 1 deletion packages/web-app-files/src/views/spaces/DriveResolver.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { linkRoleUploaderFolder } from 'web-client/src/helpers/share'
import { createFileRouteOptions } from 'web-pkg/src/helpers/router'
import AppLoadingSpinner from 'web-pkg/src/components/AppLoadingSpinner.vue'
import { dirname } from 'path'
import { configurationManager } from 'web-pkg/src/configuration'
export default defineComponent({
components: {
Expand Down Expand Up @@ -98,7 +99,11 @@ export default defineComponent({
return router.push({
name: 'resolvePrivateLink',
params: { fileId: unref(fileId) },
query: { openWithDefaultApp: 'false' }
query: {
...(configurationManager.options.openLinksWithDefaultApp && {
openWithDefaultApp: 'true'
})
}
})
}
Expand Down
Loading

0 comments on commit 7a929ea

Please sign in to comment.