Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File system api #5

Merged
merged 13 commits into from
Sep 17, 2023
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