Skip to content

Commit

Permalink
Updated onProgress in deno,cli,node,php,python
Browse files Browse the repository at this point in the history
  • Loading branch information
Meldiron committed Feb 28, 2022
1 parent b2f3f02 commit 92e68b1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
8 changes: 7 additions & 1 deletion templates/cli/lib/commands/command.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,13 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {
}

if (onProgress !== null) {
onProgress(Math.min((counter+1) * libClient.CHUNK_SIZE, size) / size * 100);
onProgress({
$id: response['$id'],
progress: Math.min((counter+1) * libClient.CHUNK_SIZE, size) / size * 100,
sizeUploaded: end+1,
chunksTotal: response['chunksTotal'],
chunksUploaded: response['chunksUploaded']
});
}
}
}
Expand Down
20 changes: 17 additions & 3 deletions templates/deno/src/services/service.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ import { basename } from "https://deno.land/std@0.122.0/path/mod.ts";
import { Service } from '../service.ts';
import { Payload, Client } from '../client.ts';
import { AppwriteException } from '../exception.ts';
import type { Models } from '../models.d.ts'
import type { Models } from '../models.d.ts';

export type UploadProgress = {
$id: string;
progress: number;
sizeUploaded: number;
chunksTotal: number;
chunksUploaded: number;
}

export class {{ service.name | caseUcfirst }} extends Service {
{% for method in service.methods %}
Expand All @@ -48,7 +56,7 @@ export class {{ service.name | caseUcfirst }} extends Service {
* @throws {AppwriteException}
* @returns {Promise}
*/
async {{ method.name | caseCamel }}{% if generics %}<{{generics}}>{% endif %}({% for parameter in method.parameters.all %}{{ parameter.name | caseCamel | escapeKeyword }}{% if not parameter.required %}?{% endif %}: {{ parameter.type | typeName }}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, onProgress = (progress: number) => {}{% endif %}): Promise<{% if method.type == 'webAuth' %}Response{% elseif method.type == 'location' %}Response{% else %}{% if method.responseModel and method.responseModel != 'any' %}{% if not spec.definitions[method.responseModel].additionalProperties %}Models.{% endif %}{{method.responseModel | caseUcfirst}}{% if generics_return %}<{{generics_return}}>{% endif %}{% else %}Response{% endif %}{% endif %}> {
async {{ method.name | caseCamel }}{% if generics %}<{{generics}}>{% endif %}({% for parameter in method.parameters.all %}{{ parameter.name | caseCamel | escapeKeyword }}{% if not parameter.required %}?{% endif %}: {{ parameter.type | typeName }}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, onProgress = (progress: UploadProgress) => {}{% endif %}): Promise<{% if method.type == 'webAuth' %}Response{% elseif method.type == 'location' %}Response{% else %}{% if method.responseModel and method.responseModel != 'any' %}{% if not spec.definitions[method.responseModel].additionalProperties %}Models.{% endif %}{{method.responseModel | caseUcfirst}}{% if generics_return %}<{{generics_return}}>{% endif %}{% else %}Response{% endif %}{% endif %}> {
{% for parameter in method.parameters.all %}
{% if parameter.required %}
if (typeof {{ parameter.name | caseCamel | escapeKeyword }} === 'undefined') {
Expand Down Expand Up @@ -137,7 +145,13 @@ export class {{ service.name | caseUcfirst }} extends Service {
}

if (onProgress !== null) {
onProgress(Math.min((counter+1) * Client.CHUNK_SIZE, size) / size * 100);
onProgress({
$id: response['$id'],
progress: Math.min((counter+1) * Client.CHUNK_SIZE, size) / size * 100,
sizeUploaded: end+1,
chunksTotal: response['chunksTotal'],
chunksUploaded: response['chunksUploaded']
});
}
}

Expand Down
8 changes: 7 additions & 1 deletion templates/node/lib/services/service.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ class {{ service.name | caseUcfirst }} extends Service {
}

if (onProgress !== null) {
onProgress(Math.min((counter+1) * client.CHUNK_SIZE, size) / size * 100);
onProgress({
$id: response['$id'],
progress: Math.min((counter+1) * client.CHUNK_SIZE, size) / size * 100,
sizeUploaded: end+1,
chunksTotal: response['chunksTotal'],
chunksUploaded: response['chunksUploaded']
});
}
}

Expand Down
8 changes: 7 additions & 1 deletion templates/php/src/Services/Service.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ class {{ service.name | caseUcfirst }} extends Service
$id = $response['$id'];
}
if($onProgress !== null) {
$onProgress(min(($counter+1) * Client.CHUNK_SIZE, $size) / $size * 100);
$onProgress([
'$id' => $response['$id'],
'progress' => min(($counter+1) * Client.CHUNK_SIZE, $size) / $size * 100,
'sizeUploaded' => $end + 1,
'chunksTotal' => $response['chunksTotal'],
'chunksUploaded' => $response['chunksUploaded']
]);
}
}
@fclose($handle);
Expand Down
8 changes: 7 additions & 1 deletion templates/python/package/client.py.twig
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ class Client:
headers["x-{{ spec.title | caseLower }}-id"] = result["$id"]

if on_progress is not None:
on_progress(min(offset, size)/size * 100)
on_progress({
"$id": result["$id"],
"progress": min(offset, size)/size * 100,
"sizeUploaded": end+1,
"chunksTotal": result["chunksTotal"],
"chunksUploaded": result["chunksUploaded"],
})

return result

Expand Down

0 comments on commit 92e68b1

Please sign in to comment.