From d04e61760724c359dc4e8f04ce7b8334aedbb4af Mon Sep 17 00:00:00 2001 From: Sergey Mankovsky Date: Fri, 6 Sep 2024 16:12:41 +0200 Subject: [PATCH] Remove nextjs zulip api --- server/reflector/zulip.py | 1 - www/app/lib/zulip.ts | 80 ----------------------------- www/pages/_app.jsx | 12 ----- www/pages/api/send-zulip-message.ts | 51 ------------------ www/pages/forbidden.tsx | 7 --- 5 files changed, 151 deletions(-) delete mode 100644 www/app/lib/zulip.ts delete mode 100644 www/pages/_app.jsx delete mode 100644 www/pages/api/send-zulip-message.ts delete mode 100644 www/pages/forbidden.tsx diff --git a/server/reflector/zulip.py b/server/reflector/zulip.py index fe8e1e61..df417558 100644 --- a/server/reflector/zulip.py +++ b/server/reflector/zulip.py @@ -45,7 +45,6 @@ def update_zulip_message(message_id: int, stream: str, topic: str, content: str) return response.json() except requests.RequestException as error: - print(content) raise Exception(f"Failed to update Zulip message: {error}") diff --git a/www/app/lib/zulip.ts b/www/app/lib/zulip.ts deleted file mode 100644 index 042f501c..00000000 --- a/www/app/lib/zulip.ts +++ /dev/null @@ -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**: -**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; -} diff --git a/www/pages/_app.jsx b/www/pages/_app.jsx deleted file mode 100644 index 819ee566..00000000 --- a/www/pages/_app.jsx +++ /dev/null @@ -1,12 +0,0 @@ -import { SessionProvider } from "next-auth/react"; - -export default function App({ - Component, - pageProps: { session, ...pageProps }, -}) { - return ( - - - - ); -} diff --git a/www/pages/api/send-zulip-message.ts b/www/pages/api/send-zulip-message.ts deleted file mode 100644 index 2f971241..00000000 --- a/www/pages/api/send-zulip-message.ts +++ /dev/null @@ -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`); - } -} diff --git a/www/pages/forbidden.tsx b/www/pages/forbidden.tsx deleted file mode 100644 index ada3d424..00000000 --- a/www/pages/forbidden.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import type { NextPage } from "next"; - -const Forbidden: NextPage = () => { - return

Sorry, you are not authorized to access this page

; -}; - -export default Forbidden;