⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
wip
daniel31x135a468b44a1f2
diff --git a/lib/api/controllers/links/linkId/updateLinkById.ts b/lib/api/controllers/links/linkId/updateLinkById.tsindex cab64add..07b9af2c 100644--- a/lib/api/controllers/links/linkId/updateLinkById.ts+++ b/lib/api/controllers/links/linkId/updateLinkById.ts@@ -178,8 +178,6 @@ export default async function updateLinkById(},});- meiliClient?.index("links").deleteDocument(updatedLink.id);-if (collectionIsAccessible?.id !== data.collection.id) {await moveFiles(linkId, collectionIsAccessible?.id, data.collection.id);}diff --git a/lib/api/searchQueryBuilder.ts b/lib/api/searchQueryBuilder.tsindex 2f1f003e..01ee504d 100644--- a/lib/api/searchQueryBuilder.ts+++ b/lib/api/searchQueryBuilder.ts@@ -9,27 +9,52 @@ export function parseSearchTokens(searchQueryString: string): Token[] {const tokens: Token[] = [];for (const token of rawTokens) {- if (token.startsWith("url:")) {+ if (token.startsWith("url:") && token.length > "url:".length) {tokens.push({ field: "url", value: token.substring("url:".length) });- } else if (token.startsWith("name:")) {+ } else if (token.startsWith("name:") && token.length > "name:".length) {tokens.push({ field: "name", value: token.substring("name:".length) });- } else if (token.startsWith("description:")) {+ } else if (+ token.startsWith("description:") &&+ token.length > "description:".length+ ) {tokens.push({field: "description",value: token.substring("description:".length),});- } else if (token.startsWith("collection:")) {+ } else if (token.startsWith("type:") && token.length > "type:".length) {+ tokens.push({ field: "type", value: token.substring("type:".length) });+ } else if (token.startsWith("before:") && token.length > "before:".length) {+ tokens.push({+ field: "before",+ value: token.substring("before:".length),+ });+ } else if (token.startsWith("after:") && token.length > "after:".length) {+ if (token.startsWith("after:")) {+ tokens.push({+ field: "after",+ value: token.substring("after:".length),+ });+ }+ } else if (+ token.startsWith("collection:") &&+ token.length > "collection:".length+ ) {tokens.push({field: "collection",value: token.substring("collection:".length),});- } else if (token.startsWith("pinned:")) {+ } else if (token === "pinned:true" || token === "pinned:false") {tokens.push({field: "pinned",value: token.substring("pinned:".length).toLowerCase(),});- } else if (token.startsWith("#")) {+ } else if (token.startsWith("#") && token.length > 1) {tokens.push({ field: "tag", value: token.substring(1) });+ } else if (token === "public:true") {+ tokens.push({+ field: "public",+ value: token.substring("public:".length).toLowerCase(),+ });} else {// everything else -> 'general' texttokens.push({ field: "general", value: token });@@ -54,32 +79,48 @@ export function buildMeiliFilters(tokens: Token[], userId: number): string[] {for (const { field, value } of tokens) {switch (field) {- // case "url":- // filters.push(`url = "${escapeForMeilisearch(value)}"`);- // break;- // case "name":- // filters.push(`name = "${escapeForMeilisearch(value)}"`);- // break;- // case "description":- // filters.push(`description = "${escapeForMeilisearch(value)}"`);- // break;-- // case "collection":- // filters.push(`collectionName = "${escapeForMeilisearch(value)}"`);- // break;-- // case "pinned":- // if (value === "true") {- // filters.push("pinnedBy = ${userId}");- // } else if (value === "false") {- // filters.push("pinned = false");- // }- // break;-- // case "tag":- // filters.push(`tags = "${escapeForMeilisearch(value)}"`);- // break;-+ case "url":+ filters.push(`url = "${escapeForMeilisearch(value)}"`);+ break;+ case "name":+ filters.push(`name = "${escapeForMeilisearch(value)}"`);+ break;+ case "description":+ filters.push(`description = "${escapeForMeilisearch(value)}"`);+ break;+ case "type":+ filters.push(`type = "${escapeForMeilisearch(value)}"`);+ break;+ case "collection":+ filters.push(`collectionName = "${escapeForMeilisearch(value)}"`);+ break;+ case "pinned":+ if (value === "true") {+ filters.push(`pinnedBy = ${userId}`);+ } else if (value === "false") {+ filters.push(`NOT pinnedBy = ${userId}`);+ }+ break;+ case "public":+ if (value === "true") {+ filters.push(`collectionIsPublic = true`);+ }+ break;+ case "before":+ if (!isNaN(Date.parse(value))) {+ const creationTimestamp = Date.parse(value) / 1000;+ filters.push(`creationTimestamp < ${creationTimestamp}`);+ }+ break;+ case "after":+ if (!isNaN(Date.parse(value))) {+ const creationTimestamp = Date.parse(value) / 1000;+ filters.push(`creationTimestamp > ${creationTimestamp}`);+ }+ break;+ case "tag":+ filters.push(`tags = "${escapeForMeilisearch(value)}"`);+ break;case "general":default:break;diff --git a/scripts/worker.ts b/scripts/worker.tsindex c15fabaf..d0ecbabf 100644--- a/scripts/worker.ts+++ b/scripts/worker.ts@@ -193,8 +193,15 @@ async function setupLinksIndexSchema() {.updateFilterableAttributes(["collectionOwnerId","collectionMemberIds",- // "collectionName",- // "tagNames",+ "collectionName",+ "tags",+ "pinnedBy",+ "url",+ "type",+ "name",+ "description",+ "collectionIsPublic",+ "creationTimestamp",]);await meiliClient.index("links")@@ -217,6 +224,8 @@ async function setupLinksIndexSchema() {.catch((err) => {console.error("\x1b[34m%s\x1b[0m", `Error indexing links:`, err);});++ // if (process.env.NODE_ENV !== "production") await clearIndexes(); // For development/debugging purposes ONLY! This function clears all the indexes and you'll have to reindex everything...}export async function startIndexing() {@@ -231,7 +240,7 @@ export async function startIndexing() {while (true) {const links = await getLinkBatch({where: {- indexVersion: { not: INDEX_VERSION },+ OR: [{ indexVersion: { not: INDEX_VERSION } }, { indexVersion: null }],lastPreserved: { not: null },},take: indexTakeCount,@@ -262,16 +271,20 @@ export async function startIndexing() {...link,collectionOwnerId: link.collection.ownerId,collectionMemberIds: link.collection.members.map((m) => m.userId),+ collectionIsPublic: link.collection.isPublic,collectionName: link.collection.name,tags: link.tags.map((t) => t.name),pinnedBy: link.pinnedBy.map((p) => p.id),+ creationTimestamp: Date.parse(link.createdAt.toISOString()) / 1000,}));+ console.log(docs);+const task = await meiliClient.index("links").addDocuments(docs);await meiliClient.index("links").waitForTask(task.taskUid, {- timeOutMs: 100000,+ timeOutMs: 300000,}).catch((err) => {console.error("\x1b[34m%s\x1b[0m", `Error indexing links:`, err);@@ -283,9 +296,18 @@ export async function startIndexing() {data: { indexVersion: INDEX_VERSION },});+ const indexesLeft = await prisma.link.count({+ where: {+ OR: [{ indexVersion: { not: INDEX_VERSION } }, { indexVersion: null }],+ lastPreserved: { not: null },+ },+ });+console.log("\x1b[34m%s\x1b[0m",- `Indexed ${links.length} link${links.length === 1 ? "" : "s"}.`+ `Indexed ${links.length} link${+ links.length === 1 ? "" : "s"+ }, ${indexesLeft} left.`);await delay(archiveIntervalInSeconds);@@ -300,3 +322,26 @@ async function init() {}init();++const clearIndexes = async () => {+ console.log("Clearing db indexes...");++ const clearedLinks = await prisma.link.updateMany({+ where: {},+ data: {+ indexVersion: null,+ },+ });++ console.log("Cleared db indexes:", clearedLinks);++ if (!meiliClient) return;++ const deleteAllDocuments = await meiliClient+ .index("links")+ .deleteAllDocuments();++ await meiliClient.index("links").waitForTask(deleteAllDocuments.taskUid, {+ timeOutMs: 1000000,+ });+};