Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

added ai tagging to the settings

daniel31x139075618e00f4
diff --git a/components/InputSelect/TagSelection.tsx b/components/InputSelect/TagSelection.tsx
index cf03e6f0..209ee7b4 100644
--- a/components/InputSelect/TagSelection.tsx
+++ b/components/InputSelect/TagSelection.tsx
@@ -3,6 +3,7 @@ import CreatableSelect from "react-select/creatable";
import { styles } from "./styles";
import { Options } from "./types";
import { useTags } from "@/hooks/store/tags";
+import { useTranslation } from "next-i18next";
type Props = {
onChange: any;
@@ -21,6 +22,7 @@ export default function TagSelection({
onBlur,
}: Props) {
const { data: tags = [] } = useTags();
+ const { t } = useTranslation();
const [options, setOptions] = useState<Options[]>([]);
@@ -41,6 +43,7 @@ export default function TagSelection({
options={options}
styles={styles}
defaultValue={defaultValue}
+ placeholder={t("tag_selection_placeholder")}
isMulti
autoFocus={autoFocus}
onBlur={onBlur}
diff --git a/components/InputSelect/styles.ts b/components/InputSelect/styles.ts
index 369366ce..ef2d8230 100644
--- a/components/InputSelect/styles.ts
+++ b/components/InputSelect/styles.ts
@@ -50,6 +50,7 @@ export const styles: StylesConfig = {
placeholder: (styles) => ({
...styles,
borderColor: "black",
+ color: "oklch(var(--n))",
}),
multiValue: (styles) => {
return {
diff --git a/components/RadioButton.tsx b/components/RadioButton.tsx
index 19d66066..978c73a3 100644
--- a/components/RadioButton.tsx
+++ b/components/RadioButton.tsx
@@ -1,18 +1,25 @@
+import clsx from "clsx";
import { ChangeEventHandler } from "react";
type Props = {
label: string;
+ className?: string;
state: boolean;
onClick: ChangeEventHandler<HTMLInputElement>;
};
-export default function RadioButton({ label, state, onClick }: Props) {
+export default function RadioButton({
+ label,
+ state,
+ onClick,
+ className,
+}: Props) {
return (
<label className="cursor-pointer flex items-center gap-2">
<input
type="radio"
value={label}
- className="peer sr-only"
+ className={clsx("peer sr-only", className)}
checked={state}
onChange={onClick}
/>
diff --git a/lib/api/controllers/users/userId/updateUserById.ts b/lib/api/controllers/users/userId/updateUserById.ts
index 8bc5e0f4..6cebe31b 100644
--- a/lib/api/controllers/users/userId/updateUserById.ts
+++ b/lib/api/controllers/users/userId/updateUserById.ts
@@ -201,6 +201,8 @@ export default async function updateUserById(
collectionOrder: data.collectionOrder?.filter(
(value, index, self) => self.indexOf(value) === index
),
+ aiTaggingMethod: data.aiTaggingMethod,
+ aiPredefinedTags: data.aiPredefinedTags,
locale: i18n.locales.includes(data.locale || "") ? data.locale : "en",
archiveAsScreenshot: data.archiveAsScreenshot,
archiveAsMonolith: data.archiveAsMonolith,
diff --git a/lib/shared/schemaValidation.ts b/lib/shared/schemaValidation.ts
index 11d6b92b..9bf402a8 100644
--- a/lib/shared/schemaValidation.ts
+++ b/lib/shared/schemaValidation.ts
@@ -1,5 +1,5 @@
import { ArchivedFormat, TokenExpiry } from "@/types/global";
-import { LinksRouteTo } from "@prisma/client";
+import { AiTaggingMethod, LinksRouteTo } from "@prisma/client";
import { z } from "zod";
// const stringField = z.string({
@@ -75,6 +75,8 @@ export const UpdateUserSchema = () => {
archiveAsPDF: z.boolean().optional(),
archiveAsMonolith: z.boolean().optional(),
archiveAsWaybackMachine: z.boolean().optional(),
+ aiTaggingMethod: z.nativeEnum(AiTaggingMethod).optional(),
+ aiPredefinedTags: z.array(z.string().max(20).trim()).max(20).optional(),
locale: z.string().max(20).optional(),
isPrivate: z.boolean().optional(),
preventDuplicateLinks: z.boolean().optional(),
diff --git a/pages/settings/account.tsx b/pages/settings/account.tsx
index db5bf345..d8dc8483 100644
--- a/pages/settings/account.tsx
+++ b/pages/settings/account.tsx
@@ -31,7 +31,6 @@ export default function Account() {
!objectIsEmpty(account)
? account
: ({
- // @ts-ignore
id: null,
name: "",
username: "",
@@ -39,8 +38,7 @@ export default function Account() {
emailVerified: null,
password: undefined,
image: "",
- isPrivate: true,
- // @ts-ignore
+ isPrivate: false,
createdAt: null,
whitelistedUsers: [],
} as unknown as AccountSettings)
diff --git a/pages/settings/preference.tsx b/pages/settings/preference.tsx
index 13e04973..a7ea3c15 100644
--- a/pages/settings/preference.tsx
+++ b/pages/settings/preference.tsx
@@ -5,9 +5,10 @@ import { toast } from "react-hot-toast";
import Checkbox from "@/components/Checkbox";
import useLocalSettingsStore from "@/store/localSettings";
import { useTranslation } from "next-i18next";
-import getServerSideProps from "@/lib/client/getServerSideProps"; // Import getServerSideProps for server-side data fetching
-import { LinksRouteTo } from "@prisma/client";
+import getServerSideProps from "@/lib/client/getServerSideProps";
+import { AiTaggingMethod, LinksRouteTo } from "@prisma/client";
import { useUpdateUser, useUser } from "@/hooks/store/user";
+import TagSelection from "@/components/InputSelect/TagSelection";
export default function Appearance() {
const { t } = useTranslation();
@@ -18,23 +19,24 @@ export default function Appearance() {
const [user, setUser] = useState(account);
const [preventDuplicateLinks, setPreventDuplicateLinks] = useState<boolean>(
- account.preventDuplicateLinks
+ account.preventDuplicateLinks || false
);
const [archiveAsScreenshot, setArchiveAsScreenshot] = useState<boolean>(
- account.archiveAsScreenshot
+ account.archiveAsScreenshot || false
);
const [archiveAsPDF, setArchiveAsPDF] = useState<boolean>(
- account.archiveAsPDF
+ account.archiveAsPDF || false
);
-
const [archiveAsMonolith, setArchiveAsMonolith] = useState<boolean>(
- account.archiveAsMonolith
+ account.archiveAsMonolith || false
);
-
const [archiveAsWaybackMachine, setArchiveAsWaybackMachine] =
- useState<boolean>(account.archiveAsWaybackMachine);
-
+ useState<boolean>(account.archiveAsWaybackMachine || false);
const [linksRouteTo, setLinksRouteTo] = useState(account.linksRouteTo);
+ const [aiTaggingMethod, setAiTaggingMethod] = useState<AiTaggingMethod>(
+ account.aiTaggingMethod
+ );
+ const [aiPredefinedTags, setAiPredefinedTags] = useState<string[]>();
useEffect(() => {
setUser({
@@ -45,6 +47,8 @@ export default function Appearance() {
archiveAsWaybackMachine,
linksRouteTo,
preventDuplicateLinks,
+ aiTaggingMethod,
+ aiPredefinedTags,
});
}, [
account,
@@ -54,6 +58,8 @@ export default function Appearance() {
archiveAsWaybackMachine,
linksRouteTo,
preventDuplicateLinks,
+ aiTaggingMethod,
+ aiPredefinedTags,
]);
function objectIsEmpty(obj: object) {
@@ -68,6 +74,8 @@ export default function Appearance() {
setArchiveAsWaybackMachine(account.archiveAsWaybackMachine);
setLinksRouteTo(account.linksRouteTo);
setPreventDuplicateLinks(account.preventDuplicateLinks);
+ setAiTaggingMethod(account.aiTaggingMethod);
+ setAiPredefinedTags(account.aiPredefinedTags);
}
}, [account]);
@@ -128,6 +136,88 @@ export default function Appearance() {
</div>
</div>
+ <div>
+ <p className="capitalize text-3xl font-thin inline">
+ {t("ai_settings")}
+ </p>
+ <div className="divider my-3"></div>
+
+ <p>{t("ai_tagging_method")}</p>
+
+ <div className="p-3">
+ <label
+ className="label cursor-pointer flex gap-2 justify-start w-fit"
+ tabIndex={0}
+ role="button"
+ >
+ <input
+ type="radio"
+ name="ai-tagging-method-radio"
+ className="radio checked:bg-primary"
+ value="DISABLED"
+ checked={aiTaggingMethod === AiTaggingMethod.DISABLED}
+ onChange={() => setAiTaggingMethod(AiTaggingMethod.DISABLED)}
+ />
+ <span className="label-text">{t("disabled")}</span>
+ </label>
+ <p className="text-neutral text-sm pl-5">
+ {t("ai_tagging_disabled_desc")}
+ </p>
+
+ <label
+ className="label cursor-pointer flex gap-2 justify-start w-fit"
+ tabIndex={0}
+ role="button"
+ >
+ <input
+ type="radio"
+ name="ai-tagging-method-radio"
+ className="radio checked:bg-primary"
+ value="GENERATE"
+ checked={aiTaggingMethod === AiTaggingMethod.GENERATE}
+ onChange={() => setAiTaggingMethod(AiTaggingMethod.GENERATE)}
+ />
+ <span className="label-text">{t("auto_generate_tags")}</span>
+ </label>
+ <p className="text-neutral text-sm pl-5">
+ {t("auto_generate_tags_desc")}
+ </p>
+
+ <label
+ className="label cursor-pointer flex gap-2 justify-start w-fit"
+ tabIndex={0}
+ role="button"
+ >
+ <input
+ type="radio"
+ name="ai-tagging-method-radio"
+ className="radio checked:bg-primary"
+ value="PREDEFINED"
+ checked={aiTaggingMethod === AiTaggingMethod.PREDEFINED}
+ onChange={() => setAiTaggingMethod(AiTaggingMethod.PREDEFINED)}
+ />
+ <span className="label-text">
+ {t("based_on_predefined_tags")}
+ </span>
+ </label>
+ <div className="pl-5">
+ <p className="text-neutral text-sm mb-2">
+ {t("based_on_predefined_tags_desc")}
+ </p>
+ {aiPredefinedTags && (
+ <TagSelection
+ onChange={(e: any) => {
+ setAiPredefinedTags(e.map((e: any) => e.label));
+ }}
+ defaultValue={aiPredefinedTags
+ .map((e) => ({ label: e }))
+ .filter((e) => e.label !== "")}
+ />
+ )}
+ </div>
+ </div>
+ </div>
+
<div>
<p className="capitalize text-3xl font-thin inline">
{t("archive_settings")}
diff --git a/prisma/migrations/20241129171823_add_ai_tagging_fields/migration.sql b/prisma/migrations/20241129171823_add_ai_tagging_fields/migration.sql
new file mode 100644
index 00000000..8ca2b4ef
--- /dev/null
+++ b/prisma/migrations/20241129171823_add_ai_tagging_fields/migration.sql
@@ -0,0 +1,6 @@
+-- CreateEnum
+CREATE TYPE "AiTaggingMethod" AS ENUM ('DISABLED', 'GENERATE', 'PREDEFINED');
+
+-- AlterTable
+ALTER TABLE "User" ADD COLUMN "aiPredefinedTags" TEXT[] DEFAULT ARRAY[]::TEXT[],
+ADD COLUMN "aiTaggingMethod" "AiTaggingMethod" NOT NULL DEFAULT 'DISABLED';
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 89738ef4..e07cd464 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -49,6 +49,8 @@ model User {
accessTokens AccessToken[]
subscriptions Subscription?
linksRouteTo LinksRouteTo @default(ORIGINAL)
+ aiTaggingMethod AiTaggingMethod @default(DISABLED)
+ aiPredefinedTags String[] @default([])
preventDuplicateLinks Boolean @default(false)
archiveAsScreenshot Boolean @default(true)
archiveAsMonolith Boolean @default(true)
@@ -60,6 +62,12 @@ model User {
updatedAt DateTime @default(now()) @updatedAt
}
+enum AiTaggingMethod {
+ DISABLED
+ GENERATE
+ PREDEFINED
+}
+
enum LinksRouteTo {
ORIGINAL
PDF
diff --git a/public/locales/en/common.json b/public/locales/en/common.json
index 256bfff0..17ae80fb 100644
--- a/public/locales/en/common.json
+++ b/public/locales/en/common.json
@@ -429,5 +429,14 @@
"reddit": "Reddit",
"lemmy": "Lemmy",
"people_recommendation": "Recommendation (Friend, Family, etc.)",
- "open_all_links": "Open all Links"
+ "open_all_links": "Open all Links",
+ "ai_settings": "AI Settings",
+ "ai_tagging_method": "AI Tagging Method:",
+ "based_on_predefined_tags": "Based on predefined Tags",
+ "based_on_predefined_tags_desc": "Auto-categorize links to predefined tags based on the content of each link.",
+ "auto_generate_tags": "Auto-generate Tags",
+ "auto_generate_tags_desc": "Auto-generate relevant tags based on the content of each link.",
+ "disabled": "Disabled",
+ "ai_tagging_disabled_desc": "AI tagging is disabled.",
+ "tag_selection_placeholder": "Choose or add custom tags…"
}
\ No newline at end of file
diff --git a/scripts/worker.ts b/scripts/worker.ts
index 81bd53ef..8629bd67 100644
--- a/scripts/worker.ts
+++ b/scripts/worker.ts
@@ -45,6 +45,20 @@ async function processBatch() {
{
monolith: "pending",
},
+ ///////////////////////
+ {
+ // See if tags are empty
+ collection: {
+ owner: {
+ NOT: {
+ aiTaggingMethod: "DISABLED",
+ },
+ },
+ },
+ tags: {
+ none: {},
+ },
+ },
],
},
take: archiveTakeCount,
@@ -89,6 +103,20 @@ async function processBatch() {
{
monolith: "pending",
},
+ ///////////////////////
+ {
+ // See if tags are empty
+ collection: {
+ owner: {
+ NOT: {
+ aiTaggingMethod: "DISABLED",
+ },
+ },
+ },
+ tags: {
+ none: {},
+ },
+ },
],
},
take: archiveTakeCount,