|
|
@ -166,6 +166,56 @@ export async function getPublicPostByPublicSlugAndSlug(publicSlug: string, postS |
|
|
return row ?? null; |
|
|
return row ?? null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function getPublicPostCommentContext( |
|
|
|
|
|
publicSlug: string, |
|
|
|
|
|
postSlug: string, |
|
|
|
|
|
): Promise<{ id: number; userId: number } | null> { |
|
|
|
|
|
const slug = postSlug.trim(); |
|
|
|
|
|
if (!slug) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
const [row] = await dbGlobal |
|
|
|
|
|
.select({ |
|
|
|
|
|
id: posts.id, |
|
|
|
|
|
userId: posts.userId, |
|
|
|
|
|
}) |
|
|
|
|
|
.from(posts) |
|
|
|
|
|
.innerJoin(users, eq(posts.userId, users.id)) |
|
|
|
|
|
.where( |
|
|
|
|
|
and( |
|
|
|
|
|
eq(users.publicSlug, publicSlug), |
|
|
|
|
|
eq(users.status, "active"), |
|
|
|
|
|
eq(posts.visibility, "public"), |
|
|
|
|
|
eq(posts.slug, slug), |
|
|
|
|
|
), |
|
|
|
|
|
) |
|
|
|
|
|
.limit(1); |
|
|
|
|
|
return row ?? null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function getUnlistedPostCommentContext( |
|
|
|
|
|
publicSlug: string, |
|
|
|
|
|
shareToken: string, |
|
|
|
|
|
): Promise<{ id: number; userId: number } | null> { |
|
|
|
|
|
const [row] = await dbGlobal |
|
|
|
|
|
.select({ |
|
|
|
|
|
id: posts.id, |
|
|
|
|
|
userId: posts.userId, |
|
|
|
|
|
}) |
|
|
|
|
|
.from(posts) |
|
|
|
|
|
.innerJoin(users, eq(posts.userId, users.id)) |
|
|
|
|
|
.where( |
|
|
|
|
|
and( |
|
|
|
|
|
eq(users.publicSlug, publicSlug), |
|
|
|
|
|
eq(users.status, "active"), |
|
|
|
|
|
eq(posts.visibility, "unlisted"), |
|
|
|
|
|
eq(posts.shareToken, shareToken), |
|
|
|
|
|
), |
|
|
|
|
|
) |
|
|
|
|
|
.limit(1); |
|
|
|
|
|
return row ?? null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
export async function getUnlistedPost(publicSlug: string, shareToken: string) { |
|
|
export async function getUnlistedPost(publicSlug: string, shareToken: string) { |
|
|
const [row] = await dbGlobal |
|
|
const [row] = await dbGlobal |
|
|
.select({ post: posts }) |
|
|
.select({ post: posts }) |
|
|
|