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

uploading mpegs

This commit is contained in:
Fedor Katurov 2019-10-09 21:17:00 +07:00
parent 60dbb496c4
commit 4a3de2ab01
3 changed files with 13 additions and 19 deletions

View file

@ -1,5 +1,5 @@
import { IFile, IUploadType } from '~/redux/types'; import { IFile, IUploadType } from '~/redux/types';
import { IUploadState, IUploadStatus } from './reducer'; import { IUploadStatus } from './reducer';
const prefix = 'UPLOAD.'; const prefix = 'UPLOAD.';
@ -62,6 +62,8 @@ export const UPLOAD_TYPES: Record<string, IUploadType> = {
}; };
export const FILE_MIMES = { export const FILE_MIMES = {
[UPLOAD_TYPES.image]: ['image/jpeg', 'image/jpg', 'image/png'], [UPLOAD_TYPES.VIDEO]: [],
[UPLOAD_TYPES.audio]: ['audio/mpeg3', 'audio/mpeg', 'audio/mp3'], [UPLOAD_TYPES.IMAGE]: ['image/jpeg', 'image/jpg', 'image/png'],
[UPLOAD_TYPES.AUDIO]: ['audio/mpeg3', 'audio/mpeg', 'audio/mp3'],
[UPLOAD_TYPES.OTHER]: [],
}; };

View file

@ -1,8 +1,6 @@
import { import { takeEvery, all, spawn, call, put, take, fork, race } from 'redux-saga/effects';
takeEvery, all, spawn, call, put, take, fork, race,
} from 'redux-saga/effects';
import { postUploadFile } from './api'; import { postUploadFile } from './api';
import { UPLOAD_ACTIONS } from '~/redux/uploads/constants'; import { UPLOAD_ACTIONS, FILE_MIMES } from '~/redux/uploads/constants';
import { import {
uploadUploadFiles, uploadUploadFiles,
uploadSetStatus, uploadSetStatus,
@ -49,9 +47,7 @@ function* uploadCancelWorker(id) {
return true; return true;
} }
function* uploadWorker({ function* uploadWorker({ file, temp_id, target, type }: IFileWithUUID) {
file, temp_id, target, type,
}: IFileWithUUID) {
const [promise, chan] = createUploader<Partial<IFileWithUUID>, Partial<IFileWithUUID>>( const [promise, chan] = createUploader<Partial<IFileWithUUID>, Partial<IFileWithUUID>>(
uploadCall, uploadCall,
{ temp_id, target, type } { temp_id, target, type }
@ -69,10 +65,8 @@ function* uploadWorker({
return result; return result;
} }
function* uploadFile({ function* uploadFile({ file, temp_id, type, target }: IFileWithUUID) {
file, temp_id, type, target, if (!file.type || !file.type || !FILE_MIMES[type].includes(file.type)) {
}: IFileWithUUID) {
if (!file.type || !VALIDATORS.IS_IMAGE_MIME(file.type)) {
return { error: 'File_Not_Image', status: HTTP_RESPONSES.BAD_REQUEST, data: {} }; return { error: 'File_Not_Image', status: HTTP_RESPONSES.BAD_REQUEST, data: {} };
} }
@ -137,6 +131,6 @@ function* uploadFiles({ files }: ReturnType<typeof uploadUploadFiles>) {
yield all(files.map(file => spawn(uploadFile, file))); yield all(files.map(file => spawn(uploadFile, file)));
} }
export default function* () { export default function*() {
yield takeEvery(UPLOAD_ACTIONS.UPLOAD_FILES, uploadFiles); yield takeEvery(UPLOAD_ACTIONS.UPLOAD_FILES, uploadFiles);
} }

View file

@ -71,11 +71,9 @@ export const fakeUploader = ({
}); });
}; };
export const getFileType = (file: File) => { export const getFileType = (file: File): keyof typeof UPLOAD_TYPES => {
console.log({ type: file.type });
return ( return (
(file.type && Object.keys(FILE_MIMES).find(mime => FILE_MIMES[mime].includes(file.type))) || (file.type && Object.keys(FILE_MIMES).find(mime => FILE_MIMES[mime].includes(file.type))) ||
UPLOAD_TYPES.OTHER null
); );
}; };