Skip to content

Commit 8b68b84

Browse files
Merge pull request #378 from appwrite/feat-php-resumable-support
2 parents abae690 + 743cc33 commit 8b68b84

File tree

17 files changed

+77
-50
lines changed

17 files changed

+77
-50
lines changed

src/SDK/Language/Dart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public function getParamExample(array $param)
217217
if(empty($example) && $example !== 0 && $example !== false) {
218218
switch ($type) {
219219
case self::TYPE_FILE:
220-
$output .= 'await MultipartFile.fromPath(\''.$param['name'].'\', \'./path-to-files/image.jpg\', \'image.jpg\')';
220+
$output .= 'InputFile(path: \'./path-to-files/image.jpg\', filename: \'image.jpg\')';
221221
break;
222222
case self::TYPE_NUMBER:
223223
case self::TYPE_INTEGER:

src/SDK/SDK.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ public function generate($target)
605605
foreach ($this->spec->getServices() as $key => $service) {
606606
$methods = $this->spec->getMethods($key);
607607
$params['service'] = [
608+
'description' => $service['description'] ?? '',
608609
'name' => $key,
609610
'features' => [
610611
'upload' => $this->hasUploads($methods),

templates/dart/lib/services/service.dart.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ part of {{ language.params.packageName }};
66
{% endmacro %}
77
{% macro map_parameter(parameter) %}'{{ parameter.name }}': {{ parameter.name | caseCamel | escapeKeyword }},{% endmacro %}
88

9+
{%if service.description %}
10+
{{ service.description|dartComment}}
11+
{% endif %}
912
class {{ service.name | caseUcfirst }} extends Service {
1013
{{ service.name | caseUcfirst }}(Client client): super(client);
1114
{% for method in service.methods %}

templates/dart/lib/src/chunked_upload_io.dart.twig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Future<Response> chunkedUpload({
2626

2727
late Response res;
2828
if (size <= Client.CHUNK_SIZE) {
29-
params[paramName] = await http.MultipartFile.fromPath(paramName, file.path!, filename: file.fileName);
29+
params[paramName] = await http.MultipartFile.fromPath(paramName, file.path!, filename: file.filename);
3030
return client.call(
3131
HttpMethod.post,
3232
path: path,
@@ -55,7 +55,7 @@ Future<Response> chunkedUpload({
5555
raf.setPositionSync(offset);
5656
final chunk = raf.readSync(Client.CHUNK_SIZE);
5757
params[paramName] =
58-
http.MultipartFile.fromBytes(paramName, chunk, filename: file.fileName);
58+
http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename);
5959
headers['content-range'] =
6060
'bytes $offset-${min<int>(((offset + Client.CHUNK_SIZE) - 1), size)}/$size';
6161
res = await client.call(HttpMethod.post,
@@ -66,8 +66,8 @@ Future<Response> chunkedUpload({
6666
}
6767
final progress = UploadProgress(
6868
$id: res.data['\$id'] ?? '',
69-
progress: min(offset,size)/size * 100,
70-
sizeUploaded: min(offset,size),
69+
progress: min(offset-1,size)/size * 100,
70+
sizeUploaded: min(offset-1,size),
7171
chunksTotal: res.data['chunksTotal'] ?? 0,
7272
chunksUploaded: res.data['chunksUploaded'] ?? 0,
7373
);

templates/dart/lib/src/input_file.dart.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:http/http.dart' show MultipartFile;
33
class InputFile {
44
final MultipartFile? file;
55
final String? path;
6-
final String? fileName;
6+
final String? filename;
77

8-
InputFile({this.file, this.path, this.fileName});
8+
InputFile({this.file, this.path, this.filename});
99
}

templates/dart/lib/src/models/model.dart.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class {{ definition.name | caseUcfirst | overrideIdentifier }} {
2323
factory {{ definition.name | caseUcfirst | overrideIdentifier}}.fromMap(Map<String, dynamic> map) {
2424
return {{ definition.name | caseUcfirst | overrideIdentifier }}(
2525
{% for property in definition.properties %}
26-
{{ property.name | escapeKeyword }}: {% if property.sub_schema %}{% if property.type == 'array' %}List<{{property.sub_schema | caseUcfirst | overrideIdentifier}}>.from(map['{{property.name | escapeDollarSign }}'].map((p) => {{property.sub_schema | caseUcfirst | overrideIdentifier}}.fromMap(p))){% else %}{{property.sub_schema | caseUcfirst | overrideIdentifier}}.fromMap(map['{{property.name | escapeDollarSign }}']){% endif %}{% else %}map['{{property.name | escapeDollarSign }}']{% if property.type == "number" %}.toDouble(){% endif %}{% if property.type == "string" %}.toString(){% endif %}{% endif %},
26+
{{ property.name | escapeKeyword }}: {% if property.sub_schema %}{% if property.type == 'array' %}List<{{property.sub_schema | caseUcfirst | overrideIdentifier}}>.from(map['{{property.name | escapeDollarSign }}'].map((p) => {{property.sub_schema | caseUcfirst | overrideIdentifier}}.fromMap(p))){% else %}{{property.sub_schema | caseUcfirst | overrideIdentifier}}.fromMap(map['{{property.name | escapeDollarSign }}']){% endif %}{% else %}map['{{property.name | escapeDollarSign }}']{% if property.type == "number" %}{% if not property.required %}?{% endif %}.toDouble(){% endif %}{% if property.type == "string" %}{% if not property.required %}?{% endif %}.toString(){% endif %}{% endif %},
2727
{% endfor %}
2828
{% if definition.additionalProperties %}
2929
data: map,

templates/flutter/lib/package.dart.twig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ library {{ language.params.packageName }};
22

33
import 'dart:async';
44
import 'dart:typed_data';
5-
import 'package:http/http.dart' as http;
65
import 'package:flutter/foundation.dart';
76
import 'src/chunked_upload_stub.dart'
87
if (dart.library.io) 'src/chunked_upload_io.dart';

templates/flutter/lib/services/service.dart.twig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ part of {{ language.params.packageName }};
55
{% if parameters.all|length > 0 %}{{ '{' }}{% for parameter in parameters.all %}{{ _self.parameter(parameter) }}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in consumes %}, Function(UploadProgress)? onProgress{% endif %}{{ '}' }}{% endif %}
66
{% endmacro %}
77
{% macro map_parameter(parameter) %}'{{ parameter.name }}': {{ parameter.name | caseCamel | escapeKeyword }},{% endmacro %}
8+
9+
{%if service.description %}
10+
{{ service.description|dartComment}}
11+
{% endif %}
812
class {{ service.name | caseUcfirst }} extends Service {
913
{{ service.name | caseUcfirst }}(Client client): super(client);
1014
{% for method in service.methods %}

templates/flutter/lib/src/chunked_upload_io.dart.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Future<Response> chunkedUpload({
2626

2727
late Response res;
2828
if (size <= Client.CHUNK_SIZE) {
29-
params[paramName] = await http.MultipartFile.fromPath(paramName, file.path!, filename: file.fileName);
29+
params[paramName] = await http.MultipartFile.fromPath(paramName, file.path!, filename: file.filename);
3030
return client.call(
3131
HttpMethod.post,
3232
path: path,
@@ -55,7 +55,7 @@ Future<Response> chunkedUpload({
5555
raf.setPositionSync(offset);
5656
final chunk = raf.readSync(Client.CHUNK_SIZE);
5757
params[paramName] =
58-
http.MultipartFile.fromBytes(paramName, chunk, filename: file.fileName);
58+
http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename);
5959
headers['content-range'] =
6060
'bytes $offset-${min<int>(((offset + Client.CHUNK_SIZE) - 1), size)}/$size';
6161
res = await client.call(HttpMethod.post,

templates/flutter/lib/src/chunked_upload_stub.dart.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Future<Response> chunkedUpload({
77
required String path,
88
required Map<String, dynamic> params,
99
required String paramName,
10+
required String idParamName,
1011
required Map<String, String> headers,
1112
Function(UploadProgress)? onProgress,
1213
}) =>

0 commit comments

Comments
 (0)