MCPcopy
hub / github.com/zws-im/zws / stats

Function stats

src/server/components/urls/service.ts:107–120  ·  view source on GitHub ↗
(id: Short)

Source from the content-addressed store, hash-verified

105 * @returns Shortened URL information and statistics, or `null` if it couldn't be found
106 */
107export async function stats(id: Short): Promise<null | Stats> {
108 const encodedId = encode(id);
109
110 const [visits, shortenedUrl] = await db.$transaction([
111 db.visit.findMany({where: {shortenedUrlId: encodedId}, select: {timestamp: true}, orderBy: {timestamp: 'asc'}}),
112 db.shortenedUrl.findUnique({where: {shortBase64: encodedId}, select: {url: true}}),
113 ]);
114
115 if (!shortenedUrl) {
116 return null;
117 }
118
119 return {visits: visits.map(visit => visit.timestamp), url: shortenedUrl.url};
120}
121
122/**
123 * Shorten a long URL

Callers

nothing calls this directly

Calls 1

encodeFunction · 0.85

Tested by

no test coverage detected