Browse Source

fix network usage

master
Gaëtan Renaudeau 7 years ago
parent
commit
c9d699c663
  1. 21
      src/helpers/devices/getOsuFirmware.js
  2. 13
      src/helpers/firmware/getFinalFirmwareById.js
  3. 4
      src/helpers/firmware/installFinalFirmware.js
  4. 1
      src/helpers/firmware/installMcu.js
  5. 4
      src/helpers/firmware/installOsuFirmware.js

21
src/helpers/devices/getOsuFirmware.js

@ -1,5 +1,5 @@
// @flow // @flow
import axios from 'axios' import network from 'api/network'
import { GET_CURRENT_OSU } from 'helpers/urls' import { GET_CURRENT_OSU } from 'helpers/urls'
@ -8,19 +8,16 @@ type Input = {
deviceId: string | number, deviceId: string | number,
} }
let error
export default async (input: Input): Promise<*> => { export default async (input: Input): Promise<*> => {
try { const provider = 1
const provider = 1 const { data } = await network({
const { data } = await axios.post(GET_CURRENT_OSU, { method: 'POST',
url: GET_CURRENT_OSU,
data: {
device_version: input.deviceId, device_version: input.deviceId,
version_name: input.version, version_name: input.version,
provider, provider,
}) },
return data })
} catch (err) { return data
error = Error(err.message)
error.stack = err.stack
throw error
}
} }

13
src/helpers/firmware/getFinalFirmwareById.js

@ -1,15 +1,8 @@
// @flow // @flow
import axios from 'axios' import network from 'api/network'
import { GET_FINAL_FIRMWARE } from 'helpers/urls' import { GET_FINAL_FIRMWARE } from 'helpers/urls'
export default async (id: number) => { export default async (id: number) => {
try { const { data } = await network({ method: 'GET', url: `${GET_FINAL_FIRMWARE}/${id}` })
const { data } = await axios.get(`${GET_FINAL_FIRMWARE}/${id}`) return data
return data
} catch (err) {
const error = Error(err.message)
error.stack = err.stack
throw err
}
} }

4
src/helpers/firmware/installFinalFirmware.js

@ -30,9 +30,7 @@ export default async (transport: Transport<*>, app: Input): Result => {
const url = WS_INSTALL(params) const url = WS_INSTALL(params)
await createDeviceSocket(transport, url).toPromise() await createDeviceSocket(transport, url).toPromise()
return { success: true } return { success: true }
} catch (err) { } catch (error) {
const error = Error(err.message)
error.stack = err.stack
const result = { success: false, error } const result = { success: false, error }
throw result throw result
} }

1
src/helpers/firmware/installMcu.js

@ -13,7 +13,6 @@ export default async (
): Result => { ): Result => {
const { version } = args const { version } = args
const nextVersion = await getNextMCU(version) const nextVersion = await getNextMCU(version)
const params = { const params = {
targetId: args.targetId, targetId: args.targetId,
version: nextVersion.name, version: nextVersion.name,

4
src/helpers/firmware/installOsuFirmware.js

@ -22,9 +22,7 @@ export default async (
const url = WS_INSTALL(params) const url = WS_INSTALL(params)
await createDeviceSocket(transport, url).toPromise() await createDeviceSocket(transport, url).toPromise()
return { success: true } return { success: true }
} catch (err) { } catch (error) {
const error = Error(err.message)
error.stack = err.stack
const result = { success: false, error } const result = { success: false, error }
throw result throw result
} }

Loading…
Cancel
Save