Browse Source

fix: disallow uploading empty file

stage
Vitalik 3 weeks ago
parent
commit
97a088f1f2
  1. 7
      src/containers/Chats/atoms/attachments-menu-item.atom.tsx
  2. 2
      src/services/domain/auth.service.ts
  3. 39
      src/services/domain/refresh-session.service.ts

7
src/containers/Chats/atoms/attachments-menu-item.atom.tsx

@ -46,10 +46,16 @@ export const AttachmentsMenuItem: FC<IProps> = ({ @@ -46,10 +46,16 @@ export const AttachmentsMenuItem: FC<IProps> = ({
);
};
const alertEmpty = () => {
notification.showError("Помилка", `Файл не може бути пустиим`);
};
const sendMediaMessage = async (item: File) => {
try {
if (!item) return;
if (item.size === 0) return alertEmpty();
const { exceeded } = checkFileSize(
item,
chatFilesSize * 1000,
@ -79,6 +85,7 @@ export const AttachmentsMenuItem: FC<IProps> = ({ @@ -79,6 +85,7 @@ export const AttachmentsMenuItem: FC<IProps> = ({
const sendFileMessage = async (file: File) => {
try {
if (!file) return;
if (file.size === 0) return alertEmpty();
if (file.size > chatFilesSize * 1000) alertExceeded(false);
else {

2
src/services/domain/auth.service.ts

@ -235,4 +235,6 @@ export const authService = { @@ -235,4 +235,6 @@ export const authService = {
refreshSession,
logout,
stopSession,
_getTokensFromStorage,
_saveTokens,
};

39
src/services/domain/refresh-session.service.ts

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
import { authApi } from "@/api";
import { authService } from "./auth.service";
class RefreshSessionService {
protected refreshTokenPromise?: Promise<any>;
public async refresh(refreshToken?: string) {
if (this.refreshTokenPromise) {
return this.refreshTokenPromise;
}
this.refreshTokenPromise = this.refreshBody(refreshToken);
return this.refreshTokenPromise;
}
private async refreshBody(refreshToken?: string, attempt = 1) {
let token = refreshToken;
if (!token) {
const existTokens = await authService._getTokensFromStorage();
token = existTokens?.refreshToken;
}
if (!token) return;
try {
const { data } = await authApi.sendRefreshToken({
refreshToken: token,
});
await authService._saveTokens(data);
} catch (e) {
console.log(e);
} finally {
this.refreshTokenPromise = null;
}
}
}
export const refreshSessionService = new RefreshSessionService();
Loading…
Cancel
Save