Skip to content

Commit

Permalink
File system api (#5)
Browse files Browse the repository at this point in the history
* fix: yarn ready fixes
  • Loading branch information
RubenGarcia committed Sep 17, 2023
1 parent 20b0012 commit 145fa59
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ import {
useSelectedWeAreAdmin,
useSelectedWeAreModerator,
} from '../../../../state/selectors/selectedConversation';
import { saveAttachmentToDisk, saveAttachmentToDiskQuietly } from '../../../../util/attachmentsUtil';
import {
saveAttachmentToDisk,
saveAttachmentToDiskQuietly,
} from '../../../../util/attachmentsUtil';
import { Reactions } from '../../../../util/reactions';
import { SessionContextMenuContainer } from '../../../SessionContextMenuContainer';
import { SessionEmojiPanel, StyledEmojiPanel } from '../../SessionEmojiPanel';
Expand Down Expand Up @@ -284,19 +287,18 @@ export const MessageContextMenu = (props: Props) => {
return;
}
const messageTimestamp = timestamp || serverTimestamp || 0;
const dir = await window.showDirectoryPicker({id: 1, mode: "readwrite"})
const perm = await dir.queryPermission({mode: "readwrite"});
const dir = await window.showDirectoryPicker({ id: 1, mode: 'readwrite' });
for (let i = 0; i < attachments?.length; i++) {
void saveAttachmentToDiskQuietly({
attachment: attachments[i],
messageTimestamp,
messageSender: sender,
conversationId: convoId,
index: i,
dir,
});
void saveAttachmentToDiskQuietly({
attachment: attachments[i],
messageTimestamp,
messageSender: sender,
conversationId: convoId,
index: i,
dir,
});
}
}
};

const saveAttachment = (e: ItemParams) => {
// this is quite dirty but considering that we want the context menu of the message to show on click on the attachment
Expand Down
8 changes: 4 additions & 4 deletions ts/types/Attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,18 +309,18 @@ export const saveQuietly = async ({
const filename = getSuggestedFilename({ attachment, timestamp, index });
const response = await fetch(attachment.url);
if (response.status !== 200) {
alert("Error downloading, response "+response.status);
return;
alert('Error downloading, response ' + response.status);
return;
}
const blob = await response.blob();
const file = await dir.getFileHandle(filename, {create: true});
const file = await dir.getFileHandle(filename, { create: true });
const writable = await file.createWritable();
await writable.write(blob);
await writable.close();
if (isObjectURLRequired) {
URL.revokeObjectURL(attachment.url);
}
}
};

export const save = ({
attachment,
Expand Down
3 changes: 1 addition & 2 deletions ts/util/attachmentsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,7 @@ export const saveAttachmentToDiskQuietly = async ({
dir,
});
await sendDataExtractionNotification(conversationId, messageSender, messageTimestamp);
}

};

export const saveAttachmentToDisk = async ({
attachment,
Expand Down

0 comments on commit 145fa59

Please sign in to comment.