Merge pull request #603 from ONLYOFFICE/bugfix/upload-quota

Fix Bug 69825 - Settings:QuotaPerRoom. Added dialog about exceeding q…
This commit is contained in:
Alexey Safronov 2024-08-28 17:09:08 +04:00 committed by GitHub
commit ce42cbcb3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 96 additions and 38 deletions

View File

@ -29,6 +29,7 @@ import { inject, observer } from "mobx-react";
import { DeviceType, RoomsType } from "@docspace/shared/enums";
import Planet12ReactSvgUrl from "PUBLIC_DIR/images/icons/12/planet.react.svg?url";
import { toastr } from "@docspace/shared/components/toast";
export default function withFileActions(WrappedFileItem) {
class WithFileActions extends React.Component {
@ -67,9 +68,13 @@ export default function withFileActions(WrappedFileItem) {
dragging && setDragging(false);
createFoldersTree(files, uploadToFolder).then((f) => {
if (f.length > 0) startUpload(f, null, t);
});
createFoldersTree(t, files, uploadToFolder)
.then((f) => {
if (f.length > 0) startUpload(f, null, t);
})
.catch((err) => {
toastr.error(err);
});
};
onDrop = (items) => {

View File

@ -45,6 +45,7 @@ import BonusItem from "./BonusItem";
import AccountsItem from "./AccountsItem";
import ClearTrashReactSvgUrl from "PUBLIC_DIR/images/clear.trash.react.svg?url";
import { toastr } from "@docspace/shared/components/toast";
const StyledDragAndDrop = styled(DragAndDrop)`
display: contents;
@ -88,9 +89,13 @@ const Item = ({
(files, uploadToFolder) => {
dragging && setDragging(false);
createFoldersTree(files, uploadToFolder).then((f) => {
if (f.length > 0) startUpload(f, null, t);
});
createFoldersTree(t, files, uploadToFolder)
.then((f) => {
if (f.length > 0) startUpload(f, null, t);
})
.catch((err) => {
toastr.error(err);
});
},
[t, dragging, setDragging, startUpload, createFoldersTree],
);

View File

@ -245,9 +245,13 @@ const ArticleMainButtonContent = (props) => {
async (e) => {
const files = await getFilesFromEvent(e);
createFoldersTree(files).then((f) => {
if (f.length > 0) startUpload(f, null, t);
});
createFoldersTree(t, files)
.then((f) => {
if (f.length > 0) startUpload(f, null, t);
})
.catch((err) => {
toastr.error(err);
});
},
[startUpload, t],
);

View File

@ -45,6 +45,7 @@ import { useParams } from "react-router-dom";
import { getCategoryType, getCategoryUrl } from "SRC_DIR/helpers/utils";
import { CategoryType } from "SRC_DIR/helpers/constants";
import { toastr } from "@docspace/shared/components/toast";
const useFiles = ({
t,
@ -118,9 +119,13 @@ const useFiles = ({
if (disableDrag) return;
createFoldersTree(files, uploadToFolder).then((f) => {
if (f.length > 0) startUpload(f, null, t);
});
createFoldersTree(t, files, uploadToFolder)
.then((f) => {
if (f.length > 0) startUpload(f, null, t);
})
.catch((err) => {
toastr.error(err);
});
};
React.useEffect(() => {

View File

@ -51,6 +51,7 @@ import {
} from "SRC_DIR/helpers/utils";
import TariffBar from "SRC_DIR/components/TariffBar";
import getFilesFromEvent from "@docspace/shared/components/drag-and-drop/get-files-from-event";
import { toastr } from "@docspace/shared/components/toast";
const StyledContainer = styled.div`
width: 100%;
@ -244,9 +245,13 @@ const SectionHeaderContent = (props) => {
async (e) => {
const files = await getFilesFromEvent(e);
createFoldersTree(files).then((f) => {
if (f.length > 0) startUpload(f, null, t);
});
createFoldersTree(t, files)
.then((f) => {
if (f.length > 0) startUpload(f, null, t);
})
.catch((err) => {
toastr.error(err);
});
},
[startUpload, t],
);

View File

@ -79,7 +79,11 @@ import { CategoryType } from "SRC_DIR/helpers/constants";
import RoomsFilter from "@docspace/shared/api/rooms/filter";
import AccountsFilter from "@docspace/shared/api/people/filter";
import { RoomSearchArea, UrlActionType } from "@docspace/shared/enums";
import { getObjectByLocation } from "@docspace/shared/utils/common";
import {
getConvertedQuota,
getConvertedSize,
getObjectByLocation,
} from "@docspace/shared/utils/common";
import uniqueid from "lodash/uniqueId";
import FilesFilter from "@docspace/shared/api/files/filter";
import {
@ -280,13 +284,41 @@ class FilesActionStore {
return treeList;
};
createFoldersTree = async (files, folderId) => {
createFoldersTree = async (t, files, folderId) => {
//console.log("createFoldersTree", files, folderId);
const { primaryProgressDataStore } = this.uploadDataStore;
const { setPrimaryProgressBarData, clearPrimaryProgressData } =
primaryProgressDataStore;
this.uploadDataStore.primaryProgressDataStore;
const roomFolder = this.selectedFolderStore.navigationPath.find(
(r) => r.isRoom,
);
const withoutHiddenFiles = Object.values(files).filter((f) => {
const isHidden = /(^|\/)\.[^\/\.]/g.test(f.name);
return !isHidden;
});
if (roomFolder && roomFolder.quotaLimit) {
const freeSpace = roomFolder.quotaLimit - roomFolder.usedSpace;
const filesSize = withoutHiddenFiles.reduce((acc, file) => {
return acc + file.size;
}, 0);
if (filesSize > freeSpace) {
clearPrimaryProgressData();
const size = getConvertedSize(t, roomFolder.quotaLimit);
throw new Error(
t("Common:RoomSpaceQuotaExceeded", {
size,
}),
);
}
}
const operationId = uniqueid("operation_");
@ -302,7 +334,7 @@ class FilesActionStore {
setPrimaryProgressBarData({ ...pbData, disableUploadPanelOpen: true });
const tree = this.convertToTree(files);
const tree = this.convertToTree(withoutHiddenFiles);
const filesList = [];
await this.createFolderTree(tree, toFolderId, filesList);

View File

@ -1606,13 +1606,16 @@ class FilesStore {
(data.current.rootFolderType === Rooms ||
data.current.rootFolderType === Archive);
let shared;
let shared, quotaLimit, usedSpace;
if (idx === 1) {
let room = data.current;
if (!isCurrentFolder) {
room = await api.files.getFolderInfo(folderId);
shared = room.shared;
quotaLimit = room.quotaLimit;
usedSpace = room.usedSpace;
this.infoPanelStore.setInfoPanelRoom(room);
}
@ -1631,6 +1634,8 @@ class FilesStore {
roomType,
isRootRoom,
shared,
quotaLimit,
usedSpace,
};
}),
).then((res) => {

View File

@ -692,9 +692,13 @@ class HotkeyStore {
const files = await getFilesFromEvent(event);
createFoldersTree(files).then((f) => {
if (f.length > 0) startUpload(f, null, t);
});
createFoldersTree(t, files)
.then((f) => {
if (f.length > 0) startUpload(f, null, t);
})
.catch((err) => {
toastr.error(err);
});
};
get countTilesInRow() {

View File

@ -714,14 +714,6 @@ class UploadDataStore {
};
startUpload = (uploadFiles, folderId, t) => {
const withoutHiddenFiles = Object.values(uploadFiles).filter((f) => {
const isHidden = /(^|\/)\.[^\/\.]/g.test(f.name);
return !isHidden;
});
console.log("startUpload", { withoutHiddenFiles, uploadFiles });
const { canConvert } = this.filesSettingsStore;
const toFolderId = folderId ? folderId : this.selectedFolderStore.id;
@ -743,10 +735,10 @@ class UploadDataStore {
let filesSize = 0;
let convertSize = 0;
const uploadFilesArray = Object.keys(withoutHiddenFiles);
const uploadFilesArray = Object.keys(uploadFiles);
const hasFolder =
uploadFilesArray.findIndex((_, ind) => {
const file = withoutHiddenFiles[ind];
const file = uploadFiles[ind];
const filePath = file.path
? file.path
@ -761,13 +753,13 @@ class UploadDataStore {
if (this.uploaded) {
this.isParallel = false;
} else if (this.isParallel) {
this.tempFiles.push({ withoutHiddenFiles, folderId, t });
this.tempFiles.push({ uploadFiles, folderId, t });
return;
}
}
for (let index of uploadFilesArray) {
const file = withoutHiddenFiles[index];
const file = uploadFiles[index];
const parts = file.name.split(".");
const ext = parts.length > 1 ? "." + parts.pop() : "";

View File

@ -515,5 +515,6 @@
"Website": "Website",
"Yes": "Yes",
"Yesterday": "Yesterday",
"You": "You"
"You": "You",
"RoomSpaceQuotaExceeded": "Room space quota exceeded ({{size}})."
}