mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
file type detection on upload
This commit is contained in:
parent
219d05f8ba
commit
60dbb496c4
3 changed files with 24 additions and 6 deletions
|
@ -3,7 +3,7 @@ import { eventChannel, END, EventChannel } from 'redux-saga';
|
|||
import { VALIDATORS } from '~/utils/validators';
|
||||
import { IResultWithStatus, IFile } from '~/redux/types';
|
||||
import { HTTP_RESPONSES } from './api';
|
||||
import { EMPTY_FILE } from '~/redux/uploads/constants';
|
||||
import { EMPTY_FILE, FILE_MIMES, UPLOAD_TYPES } from '~/redux/uploads/constants';
|
||||
|
||||
export const IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/jpg'];
|
||||
|
||||
|
@ -16,7 +16,7 @@ export function createUploader<T extends {}, R extends {}>(
|
|||
] {
|
||||
let emit;
|
||||
|
||||
const chan = eventChannel((emitter) => {
|
||||
const chan = eventChannel(emitter => {
|
||||
emit = emitter;
|
||||
return () => null;
|
||||
});
|
||||
|
@ -30,7 +30,7 @@ export function createUploader<T extends {}, R extends {}>(
|
|||
return [wrappedCallback, chan];
|
||||
}
|
||||
|
||||
export const uploadGetThumb = async (file) => {
|
||||
export const uploadGetThumb = async file => {
|
||||
if (!file.type || !VALIDATORS.IS_IMAGE_MIME(file.type)) return '';
|
||||
|
||||
return await new Promise((resolve, reject) => {
|
||||
|
@ -70,3 +70,12 @@ export const fakeUploader = ({
|
|||
}, 3000);
|
||||
});
|
||||
};
|
||||
|
||||
export const getFileType = (file: File) => {
|
||||
console.log({ type: file.type });
|
||||
|
||||
return (
|
||||
(file.type && Object.keys(FILE_MIMES).find(mime => FILE_MIMES[mime].includes(file.type))) ||
|
||||
UPLOAD_TYPES.OTHER
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue