diff options
author | 2018-01-06 23:51:04 +0100 | |
---|---|---|
committer | 2018-01-06 23:51:04 +0100 | |
commit | fb16f121e8ff6678c74148cd456b964a85742fbe (patch) | |
tree | 5534162572aca6bda4d22984ab6103c76510d193 /src/api | |
parent | Merge pull request #541 from meetfranz/feature/external-links (diff) | |
parent | fix displaying old icon while uploading new icon (diff) | |
download | ferdium-app-fb16f121e8ff6678c74148cd456b964a85742fbe.tar.gz ferdium-app-fb16f121e8ff6678c74148cd456b964a85742fbe.tar.zst ferdium-app-fb16f121e8ff6678c74148cd456b964a85742fbe.zip |
Merge pull request #525 from meetfranz/feature/icon-upload
[PR] Feature/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 d75d2e559..a684ff98b 100644 --- a/src/api/server/ServerApi.js +++ b/src/api/server/ServerApi.js | |||
@@ -171,27 +171,65 @@ export default class ServerApi { | |||
171 | throw request; | 171 | throw request; |
172 | } | 172 | } |
173 | const serviceData = await request.json(); | 173 | const serviceData = await request.json(); |
174 | |||
175 | if (data.iconFile) { | ||
176 | const iconUrl = await this.uploadServiceIcon(serviceData.data.id, data.iconFile); | ||
177 | |||
178 | serviceData.data.iconUrl = iconUrl; | ||
179 | } | ||
180 | |||
174 | const service = Object.assign(serviceData, { data: await this._prepareServiceModel(serviceData.data) }); | 181 | const service = Object.assign(serviceData, { data: await this._prepareServiceModel(serviceData.data) }); |
175 | 182 | ||
176 | console.debug('ServerApi::createService resolves', service); | 183 | console.debug('ServerApi::createService resolves', service); |
177 | return service; | 184 | return service; |
178 | } | 185 | } |
179 | 186 | ||
180 | async updateService(recipeId, data) { | 187 | async updateService(serviceId, rawData) { |
181 | const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/service/${recipeId}`, this._prepareAuthRequest({ | 188 | const data = rawData; |
189 | |||
190 | if (data.iconFile) { | ||
191 | await this.uploadServiceIcon(serviceId, data.iconFile); | ||
192 | } | ||
193 | |||
194 | const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/service/${serviceId}`, this._prepareAuthRequest({ | ||
182 | method: 'PUT', | 195 | method: 'PUT', |
183 | body: JSON.stringify(data), | 196 | body: JSON.stringify(data), |
184 | })); | 197 | })); |
198 | |||
185 | if (!request.ok) { | 199 | if (!request.ok) { |
186 | throw request; | 200 | throw request; |
187 | } | 201 | } |
202 | |||
188 | const serviceData = await request.json(); | 203 | const serviceData = await request.json(); |
204 | |||
189 | const service = Object.assign(serviceData, { data: await this._prepareServiceModel(serviceData.data) }); | 205 | const service = Object.assign(serviceData, { data: await this._prepareServiceModel(serviceData.data) }); |
190 | 206 | ||
191 | console.debug('ServerApi::updateService resolves', service); | 207 | console.debug('ServerApi::updateService resolves', service); |
192 | return service; | 208 | return service; |
193 | } | 209 | } |
194 | 210 | ||
211 | async uploadServiceIcon(serviceId, icon) { | ||
212 | const formData = new FormData(); | ||
213 | formData.append('icon', icon); | ||
214 | |||
215 | const requestData = this._prepareAuthRequest({ | ||
216 | method: 'PUT', | ||
217 | body: formData, | ||
218 | }); | ||
219 | |||
220 | delete requestData.headers['Content-Type']; | ||
221 | |||
222 | const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/service/${serviceId}`, requestData); | ||
223 | |||
224 | if (!request.ok) { | ||
225 | throw request; | ||
226 | } | ||
227 | |||
228 | const serviceData = await request.json(); | ||
229 | |||
230 | return serviceData.data.iconUrl; | ||
231 | } | ||
232 | |||
195 | async reorderService(data) { | 233 | async reorderService(data) { |
196 | const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/service/reorder`, this._prepareAuthRequest({ | 234 | const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/service/reorder`, this._prepareAuthRequest({ |
197 | method: 'PUT', | 235 | method: 'PUT', |