← back to kenta-yos__auto-sns

Function bodies 68 total

All specs Real LLM only Function bodies
removeAuthCookie function · typescript · L54-L57 (4 LOC)
src/lib/auth/index.ts
export async function removeAuthCookie() {
  const cookieStore = await cookies();
  cookieStore.delete(COOKIE_NAME);
}
getAuthFromCookie function · typescript · L59-L61 (3 LOC)
src/lib/auth/index.ts
export async function getAuthFromCookie(): Promise<{
  userId: string;
} | null> {
requireAuth function · typescript · L9-L11 (3 LOC)
src/lib/auth/middleware.ts
export async function requireAuth(
  req: NextRequest
): Promise<{ userId: string } | NextResponse> {
verifyCronSecret function · typescript · L6-L19 (14 LOC)
src/lib/cron-auth.ts
export function verifyCronSecret(req: NextRequest): NextResponse | null {
  const authHeader = req.headers.get("authorization");
  const expected = process.env.CRON_SECRET;
  if (!expected) {
    return NextResponse.json(
      { error: "CRON_SECRET not configured" },
      { status: 500 }
    );
  }
  if (authHeader !== `Bearer ${expected}`) {
    return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
  }
  return null; // OK
}
getKey function · typescript · L5-L11 (7 LOC)
src/lib/encryption.ts
function getKey(): Buffer {
  const hex = process.env.ENCRYPTION_KEY;
  if (!hex || hex.length !== 64) {
    throw new Error("ENCRYPTION_KEY must be a 64-char hex string (32 bytes)");
  }
  return Buffer.from(hex, "hex");
}
encrypt function · typescript · L13-L17 (5 LOC)
src/lib/encryption.ts
export function encrypt(plaintext: string): {
  iv: string;
  authTag: string;
  ciphertext: string;
} {
decrypt function · typescript · L31-L46 (16 LOC)
src/lib/encryption.ts
export function decrypt(data: {
  iv: string;
  authTag: string;
  ciphertext: string;
}): string {
  const key = getKey();
  const decipher = createDecipheriv(
    ALGORITHM,
    key,
    Buffer.from(data.iv, "hex")
  );
  decipher.setAuthTag(Buffer.from(data.authTag, "hex"));
  let plaintext = decipher.update(data.ciphertext, "hex", "utf8");
  plaintext += decipher.final("utf8");
  return plaintext;
}
All rows above produced by Repobility · https://repobility.com
createAgent function · typescript · L8-L15 (8 LOC)
src/lib/platforms/bluesky.ts
async function createAgent(credentials: BlueskyCredentials): Promise<BskyAgent> {
  const agent = new BskyAgent({ service: "https://bsky.social" });
  await agent.login({
    identifier: credentials.identifier,
    password: credentials.password,
  });
  return agent;
}
postToBluesky function · typescript · L17-L20 (4 LOC)
src/lib/platforms/bluesky.ts
export async function postToBluesky(
  credentials: BlueskyCredentials,
  text: string
): Promise<{ uri: string; cid: string; url: string }> {
testBlueskyConnection function · typescript · L44-L46 (3 LOC)
src/lib/platforms/bluesky.ts
export async function testBlueskyConnection(
  credentials: BlueskyCredentials
): Promise<{ success: boolean; handle?: string; error?: string }> {
getBlueskyPostMetrics function · typescript · L61-L68 (8 LOC)
src/lib/platforms/bluesky.ts
export async function getBlueskyPostMetrics(
  credentials: BlueskyCredentials,
  uri: string
): Promise<{
  likeCount: number;
  repostCount: number;
  replyCount: number;
}> {
getBlueskyProfileMetrics function · typescript · L87-L93 (7 LOC)
src/lib/platforms/bluesky.ts
export async function getBlueskyProfileMetrics(
  credentials: BlueskyCredentials
): Promise<{
  followersCount: number;
  followsCount: number;
  postsCount: number;
}> {
publishPost function · typescript · L16-L105 (90 LOC)
src/lib/platforms/publish.ts
export async function publishPost(postId: string) {
  const [post] = await db
    .select()
    .from(posts)
    .where(eq(posts.id, postId))
    .limit(1);

  if (!post) throw new Error("Post not found");

  // ステータスを publishing に更新
  await db
    .update(posts)
    .set({ status: "publishing", updatedAt: new Date() })
    .where(eq(posts.id, postId));

  const platforms = post.platforms as string[];
  const results: { platform: string; success: boolean; error?: string }[] = [];

  for (const platform of platforms) {
    try {
      // 認証情報取得
      const [cred] = await db
        .select()
        .from(platformCredentials)
        .where(eq(platformCredentials.userId, post.userId))
        .then((rows) =>
          rows.filter(
            (r) => r.platform === platform
          )
        );

      if (!cred) {
        throw new Error(`${platform} の認証情報が設定されていません`);
      }

      const decrypted = JSON.parse(
        decrypt(cred.encrypted as { iv: string; authTag: string; cipherte
postToX function · typescript · L10-L13 (4 LOC)
src/lib/platforms/x.ts
export async function postToX(
  credentials: XCredentials,
  text: string
): Promise<{ id: string; url: string }> {
testXConnection function · typescript · L28-L30 (3 LOC)
src/lib/platforms/x.ts
export async function testXConnection(
  credentials: XCredentials
): Promise<{ success: boolean; username?: string; error?: string }> {
Repobility (the analyzer behind this table) · https://repobility.com
getTemplatesByDate function · typescript · L132-L144 (13 LOC)
src/lib/templates.ts
export function getTemplatesByDate(): DayTemplates[] {
  const grouped = new Map<string, PostTemplate[]>();
  for (const t of raw) {
    const existing = grouped.get(t.date) || [];
    existing.push(t);
    grouped.set(t.date, existing);
  }
  return Array.from(grouped.entries()).map(([date, templates]) => ({
    date,
    dayOfWeek: templates[0].dayOfWeek,
    templates,
  }));
}
getTodayTemplates function · typescript · L147-L153 (7 LOC)
src/lib/templates.ts
export function getTodayTemplates(): DayTemplates | null {
  const now = new Date();
  const jst = new Date(now.toLocaleString("en-US", { timeZone: "Asia/Tokyo" }));
  const dateStr = `${jst.getMonth() + 1}/${jst.getDate()}`;
  const all = getTemplatesByDate();
  return all.find((d) => d.date === dateStr) || null;
}
middleware function · typescript · L4-L29 (26 LOC)
src/middleware.ts
export async function middleware(req: NextRequest) {
  const { pathname } = req.nextUrl;

  // 公開パス
  if (
    pathname === "/login" ||
    pathname.startsWith("/api/auth/") ||
    pathname.startsWith("/api/cron/") ||
    pathname.startsWith("/_next/") ||
    pathname === "/favicon.ico"
  ) {
    return NextResponse.next();
  }

  const token = req.cookies.get("auth_token")?.value;
  if (!token) {
    return NextResponse.redirect(new URL("/login", req.url));
  }

  const auth = await verifyToken(token);
  if (!auth) {
    return NextResponse.redirect(new URL("/login", req.url));
  }

  return NextResponse.next();
}
‹ prevpage 2 / 2