1212use  Exception ;
1313use  OC \Files \Storage \Wrapper \Wrapper ;
1414use  OCA \Circles \Api \v1 \Circles ;
15+ use  OCA \Deck \Sharing \ShareAPIHelper ;
16+ use  OCA \Federation \TrustedServers ;
1517use  OCA \Files \Helper ;
1618use  OCA \Files_Sharing \Exceptions \SharingRightsException ;
1719use  OCA \Files_Sharing \External \Storage ;
7274class  ShareAPIController extends  OCSController {
7375
7476	private  ?Node $ lockedNodenull ;
77+ 	private  array  $ trustedServerCache
7578
7679	/** 
7780	 * Share20OCS constructor. 
@@ -94,6 +97,8 @@ public function __construct(
9497		private  LoggerInterface $ logger
9598		private  IProviderFactory $ factory
9699		private  IMailer $ mailer
100+ 		private  ITagManager $ tagManager
101+ 		private  ?TrustedServers $ trustedServers
97102		private  ?string  $ userIdnull ,
98103	) {
99104		parent ::__construct ($ appName$ request
@@ -196,6 +201,32 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
196201		$ result'item_size ' ] = $ nodegetSize ();
197202		$ result'item_mtime ' ] = $ nodegetMTime ();
198203
204+ 		if  ($ this trustedServers  !== null  && in_array ($ sharegetShareType (), [IShare::TYPE_REMOTE , IShare::TYPE_REMOTE_GROUP ], true )) {
205+ 			$ result'is_trusted_server ' ] = false ;
206+ 			$ sharedWith$ sharegetSharedWith ();
207+ 			$ remoteIdentifieris_string ($ sharedWithstrrchr ($ sharedWith'@ ' ) : false ;
208+ 			if  ($ remoteIdentifierfalse ) {
209+ 				$ remotesubstr ($ remoteIdentifier1 );
210+ 
211+ 				if  (isset ($ this trustedServerCache [$ remote
212+ 					$ result'is_trusted_server ' ] = $ this trustedServerCache [$ remote
213+ 				} else  {
214+ 					try  {
215+ 						$ isTrusted$ this trustedServers ->isTrustedServer ($ remote
216+ 						$ this trustedServerCache [$ remote$ isTrusted
217+ 						$ result'is_trusted_server ' ] = $ isTrusted
218+ 					} catch  (\Exception   $ e
219+ 						// Server not found or other issue, we consider it not trusted 
220+ 						$ this trustedServerCache [$ remotefalse ;
221+ 						$ this logger ->error (
222+ 							'Error checking if remote server is trusted (treating as untrusted):  '  . $ egetMessage (),
223+ 							['exception '  => $ e
224+ 						);
225+ 					}
226+ 				}
227+ 			}
228+ 		}
229+ 
199230		$ expiration$ sharegetExpirationDate ();
200231		if  ($ expirationnull ) {
201232			$ expirationsetTimezone ($ this dateTimeZone ->getTimeZone ());
0 commit comments