mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 12:19:06 +00:00
Remove nextjs zulip api
This commit is contained in:
@@ -45,7 +45,6 @@ def update_zulip_message(message_id: int, stream: str, topic: str, content: str)
|
|||||||
|
|
||||||
return response.json()
|
return response.json()
|
||||||
except requests.RequestException as error:
|
except requests.RequestException as error:
|
||||||
print(content)
|
|
||||||
raise Exception(f"Failed to update Zulip message: {error}")
|
raise Exception(f"Failed to update Zulip message: {error}")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,80 +0,0 @@
|
|||||||
import { GetTranscript, GetTranscriptTopic } from "../api";
|
|
||||||
import { formatTime, formatTimeMs } 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.created_at);
|
|
||||||
|
|
||||||
// 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 ?? "Unnamed recording"}
|
|
||||||
|
|
||||||
**Date**: <time:${dateTimeString}>
|
|
||||||
**Link**: [${extractDomain(link)}](${link})
|
|
||||||
**Duration**: ${formatTimeMs(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.long_summary;
|
|
||||||
summary += "```\n\n";
|
|
||||||
|
|
||||||
const message = headerText + summary + topicText + "-----\n";
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import { SessionProvider } from "next-auth/react";
|
|
||||||
|
|
||||||
export default function App({
|
|
||||||
Component,
|
|
||||||
pageProps: { session, ...pageProps },
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<SessionProvider session={session}>
|
|
||||||
<Component {...pageProps} />
|
|
||||||
</SessionProvider>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
import axios from "axios";
|
|
||||||
import { URLSearchParams } from "url";
|
|
||||||
import { getConfig } from "../../app/lib/edgeConfig";
|
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
|
||||||
const config = await getConfig();
|
|
||||||
const { sendToZulip } = config.features;
|
|
||||||
|
|
||||||
if (req.method === "POST") {
|
|
||||||
const { stream, topic, message } = req.body;
|
|
||||||
|
|
||||||
if (!stream || !topic || !message) {
|
|
||||||
return res.status(400).json({ error: "Missing required parameters" });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sendToZulip) {
|
|
||||||
return res.status(403).json({ error: "Zulip integration disabled" });
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Construct URL-encoded data
|
|
||||||
const params = new URLSearchParams();
|
|
||||||
params.append("type", "stream");
|
|
||||||
params.append("to", stream);
|
|
||||||
params.append("topic", topic);
|
|
||||||
params.append("content", message);
|
|
||||||
|
|
||||||
// Send the request1
|
|
||||||
const zulipResponse = await axios.post(
|
|
||||||
`https://${process.env.ZULIP_REALM}/api/v1/messages`,
|
|
||||||
params,
|
|
||||||
{
|
|
||||||
auth: {
|
|
||||||
username: process.env.ZULIP_BOT_EMAIL || "?",
|
|
||||||
password: process.env.ZULIP_API_KEY || "?",
|
|
||||||
},
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/x-www-form-urlencoded",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
return res.status(200).json(zulipResponse.data);
|
|
||||||
} catch (error) {
|
|
||||||
return res.status(500).json({ failed: true, error: error });
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
res.setHeader("Allow", ["POST"]);
|
|
||||||
res.status(405).end(`Method ${req.method} Not Allowed`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
import type { NextPage } from "next";
|
|
||||||
|
|
||||||
const Forbidden: NextPage = () => {
|
|
||||||
return <h2>Sorry, you are not authorized to access this page</h2>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Forbidden;
|
|
||||||
Reference in New Issue
Block a user