From 7350201e22b966029696705c403337f27ab9198c Mon Sep 17 00:00:00 2001 From: muerwre Date: Mon, 12 Aug 2019 15:39:06 +0700 Subject: [PATCH] added api call (not working) --- src/constants/api.ts | 3 ++- src/redux/uploads/api.ts | 20 ++++++++++++++++++++ src/redux/uploads/sagas.ts | 5 ++++- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/redux/uploads/api.ts diff --git a/src/constants/api.ts b/src/constants/api.ts index 501fd82a..064898bc 100644 --- a/src/constants/api.ts +++ b/src/constants/api.ts @@ -3,5 +3,6 @@ export const API = { USER: { LOGIN: '/auth/login', ME: '/auth/me', // - } + UPLOAD: (target, type) => `/upload/${target}/${type}`, + }, }; diff --git a/src/redux/uploads/api.ts b/src/redux/uploads/api.ts new file mode 100644 index 00000000..42b12ee5 --- /dev/null +++ b/src/redux/uploads/api.ts @@ -0,0 +1,20 @@ +import { IResultWithStatus, IFile } from '~/redux/types'; +import { api, configWithToken } from '~/utils/api'; +import { API } from '~/constants/api'; + +export const postUploadFile = ({ + access, + file, + target = 'others', + type = 'image', +}: { +access: string; +file: File; +target: string; +type: string; +}): Promise> => { + const data = new FormData(); + data.append('file', file); + + return api.post(API.USER.UPLOAD(target, type), data, configWithToken(access)); +}; diff --git a/src/redux/uploads/sagas.ts b/src/redux/uploads/sagas.ts index ae5dc39e..1c79ab6c 100644 --- a/src/redux/uploads/sagas.ts +++ b/src/redux/uploads/sagas.ts @@ -1,4 +1,5 @@ import { takeEvery, all, spawn, call, put, take, fork, race } from 'redux-saga/effects'; +import { postUploadFile } from './api'; import { UPLOAD_ACTIONS } from '~/redux/uploads/constants'; import { uploadUploadFiles, uploadSetStatus, uploadAddStatus, uploadDropStatus, uploadAddFile @@ -9,8 +10,10 @@ import { HTTP_RESPONSES } from '~/utils/api'; import { VALIDATORS } from '~/utils/validators'; import { UUID, IFileWithUUID, IFile } from '../types'; + function* uploadCall({ temp_id, onProgress, file }) { - return yield call(reqWrapper, fakeUploader, { file: { url: 'some', error: 'cant do this boss' }, onProgress, mustSucceed: true }); + // return yield call(reqWrapper, fakeUploader, { file: { url: 'some', error: 'cant do this boss' }, onProgress, mustSucceed: true }); + return yield call(reqWrapper, postUploadFile, { file: { url: 'some', error: 'cant do this boss' }, onProgress, mustSucceed: true }); } function* onUploadProgress(chan) {