Skip to content

Commit

Permalink
fix(chat): add empty folders to the export(issue#640) (#692)
Browse files Browse the repository at this point in the history
  • Loading branch information
denys-kolomiitsev authored Feb 13, 2024
1 parent 4582175 commit bf65315
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions apps/chat/src/store/import-export/importExport.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {

import { combineEpics } from 'redux-observable';

import { filterOnlyMyEntities } from '@/src/utils/app/common';
import { combineEntities, filterOnlyMyEntities } from '@/src/utils/app/common';
import { BucketService } from '@/src/utils/app/data/bucket-service';
import { ConversationService } from '@/src/utils/app/data/conversation-service';
import { FileService } from '@/src/utils/app/data/file-service';
Expand Down Expand Up @@ -143,13 +143,17 @@ const exportConversationsEpic: AppEpic = (action$, state$) =>
new Set(conversationsListing.map((info) => info.folderId)),
);
//calculate all folders;
const folders = getFoldersFromPaths(
const foldersWithConversation = getFoldersFromPaths(
Array.from(
new Set(foldersIds.flatMap((id) => getAllPathsFromPath(id))),
),
FolderType.Chat,
);

const allFolders = ConversationsSelectors.selectFolders(state$.value);

const folders = combineEntities(foldersWithConversation, allFolders);

return forkJoin({
//get all conversations from api
conversations: zip(
Expand Down
6 changes: 3 additions & 3 deletions apps/chat/src/utils/app/import-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,12 @@ const getNewAttachmentFileFromUploaded = ({
if (!newAttachment.id) {
return;
}
const regExpForNewAttachmentId = /^imports\/[\w-]*\//;
const regExpForNewAttachmentId = /^imports\/[\w\s-]+\//;

const newAttachmentId = newAttachment.id.split(regExpForNewAttachmentId)[
attachmentIdIndex
];

return (
newAttachmentId === oldAttachmentId ||
oldAttachmentId.includes(newAttachmentId)
Expand All @@ -371,7 +372,6 @@ export const updateAttachment = ({
}

const attachmentIdIndex = 1;

const oldAttachmentId = getAttachmentId({
url: oldAttachmentUrl,
attachmentIdIndex,
Expand All @@ -390,7 +390,6 @@ export const updateAttachment = ({
const newAttachmentUrl =
oldAttachment.url &&
encodeURI(`${newAttachmentFile.absolutePath}/${newAttachmentFile.name}`);

const lastSlashIndex = oldAttachmentId.lastIndexOf('/');
const oldAttachmentNameInPath = oldAttachmentId.slice(lastSlashIndex + 1);

Expand All @@ -400,6 +399,7 @@ export const updateAttachment = ({

const updatedAttachment: Attachment = {
...oldAttachment,
type: newAttachmentFile.contentType ?? oldAttachment.type,
url: newAttachmentUrl,
reference_url: newReferenceUrl,
};
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/utils/app/zip-import-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface GetZippedFile {

const getAttachmentFromApi = async (file: DialFile) => {
const fileResult = await fetch(
`api/files/file/${constructPath(file.absolutePath, file.name)}`,
`api/${constructPath(file.absolutePath, file.name)}`,
);
return fileResult.blob();
};
Expand Down

0 comments on commit bf65315

Please sign in to comment.