diff --git a/templates/android/library/src/main/java/io/package/Client.kt.twig b/templates/android/library/src/main/java/io/package/Client.kt.twig index ddf40dbc4..cddb4007b 100644 --- a/templates/android/library/src/main/java/io/package/Client.kt.twig +++ b/templates/android/library/src/main/java/io/package/Client.kt.twig @@ -60,7 +60,7 @@ class Client @JvmOverloads constructor( internal lateinit var http: OkHttpClient internal val headers: MutableMap - + val config: MutableMap internal val cookieJar = ListenableCookieJar(CookieManager( @@ -87,14 +87,14 @@ class Client @JvmOverloads constructor( "x-sdk-platform" to "{{ sdk.platform }}", "x-sdk-language" to "{{ language.name | caseLower }}", "x-sdk-version" to "{{ sdk.version }}"{% if spec.global.defaultHeaders | length > 0 %},{% endif %} - + {% for key,header in spec.global.defaultHeaders %} "{{ key | caseLower }}" to "{{ header }}"{% if not loop.last %},{% endif %} {% endfor %} ) config = mutableMapOf() - + setSelfSigned(selfSigned) } @@ -119,10 +119,10 @@ class Client @JvmOverloads constructor( {% endfor %} /** * Set self Signed - * + * * @param status * - * @return this + * @return this */ fun setSelfSigned(status: Boolean): Client { selfSigned = status @@ -171,10 +171,10 @@ class Client @JvmOverloads constructor( /** * Set endpoint and realtime endpoint. - * + * * @param endpoint * - * @return this + * @return this */ fun setEndpoint(endpoint: String): Client { this.endpoint = endpoint @@ -200,11 +200,11 @@ class Client @JvmOverloads constructor( /** * Add Header - * + * * @param key * @param value * - * @return this + * @return this */ fun addHeader(key: String, value: String): Client { headers[key] = value @@ -232,19 +232,19 @@ class Client @JvmOverloads constructor( /** * Send the HTTP request - * + * * @param method * @param path * @param headers * @param params * - * @return [T] + * @return [T] */ @Throws({{ spec.title | caseUcfirst }}Exception::class) suspend fun call( - method: String, - path: String, - headers: Map = mapOf(), + method: String, + path: String, + headers: Map = mapOf(), params: Map = mapOf(), responseType: Class, converter: ((Any) -> T)? = null @@ -382,7 +382,7 @@ class Client @JvmOverloads constructor( var offset = 0L var result: Map<*, *>? = null - if (idParamName?.isNotEmpty() == true && params[idParamName] != "unique()") { + if (idParamName?.isNotEmpty() == true) { // Make a request to check if a file already exists val current = call( method = "GET", @@ -479,14 +479,14 @@ class Client @JvmOverloads constructor( .charStream() .buffered() .use(BufferedReader::readText) - + val error = if (response.headers["content-type"]?.contains("application/json") == true) { val map = body.fromJson>() {{ spec.title | caseUcfirst }}Exception( - map["message"] as? String ?: "", + map["message"] as? String ?: "", (map["code"] as Number).toInt(), - map["type"] as? String ?: "", + map["type"] as? String ?: "", body ) } else { @@ -546,4 +546,4 @@ class Client @JvmOverloads constructor( } }) } -} \ No newline at end of file +} diff --git a/templates/apple/Sources/Client.swift.twig b/templates/apple/Sources/Client.swift.twig index 48b023f02..93fa30c0f 100644 --- a/templates/apple/Sources/Client.swift.twig +++ b/templates/apple/Sources/Client.swift.twig @@ -387,7 +387,7 @@ open class Client { var offset = 0 var result = [String:Any]() - if idParamName != nil && params[idParamName!] as! String != "unique()" { + if idParamName != nil { // Make a request to check if a file already exists do { let map = try await call( diff --git a/templates/dart/lib/src/client_browser.dart.twig b/templates/dart/lib/src/client_browser.dart.twig index 41d9860c9..72762708e 100644 --- a/templates/dart/lib/src/client_browser.dart.twig +++ b/templates/dart/lib/src/client_browser.dart.twig @@ -121,7 +121,7 @@ class ClientBrowser extends ClientBase with ClientMixin { } var offset = 0; - if (idParamName.isNotEmpty && params[idParamName] != 'unique()') { + if (idParamName.isNotEmpty) { //make a request to check if a file already exists try { res = await call( diff --git a/templates/dart/lib/src/client_io.dart.twig b/templates/dart/lib/src/client_io.dart.twig index 09a3ca6a3..abbaeb4c5 100644 --- a/templates/dart/lib/src/client_io.dart.twig +++ b/templates/dart/lib/src/client_io.dart.twig @@ -142,7 +142,7 @@ class ClientIO extends ClientBase with ClientMixin { } var offset = 0; - if (idParamName.isNotEmpty && params[idParamName] != 'unique()') { + if (idParamName.isNotEmpty) { //make a request to check if a file already exists try { res = await call( diff --git a/templates/deno/src/services/service.ts.twig b/templates/deno/src/services/service.ts.twig index fb1336404..ca3c00ff2 100644 --- a/templates/deno/src/services/service.ts.twig +++ b/templates/deno/src/services/service.ts.twig @@ -108,7 +108,7 @@ export class {{ service.name | caseUcfirst }} extends Service { {% if parameter.type == 'file' %} const size = {{ parameter.name | caseCamel | escapeKeyword }}.size; - + const apiHeaders: { [header: string]: string } = { {% for parameter in method.parameters.header %} '{{ parameter.name }}': ${{ parameter.name | caseCamel | escapeKeyword }}, @@ -125,16 +125,14 @@ export class {{ service.name | caseUcfirst }} extends Service { {% for parameter in method.parameters.all %} {% if parameter.isUploadID %} - if({{ parameter.name | caseCamel | escapeKeyword }} != 'unique()') { - try { - response = await this.client.call( - 'get', - apiPath + '/' + {{ parameter.name }}, - apiHeaders - ); - chunksUploaded = response.chunksUploaded; - } catch(e) { - } + try { + response = await this.client.call( + 'get', + apiPath + '/' + {{ parameter.name }}, + apiHeaders + ); + chunksUploaded = response.chunksUploaded; + } catch(e) { } {% endif %} {% endfor %} @@ -160,7 +158,7 @@ export class {{ service.name | caseUcfirst }} extends Service { } let uploadableChunkTrimmed: Uint8Array; - + if(currentPosition + 1 >= Client.CHUNK_SIZE) { uploadableChunkTrimmed = uploadableChunk; } else { @@ -241,4 +239,4 @@ export class {{ service.name | caseUcfirst }} extends Service { {% endif %} } {% endfor %} -} \ No newline at end of file +} diff --git a/templates/dotnet/Package/Client.cs.twig b/templates/dotnet/Package/Client.cs.twig index fb6a3f50c..86df8976b 100644 --- a/templates/dotnet/Package/Client.cs.twig +++ b/templates/dotnet/Package/Client.cs.twig @@ -374,7 +374,7 @@ namespace {{ spec.title | caseUcfirst }} ); } - if (!string.IsNullOrEmpty(idParamName) && (string)parameters[idParamName] != "unique()") + if (!string.IsNullOrEmpty(idParamName)) { try { diff --git a/templates/flutter/lib/src/client_browser.dart.twig b/templates/flutter/lib/src/client_browser.dart.twig index 22b0d6bc6..f96a881e4 100644 --- a/templates/flutter/lib/src/client_browser.dart.twig +++ b/templates/flutter/lib/src/client_browser.dart.twig @@ -142,7 +142,7 @@ class ClientBrowser extends ClientBase with ClientMixin { } var offset = 0; - if (idParamName.isNotEmpty && params[idParamName] != 'unique()') { + if (idParamName.isNotEmpty) { //make a request to check if a file already exists try { res = await call( diff --git a/templates/flutter/lib/src/client_io.dart.twig b/templates/flutter/lib/src/client_io.dart.twig index f93ab9ac1..5642c1b0e 100644 --- a/templates/flutter/lib/src/client_io.dart.twig +++ b/templates/flutter/lib/src/client_io.dart.twig @@ -262,7 +262,7 @@ class ClientIO extends ClientBase with ClientMixin { } var offset = 0; - if (idParamName.isNotEmpty && params[idParamName] != 'unique()') { + if (idParamName.isNotEmpty) { //make a request to check if a file already exists try { res = await call( diff --git a/templates/go/client.go.twig b/templates/go/client.go.twig index 2316630a7..e268d26b3 100644 --- a/templates/go/client.go.twig +++ b/templates/go/client.go.twig @@ -157,7 +157,7 @@ func (client *Client) FileUpload(url string, headers map[string]interface{}, par numChunks++ } var currentChunk int64 = 0 - if uploadId != "" && uploadId != "unique()" { + if uploadId != "" { resp, err := client.Call("GET", url+"/"+uploadId, nil, nil) if err == nil { currentChunk = int64(resp.Result.(map[string]interface{})["chunksUploaded"].(float64)) @@ -165,7 +165,7 @@ func (client *Client) FileUpload(url string, headers map[string]interface{}, par } if fileInfo.Size() <= client.ChunkSize { - if uploadId != "" && uploadId != "unique()" { + if uploadId != "" { headers["x-appwrite-id"] = uploadId } inputFile.Data = make([]byte, fileInfo.Size()) @@ -203,7 +203,7 @@ func (client *Client) FileUpload(url string, headers map[string]interface{}, par return nil, err } params[paramName] = inputFile - if uploadId != "" && uploadId != "unique()" { + if uploadId != "" { headers["x-appwrite-id"] = uploadId } totalSize := fileInfo.Size() diff --git a/templates/kotlin/src/main/kotlin/io/appwrite/Client.kt.twig b/templates/kotlin/src/main/kotlin/io/appwrite/Client.kt.twig index 2eceab281..afd9916ff 100644 --- a/templates/kotlin/src/main/kotlin/io/appwrite/Client.kt.twig +++ b/templates/kotlin/src/main/kotlin/io/appwrite/Client.kt.twig @@ -191,7 +191,7 @@ class Client @JvmOverloads constructor( /** * Prepare the HTTP request - * + * * @param method * @param path * @param headers @@ -286,7 +286,7 @@ class Client @JvmOverloads constructor( * @param headers * @param params * - * @return [T] + * @return [T] */ @Throws({{ spec.title | caseUcfirst }}Exception::class) suspend fun call( @@ -309,7 +309,7 @@ class Client @JvmOverloads constructor( * @param headers * @param params * - * @return [T] + * @return [T] */ @Throws({{ spec.title | caseUcfirst }}Exception::class) suspend fun redirect( @@ -381,7 +381,7 @@ class Client @JvmOverloads constructor( var offset = 0L var result: Map<*, *>? = null - if (idParamName?.isNotEmpty() == true && params[idParamName] != "unique()") { + if (idParamName?.isNotEmpty() == true) { // Make a request to check if a file already exists val current = call( method = "GET", @@ -448,7 +448,7 @@ class Client @JvmOverloads constructor( return converter(result as Map) } - /** + /** * Await Redirect * * @param request @@ -475,14 +475,14 @@ class Client @JvmOverloads constructor( .charStream() .buffered() .use(BufferedReader::readText) - + val error = if (response.headers["content-type"]?.contains("application/json") == true) { val map = body.fromJson>() {{ spec.title | caseUcfirst }}Exception( - map["message"] as? String ?: "", + map["message"] as? String ?: "", (map["code"] as Number).toInt(), - map["type"] as? String ?: "", + map["type"] as? String ?: "", body ) } else { @@ -526,14 +526,14 @@ class Client @JvmOverloads constructor( .charStream() .buffered() .use(BufferedReader::readText) - + val error = if (response.headers["content-type"]?.contains("application/json") == true) { val map = body.fromJson>() {{ spec.title | caseUcfirst }}Exception( - map["message"] as? String ?: "", + map["message"] as? String ?: "", (map["code"] as Number).toInt(), - map["type"] as? String ?: "", + map["type"] as? String ?: "", body ) } else { @@ -591,4 +591,4 @@ class Client @JvmOverloads constructor( } }) } -} \ No newline at end of file +} diff --git a/templates/php/base/requests/file.twig b/templates/php/base/requests/file.twig index e80c793da..e67dd01fa 100644 --- a/templates/php/base/requests/file.twig +++ b/templates/php/base/requests/file.twig @@ -41,12 +41,10 @@ {% for parameter in method.parameters.all %} {% if parameter.isUploadID %} - if(${{ parameter.name | caseCamel | escapeKeyword }} != 'unique()') { - try { - $response = $this->client->call(Client::METHOD_GET, $apiPath . '/' . ${{ parameter.name }}); - $counter = $response['chunksUploaded'] ?? 0; - } catch(\Exception $e) { - } + try { + $response = $this->client->call(Client::METHOD_GET, $apiPath . '/' . ${{ parameter.name }}); + $counter = $response['chunksUploaded'] ?? 0; + } catch(\Exception $e) { } {% endif %} {% endfor %} @@ -84,7 +82,7 @@ 'progress' => min(((($counter * Client::CHUNK_SIZE) + Client::CHUNK_SIZE)), $size) / $size * 100, 'sizeUploaded' => min($counter * Client::CHUNK_SIZE), 'chunksTotal' => $response['chunksTotal'], - 'chunksUploaded' => $response['chunksUploaded'], + 'chunksUploaded' => $response['chunksUploaded'], ]); } } @@ -93,4 +91,4 @@ } return $response; {% endif %} -{% endfor %} \ No newline at end of file +{% endfor %} diff --git a/templates/python/package/client.py.twig b/templates/python/package/client.py.twig index c7a3d4feb..99eafbe19 100644 --- a/templates/python/package/client.py.twig +++ b/templates/python/package/client.py.twig @@ -57,7 +57,7 @@ class Client: data = {} files = {} stringify = False - + headers = {**self._global_headers, **headers} if method != 'get': @@ -148,12 +148,11 @@ class Client: offset = 0 counter = 0 - if upload_id != 'unique()': - try: - result = self.call('get', path + '/' + upload_id, headers) - counter = result['chunksUploaded'] - except: - pass + try: + result = self.call('get', path + '/' + upload_id, headers) + counter = result['chunksUploaded'] + except: + pass if counter > 0: offset = counter * self._chunk_size @@ -178,10 +177,10 @@ class Client: headers, params, ) - + offset = offset + self._chunk_size - - if "$id" in result: + + if "$id" in result: headers["x-{{ spec.title | caseLower }}-id"] = result["$id"] if on_progress is not None: @@ -207,7 +206,7 @@ class Client: finalKey = prefix + '[' + key +']' if prefix else key finalKey = prefix + '[' + str(i) +']' if isinstance(data, list) else finalKey i += 1 - + if isinstance(value, list) or isinstance(value, dict): output = {**output, **self.flatten(value, finalKey, stringify)} else: @@ -217,4 +216,3 @@ class Client: output[finalKey] = value return output - diff --git a/templates/react-native/src/services/template.ts.twig b/templates/react-native/src/services/template.ts.twig index 347ecfb73..c816df6dd 100644 --- a/templates/react-native/src/services/template.ts.twig +++ b/templates/react-native/src/services/template.ts.twig @@ -118,12 +118,10 @@ export class {{ service.name | caseUcfirst }} extends Service { let response = undefined; {% for parameter in method.parameters.all %} {% if parameter.isUploadID %} - if({{ parameter.name | caseCamel | escapeKeyword }} != 'unique()') { - try { - response = await this.client.call('GET', new URL(this.client.config.endpoint + apiPath + '/' + {{ parameter.name }}), apiHeaders); - offset = response.chunksUploaded * Service.CHUNK_SIZE; - } catch(e) { - } + try { + response = await this.client.call('GET', new URL(this.client.config.endpoint + apiPath + '/' + {{ parameter.name }}), apiHeaders); + offset = response.chunksUploaded * Service.CHUNK_SIZE; + } catch(e) { } {% endif %} {% endfor %} diff --git a/templates/ruby/lib/container/client.rb.twig b/templates/ruby/lib/container/client.rb.twig index 0eb2f86fb..9e5bb98a5 100644 --- a/templates/ruby/lib/container/client.rb.twig +++ b/templates/ruby/lib/container/client.rb.twig @@ -16,7 +16,7 @@ module {{ spec.title | caseUcfirst }} 'x-sdk-platform'=> '{{ sdk.platform }}', 'x-sdk-language'=> '{{ language.name | caseLower }}', 'x-sdk-version'=> '{{ sdk.version }}'{% if spec.global.defaultHeaders | length > 0 %},{% endif %} - + {% for key,header in spec.global.defaultHeaders %} '{{key}}' => '{{header}}'{% if not loop.last %},{% endif %} {% endfor %} @@ -49,7 +49,7 @@ module {{ spec.title | caseUcfirst }} # @return [self] def set_endpoint(endpoint) @endpoint = endpoint - + self end @@ -132,7 +132,7 @@ module {{ spec.title | caseUcfirst }} offset = 0 id_param_name = id_param_name.to_sym if id_param_name - if id_param_name&.empty? == false && params[id_param_name] != "unique()" + if id_param_name&.empty? == false # Make a request to check if a file already exists current = call( method: "GET", @@ -202,7 +202,7 @@ module {{ spec.title | caseUcfirst }} @http = Net::HTTP.new(uri.host, uri.port) unless defined? @http @http.use_ssl = !@self_signed payload = '' - + headers = @headers.merge(headers) params.compact! @@ -237,7 +237,7 @@ module {{ spec.title | caseUcfirst }} if response_type == "location" return location end - + # Handle Redirects if (response.class == Net::HTTPRedirection || response.class == Net::HTTPMovedPermanently) uri = URI.parse(uri.scheme + "://" + uri.host + "" + location) @@ -272,7 +272,7 @@ module {{ spec.title | caseUcfirst }} return response end - + def encode_form_data(value, key=nil) case value when Hash @@ -304,13 +304,13 @@ module {{ spec.title | caseUcfirst }} when Hash then value.map { |k,v| encode(v, append_key(key,k)) }.join('&') when Array then value.map { |v| encode(v, "#{key}[]") }.join('&') when nil then '' - else - "#{key}=#{CGI.escape(value.to_s)}" + else + "#{key}=#{CGI.escape(value.to_s)}" end end def append_key(root_key, key) root_key.nil? ? key : "#{root_key}[#{key.to_s}]" end - end + end end diff --git a/templates/swift/Sources/Client.swift.twig b/templates/swift/Sources/Client.swift.twig index 3e1c63d56..011d5545d 100644 --- a/templates/swift/Sources/Client.swift.twig +++ b/templates/swift/Sources/Client.swift.twig @@ -423,7 +423,7 @@ open class Client { var offset = 0 var result = [String:Any]() - if idParamName != nil && params[idParamName!] as! String != "unique()" { + if idParamName != nil { // Make a request to check if a file already exists do { let map = try await call(