Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] MIME type 상수화 #1589

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions components/agenda/Form/SubmitAgendaForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { NextRouter } from 'next/router';
import { SetterOrUpdater } from 'recoil';
import { agendaModal } from 'types/agenda/modalTypes';
import { instanceInAgenda } from 'utils/axios';
import MIME_TYPE from 'constants/common/mimeType';

function agendadataToMsg(data: FormData, isEdit: boolean) {
let msg = '';
msg += '행사 제목 : ' + data.get('agendaTitle') + '\n';
Expand Down Expand Up @@ -88,8 +90,8 @@ const SubmitAgendaForm = async (
}
if (
poster.size != 0 &&
poster.type !== 'image/jpeg' &&
poster.type !== 'image/jpg'
poster.type !== MIME_TYPE.JPEG &&
poster.type !== MIME_TYPE.JPG
) {
errMsg = 'jpg, jpeg 파일만 업로드 가능합니다.\n';
document.getElementById('agendaPoster')?.focus();
Expand Down
8 changes: 3 additions & 5 deletions components/takgu/modal/admin/AdminEditItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Item } from 'types/takgu/itemTypes';
import { instanceInManage } from 'utils/axios';
import { modalState } from 'utils/recoil/takgu/modal';
import { toastState } from 'utils/recoil/toast';
import MIME_TYPE from 'constants/common/mimeType';
import useUploadImg from 'hooks/useUploadImg';
import styles from 'styles/admin/takgu/modal/AdminEditItem.module.scss';

Expand Down Expand Up @@ -70,14 +71,11 @@ export default function AdminEditItemModal(item: Item) {
formData.append(
'updateItemInfo',
new Blob([JSON.stringify(data)], {
type: 'application/json',
type: MIME_TYPE.JSON,
})
);
if (imgData) {
formData.append(
'imgData',
new Blob([imgData], { type: 'image/takgu/jpeg' })
);
formData.append('imgData', new Blob([imgData], { type: MIME_TYPE.JPEG }));
}

mutation.mutate(formData, {
Expand Down
8 changes: 3 additions & 5 deletions components/takgu/modal/admin/AdminProfileModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { racketTypes } from 'types/takgu/userTypes';
import { instanceInManage } from 'utils/axios';
import { modalState } from 'utils/recoil/takgu/modal';
import { toastState } from 'utils/recoil/toast';
import MIME_TYPE from 'constants/common/mimeType';
import useUploadImg from 'hooks/useUploadImg';
import styles from 'styles/admin/takgu/modal/AdminProfile.module.scss';

Expand Down Expand Up @@ -89,14 +90,11 @@ export default function AdminProfileModal(props: { intraId: string }) {
formData.append(
'updateUserInfo',
new Blob([JSON.stringify(data)], {
type: 'application/json',
type: MIME_TYPE.JSON,
})
);
if (imgData) {
formData.append(
'imgData',
new Blob([imgData], { type: 'image/takgu/jpeg' })
);
formData.append('imgData', new Blob([imgData], { type: MIME_TYPE.JPEG }));
}
try {
const res = await instanceInManage.put(
Expand Down
7 changes: 4 additions & 3 deletions components/takgu/modal/store/inventory/ProfileImageModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { UseItemData } from 'types/takgu/inventoryTypes';
import { instance, isAxiosError } from 'utils/axios';
import { errorState } from 'utils/recoil/error';
import { modalState } from 'utils/recoil/takgu/modal';
import MIME_TYPE from 'constants/common/mimeType';
import { ITEM_ALERT_MESSAGE } from 'constants/takgu/store/itemAlertMessage';
import {
ModalButtonContainer,
Expand Down Expand Up @@ -83,12 +84,12 @@ export default function ProfileImageModal({
formData.append(
'userProfileImageRequestDto',
new Blob([JSON.stringify({ receiptId: receiptId })], {
type: 'application/json',
type: MIME_TYPE.JSON,
})
);
formData.append(
'profileImage',
new Blob([imgData], { type: 'image/takgu/jpeg' })
new Blob([imgData], { type: MIME_TYPE.JPEG })
);
await instance.post('/pingpong/users/profile-image', formData);
queryClient.invalidateQueries('user');
Expand Down Expand Up @@ -140,7 +141,7 @@ export default function ProfileImageModal({
)}
<input
type='file'
accept='image/takgu/jpeg'
accept={MIME_TYPE.JPEG}
style={{ display: 'none' }}
onChange={uploadImg}
/>
Expand Down
7 changes: 7 additions & 0 deletions constants/common/mimeType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const MIME_TYPE = Object.freeze({
JPEG: 'image/jpeg' as const,
JSON: 'application/json' as const,
JPG: 'image/jpg' as const,
});
nerdchanii marked this conversation as resolved.
Show resolved Hide resolved

export default MIME_TYPE;
3 changes: 2 additions & 1 deletion hooks/useUploadImg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import imageCompression from 'browser-image-compression';
import { ChangeEvent, useEffect, useState } from 'react';
import { useSetRecoilState } from 'recoil';
import { toastState } from 'utils/recoil/toast';
import MIME_TYPE from 'constants/common/mimeType';

interface ICompressProps {
maxSizeMB: number;
Expand All @@ -25,7 +26,7 @@ export default function useUploadImg({
const options = {
maxSizeMB: maxSizeMB,
maxWidthOrHeight: maxWidthOrHeight,
filetype: 'image/takgu/jpeg',
filetype: MIME_TYPE.JPEG,
useWebWorker: true,
};
try {
Expand Down