mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-08 05:39:13 +00:00
Only allow search model to be updated without being subscribed
Do not make fetch request to server if user is not subscribed
This commit is contained in:
@@ -13,6 +13,8 @@ export interface LocationData {
|
|||||||
|
|
||||||
const locationFetcher = () => window.fetch("https://ipapi.co/json").then((res) => res.json()).catch((err) => console.log(err));
|
const locationFetcher = () => window.fetch("https://ipapi.co/json").then((res) => res.json()).catch((err) => console.log(err));
|
||||||
|
|
||||||
|
export const toTitleCase = (str: string) => str.replace(/\w\S*/g, (txt) => txt.charAt(0).toUpperCase() + txt.slice(1).toLowerCase());
|
||||||
|
|
||||||
export function welcomeConsole() {
|
export function welcomeConsole() {
|
||||||
console.log(`%c %s`, "font-family:monospace", `
|
console.log(`%c %s`, "font-family:monospace", `
|
||||||
__ __ __ __ ______ __ _____ __
|
__ __ __ __ ______ __ _____ __
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { Suspense, useEffect, useState } from "react";
|
|||||||
import { useToast } from "@/components/ui/use-toast"
|
import { useToast } from "@/components/ui/use-toast"
|
||||||
|
|
||||||
import { useUserConfig, ModelOptions, UserConfig } from "../common/auth";
|
import { useUserConfig, ModelOptions, UserConfig } from "../common/auth";
|
||||||
|
import { toTitleCase } from "../common/utils";
|
||||||
|
|
||||||
import { isValidPhoneNumber } from 'libphonenumber-js';
|
import { isValidPhoneNumber } from 'libphonenumber-js';
|
||||||
|
|
||||||
@@ -449,7 +450,7 @@ export default function SettingsView() {
|
|||||||
title: "💳 Subscription",
|
title: "💳 Subscription",
|
||||||
description: state === "cancel" ? "Failed to cancel subscription. Try again or contact us at team@khoj.dev" : "Failed to renew subscription. Try again or contact us at team@khoj.dev",
|
description: state === "cancel" ? "Failed to cancel subscription. Try again or contact us at team@khoj.dev" : "Failed to renew subscription. Try again or contact us at team@khoj.dev",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const saveName = async () => {
|
const saveName = async () => {
|
||||||
@@ -485,6 +486,7 @@ export default function SettingsView() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const updateModel = (name: string) => async (id: string) => {
|
const updateModel = (name: string) => async (id: string) => {
|
||||||
|
if (!userConfig?.is_active && name !== "search") return;
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/model/${name}?id=` + id, {
|
const response = await fetch(`/api/model/${name}?id=` + id, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -496,12 +498,12 @@ export default function SettingsView() {
|
|||||||
if (!response.ok) throw new Error('Failed to update model');
|
if (!response.ok) throw new Error('Failed to update model');
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
description: `${name} model updated succesfully`,
|
title: `✅ Updated ${toTitleCase(name)} Model`,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Failed to update ${name} model:`, error);
|
console.error(`Failed to update ${name} model:`, error);
|
||||||
toast({
|
toast({
|
||||||
description: `Failed to update ${name} model. Try again.`,
|
description: `❌ Failed to update ${toTitleCase(name)} model. Try again.`,
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -601,7 +603,6 @@ export default function SettingsView() {
|
|||||||
description: `Your ${type} integration to Khoj has been disconnected.`,
|
description: `Your ${type} integration to Khoj has been disconnected.`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error disconnecting ${type}:`, error);
|
console.error(`Error disconnecting ${type}:`, error);
|
||||||
toast({
|
toast({
|
||||||
@@ -853,9 +854,6 @@ export default function SettingsView() {
|
|||||||
/>
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
<CardFooter className="flex flex-wrap gap-4">
|
<CardFooter className="flex flex-wrap gap-4">
|
||||||
{!userConfig.is_active && (
|
|
||||||
<p className="text-gray-400">Subscribe to switch model</p>
|
|
||||||
)}
|
|
||||||
</CardFooter>
|
</CardFooter>
|
||||||
</Card>
|
</Card>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user