1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +07:00

added api call (not working)

This commit is contained in:
muerwre 2019-08-12 15:39:06 +07:00
parent 92f097d161
commit 7350201e22
3 changed files with 26 additions and 2 deletions

View file

@ -3,5 +3,6 @@ export const API = {
USER: { USER: {
LOGIN: '/auth/login', LOGIN: '/auth/login',
ME: '/auth/me', // ME: '/auth/me', //
} UPLOAD: (target, type) => `/upload/${target}/${type}`,
},
}; };

20
src/redux/uploads/api.ts Normal file
View file

@ -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<IResultWithStatus<IFile>> => {
const data = new FormData();
data.append('file', file);
return api.post(API.USER.UPLOAD(target, type), data, configWithToken(access));
};

View file

@ -1,4 +1,5 @@
import { takeEvery, all, spawn, call, put, take, fork, race } from 'redux-saga/effects'; 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 { UPLOAD_ACTIONS } from '~/redux/uploads/constants';
import { import {
uploadUploadFiles, uploadSetStatus, uploadAddStatus, uploadDropStatus, uploadAddFile uploadUploadFiles, uploadSetStatus, uploadAddStatus, uploadDropStatus, uploadAddFile
@ -9,8 +10,10 @@ import { HTTP_RESPONSES } from '~/utils/api';
import { VALIDATORS } from '~/utils/validators'; import { VALIDATORS } from '~/utils/validators';
import { UUID, IFileWithUUID, IFile } from '../types'; import { UUID, IFileWithUUID, IFile } from '../types';
function* uploadCall({ temp_id, onProgress, file }) { 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) { function* onUploadProgress(chan) {