|
|
@ -1,8 +1,10 @@ |
|
|
import { dbGlobal } from "drizzle-pkg/lib/db"; |
|
|
import { dbGlobal } from "drizzle-pkg/lib/db"; |
|
|
import { timelineEvents } from "drizzle-pkg/lib/schema/content"; |
|
|
import { timelineEvents } from "drizzle-pkg/lib/schema/content"; |
|
|
import { users } from "drizzle-pkg/lib/schema/auth"; |
|
|
import { users } from "drizzle-pkg/lib/schema/auth"; |
|
|
import { and, desc, eq } from "drizzle-orm"; |
|
|
import { and, count, desc, eq } from "drizzle-orm"; |
|
|
|
|
|
import { PUBLIC_LIST_PAGE_SIZE, PUBLIC_PREVIEW_LIMIT } from "#server/constants/public-profile-lists"; |
|
|
import { visibilitySchema, type Visibility } from "#server/constants/visibility"; |
|
|
import { visibilitySchema, type Visibility } from "#server/constants/visibility"; |
|
|
|
|
|
import { normalizePublicListPage } from "#server/utils/public-pagination"; |
|
|
import { visibilityShareToken } from "#server/utils/share-token"; |
|
|
import { visibilityShareToken } from "#server/utils/share-token"; |
|
|
import { nextIntegerId } from "#server/utils/sqlite-id"; |
|
|
import { nextIntegerId } from "#server/utils/sqlite-id"; |
|
|
|
|
|
|
|
|
@ -100,20 +102,54 @@ export async function deleteTimelineEvent(userId: number, id: number) { |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export async function listPublicTimelineBySlug(publicSlug: string) { |
|
|
function publicTimelineListWhere(publicSlug: string) { |
|
|
const rows = await dbGlobal |
|
|
return and( |
|
|
.select({ ev: timelineEvents }) |
|
|
|
|
|
.from(timelineEvents) |
|
|
|
|
|
.innerJoin(users, eq(timelineEvents.userId, users.id)) |
|
|
|
|
|
.where( |
|
|
|
|
|
and( |
|
|
|
|
|
eq(users.publicSlug, publicSlug), |
|
|
eq(users.publicSlug, publicSlug), |
|
|
eq(users.status, "active"), |
|
|
eq(users.status, "active"), |
|
|
eq(timelineEvents.visibility, "public"), |
|
|
eq(timelineEvents.visibility, "public"), |
|
|
), |
|
|
); |
|
|
) |
|
|
} |
|
|
.orderBy(desc(timelineEvents.occurredOn), desc(timelineEvents.id)); |
|
|
|
|
|
return rows.map((r) => r.ev); |
|
|
export async function getPublicTimelinePreviewBySlug(publicSlug: string) { |
|
|
|
|
|
const whereClause = publicTimelineListWhere(publicSlug); |
|
|
|
|
|
const [countRows, rows] = await Promise.all([ |
|
|
|
|
|
dbGlobal |
|
|
|
|
|
.select({ total: count() }) |
|
|
|
|
|
.from(timelineEvents) |
|
|
|
|
|
.innerJoin(users, eq(timelineEvents.userId, users.id)) |
|
|
|
|
|
.where(whereClause), |
|
|
|
|
|
dbGlobal |
|
|
|
|
|
.select({ ev: timelineEvents }) |
|
|
|
|
|
.from(timelineEvents) |
|
|
|
|
|
.innerJoin(users, eq(timelineEvents.userId, users.id)) |
|
|
|
|
|
.where(whereClause) |
|
|
|
|
|
.orderBy(desc(timelineEvents.occurredOn), desc(timelineEvents.id)) |
|
|
|
|
|
.limit(PUBLIC_PREVIEW_LIMIT), |
|
|
|
|
|
]); |
|
|
|
|
|
return { items: rows.map((r) => r.ev), total: countRows[0]?.total ?? 0 }; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function getPublicTimelinePageBySlug(publicSlug: string, pageRaw: unknown) { |
|
|
|
|
|
const page = normalizePublicListPage(pageRaw); |
|
|
|
|
|
const pageSize = PUBLIC_LIST_PAGE_SIZE; |
|
|
|
|
|
const offset = (page - 1) * pageSize; |
|
|
|
|
|
const whereClause = publicTimelineListWhere(publicSlug); |
|
|
|
|
|
const [countRows, rows] = await Promise.all([ |
|
|
|
|
|
dbGlobal |
|
|
|
|
|
.select({ total: count() }) |
|
|
|
|
|
.from(timelineEvents) |
|
|
|
|
|
.innerJoin(users, eq(timelineEvents.userId, users.id)) |
|
|
|
|
|
.where(whereClause), |
|
|
|
|
|
dbGlobal |
|
|
|
|
|
.select({ ev: timelineEvents }) |
|
|
|
|
|
.from(timelineEvents) |
|
|
|
|
|
.innerJoin(users, eq(timelineEvents.userId, users.id)) |
|
|
|
|
|
.where(whereClause) |
|
|
|
|
|
.orderBy(desc(timelineEvents.occurredOn), desc(timelineEvents.id)) |
|
|
|
|
|
.limit(pageSize) |
|
|
|
|
|
.offset(offset), |
|
|
|
|
|
]); |
|
|
|
|
|
return { items: rows.map((r) => r.ev), total: countRows[0]?.total ?? 0, page, pageSize }; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export async function getUnlistedTimeline(publicSlug: string, shareToken: string) { |
|
|
export async function getUnlistedTimeline(publicSlug: string, shareToken: string) { |
|
|
|