diff options
author | 2017-12-24 22:11:36 +0100 | |
---|---|---|
committer | 2017-12-24 22:11:36 +0100 | |
commit | df44b69c4655415fe1e44689ece443ec06ef0f52 (patch) | |
tree | e677ed5f5328bb3b14bc976c7392d8e259f89034 /src/api/server | |
parent | [wip] add icon upload (diff) | |
parent | Merge pull request #494 from heavypackets/websecurity-enable-patch (diff) | |
download | ferdium-app-df44b69c4655415fe1e44689ece443ec06ef0f52.tar.gz ferdium-app-df44b69c4655415fe1e44689ece443ec06ef0f52.tar.zst ferdium-app-df44b69c4655415fe1e44689ece443ec06ef0f52.zip |
Merge branch 'develop' into feature/icon-upload
Diffstat (limited to 'src/api/server')
-rw-r--r-- | src/api/server/ServerApi.js | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/api/server/ServerApi.js b/src/api/server/ServerApi.js index 932b70cdc..8b3136d27 100644 --- a/src/api/server/ServerApi.js +++ b/src/api/server/ServerApi.js | |||
@@ -12,6 +12,8 @@ import NewsModel from '../../models/News'; | |||
12 | import UserModel from '../../models/User'; | 12 | import UserModel from '../../models/User'; |
13 | import OrderModel from '../../models/Order'; | 13 | import OrderModel from '../../models/Order'; |
14 | 14 | ||
15 | import { sleep } from '../../helpers/async-helpers'; | ||
16 | |||
15 | import { API } from '../../environment'; | 17 | import { API } from '../../environment'; |
16 | 18 | ||
17 | import { | 19 | import { |
@@ -125,6 +127,19 @@ export default class ServerApi { | |||
125 | return user; | 127 | return user; |
126 | } | 128 | } |
127 | 129 | ||
130 | async deleteAccount() { | ||
131 | const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/me`, this._prepareAuthRequest({ | ||
132 | method: 'DELETE', | ||
133 | })); | ||
134 | if (!request.ok) { | ||
135 | throw request; | ||
136 | } | ||
137 | const data = await request.json(); | ||
138 | |||
139 | console.debug('ServerApi::deleteAccount resolves', data); | ||
140 | return data; | ||
141 | } | ||
142 | |||
128 | // Services | 143 | // Services |
129 | async getServices() { | 144 | async getServices() { |
130 | const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/me/services`, this._prepareAuthRequest({ | 145 | const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/me/services`, this._prepareAuthRequest({ |
@@ -290,18 +305,25 @@ export default class ServerApi { | |||
290 | 305 | ||
291 | fs.ensureDirSync(recipeTempDirectory); | 306 | fs.ensureDirSync(recipeTempDirectory); |
292 | const res = await fetch(packageUrl); | 307 | const res = await fetch(packageUrl); |
308 | console.debug('Recipe downloaded', recipeId); | ||
293 | const buffer = await res.buffer(); | 309 | const buffer = await res.buffer(); |
294 | fs.writeFileSync(archivePath, buffer); | 310 | fs.writeFileSync(archivePath, buffer); |
295 | 311 | ||
296 | tar.x({ | 312 | await sleep(10); |
313 | |||
314 | await tar.x({ | ||
297 | file: archivePath, | 315 | file: archivePath, |
298 | cwd: recipeTempDirectory, | 316 | cwd: recipeTempDirectory, |
299 | sync: true, | 317 | preservePaths: true, |
318 | unlink: true, | ||
319 | preserveOwner: false, | ||
320 | onwarn: x => console.log('warn', recipeId, x), | ||
300 | }); | 321 | }); |
301 | 322 | ||
323 | await sleep(10); | ||
324 | |||
302 | const { id } = fs.readJsonSync(path.join(recipeTempDirectory, 'package.json')); | 325 | const { id } = fs.readJsonSync(path.join(recipeTempDirectory, 'package.json')); |
303 | const recipeDirectory = path.join(recipesDirectory, id); | 326 | const recipeDirectory = path.join(recipesDirectory, id); |
304 | |||
305 | fs.copySync(recipeTempDirectory, recipeDirectory); | 327 | fs.copySync(recipeTempDirectory, recipeDirectory); |
306 | fs.remove(recipeTempDirectory); | 328 | fs.remove(recipeTempDirectory); |
307 | fs.remove(path.join(recipesDirectory, recipeId, 'recipe.tar.gz')); | 329 | fs.remove(path.join(recipesDirectory, recipeId, 'recipe.tar.gz')); |
@@ -374,7 +396,7 @@ export default class ServerApi { | |||
374 | // News | 396 | // News |
375 | async getLatestNews() { | 397 | async getLatestNews() { |
376 | // eslint-disable-next-line | 398 | // eslint-disable-next-line |
377 | const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/news?platform=${os.platform()}&arch=${os.arch()}version=${app.getVersion()}`, | 399 | const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/news?platform=${os.platform()}&arch=${os.arch()}&version=${app.getVersion()}`, |
378 | this._prepareAuthRequest({ | 400 | this._prepareAuthRequest({ |
379 | method: 'GET', | 401 | method: 'GET', |
380 | })); | 402 | })); |