diff options
Diffstat (limited to 'app/client/api')
| -rw-r--r-- | app/client/api/crud.actions.js | 23 | ||||
| -rw-r--r-- | app/client/api/crud.fetch.js | 8 | ||||
| -rw-r--r-- | app/client/api/crud.upload.js | 4 | ||||
| -rw-r--r-- | app/client/api/index.js | 21 |
4 files changed, 25 insertions, 31 deletions
diff --git a/app/client/api/crud.actions.js b/app/client/api/crud.actions.js index ca51dbb..10abbba 100644 --- a/app/client/api/crud.actions.js +++ b/app/client/api/crud.actions.js @@ -1,27 +1,28 @@ -import crud from '../../api/crud.fetch' +import crud from './crud.fetch' import { as_type } from './crud.types' +import { uploadAction } from './crud.upload' /* for our crud events, create corresponding actions the actions fire a 'loading' event, call the underlying api method, and then resolve. so you can do ... - var folderActions = crud_actions('folder') - folderActions('upload', (dispatch) => { - new Promise((resolve, reject) => { - fetch(...) - .then(() => resolve(data)) - .catch(e => throw e) - }) - }) + var folderActions = crud_actions('folder') folderActions.index({ module: 'samplernn' }) + folderActions.show(12) + folderActions.create({ module: 'samplernn', name: 'foo' }) + folderActions.update(12, { module: 'pix2pix' }) + folderActions.destroy(12, { confirm: true }) */ export function crud_actions(type) { const fetch_type = crud_fetch(type) return ['index', 'show', 'create', 'update', 'destroy'].reduce((lookup, param) => { - lookup[param] = crud_action(type, 'index', () => fetch_type[type](param)]), + lookup[param] = crud_action(type, param, () => fetch_type[type](param)]), return lookup - }, { action: (method, fn) => crud_action(type, method, fn) }) + }, { + action: (method, fn) => crud_action(type, method, fn) + upload: (id, fd) => uploadAction(type, id, fd) + }) } export const crud_action = (type, method, fn) => dispatch => { diff --git a/app/client/api/crud.fetch.js b/app/client/api/crud.fetch.js index fadd2b6..421510b 100644 --- a/app/client/api/crud.fetch.js +++ b/app/client/api/crud.fetch.js @@ -1,7 +1,7 @@ import fetch from 'node-fetch' export function crud_fetch(type, tag) { - const uri = '/' + type + 's/' + (tag || '') + const uri = '/api/' + type + '/' + (tag || '') return { index: q => { return fetch(_get_url(uri, q), _get_headers()) @@ -32,12 +32,6 @@ export function crud_fetch(type, tag) { .then(req => req.json()) .catch(error) }, - - upload: data => { - return fetch(uri, postBody(data)) - .then(req => req.json()) - .catch(error) - }, } } diff --git a/app/client/api/crud.upload.js b/app/client/api/crud.upload.js index 42aae2b..26917ff 100644 --- a/app/client/api/crud.upload.js +++ b/app/client/api/crud.upload.js @@ -1,6 +1,6 @@ import { as_type } from './crud.types' -export function upload(type, id, fd, dispatch) => { +export function crud_upload(type, id, fd, dispatch) => { return new Promise( (resolve, reject) => { const xhr = new XMLHttpRequest() xhr.upload.addEventListener("progress", uploadProgress, false) @@ -66,5 +66,5 @@ export function upload(type, id, fd, dispatch) => { } export function uploadAction(type, id, fd) { - return dispatch => upload(type, id, fd, dispatch) + return dispatch => crud_upload(type, id, fd, dispatch) }
\ No newline at end of file diff --git a/app/client/api/index.js b/app/client/api/index.js index 2603b38..857cdc7 100644 --- a/app/client/api/index.js +++ b/app/client/api/index.js @@ -4,17 +4,16 @@ import fetch from 'node-fetch' import { crud_fetch, postBody } from './crud.fetch' export const folder = crud_fetch('folder') - -folder.upload = (folder_id, files) => { - var data = new FormData() - for (var i = 0; i < files.length; i++) { - data.append('file', files[i]) - } - return fetch('/api/folders/' + folder_id, postBody(data)) - .then(req => req.json()) - .catch(error) -} - export const file = crud_fetch('file') export const task = crud_fetch('dataset') export const task = crud_fetch('task') + +// folder.upload = (folder_id, files) => { +// var data = new FormData() +// for (var i = 0; i < files.length; i++) { +// data.append('file', files[i]) +// } +// return fetch('/api/folders/' + folder_id, postBody(data)) +// .then(req => req.json()) +// .catch(error) +// } |
