aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/open-api/karakeep-openapi-spec.json32
-rw-r--r--packages/shared/types/users.ts8
-rw-r--r--packages/trpc/models/users.ts13
3 files changed, 52 insertions, 1 deletions
diff --git a/packages/open-api/karakeep-openapi-spec.json b/packages/open-api/karakeep-openapi-spec.json
index 2e791fbf..4f846cef 100644
--- a/packages/open-api/karakeep-openapi-spec.json
+++ b/packages/open-api/karakeep-openapi-spec.json
@@ -3397,6 +3397,35 @@
]
},
"maxItems": 10
+ },
+ "bookmarksBySource": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "source": {
+ "type": "string",
+ "nullable": true,
+ "enum": [
+ "api",
+ "web",
+ "cli",
+ "mobile",
+ "extension",
+ "singlefile",
+ "rss",
+ "import"
+ ]
+ },
+ "count": {
+ "type": "number"
+ }
+ },
+ "required": [
+ "source",
+ "count"
+ ]
+ }
}
},
"required": [
@@ -3411,7 +3440,8 @@
"totalAssetSize",
"assetsByType",
"bookmarkingActivity",
- "tagUsage"
+ "tagUsage",
+ "bookmarksBySource"
]
}
}
diff --git a/packages/shared/types/users.ts b/packages/shared/types/users.ts
index 758b757d..830fe87b 100644
--- a/packages/shared/types/users.ts
+++ b/packages/shared/types/users.ts
@@ -1,5 +1,7 @@
import { z } from "zod";
+import { zBookmarkSourceSchema } from "./bookmarks";
+
export const PASSWORD_MIN_LENGTH = 8;
export const PASSWORD_MAX_LENGTH = 100;
@@ -91,6 +93,12 @@ export const zUserStatsResponseSchema = z.object({
}),
)
.max(10),
+ bookmarksBySource: z.array(
+ z.object({
+ source: zBookmarkSourceSchema.nullable(),
+ count: z.number(),
+ }),
+ ),
});
export const zUserSettingsSchema = z.object({
diff --git a/packages/trpc/models/users.ts b/packages/trpc/models/users.ts
index a327e7db..7e6be7a5 100644
--- a/packages/trpc/models/users.ts
+++ b/packages/trpc/models/users.ts
@@ -506,6 +506,7 @@ export class User implements PrivacyAware {
[{ thisYear }],
bookmarkTimestamps,
tagUsage,
+ bookmarksBySource,
] = await Promise.all([
// Basic counts
this.ctx.db
@@ -677,6 +678,17 @@ export class User implements PrivacyAware {
.groupBy(bookmarkTags.name)
.orderBy(desc(count()))
.limit(10),
+
+ // Bookmarks by source
+ this.ctx.db
+ .select({
+ source: bookmarks.source,
+ count: count(),
+ })
+ .from(bookmarks)
+ .where(eq(bookmarks.userId, this.user.id))
+ .groupBy(bookmarks.source)
+ .orderBy(desc(count())),
]);
// Process bookmarks by type
@@ -735,6 +747,7 @@ export class User implements PrivacyAware {
byDayOfWeek: dailyActivity,
},
tagUsage,
+ bookmarksBySource,
};
}