mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	Add download file to file service
This commit is contained in:
		
							parent
							
								
									3af48d2147
								
							
						
					
					
						commit
						cd63ee8f21
					
				| @ -61,10 +61,10 @@ class DownloadRemoteFileOperation( | ||||
|     override fun run(client: OwnCloudClient): RemoteOperationResult<Any> { | ||||
|         var result: RemoteOperationResult<Any> | ||||
| 
 | ||||
|         /// download will be performed to a temporal file, then moved to the final location | ||||
|         // download will be performed to a temporal file, then moved to the final location | ||||
|         val tmpFile = File(tmpPath) | ||||
| 
 | ||||
|         /// perform the download | ||||
|         // perform the download | ||||
|         try { | ||||
|             tmpFile.mkdirs() | ||||
|             result = downloadFile(client, tmpFile) | ||||
| @ -145,15 +145,15 @@ class DownloadRemoteFileOperation( | ||||
|                     // TODO some kind of error control! | ||||
|                 } | ||||
| 
 | ||||
|             } else if (status != FORBIDDEN_ERROR && status != SERVICE_UNAVAILABLE_ERROR) { | ||||
|             } else if (status != HttpConstants.HTTP_FORBIDDEN && status != HttpConstants.HTTP_SERVICE_UNAVAILABLE) { | ||||
|                 client.exhaustResponse(getMethod.getResponseBodyAsStream()) | ||||
|             } // else, body read by RemoteOperationResult constructor | ||||
| 
 | ||||
|             result = | ||||
|                 if (isSuccess(status)) { | ||||
|                     RemoteOperationResult<Any>(RemoteOperationResult.ResultCode.OK) | ||||
|                     RemoteOperationResult(RemoteOperationResult.ResultCode.OK) | ||||
|                 } else { | ||||
|                     RemoteOperationResult<Any>(getMethod) | ||||
|                     RemoteOperationResult(getMethod) | ||||
|                 } | ||||
|         } finally { | ||||
|             fos?.close() | ||||
| @ -181,9 +181,4 @@ class DownloadRemoteFileOperation( | ||||
|         mCancellationRequested.set(true) // atomic set; there is no need of synchronizing it | ||||
|     } | ||||
| 
 | ||||
|     companion object { | ||||
|         private const val FORBIDDEN_ERROR = 403 | ||||
|         private const val SERVICE_UNAVAILABLE_ERROR = 503 | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -41,6 +41,11 @@ interface FileService : Service { | ||||
|         isChunkFolder: Boolean = false | ||||
|     ): RemoteOperationResult<Unit> | ||||
| 
 | ||||
|     fun downloadFile( | ||||
|         remotePath: String, | ||||
|         localTempPath: String | ||||
|     ): RemoteOperationResult<Any> | ||||
| 
 | ||||
|     fun refreshFolder( | ||||
|         remotePath: String | ||||
|     ): RemoteOperationResult<ArrayList<RemoteFile>> | ||||
|  | ||||
| @ -27,12 +27,14 @@ import com.owncloud.android.lib.common.OwnCloudClient | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult | ||||
| import com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation | ||||
| import com.owncloud.android.lib.resources.files.CreateRemoteFolderOperation | ||||
| import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation | ||||
| import com.owncloud.android.lib.resources.files.GetUrlToOpenInWebRemoteOperation | ||||
| import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation | ||||
| import com.owncloud.android.lib.resources.files.RemoteFile | ||||
| import com.owncloud.android.lib.resources.files.services.FileService | ||||
| 
 | ||||
| class OCFileService(override val client: OwnCloudClient) : FileService { | ||||
| 
 | ||||
|     override fun checkPathExistence( | ||||
|         path: String, | ||||
|         isUserLogged: Boolean | ||||
| @ -56,6 +58,15 @@ class OCFileService(override val client: OwnCloudClient) : FileService { | ||||
|             isChunksFolder = isChunkFolder | ||||
|         ).execute(client) | ||||
| 
 | ||||
|     override fun downloadFile( | ||||
|         remotePath: String, | ||||
|         localTempPath: String | ||||
|     ): RemoteOperationResult<Any> = | ||||
|         DownloadRemoteFileOperation( | ||||
|             remotePath = remotePath, | ||||
|             localFolderPath = localTempPath | ||||
|         ).execute(client) | ||||
| 
 | ||||
|     override fun refreshFolder(remotePath: String): RemoteOperationResult<ArrayList<RemoteFile>> = | ||||
|         ReadRemoteFolderOperation( | ||||
|             remotePath = remotePath | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user