aboutsummaryrefslogtreecommitdiff
path: root/apps/cf-ai-backend/src/queueConsumer/helpers/processNotes.ts
blob: 466690cc9f9de5c2833124ecb7eef580ca590bab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Result, Ok, Err } from "../../errors/results";
import { BaseError } from "../../errors/baseError";
import { Metadata } from "../utils/get-metadata";

class ProcessNotesError extends BaseError {
	constructor(message?: string, source?: string) {
		super("[Note Processing Error]", message, source);
	}
}

type ProcessNoteResult = {
	noteContent: { noteId: number; noteContent: string };
	metadata: Metadata;
};

export function processNote(
	content: string,
): Result<ProcessNoteResult, ProcessNotesError> {
	try {
		const pageContent = content;
		const noteId = new Date().getTime();

		const metadata = {
			baseUrl: `https://supermemory.ai/note/${noteId}`,
			description: `Note created at ${new Date().toLocaleString()}`,
			image: "https://supermemory.ai/logo.png",
			title: `${pageContent.slice(0, 20)} ${pageContent.length > 20 ? "..." : ""}`,
		};

		const noteContent = { noteId: noteId, noteContent: pageContent };
		return Ok({ noteContent, metadata });
	} catch (e) {
		console.error("[Note Processing Error]", e);
		return Err(new ProcessNotesError((e as Error).message, "processNote"));
	}
}