Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 10 additions & 24 deletions apps/mobile/app/screens/editor/tiptap/picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,30 +126,16 @@ const file = async (fileOptions: PickerOptions) => {
useTabStore.getState().getNoteIdForTab(fileOptions.tabId) ===
fileOptions.noteId
) {
if (isImage(file.type || "application/octet-stream")) {
editorController.current?.commands.insertImage(
{
hash: hash,
filename: fileName,
mime: file.type || "application/octet-stream",
size: file.size || 0,
dataurl: (await db.attachments.read(hash, "base64")) as string,
type: "image"
},
fileOptions.tabId
);
} else {
editorController.current?.commands.insertAttachment(
{
hash: hash,
filename: fileName,
mime: file.type || "application/octet-stream",
size: file.size || 0,
type: "file"
},
fileOptions.tabId
);
}
editorController.current?.commands.insertAttachment(
{
hash: hash,
filename: fileName,
mime: file.type || "application/octet-stream",
size: file.size || 0,
type: "file"
},
fileOptions.tabId
);
} else {
throw new Error("Failed to attach file, no tabId is set");
}
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,9 @@ export function Editor(props: EditorProps) {
onChange={onSave}
onDownloadAttachment={(attachment) => saveAttachment(attachment.hash)}
onPreviewAttachment={async (data) => {
const { hash, type } = data;
const { hash, type, mime } = data;
const attachment = await db.attachments.attachment(hash);
if (attachment && type === "image") {
if (attachment && mime.startsWith("image/")) {
await previewImageAttachment(attachment);
} else if (
attachment &&
Expand Down
9 changes: 6 additions & 3 deletions apps/web/src/components/editor/picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ export async function insertAttachments(type = "*/*") {
multiple: true
});
if (!files) return;
return await attachFiles(files);
return await attachFiles(files, type === "*/*");
}

export async function attachFiles(files: File[]) {
export async function attachFiles(
files: File[],
skipSpecialImageHandling = false
) {
let images = files.filter((f) => f.type.startsWith("image/"));
const imageCompressionConfig = Config.get<ImageCompressionOptions>(
"imageCompression",
Expand Down Expand Up @@ -87,7 +90,7 @@ export async function attachFiles(files: File[]) {
const documents = files.filter((f) => !f.type.startsWith("image/"));
const attachments: Attachment[] = [];
for (const file of [...images, ...documents]) {
const attachment = file.type.startsWith("image/")
const attachment = !skipSpecialImageHandling && file.type.startsWith("image/")
? await pickImage(file)
: await pickFile(file);
if (!attachment) continue;
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/toolbar/tools/attachment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function RemoveAttachment(props: ToolProps) {
}

const previewableFileExtensions = ["pdf"];
const previewableMimeTypes = ["application/pdf"];
const previewableMimeTypes = ["application/pdf", "image/"];

function canPreviewAttachment(attachment: Attachment) {
if (!attachment) return false;
Expand Down
Loading