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

13
src/helpers/firmware/getFinalFirmwareById.js

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

4
src/helpers/firmware/installFinalFirmware.js

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

1
src/helpers/firmware/installMcu.js

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

4
src/helpers/firmware/installOsuFirmware.js

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

Loading…
Cancel
Save