Web: Files: Public-room: fixed socket error, refactoring
This commit is contained in:
parent
c65504a7a8
commit
a908363898
@ -58,7 +58,7 @@ export default function withContent(WrappedContent) {
|
||||
viewer,
|
||||
titleWithoutExt,
|
||||
isPublicRoom,
|
||||
publicKey,
|
||||
publicRoomKey,
|
||||
} = this.props;
|
||||
|
||||
const { access, createdBy, fileStatus, href } = item;
|
||||
@ -80,7 +80,9 @@ export default function withContent(WrappedContent) {
|
||||
: { onClick: onFilesClick };
|
||||
|
||||
if (!isDesktop && !isTrashFolder && !isArchiveFolder) {
|
||||
linkStyles.href = isPublicRoom ? `${href}&share=${publicKey}` : href;
|
||||
linkStyles.href = isPublicRoom
|
||||
? `${href}&share=${publicRoomKey}`
|
||||
: href;
|
||||
}
|
||||
|
||||
const newItems =
|
||||
@ -133,7 +135,7 @@ export default function withContent(WrappedContent) {
|
||||
setCreatedItem,
|
||||
} = filesStore;
|
||||
|
||||
const { isPublicRoom, publicKey } = publicRoomStore;
|
||||
const { isPublicRoom, publicRoomKey } = publicRoomStore;
|
||||
|
||||
const { clearActiveOperations, fileCopyAs } = uploadDataStore;
|
||||
const { isRecycleBinFolder, isPrivacyFolder, isArchiveFolder } =
|
||||
@ -186,7 +188,7 @@ export default function withContent(WrappedContent) {
|
||||
setCreatedItem,
|
||||
personal,
|
||||
isPublicRoom,
|
||||
publicKey,
|
||||
publicRoomKey,
|
||||
};
|
||||
}
|
||||
)(observer(WithContent));
|
||||
|
@ -24,7 +24,7 @@ const EmptyFilterContainer = ({
|
||||
setClearSearch,
|
||||
theme,
|
||||
isPublicRoom,
|
||||
publicKey,
|
||||
publicRoomKey,
|
||||
}) => {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
@ -53,7 +53,7 @@ const EmptyFilterContainer = ({
|
||||
|
||||
if (isPublicRoom) {
|
||||
navigate(
|
||||
`${location.pathname}?key=${publicKey}&${newFilter.toUrlParams()}`
|
||||
`${location.pathname}?key=${publicRoomKey}&${newFilter.toUrlParams()}`
|
||||
);
|
||||
} else {
|
||||
navigate(`${location.pathname}?${newFilter.toUrlParams()}`);
|
||||
@ -102,7 +102,7 @@ export default inject(
|
||||
const { isRoomsFolder, isArchiveFolder } = treeFoldersStore;
|
||||
|
||||
const isRooms = isRoomsFolder || isArchiveFolder;
|
||||
const { isPublicRoom, publicKey } = publicRoomStore;
|
||||
const { isPublicRoom, publicRoomKey } = publicRoomStore;
|
||||
|
||||
return {
|
||||
selectedFolderId: selectedFolderStore.id,
|
||||
@ -114,7 +114,7 @@ export default inject(
|
||||
theme: auth.settingsStore.theme,
|
||||
|
||||
isPublicRoom,
|
||||
publicKey,
|
||||
publicRoomKey,
|
||||
};
|
||||
}
|
||||
)(withTranslation(["Files", "Common"])(observer(EmptyFilterContainer)));
|
||||
|
@ -342,7 +342,7 @@ class FilesTableHeader extends React.Component {
|
||||
};
|
||||
|
||||
onFilter = (sortBy) => {
|
||||
const { filter, setIsLoading, isPublicRoom, publicKey } = this.props;
|
||||
const { filter, setIsLoading, isPublicRoom, publicRoomKey } = this.props;
|
||||
const newFilter = filter.clone();
|
||||
|
||||
if (newFilter.sortBy !== sortBy) {
|
||||
@ -358,7 +358,7 @@ class FilesTableHeader extends React.Component {
|
||||
window.DocSpace.navigate(
|
||||
`${
|
||||
window.DocSpace.location.pathname
|
||||
}?key=${publicKey}&${newFilter.toUrlParams()}`
|
||||
}?key=${publicRoomKey}&${newFilter.toUrlParams()}`
|
||||
);
|
||||
} else {
|
||||
window.DocSpace.navigate(
|
||||
@ -492,7 +492,7 @@ export default inject(
|
||||
setColumnEnable,
|
||||
} = tableStore;
|
||||
|
||||
const { isPublicRoom, publicKey } = publicRoomStore;
|
||||
const { isPublicRoom, publicRoomKey } = publicRoomStore;
|
||||
|
||||
return {
|
||||
isHeaderChecked,
|
||||
@ -540,7 +540,7 @@ export default inject(
|
||||
isRooms,
|
||||
isTrashFolder,
|
||||
isPublicRoom,
|
||||
publicKey,
|
||||
publicRoomKey,
|
||||
};
|
||||
}
|
||||
)(
|
||||
|
@ -247,7 +247,7 @@ const SectionFilterContent = ({
|
||||
accountsFilter,
|
||||
showFilterLoader,
|
||||
isPublicRoom,
|
||||
publicKey,
|
||||
publicRoomKey,
|
||||
}) => {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
@ -258,7 +258,7 @@ const SectionFilterContent = ({
|
||||
|
||||
const onNavigate = (path, filter) => {
|
||||
if (isPublicRoom) {
|
||||
navigate(`${path}?key=${publicKey}&${filter.toUrlParams()}`);
|
||||
navigate(`${path}?key=${publicRoomKey}&${filter.toUrlParams()}`);
|
||||
} else {
|
||||
navigate(`${path}/filter?${filter.toUrlParams()}`);
|
||||
}
|
||||
@ -2086,7 +2086,7 @@ export default inject(
|
||||
const { groups } = groupsStore;
|
||||
|
||||
const { filter: accountsFilter } = filterStore;
|
||||
const { isPublicRoom, publicKey } = publicRoomStore;
|
||||
const { isPublicRoom, publicRoomKey } = publicRoomStore;
|
||||
|
||||
return {
|
||||
user,
|
||||
@ -2130,7 +2130,7 @@ export default inject(
|
||||
|
||||
accountsFilter,
|
||||
isPublicRoom,
|
||||
publicKey,
|
||||
publicRoomKey,
|
||||
};
|
||||
}
|
||||
)(
|
||||
|
@ -20,6 +20,7 @@ const PublicRoom = (props) => {
|
||||
roomId,
|
||||
validatePublicRoomKey,
|
||||
getFilesSettings,
|
||||
setPublicRoomKey,
|
||||
} = props;
|
||||
|
||||
const navigate = useNavigate();
|
||||
@ -35,6 +36,7 @@ const PublicRoom = (props) => {
|
||||
}, [validatePublicRoomKey]);
|
||||
|
||||
const fetchRoomFiles = async () => {
|
||||
setPublicRoomKey(key);
|
||||
await getFilesSettings();
|
||||
|
||||
const filterObj = FilesFilter.getFilter(window.location);
|
||||
@ -92,11 +94,12 @@ const PublicRoom = (props) => {
|
||||
);
|
||||
};
|
||||
|
||||
export default inject(({ publicRoomStore, settingsStore }) => {
|
||||
export default inject(({ auth, publicRoomStore, settingsStore }) => {
|
||||
const { validatePublicRoomKey, isLoaded, isLoading, roomStatus, roomId } =
|
||||
publicRoomStore;
|
||||
|
||||
const { getFilesSettings } = settingsStore;
|
||||
const { setPublicRoomKey } = auth.settingsStore;
|
||||
|
||||
return {
|
||||
roomId,
|
||||
@ -107,5 +110,6 @@ export default inject(({ publicRoomStore, settingsStore }) => {
|
||||
getFilesSettings,
|
||||
|
||||
validatePublicRoomKey,
|
||||
setPublicRoomKey,
|
||||
};
|
||||
})(observer(PublicRoom));
|
||||
|
@ -541,7 +541,7 @@ class FilesActionStore {
|
||||
const fileIds = fileConvertIds.map((f) => f.key || f);
|
||||
addActiveItems(fileIds, folderIds);
|
||||
|
||||
const shareKey = this.publicRoomStore.publicKey;
|
||||
const shareKey = this.publicRoomStore.publicRoomKey;
|
||||
|
||||
try {
|
||||
await downloadFiles(fileConvertIds, folderIds, shareKey).then(
|
||||
@ -2195,7 +2195,7 @@ class FilesActionStore {
|
||||
|
||||
moveToPublicRoom = (folderId) => {
|
||||
const { navigationPath, rootFolderType } = this.selectedFolderStore;
|
||||
const { publicKey } = this.publicRoomStore;
|
||||
const { publicRoomKey } = this.publicRoomStore;
|
||||
const { setIsSectionFilterLoading } = this.clientLoadingStore;
|
||||
|
||||
const id = folderId ? folderId : this.selectedFolderStore.parentId;
|
||||
@ -2211,7 +2211,7 @@ class FilesActionStore {
|
||||
|
||||
setIsSectionFilterLoading(true);
|
||||
window.DocSpace.navigate(
|
||||
`${path}?key=${publicKey}&${filter.toUrlParams()}`,
|
||||
`${path}?key=${publicRoomKey}&${filter.toUrlParams()}`,
|
||||
{ state }
|
||||
);
|
||||
};
|
||||
|
@ -306,10 +306,7 @@ class FilesStore {
|
||||
|
||||
if (foundIndex > -1) return;
|
||||
|
||||
const fileInfo = await api.files.getFileInfo(
|
||||
file.id,
|
||||
this.publicRoomStore.publicKey
|
||||
);
|
||||
const fileInfo = await api.files.getFileInfo(file.id);
|
||||
|
||||
if (this.files.findIndex((x) => x.id === opt?.id) > -1) return;
|
||||
console.log("[WS] create new file", fileInfo.id, fileInfo.title);
|
||||
@ -355,7 +352,7 @@ class FilesStore {
|
||||
|
||||
const folderInfo = await api.files.getFolderInfo(
|
||||
folder.id,
|
||||
this.publicRoomStore.publicKey
|
||||
this.publicRoomStore.publicRoomKey
|
||||
);
|
||||
|
||||
console.log("[WS] create new folder", folderInfo.id, folderInfo.title);
|
||||
@ -393,7 +390,7 @@ class FilesStore {
|
||||
if (!folder || !folder.id) return;
|
||||
|
||||
api.files
|
||||
.getFolderInfo(folder.id, this.publicRoomStore.publicKey)
|
||||
.getFolderInfo(folder.id, this.publicRoomStore.publicRoomKey)
|
||||
.then(() => this.setFolder(folderInfo))
|
||||
.catch(() => {
|
||||
// console.log("Folder deleted")
|
||||
@ -1103,8 +1100,8 @@ class FilesStore {
|
||||
const filterParamsStr = filter.toUrlParams();
|
||||
|
||||
const url = getCategoryUrl(this.categoryType, filter.folder);
|
||||
const shareKey = this.publicRoomStore.publicKey
|
||||
? `key=${this.publicRoomStore.publicKey}&`
|
||||
const shareKey = this.publicRoomStore.publicRoomKey
|
||||
? `key=${this.publicRoomStore.publicRoomKey}&`
|
||||
: "";
|
||||
|
||||
const pathname = `${url}?${shareKey}${filterParamsStr}`;
|
||||
@ -1313,7 +1310,7 @@ class FilesStore {
|
||||
? data.current
|
||||
: await api.files.getFolderInfo(
|
||||
folderId,
|
||||
this.publicRoomStore.publicKey
|
||||
this.publicRoomStore.publicRoomKey
|
||||
);
|
||||
|
||||
const {
|
||||
@ -3216,10 +3213,7 @@ class FilesStore {
|
||||
unpinRoom = (id) => api.rooms.unpinRoom(id);
|
||||
|
||||
getFileInfo = async (id) => {
|
||||
const fileInfo = await api.files.getFileInfo(
|
||||
id,
|
||||
this.publicRoomStore.publicKey
|
||||
);
|
||||
const fileInfo = await api.files.getFileInfo(id);
|
||||
this.setFile(fileInfo);
|
||||
return fileInfo;
|
||||
};
|
||||
@ -3227,7 +3221,7 @@ class FilesStore {
|
||||
getFolderInfo = async (id) => {
|
||||
const folderInfo = await api.files.getFolderInfo(
|
||||
id,
|
||||
this.publicRoomStore.publicKey
|
||||
this.publicRoomStore.publicRoomKey
|
||||
);
|
||||
this.setFolder(folderInfo);
|
||||
return folderInfo;
|
||||
@ -3261,7 +3255,7 @@ class FilesStore {
|
||||
tab,
|
||||
url,
|
||||
isPrivacy,
|
||||
this.publicRoomStore.publicKey
|
||||
this.publicRoomStore.publicRoomKey
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -8,7 +8,7 @@ class PublicRoomStore {
|
||||
roomId = null;
|
||||
roomStatus = null;
|
||||
roomType = null;
|
||||
publicKey = null;
|
||||
publicRoomKey = null;
|
||||
|
||||
isLoaded = false;
|
||||
isLoading = false;
|
||||
@ -77,7 +77,7 @@ class PublicRoomStore {
|
||||
api.rooms
|
||||
.validatePublicRoomKey(key)
|
||||
.then((res) => {
|
||||
this.publicKey = key;
|
||||
this.publicRoomKey = key;
|
||||
this.setRoomData(res);
|
||||
})
|
||||
.finally(() => this.setIsLoading(false));
|
||||
|
@ -445,12 +445,10 @@ export function createHtmlFileInCommon(title, content) {
|
||||
return request(options);
|
||||
}
|
||||
|
||||
export function getFileInfo(fileId, publicKey) {
|
||||
const key = publicKey ? `?share=${publicKey}` : "";
|
||||
|
||||
export function getFileInfo(fileId) {
|
||||
const options = {
|
||||
method: "get",
|
||||
url: `/files/file/${fileId}${key}`,
|
||||
url: `/files/file/${fileId}`,
|
||||
};
|
||||
|
||||
return request(options);
|
||||
|
@ -141,6 +141,7 @@ class SettingsStore {
|
||||
legalTerms = null;
|
||||
baseDomain = "onlyoffice.io";
|
||||
documentationEmail = null;
|
||||
publicRoomKey = "";
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this);
|
||||
@ -317,17 +318,9 @@ class SettingsStore {
|
||||
getSettings = async () => {
|
||||
let newSettings = null;
|
||||
|
||||
const lastKeySymbol = location.search.indexOf("&");
|
||||
const lastIndex =
|
||||
lastKeySymbol === -1 ? location.search.length : lastKeySymbol;
|
||||
|
||||
const publicKey = this.isPublicRoom
|
||||
? location.search.substring(5, lastIndex)
|
||||
: null;
|
||||
|
||||
if (window?.__ASC_INITIAL_EDITOR_STATE__?.portalSettings)
|
||||
newSettings = window.__ASC_INITIAL_EDITOR_STATE__.portalSettings;
|
||||
else newSettings = await api.settings.getSettings(true, publicKey);
|
||||
else newSettings = await api.settings.getSettings(true);
|
||||
|
||||
if (window["AscDesktopEditor"] !== undefined || this.personal) {
|
||||
const dp = combineUrl(window.DocSpaceConfig?.proxy?.url, "/products/files/");
|
||||
@ -650,16 +643,15 @@ class SettingsStore {
|
||||
return window.firebaseHelper;
|
||||
}
|
||||
|
||||
setPublicRoomKey = (key) => {
|
||||
this.publicRoomKey = key;
|
||||
};
|
||||
|
||||
get socketHelper() {
|
||||
const lastKeySymbol = location.search.indexOf("&");
|
||||
const lastIndex =
|
||||
lastKeySymbol === -1 ? location.search.length : lastKeySymbol;
|
||||
const socketUrl =
|
||||
this.isPublicRoom && this.publicRoomKey ? this.socketUrl : null;
|
||||
|
||||
const publicKey = this.isPublicRoom
|
||||
? location.search.substring(5, lastIndex)
|
||||
: null;
|
||||
|
||||
return new SocketIOHelper(this.socketUrl, publicKey);
|
||||
return new SocketIOHelper(socketUrl, this.publicRoomKey);
|
||||
}
|
||||
|
||||
getBuildVersionInfo = async () => {
|
||||
|
@ -29,10 +29,10 @@ class AxiosClient {
|
||||
const lastKeySymbol = location.search.indexOf("&");
|
||||
const lastIndex =
|
||||
lastKeySymbol === -1 ? location.search.length : lastKeySymbol;
|
||||
const publicKey = location.search.substring(5, lastIndex);
|
||||
const publicRoomKey = location.search.substring(5, lastIndex);
|
||||
|
||||
if (publicKey) {
|
||||
headers = { ...headers, "Request-Token": publicKey };
|
||||
if (publicRoomKey) {
|
||||
headers = { ...headers, "Request-Token": publicRoomKey };
|
||||
}
|
||||
|
||||
const apiBaseURL = combineUrl(origin, proxy, prefix);
|
||||
|
Loading…
Reference in New Issue
Block a user