diff options
| author | Mohamed Bassem <me@mbassem.com> | 2024-11-17 02:39:06 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2024-11-17 02:39:33 +0000 |
| commit | 82cd3bb8fa2814b7e27b610682cd04d6f471ac2d (patch) | |
| tree | 26b06ca73f3a4bf754953475dca26cacefe10b35 /packages | |
| parent | 64e759a82349a85c4da55dbb47bb4b939dfeb322 (diff) | |
| download | karakeep-82cd3bb8fa2814b7e27b610682cd04d6f471ac2d.tar.zst | |
feature: Allow setting bookmark metadata during creation
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/open-api/hoarder-openapi-spec.json | 188 | ||||
| -rw-r--r-- | packages/shared/types/bookmarks.ts | 27 | ||||
| -rw-r--r-- | packages/trpc/routers/bookmarks.ts | 9 |
3 files changed, 111 insertions, 113 deletions
diff --git a/packages/open-api/hoarder-openapi-spec.json b/packages/open-api/hoarder-openapi-spec.json index eac98326..7a490d36 100644 --- a/packages/open-api/hoarder-openapi-spec.json +++ b/packages/open-api/hoarder-openapi-spec.json @@ -454,136 +454,106 @@ "content": { "application/json": { "schema": { - "oneOf": [ + "allOf": [ { "type": "object", "properties": { - "type": { - "type": "string", - "enum": [ - "link" - ] - }, - "url": { - "type": "string", - "format": "uri" - }, "title": { "type": "string", - "nullable": true - }, - "description": { - "type": "string", - "nullable": true - }, - "imageUrl": { - "type": "string", "nullable": true, - "format": "uri" - }, - "imageAssetId": { - "type": "string", - "nullable": true - }, - "screenshotAssetId": { - "type": "string", - "nullable": true - }, - "fullPageArchiveAssetId": { - "type": "string", - "nullable": true + "maxLength": 250 }, - "videoAssetId": { - "type": "string", - "nullable": true - }, - "favicon": { - "type": "string", - "nullable": true, - "format": "uri" + "archived": { + "type": "boolean" }, - "htmlContent": { - "type": "string", - "nullable": true + "favourited": { + "type": "boolean" }, - "crawledAt": { - "type": "string", - "nullable": true - } - }, - "required": [ - "type", - "url" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "enum": [ - "text" - ] + "note": { + "type": "string" }, - "text": { + "summary": { "type": "string" }, - "sourceUrl": { - "type": "string", - "nullable": true + "createdAt": { + "type": "string" } - }, - "required": [ - "type", - "text" - ] + } }, { - "type": "object", - "properties": { - "type": { - "type": "string", - "enum": [ - "asset" + "oneOf": [ + { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "link" + ] + }, + "url": { + "type": "string", + "format": "uri" + } + }, + "required": [ + "type", + "url" ] }, - "assetType": { - "type": "string", - "enum": [ - "image", - "pdf" + { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "text" + ] + }, + "text": { + "type": "string" + }, + "sourceUrl": { + "type": "string" + } + }, + "required": [ + "type", + "text" ] }, - "assetId": { - "type": "string" - }, - "fileName": { - "type": "string", - "nullable": true - }, - "sourceUrl": { - "type": "string", - "nullable": true - } - }, - "required": [ - "type", - "assetType", - "assetId" - ] - }, - { - "type": "object", - "properties": { - "type": { - "type": "string", - "enum": [ - "unknown" + { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "asset" + ] + }, + "assetType": { + "type": "string", + "enum": [ + "image", + "pdf" + ] + }, + "assetId": { + "type": "string" + }, + "fileName": { + "type": "string" + }, + "sourceUrl": { + "type": "string" + } + }, + "required": [ + "type", + "assetType", + "assetId" ] } - }, - "required": [ - "type" ] } ] diff --git a/packages/shared/types/bookmarks.ts b/packages/shared/types/bookmarks.ts index 1d8052f4..a02a4b29 100644 --- a/packages/shared/types/bookmarks.ts +++ b/packages/shared/types/bookmarks.ts @@ -114,7 +114,32 @@ const zBookmarkTypeAssetSchema = zBareBookmarkSchema.merge( export type ZBookmarkTypeAsset = z.infer<typeof zBookmarkTypeAssetSchema>; // POST /v1/bookmarks -export const zNewBookmarkRequestSchema = zBookmarkContentSchema; +export const zNewBookmarkRequestSchema = z + .object({ + title: z.string().max(MAX_TITLE_LENGTH).nullish(), + archived: z.boolean().optional(), + favourited: z.boolean().optional(), + note: z.string().optional(), + summary: z.string().optional(), + createdAt: z.date().optional(), + }) + .and( + z.discriminatedUnion("type", [ + z.object({ type: z.literal(BookmarkTypes.LINK), url: z.string().url() }), + z.object({ + type: z.literal(BookmarkTypes.TEXT), + text: z.string(), + sourceUrl: z.string().optional(), + }), + z.object({ + type: z.literal(BookmarkTypes.ASSET), + assetType: z.enum(["image", "pdf"]), + assetId: z.string(), + fileName: z.string().optional(), + sourceUrl: z.string().optional(), + }), + ]), + ); export type ZNewBookmarkRequest = z.infer<typeof zNewBookmarkRequestSchema>; // GET /v1/bookmarks diff --git a/packages/trpc/routers/bookmarks.ts b/packages/trpc/routers/bookmarks.ts index 4e58bcdc..c7fdcc17 100644 --- a/packages/trpc/routers/bookmarks.ts +++ b/packages/trpc/routers/bookmarks.ts @@ -271,9 +271,6 @@ export const bookmarksAppRouter = router({ return { ...alreadyExists, alreadyExists: true }; } } - if (input.type == BookmarkTypes.UNKNOWN) { - throw new TRPCError({ code: "BAD_REQUEST" }); - } const bookmark = await ctx.db.transaction(async (tx) => { const bookmark = ( await tx @@ -281,6 +278,12 @@ export const bookmarksAppRouter = router({ .values({ userId: ctx.user.id, type: input.type, + title: input.title, + archived: input.archived, + favourited: input.favourited, + note: input.note, + summary: input.summary, + createdAt: input.createdAt, }) .returning() )[0]; |
