Skip to content

Commit 79aae36

Browse files
committed
Fix bugs
1 parent 09216b7 commit 79aae36

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

templates/deno/src/client.ts.twig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ export class Client {
7878
const formData = new FormData();
7979
const flatParams = this.flatten(params);
8080
for (const key in flatParams) {
81-
formData.append(key, flatParams[key]);
81+
const value = flatParams[key];
82+
83+
if(value && value.type && value.type === 'file') {
84+
formData.append(key, value.file, value.filename);
85+
} else {
86+
formData.append(key, flatParams[key]);
87+
}
8288
}
8389
body = formData;
8490
} else {

templates/deno/src/services/service.ts.twig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,12 @@ export class {{ service.name | caseUcfirst }} extends Service {
128128
headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
129129
}
130130

131-
console.log(headers['content-range']);
132-
133131
let uploadableChunkTrimmed: Uint8Array;
134132

135-
if(currentPosition >= Client.CHUNK_SIZE) {
133+
if(currentPosition + 1 >= Client.CHUNK_SIZE) {
136134
uploadableChunkTrimmed = uploadableChunk;
137135
} else {
138-
uploadableChunkTrimmed = new Uint8Array(currentPosition);
136+
uploadableChunkTrimmed = new Uint8Array(currentPosition + 1);
139137
for(let i = 0; i <= currentPosition; i++) {
140138
uploadableChunkTrimmed[i] = uploadableChunk[i];
141139
}
@@ -145,7 +143,7 @@ export class {{ service.name | caseUcfirst }} extends Service {
145143
headers['x-{{spec.title | caseLower }}-id'] = id;
146144
}
147145

148-
payload['{{ parameter.name }}'] = new File([uploadableChunkTrimmed], {{ parameter.name | caseCamel | escapeKeyword }}.name);
146+
payload['{{ parameter.name }}'] = { type: 'file', file: new File([uploadableChunkTrimmed], {{ parameter.name | caseCamel | escapeKeyword }}.name), filename: {{ parameter.name | caseCamel | escapeKeyword }}.name };
149147

150148
response = await this.client.call('{{ method.method | caseLower }}', path, headers, payload{% if method.type == 'location' %}, 'arraybuffer'{% endif %});
151149

@@ -172,12 +170,14 @@ export class {{ service.name | caseUcfirst }} extends Service {
172170
let i = 0;
173171
for(const b of chunk) {
174172
uploadableChunk[currentPosition] = chunk[i];
175-
i++;
176-
currentPosition++;
177173

178-
if(currentPosition >= Client.CHUNK_SIZE) {
174+
if(currentPosition + 1 >= Client.CHUNK_SIZE) {
179175
await uploadChunk();
176+
currentPosition--;
180177
}
178+
179+
i++;
180+
currentPosition++;
181181
}
182182
}
183183

0 commit comments

Comments
 (0)