@@ -101,58 +101,73 @@ export class {{ service.name | caseUcfirst }} extends Service {
101
101
let id = undefined;
102
102
let response = undefined;
103
103
104
+ let counter = 0;
104
105
const totalCounters = Math.ceil(size / Client.CHUNK_SIZE);
105
106
106
- for (let counter = 0; counter < totalCounters; counter++) {
107
- const start = (counter * Client.CHUNK_SIZE);
108
- const end = Math.min((((counter * Client.CHUNK_SIZE) + Client.CHUNK_SIZE) - 1), size);
109
- const headers: { [header: string]: string } = {
107
+ const headers: { [header: string]: string } = {
110
108
{% for parameter in method .parameters .header %}
111
- '{{ parameter .name }}': ${{ parameter .name | caseCamel | escapeKeyword }},
109
+ '{{ parameter .name }}': ${{ parameter .name | caseCamel | escapeKeyword }},
112
110
{% endfor %}
113
111
{% for key , header in method .headers %}
114
- '{{ key }}': '{{ header }}',
112
+ '{{ key }}': '{{ header }}',
115
113
{% endfor %}
116
- 'content-range': 'bytes ' + start + '-' + end + '/' + size
117
- };
114
+ };
118
115
119
- if (id) {
120
- headers['x-{{spec .title | caseLower }}-id'] = id;
121
- }
122
-
123
- const totalBuffer = new Uint8Array(Client.CHUNK_SIZE);
124
-
125
- for (let blockIndex = 0; blockIndex < Client.CHUNK_SIZE / Client.DENO_READ_CHUNK_SIZE; blockIndex++) {
126
- const buf = new Uint8Array(Client.DENO_READ_CHUNK_SIZE);
127
- const cursorPosition = await Deno.seek(stream.rid, start + (blockIndex * 16384), Deno.SeekMode.Start);
128
- const numberOfBytesRead = await Deno.read(stream.rid, buf);
129
-
130
- if (!numberOfBytesRead) {
131
- break;
132
- }
133
-
134
- for (let byteIndex = 0; byteIndex < Client.DENO_READ_CHUNK_SIZE; byteIndex++) {
135
- totalBuffer[(blockIndex * Client.DENO_READ_CHUNK_SIZE) + byteIndex] = buf[byteIndex];
136
- }
137
- }
138
-
139
- payload['{{ parameter .name }}'] = new File([totalBuffer], basename({{ parameter .name | caseCamel | escapeKeyword }}));
140
-
141
- response = await this.client.call('{{ method .method | caseLower }}', path, headers, payload{% if method .type == ' location' %}, 'arraybuffer'{% endif %});
116
+ {% for parameter in method .parameters .all %}
117
+ {% if parameter .isUploadID %}
118
+ if({{ parameter .name | caseCamel | escapeKeyword }} != 'unique()') {
119
+ try {
120
+ response = await this.client.call('get', path + '/' + {{ parameter .name }}, headers);
121
+ counter = response.chunksUploaded;
122
+ } catch(e) {
123
+ }
124
+ }
125
+ {% endif %}
126
+ {% endfor %}
142
127
143
- if (!id) {
144
- id = response['$id'];
128
+ for (counter; counter < totalCounters; counter++) {
129
+ const start = (counter * Client.CHUNK_SIZE);
130
+ const end = Math.min((((counter * Client.CHUNK_SIZE) + Client.CHUNK_SIZE) - 1), size);
131
+
132
+ headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size
133
+
134
+ if (id) {
135
+ headers['x-{{spec .title | caseLower }}-id'] = id;
136
+ }
137
+
138
+ const totalBuffer = new Uint8Array(Client.CHUNK_SIZE);
139
+
140
+ for (let blockIndex = 0; blockIndex < Client.CHUNK_SIZE / Client.DENO_READ_CHUNK_SIZE; blockIndex++) {
141
+ const buf = new Uint8Array(Client.DENO_READ_CHUNK_SIZE);
142
+ const cursorPosition = await Deno.seek(stream.rid, start + (blockIndex * 16384), Deno.SeekMode.Start);
143
+ const numberOfBytesRead = await Deno.read(stream.rid, buf);
144
+
145
+ if (!numberOfBytesRead) {
146
+ break;
145
147
}
146
148
147
- if (onProgress !== null) {
148
- onProgress({
149
- $id: response['$id'],
150
- progress: Math.min((counter+1) * Client.CHUNK_SIZE, size) / size * 100,
151
- sizeUploaded: end+1,
152
- chunksTotal: response['chunksTotal'],
153
- chunksUploaded: response['chunksUploaded']
154
- });
149
+ for (let byteIndex = 0; byteIndex < Client.DENO_READ_CHUNK_SIZE; byteIndex++) {
150
+ totalBuffer[(blockIndex * Client.DENO_READ_CHUNK_SIZE) + byteIndex] = buf[byteIndex];
155
151
}
152
+ }
153
+
154
+ payload['{{ parameter .name }}'] = new File([totalBuffer], basename({{ parameter .name | caseCamel | escapeKeyword }}));
155
+
156
+ response = await this.client.call('{{ method .method | caseLower }}', path, headers, payload{% if method .type == ' location' %}, 'arraybuffer'{% endif %});
157
+
158
+ if (!id) {
159
+ id = response['$id'];
160
+ }
161
+
162
+ if (onProgress !== null) {
163
+ onProgress({
164
+ $id: response['$id'],
165
+ progress: Math.min((counter+1) * Client.CHUNK_SIZE, size) / size * 100,
166
+ sizeUploaded: end+1,
167
+ chunksTotal: response['chunksTotal'],
168
+ chunksUploaded: response['chunksUploaded']
169
+ });
170
+ }
156
171
}
157
172
158
173
return response;
0 commit comments