mirror of
https://github.com/nextcloud/server.git
synced 2026-04-27 01:00:20 -04:00
Merge pull request #49803 from nextcloud/backport/49432/master
This commit is contained in:
commit
30ff2ae5cc
3 changed files with 25 additions and 4 deletions
|
|
@ -11,6 +11,7 @@ import { encodePath } from '@nextcloud/paths'
|
|||
import { generateUrl } from '@nextcloud/router'
|
||||
import { isPublicShare } from '@nextcloud/sharing/public'
|
||||
import axios from '@nextcloud/axios'
|
||||
import PQueue from 'p-queue'
|
||||
import Vue from 'vue'
|
||||
|
||||
import StarOutlineSvg from '@mdi/svg/svg/star-outline.svg?raw'
|
||||
|
|
@ -18,6 +19,8 @@ import StarSvg from '@mdi/svg/svg/star.svg?raw'
|
|||
|
||||
import logger from '../logger.ts'
|
||||
|
||||
const queue = new PQueue({ concurrency: 5 })
|
||||
|
||||
// If any of the nodes is not favorited, we display the favorite action.
|
||||
const shouldFavorite = (nodes: Node[]): boolean => {
|
||||
return nodes.some(node => node.attributes.favorite !== 1)
|
||||
|
|
@ -89,7 +92,25 @@ export const action = new FileAction({
|
|||
},
|
||||
async execBatch(nodes: Node[], view: View) {
|
||||
const willFavorite = shouldFavorite(nodes)
|
||||
return Promise.all(nodes.map(async node => await favoriteNode(node, view, willFavorite)))
|
||||
|
||||
// Map each node to a promise that resolves with the result of exec(node)
|
||||
const promises = nodes.map(node => {
|
||||
// Create a promise that resolves with the result of exec(node)
|
||||
const promise = new Promise<boolean>(resolve => {
|
||||
queue.add(async () => {
|
||||
try {
|
||||
await favoriteNode(node, view, willFavorite)
|
||||
resolve(true)
|
||||
} catch (error) {
|
||||
logger.error('Error while adding file to favorite', { error, source: node.source, node })
|
||||
resolve(false)
|
||||
}
|
||||
})
|
||||
})
|
||||
return promise
|
||||
})
|
||||
|
||||
return Promise.all(promises)
|
||||
},
|
||||
|
||||
order: -50,
|
||||
|
|
|
|||
4
dist/files-init.js
vendored
4
dist/files-init.js
vendored
File diff suppressed because one or more lines are too long
2
dist/files-init.js.map
vendored
2
dist/files-init.js.map
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue