|
2 | 2 | * SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
|
3 | 3 | * SPDX-License-Identifier: AGPL-3.0-or-later
|
4 | 4 | */
|
5 |
| -import axios from '@nextcloud/axios' |
6 | 5 | import { FileAction, registerFileAction } from '@nextcloud/files'
|
7 | 6 | import { loadState } from '@nextcloud/initial-state'
|
8 | 7 | import { t } from '@nextcloud/l10n'
|
9 |
| -import { generateOcsUrl } from '@nextcloud/router' |
10 | 8 |
|
11 | 9 | import { SIGN_STATUS } from '../domains/sign/enum.js'
|
12 | 10 | import { fileStatus } from '../helpers/fileStatus.js'
|
13 | 11 |
|
14 |
| -let nodeIds = [] |
15 |
| -const nodeStatusById = new Map() |
16 |
| - |
17 | 12 | const action = new FileAction({
|
18 | 13 | id: 'show-status-inline',
|
19 | 14 | displayName: () => '',
|
20 | 15 | title: (nodes) => {
|
21 |
| - const nodeId = nodes[0].fileid |
22 |
| - |
23 |
| - if (nodeStatusById.has(nodeId)) { |
24 |
| - const node = nodeStatusById.get(nodeId) |
| 16 | + const node = nodes[0] |
25 | 17 |
|
26 |
| - if ([SIGN_STATUS.PARTIAL_SIGNED, SIGN_STATUS.SIGNED].includes(node.status)) { |
27 |
| - return node.original |
28 |
| - ? t('libresign', 'original file') |
29 |
| - : fileStatus.find(status => status.id === node.status).label |
30 |
| - } |
31 |
| - } |
| 18 | + const signedNodeId = node.attributes['signed-node-id']; |
32 | 19 |
|
33 |
| - nodeIds.push(nodeId) |
34 |
| - |
35 |
| - return '' |
| 20 | + return !signedNodeId || node.fileid === signedNodeId |
| 21 | + ? fileStatus.find(status => status.id === node.attributes['signature-status']).label |
| 22 | + : t('libresign', 'original file') |
36 | 23 | },
|
37 | 24 | exec: async () => null,
|
38 | 25 | iconSvgInline: (nodes) => {
|
39 |
| - const nodeId = nodes[0].fileid |
40 |
| - |
41 |
| - if (nodeStatusById.has(nodeId)) { |
42 |
| - const node = nodeStatusById.get(nodeId) |
| 26 | + const node = nodes[0] |
43 | 27 |
|
44 |
| - if ([SIGN_STATUS.PARTIAL_SIGNED, SIGN_STATUS.SIGNED].includes(node.status)) { |
45 |
| - return node.original |
46 |
| - ? fileStatus.find(status => status.id === SIGN_STATUS.ABLE_TO_SIGN).icon |
47 |
| - : fileStatus.find(status => status.id === node.status).icon |
48 |
| - } |
49 |
| - } |
| 28 | + const signedNodeId = node.attributes['signed-node-id']; |
50 | 29 |
|
51 |
| - return '' |
| 30 | + return !signedNodeId || node.fileid === signedNodeId |
| 31 | + ? fileStatus.find(status => status.id === node.attributes['signature-status']).icon |
| 32 | + : fileStatus.find(status => status.id === SIGN_STATUS.ABLE_TO_SIGN).icon |
52 | 33 | },
|
53 | 34 | inline: () => true,
|
54 | 35 | enabled: (nodes) => {
|
55 | 36 | return loadState('libresign', 'certificate_ok')
|
56 |
| - && nodes.length > 0 && nodes |
| 37 | + && nodes.length > 0 |
| 38 | + && nodes |
57 | 39 | .map(node => node.mime)
|
58 | 40 | .every(mime => mime === 'application/pdf')
|
| 41 | + && nodes.every(node => node.attributes['signature-status']) |
59 | 42 | },
|
60 | 43 | order: -1,
|
61 | 44 | })
|
62 | 45 |
|
63 |
| -axios.get(generateOcsUrl('/apps/libresign/api/v1/file/list'), { |
64 |
| - params: { |
65 |
| - nodeIds, |
66 |
| - }, |
67 |
| -}).then(({ data }) => { |
68 |
| - data.ocs.data.data.forEach(node => { |
69 |
| - nodeStatusById.set(node.nodeId, { status: node.status, original: true }) |
70 |
| - |
71 |
| - if (node.signedNodeId) { |
72 |
| - nodeStatusById.set(node.signedNodeId, { status: node.status, original: false }) |
73 |
| - } |
74 |
| - }) |
75 |
| - |
76 |
| - registerFileAction(action) |
77 |
| -}).finally(() => { nodeIds = [] }) |
| 46 | +registerFileAction(action) |
0 commit comments