diff options
author | 2017-12-27 13:09:17 +0100 | |
---|---|---|
committer | 2017-12-27 13:09:17 +0100 | |
commit | 150cfe764aeb9e93341ba2f231fd121fe85472af (patch) | |
tree | bc398a878ec736f666502af983160aa7829a7a3d /src/api | |
parent | Merge branch 'develop' into feature/icon-upload (diff) | |
download | ferdium-app-150cfe764aeb9e93341ba2f231fd121fe85472af.tar.gz ferdium-app-150cfe764aeb9e93341ba2f231fd121fe85472af.tar.zst ferdium-app-150cfe764aeb9e93341ba2f231fd121fe85472af.zip |
First working draft of icon upload
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/server/ServerApi.js | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/api/server/ServerApi.js b/src/api/server/ServerApi.js index 8b3136d27..6b96f709e 100644 --- a/src/api/server/ServerApi.js +++ b/src/api/server/ServerApi.js | |||
@@ -167,27 +167,65 @@ export default class ServerApi { | |||
167 | throw request; | 167 | throw request; |
168 | } | 168 | } |
169 | const serviceData = await request.json(); | 169 | const serviceData = await request.json(); |
170 | |||
171 | if (data.iconFile) { | ||
172 | const iconUrl = await this.uploadServiceIcon(serviceData.data.id, data.iconFile); | ||
173 | |||
174 | serviceData.data.iconUrl = iconUrl; | ||
175 | } | ||
176 | |||
170 | const service = Object.assign(serviceData, { data: await this._prepareServiceModel(serviceData.data) }); | 177 | const service = Object.assign(serviceData, { data: await this._prepareServiceModel(serviceData.data) }); |
171 | 178 | ||
172 | console.debug('ServerApi::createService resolves', service); | 179 | console.debug('ServerApi::createService resolves', service); |
173 | return service; | 180 | return service; |
174 | } | 181 | } |
175 | 182 | ||
176 | async updateService(recipeId, data) { | 183 | async updateService(serviceId, rawData) { |
177 | const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/service/${recipeId}`, this._prepareAuthRequest({ | 184 | const data = rawData; |
185 | |||
186 | if (data.iconFile) { | ||
187 | await this.uploadServiceIcon(serviceId, data.iconFile); | ||
188 | } | ||
189 | |||
190 | const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/service/${serviceId}`, this._prepareAuthRequest({ | ||
178 | method: 'PUT', | 191 | method: 'PUT', |
179 | body: JSON.stringify(data), | 192 | body: JSON.stringify(data), |
180 | })); | 193 | })); |
194 | |||
181 | if (!request.ok) { | 195 | if (!request.ok) { |
182 | throw request; | 196 | throw request; |
183 | } | 197 | } |
198 | |||
184 | const serviceData = await request.json(); | 199 | const serviceData = await request.json(); |
200 | |||
185 | const service = Object.assign(serviceData, { data: await this._prepareServiceModel(serviceData.data) }); | 201 | const service = Object.assign(serviceData, { data: await this._prepareServiceModel(serviceData.data) }); |
186 | 202 | ||
187 | console.debug('ServerApi::updateService resolves', service); | 203 | console.debug('ServerApi::updateService resolves', service); |
188 | return service; | 204 | return service; |
189 | } | 205 | } |
190 | 206 | ||
207 | async uploadServiceIcon(serviceId, icon) { | ||
208 | const formData = new FormData(); | ||
209 | formData.append('icon', icon); | ||
210 | |||
211 | const requestData = this._prepareAuthRequest({ | ||
212 | method: 'PUT', | ||
213 | body: formData, | ||
214 | }); | ||
215 | |||
216 | delete requestData.headers['Content-Type']; | ||
217 | |||
218 | const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/service/${serviceId}`, requestData); | ||
219 | |||
220 | if (!request.ok) { | ||
221 | throw request; | ||
222 | } | ||
223 | |||
224 | const serviceData = await request.json(); | ||
225 | |||
226 | return serviceData.data.iconUrl; | ||
227 | } | ||
228 | |||
191 | async reorderService(data) { | 229 | async reorderService(data) { |
192 | const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/service/reorder`, this._prepareAuthRequest({ | 230 | const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/service/reorder`, this._prepareAuthRequest({ |
193 | method: 'PUT', | 231 | method: 'PUT', |