@@ -32,6 +32,7 @@ public function __construct(
3232 private BoardMapper $ boardMapper ,
3333 private IURLGenerator $ urlGenerator ,
3434 private DeckShareProvider $ deckShareProvider ,
35+ private FilesAppService $ filesAppService ,
3536 private ?string $ userId ,
3637 ) {
3738 }
@@ -600,7 +601,7 @@ public function localizeRemoteAttachments(Board $localBoard, array $attachments)
600601 $ attachments [$ i ]['extendedData ' ]['attachmentCreator ' ]['displayName ' ] = $ createdByUser ->getCloudId ()->getId ();
601602 }
602603 if (!empty ($ attachment ['extendedData ' ]['shareToken ' ])) {
603- $ file = $ this ->deckShareProvider ->ensureAcceptRemoteShare ($ attachment ['extendedData ' ]['shareToken ' ], $ ownerCloudId ->getRemote ());
604+ $ file = $ this ->deckShareProvider ->getRemoteFile ($ attachment ['extendedData ' ]['shareToken ' ], $ ownerCloudId ->getRemote ());
604605
605606 if (empty ($ file )) {
606607 unset($ attachments [$ i ]);
@@ -627,44 +628,22 @@ public function getAttachmentsFromRemote(Board $localBoard, int $cardId): array
627628 return $ this ->localizeRemoteAttachments ($ localBoard , $ attachments );
628629 }
629630
630- public function createAttachmentOnRemote (Board $ localBoard , int $ cardId, string $ type , string $ data = '' , ? array $ uploadedFile = null ): array {
631+ public function createAttachmentForRemote (Board $ localBoard , int $ cardId ): array {
631632 $ this ->configService ->ensureFederationEnabled ();
632633 $ this ->permissionService ->checkPermission ($ this ->boardMapper , $ localBoard ->getId (), Acl::PERMISSION_EDIT , $ this ->userId , false , false );
633634 $ shareToken = $ localBoard ->getShareToken ();
634635 $ participantCloudId = $ this ->cloudIdManager ->getCloudId ($ this ->userId , null );
635636 $ ownerCloudId = $ this ->cloudIdManager ->resolveCloudId ($ localBoard ->getOwner ());
636- $ url = $ ownerCloudId ->getRemote () . '/ocs/v2.php/apps/deck/api/v1.0/cards/ ' . $ cardId . '/attachment ' ;
637- if ($ uploadedFile !== null ) {
638- $ content = fopen ($ uploadedFile ['tmp_name ' ], 'rb ' );
639- if ($ content === false ) {
640- throw new Exception ('Could not read uploaded file ' );
641- }
642- $ params = [
643- [
644- 'name ' => 'boardId ' ,
645- 'contents ' => (string )$ localBoard ->getExternalId (),
646- ],
647- [
648- 'name ' => 'file ' ,
649- 'contents ' => $ content ,
650- 'filename ' => $ uploadedFile ['name ' ],
651- ],
652- [
653- 'name ' => 'type ' ,
654- 'contents ' => $ type ,
655- ],
656- [
657- 'name ' => 'data ' ,
658- 'contents ' => $ data ,
659- ],
660- ];
661- $ resp = $ this ->proxy ->post ($ participantCloudId ->getId (), $ shareToken , $ url , ['multipart ' => $ params ]);
662- return $ this ->proxy ->getOcsData ($ resp );
663- }
637+
638+ // Upload and create remote share
639+ $ shareWithFederatedId = $ ownerCloudId ->getId ();
640+ $ fileShareToken = $ this ->filesAppService ->createForRemote ($ shareWithFederatedId );
641+
642+ $ url = $ ownerCloudId ->getRemote () . '/ocs/v2.php/apps/deck/api/v1.0/cards/ ' . $ cardId . '/remote-attachment ' ;
664643 $ resp = $ this ->proxy ->post ($ participantCloudId ->getId (), $ shareToken , $ url , [
665644 'boardId ' => $ localBoard ->getExternalId (),
666- 'type ' => $ type ,
667- 'data ' => $ data ,
645+ 'cardId ' => $ cardId ,
646+ 'token ' => $ fileShareToken ,
668647 ]);
669648 return $ this ->proxy ->getOcsData ($ resp );
670649 }
0 commit comments