Repository navigation
Expand file tree
/
Copy pathcontent.ts
More file actions
177 lines (146 loc) · 5.38 KB
/
Copy pathcontent.ts
File metadata and controls
177 lines (146 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import z from "zod";
import { httpUrl } from "./shared";
// Content Type enum matching the database
// POST/ARTICLE = user-created articles, LINK = external/RSS content
// ARTICLE is an alias for POST (frontend uses ARTICLE, backend uses POST)
export const ContentTypeSchema = z.enum([
"POST",
"LINK",
"TIL",
"QUESTION",
"VIDEO",
"DISCUSSION",
"ARTICLE", // Alias for POST
]);
export type ContentType = z.TypeOf<typeof ContentTypeSchema>;
// Get Feed Schema - unified feed with type filtering
export const GetUnifiedFeedSchema = z.object({
limit: z.number().min(1).max(100).nullish(),
cursor: z
.object({
id: z.string(),
publishedAt: z.string().optional(),
score: z.number().optional(),
})
.nullish(),
sort: z.enum(["recent", "trending", "popular"]).default("recent"),
type: ContentTypeSchema.nullish(), // Filter by content type
kinds: z.array(ContentTypeSchema).nullish(), // Filter by multiple kinds (e.g. Discussions = discussion + question)
category: z.string().nullish(),
tag: z.string().nullish(),
sourceId: z.number().nullish(),
userId: z.string().nullish(), // Filter by author
following: z.boolean().nullish(), // Only authors the current user follows
});
export type GetUnifiedFeedInput = z.TypeOf<typeof GetUnifiedFeedSchema>;
// Get Content by Slug
export const GetContentBySlugSchema = z.object({
slug: z.string().min(1).max(300),
});
export type GetContentBySlugInput = z.TypeOf<typeof GetContentBySlugSchema>;
// Create Content Schema
export const CreateContentSchema = z.object({
type: ContentTypeSchema,
title: z.string().min(1).max(500),
body: z.string().nullish(), // Required for ARTICLE, optional for others
excerpt: z.string().max(300).nullish(),
externalUrl: httpUrl().max(2000).nullish(), // Required for LINK, VIDEO
imageUrl: z.string().url().nullish(),
tags: z.array(z.string()).max(5).optional(),
published: z.boolean().default(false),
showComments: z.boolean().default(true),
canonicalUrl: z.string().url().nullish(),
coverImage: z.string().url().nullish(),
});
export type CreateContentInput = z.TypeOf<typeof CreateContentSchema>;
// Update Content Schema
export const UpdateContentSchema = z.object({
id: z.string(),
title: z.string().min(1).max(500).optional(),
body: z.string().nullish(),
excerpt: z.string().max(300).nullish(),
externalUrl: httpUrl().max(2000).nullish(),
imageUrl: z.string().url().nullish(),
tags: z.array(z.string()).max(5).optional(),
published: z.boolean().optional(),
showComments: z.boolean().optional(),
canonicalUrl: z.string().url().nullish(),
coverImage: z.string().url().nullish(),
});
export type UpdateContentInput = z.TypeOf<typeof UpdateContentSchema>;
// Delete Content Schema
export const DeleteContentSchema = z.object({
id: z.string(),
});
export type DeleteContentInput = z.TypeOf<typeof DeleteContentSchema>;
// Vote Schema
export const VoteContentSchema = z.object({
contentId: z.string(),
voteType: z.enum(["up", "down"]).nullable(), // null removes the vote
});
export type VoteContentInput = z.TypeOf<typeof VoteContentSchema>;
// Bookmark Schema
export const BookmarkContentSchema = z.object({
contentId: z.string(),
setBookmarked: z.boolean(),
});
export type BookmarkContentInput = z.TypeOf<typeof BookmarkContentSchema>;
// Track Click Schema
export const TrackClickContentSchema = z.object({
contentId: z.string(),
});
export type TrackClickContentInput = z.TypeOf<typeof TrackClickContentSchema>;
// Get Saved Content Schema
export const GetSavedContentSchema = z.object({
limit: z.number().min(1).max(100).default(20),
cursor: z
.object({
id: z.string(),
createdAt: z.string().optional(),
})
.nullish(),
});
export type GetSavedContentInput = z.TypeOf<typeof GetSavedContentSchema>;
// Edit Draft Schema - get user's own content by ID for editing
export const EditDraftContentSchema = z.object({
id: z.string(),
});
export type EditDraftContentInput = z.TypeOf<typeof EditDraftContentSchema>;
// Publish Content Schema - separate publish action
export const PublishContentSchema = z.object({
id: z.string(),
published: z.boolean(),
publishTime: z.date().optional(), // For scheduling
});
export type PublishContentInput = z.TypeOf<typeof PublishContentSchema>;
// Confirm Content Schema - validation before publishing
export const ConfirmContentSchema = z.object({
body: z
.string()
.trim()
.min(50, "Content is too short. Minimum of 50 characters."),
title: z
.string()
.trim()
.max(500)
.min(10, "Title is too short. Minimum of 10 characters."),
excerpt: z.string().trim().max(300).optional(),
canonicalUrl: z.string().trim().url().optional().or(z.literal("")),
tags: z.string().array().max(5).optional(),
});
export type ConfirmContentInput = z.TypeOf<typeof ConfirmContentSchema>;
// My Drafts Schema
export const MyDraftsContentSchema = z.object({
limit: z.number().min(1).max(100).default(20),
});
export type MyDraftsContentInput = z.TypeOf<typeof MyDraftsContentSchema>;
// My Published Schema
export const MyPublishedContentSchema = z.object({
limit: z.number().min(1).max(100).default(20),
});
export type MyPublishedContentInput = z.TypeOf<typeof MyPublishedContentSchema>;
// My Scheduled Schema
export const MyScheduledContentSchema = z.object({
limit: z.number().min(1).max(100).default(20),
});
export type MyScheduledContentInput = z.TypeOf<typeof MyScheduledContentSchema>;