diff --git a/packages/core/src/collections/attachments.ts b/packages/core/src/collections/attachments.ts
index 8f5fcce2e..dbd15de85 100644
--- a/packages/core/src/collections/attachments.ts
+++ b/packages/core/src/collections/attachments.ts
@@ -315,7 +315,7 @@ export class Attachments implements ICollection {
if (!data) return;
return (
- outputType === "base64"
+ outputType === "base64" && typeof data === "string"
? dataurl.fromObject({
mimeType: attachment.mimeType,
data
diff --git a/packages/core/src/collections/content.ts b/packages/core/src/collections/content.ts
index aef445505..5068640f2 100644
--- a/packages/core/src/collections/content.ts
+++ b/packages/core/src/collections/content.ts
@@ -20,10 +20,8 @@ along with this program. If not, see .
import { ICollection } from "./collection";
import { getId } from "../utils/id";
import { getContentFromData } from "../content-types";
-import { ResolveHashes } from "../content-types/tiptap";
import { isCipher } from "../database/crypto";
import {
- Attachment,
ContentItem,
ContentType,
UnencryptedContentItem,
@@ -254,24 +252,6 @@ export class Content implements ICollection {
// );
// }
- insertMedia(contentItem: UnencryptedContentItem) {
- return this.insert(contentItem, async (hashes) => {
- const sources: Record = {};
- for (const hash of hashes) {
- const src = await this.db.attachments.read(hash, "base64");
- if (!src) continue;
- sources[hash] = src;
- }
- return sources;
- });
- }
-
- insertPlaceholders(contentItem: UnencryptedContentItem, placeholder: string) {
- return this.insert(contentItem, async (hashes) => {
- return Object.fromEntries(hashes.map((h) => [h, placeholder]));
- });
- }
-
async downloadMedia(
groupId: string,
contentItem: { type: ContentType; data: string },
@@ -280,12 +260,9 @@ export class Content implements ICollection {
const content = getContentFromData(contentItem.type, contentItem.data);
if (!content) return contentItem;
contentItem.data = await content.insertMedia(async (hashes) => {
- const attachments: Attachment[] = [];
- for (const hash of hashes) {
- const attachment = await this.db.attachments.attachment(hash);
- if (!attachment) continue;
- attachments.push(attachment);
- }
+ const attachments = await this.db.attachments.all
+ .where((eb) => eb("attachments.hash", "in", hashes))
+ .items();
await this.db.fs().queueDownloads(
attachments.map((a) => ({
@@ -302,7 +279,7 @@ export class Content implements ICollection {
attachment.hash,
getOutputType(attachment)
);
- if (!src) continue;
+ if (!src || typeof src !== "string") continue;
sources[attachment.hash] = src;
}
return sources;
@@ -310,16 +287,6 @@ export class Content implements ICollection {
return contentItem;
}
- private async insert(
- contentItem: UnencryptedContentItem,
- getData: ResolveHashes
- ) {
- const content = getContentFromData(contentItem.type, contentItem.data);
- if (!content) return contentItem;
- contentItem.data = await content.insertMedia(getData);
- return contentItem;
- }
-
async removeAttachments(id: string, hashes: string[]) {
const contentItem = await this.get(id);
if (!contentItem || isCipher(contentItem.data)) return;