diff --git a/src/extenssion/bookmarkManager.js b/src/extenssion/bookmarkManager.js index f483262..5b1100a 100644 --- a/src/extenssion/bookmarkManager.js +++ b/src/extenssion/bookmarkManager.js @@ -5,6 +5,20 @@ import { updateBookmark, deleteBookmark, } from "../service/bookmarkService.js"; +import { + collection, + addDoc, + getDoc, + getDocs, + updateDoc, + deleteDoc, + doc, + query, + where, +} from "https://www.gstatic.com/firebasejs/9.22.1/firebase-firestore.js"; +import { db } from "../firebaseConfig.js"; + +const COLLECTION_NAME = "bookmarks"; class BookmarkManager { constructor(userId) { @@ -63,6 +77,61 @@ class BookmarkManager { throw error; } } + + async getAllTags() { + try { + const q = query( + collection(db, COLLECTION_NAME), + where("userId", "==", this.userId) + ); + const querySnapshot = await getDocs(q); + + // Use a Set to store unique tags + const tagSet = new Set(); + + querySnapshot.forEach((doc) => { + const bookmark = doc.data(); + if (bookmark.keywords && Array.isArray(bookmark.keywords)) { + bookmark.keywords.forEach((tag) => tagSet.add(tag)); + } + }); + + // Convert Set to Array and sort alphabetically + const allTags = Array.from(tagSet).sort((a, b) => a.localeCompare(b)); + + return allTags; + } catch (error) { + console.error("Error fetching all tags:", error); + throw error; + } + } + + async getTagCount() { + try { + const allTags = await this.getAllTags(); + const tagCount = {}; + + const q = query( + collection(db, COLLECTION_NAME), + where("userId", "==", this.userId) + ); + const querySnapshot = await getDocs(q); + + querySnapshot.forEach((doc) => { + const bookmark = doc.data(); + if (bookmark.keywords && Array.isArray(bookmark.keywords)) { + bookmark.keywords.forEach((tag) => { + tagCount[tag] = (tagCount[tag] || 0) + 1; + }); + } + }); + + return allTags.map((tag) => ({ tag, count: tagCount[tag] || 0 })); + } catch (error) { + console.error("Error getting tag count:", error); + throw error; + } + } } export default BookmarkManager; diff --git a/src/extenssion/bookmarks.js b/src/extenssion/bookmarks.js index 609a76f..3998366 100644 --- a/src/extenssion/bookmarks.js +++ b/src/extenssion/bookmarks.js @@ -9,6 +9,8 @@ let bookmarkManager; async function fetchLatestBookmarks() { try { + const tags = await bookmarkManager.getTagCount(); + console.log(tags); const allBookmarks = await bookmarkManager.getAllBookmarks(); const sortedBookmarks = allBookmarks.sort( (a, b) => b.timestamp - a.timestamp diff --git a/src/tag-classification/index.js b/src/tag-classification/index.js index 6b75328..0122459 100644 --- a/src/tag-classification/index.js +++ b/src/tag-classification/index.js @@ -1,6 +1,6 @@ import { GoogleGenerativeAI } from "https://esm.run/@google/generative-ai"; -const genAI = new GoogleGenerativeAI("AIzaSyAGGFFsi64yOm93TypJeZrweUo23gCKw2M"); +const genAI = new GoogleGenerativeAI(""); async function generateTags(url, title, summary, notes) { const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" }); diff --git a/src/text-summarization-model/index.js b/src/text-summarization-model/index.js index 5a9a6ce..96d6d35 100644 --- a/src/text-summarization-model/index.js +++ b/src/text-summarization-model/index.js @@ -1,6 +1,6 @@ import { GoogleGenerativeAI } from "https://esm.run/@google/generative-ai"; -const genAI = new GoogleGenerativeAI("AIzaSyAGGFFsi64yOm93TypJeZrweUo23gCKw2M"); +const genAI = new GoogleGenerativeAI(""); const parseCustomJson = async (text) => { try {