mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
fixed uploads
This commit is contained in:
parent
cad4e683bc
commit
32b9a0dbbb
9 changed files with 52 additions and 37 deletions
|
@ -17,20 +17,14 @@ import { IUser } from './types';
|
|||
export function* reqWrapper(requestAction, props = {}): ReturnType<typeof requestAction> {
|
||||
const access = yield select(selectToken);
|
||||
|
||||
console.log('firing reqWrapper');
|
||||
|
||||
const result = yield call(requestAction, { access, ...props });
|
||||
|
||||
console.log('at reqWrapper', { result });
|
||||
|
||||
if (result && result.status === 401) {
|
||||
yield put(push(URLS.BASE));
|
||||
yield put(modalShowDialog(DIALOGS.LOGIN));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
console.log('reqWrapper will return');
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -112,4 +112,4 @@ export interface INode {
|
|||
updatedAt?: string;
|
||||
}
|
||||
|
||||
export type IUploadProgressHandler = (current: number, total: number) => void;
|
||||
export type IUploadProgressHandler = (progressEvent: any) => void;
|
||||
|
|
|
@ -9,6 +9,7 @@ export const postUploadFile = ({
|
|||
file,
|
||||
target = 'others',
|
||||
type = 'image',
|
||||
onProgress,
|
||||
}: IFileWithUUID & {
|
||||
access: string;
|
||||
onProgress: IUploadProgressHandler;
|
||||
|
@ -16,5 +17,9 @@ export const postUploadFile = ({
|
|||
const data = new FormData();
|
||||
data.append('file', file);
|
||||
|
||||
return api.post(API.USER.UPLOAD(target, type), data, configWithToken(access));
|
||||
return api.post(
|
||||
API.USER.UPLOAD(target, type),
|
||||
data,
|
||||
configWithToken(access, { onUploadProgress: onProgress })
|
||||
);
|
||||
};
|
||||
|
|
|
@ -57,18 +57,20 @@ function* uploadWorker({
|
|||
{ temp_id, target, type }
|
||||
);
|
||||
|
||||
fork(onUploadProgress, chan);
|
||||
yield fork(onUploadProgress, chan);
|
||||
|
||||
return yield call(promise, {
|
||||
const result = yield call(promise, {
|
||||
temp_id,
|
||||
file,
|
||||
target,
|
||||
type,
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function* uploadFile({
|
||||
file, temp_id, type, target, subject,
|
||||
file, temp_id, type, target,
|
||||
}: IFileWithUUID) {
|
||||
if (!file.type || !VALIDATORS.IS_IMAGE_MIME(file.type)) {
|
||||
return { error: 'File_Not_Image', status: HTTP_RESPONSES.BAD_REQUEST, data: {} };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue