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:
parent
60dbb496c4
commit
4a3de2ab01
3 changed files with 13 additions and 19 deletions
|
@ -1,5 +1,5 @@
|
|||
import { IFile, IUploadType } from '~/redux/types';
|
||||
import { IUploadState, IUploadStatus } from './reducer';
|
||||
import { IUploadStatus } from './reducer';
|
||||
|
||||
const prefix = 'UPLOAD.';
|
||||
|
||||
|
@ -62,6 +62,8 @@ export const UPLOAD_TYPES: Record<string, IUploadType> = {
|
|||
};
|
||||
|
||||
export const FILE_MIMES = {
|
||||
[UPLOAD_TYPES.image]: ['image/jpeg', 'image/jpg', 'image/png'],
|
||||
[UPLOAD_TYPES.audio]: ['audio/mpeg3', 'audio/mpeg', 'audio/mp3'],
|
||||
[UPLOAD_TYPES.VIDEO]: [],
|
||||
[UPLOAD_TYPES.IMAGE]: ['image/jpeg', 'image/jpg', 'image/png'],
|
||||
[UPLOAD_TYPES.AUDIO]: ['audio/mpeg3', 'audio/mpeg', 'audio/mp3'],
|
||||
[UPLOAD_TYPES.OTHER]: [],
|
||||
};
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
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, FILE_MIMES } from '~/redux/uploads/constants';
|
||||
import {
|
||||
uploadUploadFiles,
|
||||
uploadSetStatus,
|
||||
|
@ -49,9 +47,7 @@ function* uploadCancelWorker(id) {
|
|||
return true;
|
||||
}
|
||||
|
||||
function* uploadWorker({
|
||||
file, temp_id, target, type,
|
||||
}: IFileWithUUID) {
|
||||
function* uploadWorker({ file, temp_id, target, type }: IFileWithUUID) {
|
||||
const [promise, chan] = createUploader<Partial<IFileWithUUID>, Partial<IFileWithUUID>>(
|
||||
uploadCall,
|
||||
{ temp_id, target, type }
|
||||
|
@ -69,10 +65,8 @@ function* uploadWorker({
|
|||
return result;
|
||||
}
|
||||
|
||||
function* uploadFile({
|
||||
file, temp_id, type, target,
|
||||
}: IFileWithUUID) {
|
||||
if (!file.type || !VALIDATORS.IS_IMAGE_MIME(file.type)) {
|
||||
function* uploadFile({ file, temp_id, type, target }: IFileWithUUID) {
|
||||
if (!file.type || !file.type || !FILE_MIMES[type].includes(file.type)) {
|
||||
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)));
|
||||
}
|
||||
|
||||
export default function* () {
|
||||
export default function*() {
|
||||
yield takeEvery(UPLOAD_ACTIONS.UPLOAD_FILES, uploadFiles);
|
||||
}
|
||||
|
|
|
@ -71,11 +71,9 @@ export const fakeUploader = ({
|
|||
});
|
||||
};
|
||||
|
||||
export const getFileType = (file: File) => {
|
||||
console.log({ type: file.type });
|
||||
|
||||
export const getFileType = (file: File): keyof typeof UPLOAD_TYPES => {
|
||||
return (
|
||||
(file.type && Object.keys(FILE_MIMES).find(mime => FILE_MIMES[mime].includes(file.type))) ||
|
||||
UPLOAD_TYPES.OTHER
|
||||
null
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue