diff options
Diffstat (limited to 'src/api/server/ServerApi.js')
-rw-r--r-- | src/api/server/ServerApi.js | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/api/server/ServerApi.js b/src/api/server/ServerApi.js index f25f02eaa..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')); |