mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
Temp commit to merge main into this branch
This commit is contained in:
@@ -121,3 +121,13 @@ export const generateHighContrastColor = (
|
||||
|
||||
return getCssColor(red, green, blue);
|
||||
};
|
||||
|
||||
export function extractDomain(url) {
|
||||
try {
|
||||
const parsedUrl = new URL(url);
|
||||
return parsedUrl.host;
|
||||
} catch (error) {
|
||||
console.error("Invalid URL:", error.message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
80
www/app/lib/zulip.ts
Normal file
80
www/app/lib/zulip.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { GetTranscript, GetTranscriptTopic } from "../api";
|
||||
import { formatTime } from "./time";
|
||||
import { extractDomain } from "./utils";
|
||||
|
||||
export async function sendZulipMessage(
|
||||
stream: string,
|
||||
topic: string,
|
||||
message: string,
|
||||
) {
|
||||
console.log("Sendiing zulip message", stream, topic);
|
||||
try {
|
||||
const response = await fetch("/api/send-zulip-message", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ stream, topic, message }),
|
||||
});
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export const ZULIP_MSG_MAX_LENGTH = 10000;
|
||||
|
||||
export function getZulipMessage(
|
||||
transcript: GetTranscript,
|
||||
topics: GetTranscriptTopic[] | null,
|
||||
includeTopics: boolean,
|
||||
) {
|
||||
const date = new Date(transcript.createdAt);
|
||||
|
||||
// Get the timezone offset in minutes and convert it to hours and minutes
|
||||
const timezoneOffset = -date.getTimezoneOffset();
|
||||
const offsetHours = String(
|
||||
Math.floor(Math.abs(timezoneOffset) / 60),
|
||||
).padStart(2, "0");
|
||||
const offsetMinutes = String(Math.abs(timezoneOffset) % 60).padStart(2, "0");
|
||||
const offsetSign = timezoneOffset >= 0 ? "+" : "-";
|
||||
|
||||
// Combine to get the formatted timezone offset
|
||||
const formattedOffset = `${offsetSign}${offsetHours}:${offsetMinutes}`;
|
||||
|
||||
// Now you can format your date and time string using this offset
|
||||
const formattedDate = date.toISOString().slice(0, 10);
|
||||
const hours = String(date.getHours()).padStart(2, "0");
|
||||
const minutes = String(date.getMinutes()).padStart(2, "0");
|
||||
const seconds = String(date.getSeconds()).padStart(2, "0");
|
||||
|
||||
const dateTimeString = `${formattedDate}T${hours}:${minutes}:${seconds}${formattedOffset}`;
|
||||
|
||||
const domain = window.location.origin; // Gives you "http://localhost:3000" or your deployment base URL
|
||||
const link = `${domain}/transcripts/${transcript.id}`;
|
||||
|
||||
let headerText = `# Reflector – ${transcript.title}
|
||||
|
||||
**Date**: <time:${dateTimeString}>
|
||||
**Link**: [${extractDomain(link)}](${link})
|
||||
**Duration**: ${formatTime(transcript.duration)}
|
||||
|
||||
`;
|
||||
let topicText = "";
|
||||
|
||||
if (topics && includeTopics) {
|
||||
topicText = "```spoiler Topics\n";
|
||||
topics.forEach((topic) => {
|
||||
topicText += `1. [${formatTime(topic.timestamp)}] ${topic.title}\n`;
|
||||
});
|
||||
topicText += "```\n\n";
|
||||
}
|
||||
|
||||
let summary = "```spoiler Summary\n";
|
||||
summary += transcript.longSummary;
|
||||
summary += "```\n\n";
|
||||
|
||||
const message = "----\n\n" + headerText + summary + topicText + "-----\n";
|
||||
return message;
|
||||
}
|
||||
Reference in New Issue
Block a user