Added feature for "sendToZulip", fixed visual issue, .gitignore for db dump files

This commit is contained in:
Koper
2023-12-05 20:17:25 +07:00
parent 702dd5968b
commit 9df6ab4429
8 changed files with 28 additions and 12 deletions

BIN
dump.rdb

Binary file not shown.

2
server/.gitignore vendored
View File

@@ -178,3 +178,5 @@ audio_*.wav
# ignore local database # ignore local database
reflector.sqlite3 reflector.sqlite3
data/ data/
dump.rdb

Binary file not shown.

View File

@@ -9,6 +9,7 @@ export const DomainContext = createContext<DomainContextType>({
requireLogin: false, requireLogin: false,
privacy: true, privacy: true,
browse: false, browse: false,
sendToZulip: false,
}, },
api_url: "", api_url: "",
websocket_url: "", websocket_url: "",
@@ -38,7 +39,7 @@ export const DomainContextProvider = ({
// Get feature config client-side with // Get feature config client-side with
export const featureEnabled = ( export const featureEnabled = (
featureName: "requireLogin" | "privacy" | "browse", featureName: "requireLogin" | "privacy" | "browse" | "sendToZulip",
) => { ) => {
const context = useContext(DomainContext); const context = useContext(DomainContext);
return context.features[featureName] as boolean | undefined; return context.features[featureName] as boolean | undefined;

View File

@@ -87,7 +87,7 @@ const ShareModal = (props: ShareModal) => {
} }
return ( return (
<div> <div className="absolute">
{props.show && ( {props.show && (
<div className="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full z-50"> <div className="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full z-50">
<div className="relative top-20 mx-auto p-5 w-96 shadow-lg rounded-md bg-white"> <div className="relative top-20 mx-auto p-5 w-96 shadow-lg rounded-md bg-white">

View File

@@ -3,6 +3,7 @@ import React from "react";
import Markdown from "react-markdown"; import Markdown from "react-markdown";
import "../../styles/markdown.css"; import "../../styles/markdown.css";
import getApi from "../../lib/getApi"; import getApi from "../../lib/getApi";
import { featureEnabled } from "../domainContext";
type FinalSummaryProps = { type FinalSummaryProps = {
summary: string; summary: string;
@@ -117,14 +118,17 @@ export default function FinalSummary(props: FinalSummaryProps) {
{!isEditMode && ( {!isEditMode && (
<> <>
<button {featureEnabled("sendToZulip") && (
className={ <button
"bg-blue-400 hover:bg-blue-500 focus-visible:bg-blue-500 text-white rounded p-2 sm:text-base" className={
} "bg-blue-400 hover:bg-blue-500 focus-visible:bg-blue-500 text-white rounded p-2 sm:text-base"
onClick={() => props.openZulipModal()} }
> onClick={() => props.openZulipModal()}
<span className="text-xs"> Zulip</span> >
</button> <span className="text-xs"> Zulip</span>
</button>
)}
<button <button
onClick={onEditClick} onClick={onEditClick}
className={ className={

View File

@@ -6,6 +6,7 @@ const localConfig = {
requireLogin: true, requireLogin: true,
privacy: true, privacy: true,
browse: true, browse: true,
sendToZulip: true,
}, },
api_url: "http://127.0.0.1:1250", api_url: "http://127.0.0.1:1250",
websocket_url: "ws://127.0.0.1:1250", websocket_url: "ws://127.0.0.1:1250",
@@ -15,7 +16,11 @@ const localConfig = {
type EdgeConfig = { type EdgeConfig = {
[domainWithDash: string]: { [domainWithDash: string]: {
features: { features: {
[featureName in "requireLogin" | "privacy" | "browse"]: boolean; [featureName in
| "requireLogin"
| "privacy"
| "browse"
| "sendToZulip"]: boolean;
}; };
auth_callback_url: string; auth_callback_url: string;
websocket_url: string; websocket_url: string;

View File

@@ -1,15 +1,19 @@
import axios from "axios"; import axios from "axios";
import { URLSearchParams } from "url"; import { URLSearchParams } from "url";
import { featureEnabled } from "../../app/[domain]/domainContext";
export default async function handler(req, res) { export default async function handler(req, res) {
if (req.method === "POST") { if (req.method === "POST") {
const { stream, topic, message } = req.body; const { stream, topic, message } = req.body;
console.log("Sending zulip message", stream, topic);
if (!stream || !topic || !message) { if (!stream || !topic || !message) {
return res.status(400).json({ error: "Missing required parameters" }); return res.status(400).json({ error: "Missing required parameters" });
} }
if (!featureEnabled("sendToZulip")) {
return res.status(403).json({ error: "Zulip integration disabled" });
}
try { try {
// Construct URL-encoded data // Construct URL-encoded data
const params = new URLSearchParams(); const params = new URLSearchParams();