1
- import { Service } from '../service';
2
1
import { {{ spec .title | caseUcfirst }}Exception, Client, type Payload, UploadProgress } from '../client';
3
2
import type { Models } from '../models';
4
3
{% set added = [] %}
@@ -60,49 +59,6 @@ export class {{ service.name | caseUcfirst }} {
60
59
}
61
60
{%~ endfor %}
62
61
const uri = new URL(this.client.config.endpoint + apiPath);
63
- {%~ if method .type == ' location' or method .type == ' webAuth' %}
64
- {%~ if method .auth | length > 0 %}
65
- {%~ for node in method .auth %}
66
- {%~ for key ,header in node | keys %}
67
- payload['{{header | caseLower}}'] = this.client.config.{{header | caseLower}};
68
-
69
- {%~ endfor %}
70
- {%~ endfor %}
71
- {%~ endif %}
72
-
73
- for (const [key, value] of Object.entries(Service.flatten(payload))) {
74
- uri.searchParams.append(key, value);
75
- }
76
- {%~ endif %}
77
- {%~ if method .type == ' webAuth' %}
78
- if (typeof window !== 'undefined' && window?.location) {
79
- window.location.href = uri.toString();
80
- } else {
81
- return uri;
82
- }
83
- {%~ elseif method .type == ' location' %}
84
- return uri;
85
- {%~ else %}
86
- {%~ if ' multipart/form-data' in method .consumes %}
87
- {%~ for parameter in method .parameters .all %}
88
- {%~ if parameter .type == ' file' %}
89
-
90
- if(!({{ parameter .name | caseCamel | escapeKeyword }} instanceof File)) {
91
- throw new {{spec .title | caseUcfirst }}Exception('Parameter "{{ parameter .name | caseCamel | escapeKeyword }}" has to be a File.');
92
- }
93
-
94
- const size = {{ parameter .name | caseCamel | escapeKeyword }}.size;
95
-
96
- if (size < = Service.CHUNK_SIZE) {
97
- return await this.client.call('{{ method .method | caseLower }}', uri, {
98
- {% for parameter in method .parameters .header %}
99
- '{{ parameter .name | caseCamel | escapeKeyword }}': this.client.${{ parameter .name | caseCamel | escapeKeyword }},
100
- {%~ endfor %}
101
- {%~ for key , header in method .headers %}
102
- '{{ key }}': '{{ header }}',
103
- {%~ endfor %}
104
- }, payload);
105
- }
106
62
107
63
const apiHeaders: { [header: string]: string } = {
108
64
{%~ for parameter in method .parameters .header %}
@@ -114,12 +70,29 @@ export class {{ service.name | caseUcfirst }} {
114
70
}
115
71
116
72
{%~ if method .type == ' webAuth' %}
117
- return await this.client.redirect(
73
+ const location = await this.client.redirect(
118
74
'{{ method .method | caseLower }}',
119
75
uri,
120
76
apiHeaders,
121
77
payload
122
78
);
79
+ if (typeof window !== 'undefined') {
80
+ window.location.href = location;
81
+ } else {
82
+ return location;
83
+ }
84
+ {%~ elseif method .type == ' location' %}
85
+ {%~ for node in method .auth %}
86
+ {%~ for key , header in node | keys %}
87
+ payload['{{ header | caseLower }}'] = this.client.config.{{ header | caseLower }};
88
+ {%~ endfor %}
89
+ {%~ endfor %}
90
+
91
+ for (const [key, value] of Object.entries(Client.flatten(payload))) {
92
+ uri.searchParams.append(key, value);
93
+ }
94
+
95
+ return uri.toString();
123
96
{%~ elseif ' multipart/form-data' in method .consumes %}
124
97
return await this.client.chunkedUpload(
125
98
'{{ method .method | caseLower }}',
@@ -130,9 +103,9 @@ export class {{ service.name | caseUcfirst }} {
130
103
);
131
104
{%~ else %}
132
105
return await this.client.call(
133
- '{{ method .method | caseLower }}',
106
+ '{{ method .method | caseLower }}',
134
107
uri,
135
- apiHeaders,
108
+ apiHeaders,
136
109
payload
137
110
);
138
111
{%~ endif %}
0 commit comments