1- /**
1+ /*!
22 * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
33 * SPDX-License-Identifier: AGPL-3.0-or-later
44 */
5+
6+ import type { IFileAction } from '@nextcloud/files'
7+
58import AutoRenewSvg from '@mdi/svg/svg/autorenew.svg?raw'
69import { getCapabilities } from '@nextcloud/capabilities'
7- import { FileAction , registerFileAction } from '@nextcloud/files'
10+ import { registerFileAction } from '@nextcloud/files'
811import { t } from '@nextcloud/l10n'
912import { generateUrl } from '@nextcloud/router'
1013import { convertFile , convertFiles } from './convertUtils.ts'
@@ -18,47 +21,45 @@ type ConversionsProvider = {
1821export const ACTION_CONVERT = 'convert'
1922
2023/**
21- *
24+ * Registers the convert actions based on the capabilities provided by the server.
2225 */
2326export function registerConvertActions ( ) {
2427 // Generate sub actions
2528 const convertProviders = getCapabilities ( ) ?. files ?. file_conversions as ConversionsProvider [ ] ?? [ ]
26- const actions = convertProviders . map ( ( { to, from, displayName } ) => {
27- return new FileAction ( {
28- id : `convert-${ from } -${ to } ` ,
29- displayName : ( ) => t ( 'files' , 'Save as {displayName}' , { displayName } ) ,
30- iconSvgInline : ( ) => generateIconSvg ( to ) ,
31- enabled : ( { nodes } ) => {
32- // Check that all nodes have the same mime type
33- return nodes . every ( ( node ) => from === node . mime )
34- } ,
29+ const actions = convertProviders . map ( ( { to, from, displayName } ) => ( {
30+ id : `convert-${ from } -${ to } ` ,
31+ displayName : ( ) => t ( 'files' , 'Save as {displayName}' , { displayName } ) ,
32+ iconSvgInline : ( ) => generateIconSvg ( to ) ,
33+ enabled : ( { nodes } ) => {
34+ // Check that all nodes have the same mime type
35+ return nodes . every ( ( node ) => from === node . mime )
36+ } ,
3537
36- async exec ( { nodes } ) {
37- if ( ! nodes [ 0 ] ) {
38- return false
39- }
38+ async exec ( { nodes } ) {
39+ if ( ! nodes [ 0 ] ) {
40+ return false
41+ }
4042
41- // If we're here, we know that the node has a fileid
42- convertFile ( nodes [ 0 ] . fileid as number , to )
43+ // If we're here, we know that the node has a fileid
44+ convertFile ( nodes [ 0 ] . fileid as number , to )
4345
44- // Silently terminate, we'll handle the UI in the background
45- return null
46- } ,
46+ // Silently terminate, we'll handle the UI in the background
47+ return null
48+ } ,
4749
48- async execBatch ( { nodes } ) {
49- const fileIds = nodes . map ( ( node ) => node . fileid ) . filter ( Boolean ) as number [ ]
50- convertFiles ( fileIds , to )
50+ async execBatch ( { nodes } ) {
51+ const fileIds = nodes . map ( ( node ) => node . fileid ) . filter ( Boolean ) as number [ ]
52+ convertFiles ( fileIds , to )
5153
52- // Silently terminate, we'll handle the UI in the background
53- return Array ( nodes . length ) . fill ( null )
54- } ,
54+ // Silently terminate, we'll handle the UI in the background
55+ return Array ( nodes . length ) . fill ( null )
56+ } ,
5557
56- parent : ACTION_CONVERT ,
57- } )
58- } )
58+ parent : ACTION_CONVERT ,
59+ } satisfies IFileAction ) )
5960
6061 // Register main action
61- registerFileAction ( new FileAction ( {
62+ registerFileAction ( {
6263 id : ACTION_CONVERT ,
6364 displayName : ( ) => t ( 'files' , 'Save as …' ) ,
6465 iconSvgInline : ( ) => AutoRenewSvg ,
@@ -69,15 +70,16 @@ export function registerConvertActions() {
6970 return null
7071 } ,
7172 order : 25 ,
72- } ) )
73+ } satisfies IFileAction )
7374
7475 // Register sub actions
7576 actions . forEach ( registerFileAction )
7677}
7778
7879/**
80+ * Generates an SVG icon for a given mime type by using the server's mime icon endpoint.
7981 *
80- * @param mime
82+ * @param mime - The mime type to generate the icon for
8183 */
8284export function generateIconSvg ( mime : string ) {
8385 // Generate icon based on mime type
0 commit comments