fix(deploy): Flatten apps/web to root for deployment
This commit is contained in:
parent
12da1e9d44
commit
3038e4875c
64 changed files with 261 additions and 1812 deletions
37
Dockerfile
37
Dockerfile
|
|
@ -1,10 +1,10 @@
|
||||||
FROM node:22-alpine AS base
|
FROM oven/bun:latest AS base
|
||||||
|
|
||||||
# Install dependencies only when needed
|
# Install dependencies only when needed
|
||||||
FROM base AS deps
|
FROM base AS deps
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package.json package-lock.json* ./
|
COPY package.json ./
|
||||||
RUN npm install
|
RUN bun install
|
||||||
|
|
||||||
# Rebuild the source code only when needed
|
# Rebuild the source code only when needed
|
||||||
FROM base AS builder
|
FROM base AS builder
|
||||||
|
|
@ -12,47 +12,34 @@ WORKDIR /app
|
||||||
COPY --from=deps /app/node_modules ./node_modules
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Generate migration SQL files
|
|
||||||
# RUN npx drizzle-kit generate <-- DISABLED: We are providing generated migrations with custom edits
|
|
||||||
|
|
||||||
# Build Next.js
|
# Build Next.js
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
RUN npm run build
|
RUN bun run build
|
||||||
|
|
||||||
# Production image, copy all the files and run next
|
# # Production image, copy all the files and run next
|
||||||
FROM base AS runner
|
FROM base AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
|
|
||||||
RUN addgroup --system --gid 1001 nodejs
|
|
||||||
RUN adduser --system --uid 1001 nextjs
|
|
||||||
|
|
||||||
# Copy public folder
|
# Copy public folder
|
||||||
COPY --from=builder /app/public ./public
|
COPY --from=builder /app/public ./public
|
||||||
|
|
||||||
# Set permission for prerender cache
|
# Set permission for prerender cache
|
||||||
RUN mkdir .next
|
RUN mkdir .next
|
||||||
RUN chown nextjs:nodejs .next
|
|
||||||
|
|
||||||
# Automatically leverage output traces to reduce image size
|
# Automatically leverage output traces to reduce image size
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
COPY --from=builder /app/.next/standalone ./
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
COPY --from=builder /app/.next/static ./.next/static
|
||||||
|
|
||||||
# Copy migrations and migration script
|
# Copy migrations and migration script
|
||||||
# Ensure we copy from the source (which now includes them via COPY . . in builder)
|
COPY --from=builder /app/drizzle ./drizzle
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/drizzle ./drizzle
|
COPY --from=builder /app/src/db/migrate.ts ./src/db/migrate.ts
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/src/db/migrate.ts ./src/db/migrate.ts
|
COPY --from=builder /app/src ./src
|
||||||
|
|
||||||
# Runtime dependencies
|
RUN bun install drizzle-orm pg dotenv
|
||||||
RUN npm install -g tsx
|
|
||||||
RUN npm install drizzle-orm pg dotenv
|
|
||||||
|
|
||||||
# Copy the source so tsx can run migrate.ts
|
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/src ./src
|
|
||||||
|
|
||||||
USER nextjs
|
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
|
|
@ -60,4 +47,4 @@ ENV PORT=3000
|
||||||
ENV HOSTNAME="0.0.0.0"
|
ENV HOSTNAME="0.0.0.0"
|
||||||
|
|
||||||
# Custom entrypoint to run migrations then start app
|
# Custom entrypoint to run migrations then start app
|
||||||
CMD ["sh", "-c", "npx tsx src/db/migrate.ts && node server.js"]
|
CMD ["sh", "-c", "bun --bun run src/db/migrate.ts && bun --bun run server.js"]
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
FROM oven/bun:latest AS base
|
|
||||||
|
|
||||||
# Install dependencies only when needed
|
|
||||||
FROM base AS deps
|
|
||||||
WORKDIR /app
|
|
||||||
COPY package.json ./
|
|
||||||
RUN bun install
|
|
||||||
|
|
||||||
# Rebuild the source code only when needed
|
|
||||||
FROM base AS builder
|
|
||||||
WORKDIR /app
|
|
||||||
COPY --from=deps /app/node_modules ./node_modules
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
# Build Next.js
|
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
|
||||||
RUN bun run build
|
|
||||||
|
|
||||||
# # Production image, copy all the files and run next
|
|
||||||
FROM base AS runner
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
|
||||||
|
|
||||||
# Copy public folder
|
|
||||||
COPY --from=builder /app/public ./public
|
|
||||||
|
|
||||||
# Set permission for prerender cache
|
|
||||||
RUN mkdir .next
|
|
||||||
|
|
||||||
# Automatically leverage output traces to reduce image size
|
|
||||||
COPY --from=builder /app/.next/standalone ./
|
|
||||||
COPY --from=builder /app/.next/static ./.next/static
|
|
||||||
|
|
||||||
# Copy migrations and migration script
|
|
||||||
COPY --from=builder /app/drizzle ./drizzle
|
|
||||||
COPY --from=builder /app/src/db/migrate.ts ./src/db/migrate.ts
|
|
||||||
COPY --from=builder /app/src ./src
|
|
||||||
|
|
||||||
RUN bun install drizzle-orm pg dotenv
|
|
||||||
|
|
||||||
|
|
||||||
EXPOSE 3000
|
|
||||||
|
|
||||||
ENV PORT=3000
|
|
||||||
ENV HOSTNAME="0.0.0.0"
|
|
||||||
|
|
||||||
# Custom entrypoint to run migrations then start app
|
|
||||||
CMD ["sh", "-c", "bun --bun run src/db/migrate.ts && bun --bun run server.js"]
|
|
||||||
|
|
@ -1,92 +0,0 @@
|
||||||
# Kites - Agentic Pastebin
|
|
||||||
|
|
||||||
Kites is a clean, agent-native pastebin service designed for LLMs and humans. It features a simple API, structured data model (Sessions, Tags), and a polished UI.
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- **Agent-First API**: Simple REST endpoints for creating and retrieving pastes.
|
|
||||||
- **Sessions**: Group pastes by "run" or logical session.
|
|
||||||
- **Tags**: Organize pastes with tags.
|
|
||||||
- **Syntax Highlighting**: Automatic highlighting for various languages.
|
|
||||||
- **Theming**: Light and Dark mode support.
|
|
||||||
- **Self-Hostable**: Built with Next.js and SQLite for easy deployment.
|
|
||||||
|
|
||||||
## Tech Stack
|
|
||||||
|
|
||||||
- **Framework**: Next.js 15 (App Router)
|
|
||||||
- **Database**: SQLite
|
|
||||||
- **ORM**: Drizzle ORM
|
|
||||||
- **Styling**: Tailwind CSS v4
|
|
||||||
- **Validation**: Zod
|
|
||||||
|
|
||||||
## Getting Started
|
|
||||||
|
|
||||||
### Prerequisites
|
|
||||||
|
|
||||||
- Node.js 18+
|
|
||||||
- npm
|
|
||||||
|
|
||||||
### Installation
|
|
||||||
|
|
||||||
1. Clone the repository:
|
|
||||||
```bash
|
|
||||||
git clone https://github.com/fullsizemalt/kites.git
|
|
||||||
cd kites
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Install dependencies:
|
|
||||||
```bash
|
|
||||||
npm install
|
|
||||||
```
|
|
||||||
|
|
||||||
3. Initialize the database:
|
|
||||||
```bash
|
|
||||||
npx drizzle-kit push
|
|
||||||
```
|
|
||||||
|
|
||||||
4. Run the development server:
|
|
||||||
```bash
|
|
||||||
npm run dev
|
|
||||||
```
|
|
||||||
|
|
||||||
Open [http://localhost:3000](http://localhost:3000) with your browser.
|
|
||||||
|
|
||||||
## API Usage
|
|
||||||
|
|
||||||
### Create a Paste
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -X POST http://localhost:3000/api/v1/pastes \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{
|
|
||||||
"content": "console.log(\"Hello Kites!\");",
|
|
||||||
"title": "My First Paste",
|
|
||||||
"syntax": "javascript",
|
|
||||||
"tags": ["demo", "js"]
|
|
||||||
}'
|
|
||||||
```
|
|
||||||
|
|
||||||
### Get a Paste (Raw)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl http://localhost:3000/api/v1/pastes/<PASTE_ID>?raw=1
|
|
||||||
```
|
|
||||||
|
|
||||||
### Create a Session
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -X POST http://localhost:3000/api/v1/sessions \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{
|
|
||||||
"title": "Agent Run 101",
|
|
||||||
"agentName": "GPT-4"
|
|
||||||
}'
|
|
||||||
```
|
|
||||||
|
|
||||||
## Agent Example
|
|
||||||
|
|
||||||
See `examples/agent_usage.py` for a Python script that demonstrates how an agent can interact with Kites.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
python3 examples/agent_usage.py
|
|
||||||
```
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
import type { Config } from 'drizzle-kit';
|
|
||||||
import 'dotenv/config';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
schema: './src/db/schema.ts',
|
|
||||||
out: './drizzle',
|
|
||||||
dialect: 'postgresql',
|
|
||||||
dbCredentials: {
|
|
||||||
url: process.env.DATABASE_URL!,
|
|
||||||
},
|
|
||||||
} satisfies Config;
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
import { defineConfig, globalIgnores } from "eslint/config";
|
|
||||||
import nextVitals from "eslint-config-next/core-web-vitals";
|
|
||||||
import nextTs from "eslint-config-next/typescript";
|
|
||||||
|
|
||||||
const eslintConfig = defineConfig([
|
|
||||||
...nextVitals,
|
|
||||||
...nextTs,
|
|
||||||
// Override default ignores of eslint-config-next.
|
|
||||||
globalIgnores([
|
|
||||||
// Default ignores of eslint-config-next:
|
|
||||||
".next/**",
|
|
||||||
"out/**",
|
|
||||||
"build/**",
|
|
||||||
"next-env.d.ts",
|
|
||||||
]),
|
|
||||||
]);
|
|
||||||
|
|
||||||
export default eslintConfig;
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
import type { NextConfig } from "next";
|
|
||||||
|
|
||||||
const nextConfig: NextConfig = {
|
|
||||||
output: "standalone",
|
|
||||||
};
|
|
||||||
|
|
||||||
export default nextConfig;
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
{
|
|
||||||
"name": "web",
|
|
||||||
"version": "0.1.0",
|
|
||||||
"private": true,
|
|
||||||
"scripts": {
|
|
||||||
"dev": "bun --bun next dev",
|
|
||||||
"build": "bun --bun next build",
|
|
||||||
"start": "bun --bun next start",
|
|
||||||
"lint": "bun --bun next lint",
|
|
||||||
"db:push": "bun --bun drizzle-kit push:pg",
|
|
||||||
"db:migrate": "bun --bun drizzle-kit migrate",
|
|
||||||
"db:generate": "bun --bun drizzle-kit generate"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@auth/drizzle-adapter": "^1.11.1",
|
|
||||||
"@types/react-syntax-highlighter": "^15.5.13",
|
|
||||||
"pg": "^8.13.1",
|
|
||||||
"class-variance-authority": "^0.7.1",
|
|
||||||
"clsx": "^2.1.1",
|
|
||||||
"date-fns": "^4.1.0",
|
|
||||||
"dotenv": "^16.4.5",
|
|
||||||
"drizzle-orm": "^0.44.7",
|
|
||||||
"lucide-react": "^0.554.0",
|
|
||||||
"nanoid": "^5.1.6",
|
|
||||||
"next": "16.0.3",
|
|
||||||
"next-auth": "^5.0.0-beta.30",
|
|
||||||
"next-themes": "^0.4.6",
|
|
||||||
"@radix-ui/react-select": "^2.1.0",
|
|
||||||
"@radix-ui/react-popover": "^1.1.0",
|
|
||||||
"react": "19.2.0",
|
|
||||||
"react-dom": "19.2.0",
|
|
||||||
"react-syntax-highlighter": "^16.1.0",
|
|
||||||
"tailwind-merge": "^3.4.0",
|
|
||||||
"zod": "^4.1.12"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@tailwindcss/postcss": "^4",
|
|
||||||
"@types/pg": "^8.11.0",
|
|
||||||
"@types/node": "^20",
|
|
||||||
"@types/react": "^19",
|
|
||||||
"@types/react-dom": "^19",
|
|
||||||
"drizzle-kit": "^0.31.7",
|
|
||||||
"eslint": "^9",
|
|
||||||
"eslint-config-next": "16.0.3",
|
|
||||||
"tailwindcss": "^4",
|
|
||||||
"typescript": "^5"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
const config = {
|
|
||||||
plugins: {
|
|
||||||
"@tailwindcss/postcss": {},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default config;
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>
|
|
||||||
|
Before Width: | Height: | Size: 391 B |
|
|
@ -1 +0,0 @@
|
||||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>
|
|
||||||
|
Before Width: | Height: | Size: 1 KiB |
|
|
@ -1 +0,0 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
|
|
||||||
|
Before Width: | Height: | Size: 1.3 KiB |
|
|
@ -1 +0,0 @@
|
||||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>
|
|
||||||
|
Before Width: | Height: | Size: 128 B |
|
|
@ -1 +0,0 @@
|
||||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>
|
|
||||||
|
Before Width: | Height: | Size: 385 B |
Binary file not shown.
|
|
@ -1,2 +0,0 @@
|
||||||
import { handlers } from "@/auth"
|
|
||||||
export const { GET, POST } = handlers
|
|
||||||
|
|
@ -1,69 +0,0 @@
|
||||||
import { NextRequest, NextResponse } from 'next/server';
|
|
||||||
import { db } from '@/db';
|
|
||||||
import { pastes } from '@/db/schema';
|
|
||||||
import { eq } from 'drizzle-orm';
|
|
||||||
import { z, ZodError } from 'zod';
|
|
||||||
|
|
||||||
export async function GET(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
|
||||||
const { id } = await params;
|
|
||||||
const { searchParams } = new URL(req.url);
|
|
||||||
const raw = searchParams.get('raw') === '1';
|
|
||||||
|
|
||||||
const paste = (await db.select().from(pastes).where(eq(pastes.id, id)).limit(1))[0];
|
|
||||||
|
|
||||||
if (!paste) {
|
|
||||||
return NextResponse.json({ error: 'Not found' }, { status: 404 });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (raw) {
|
|
||||||
return new NextResponse(paste.content, {
|
|
||||||
headers: {
|
|
||||||
'Content-Type': paste.contentType || 'text/plain',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return NextResponse.json(paste);
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatePasteSchema = z.object({
|
|
||||||
title: z.string().optional(),
|
|
||||||
content: z.string().optional(),
|
|
||||||
visibility: z.enum(['public', 'unlisted', 'private']).optional(),
|
|
||||||
syntax: z.string().optional(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export async function PATCH(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
|
||||||
try {
|
|
||||||
const { id } = await params;
|
|
||||||
const body = await req.json();
|
|
||||||
const validated = updatePasteSchema.parse(body);
|
|
||||||
|
|
||||||
const updated = await db.update(pastes)
|
|
||||||
.set({
|
|
||||||
...validated,
|
|
||||||
updatedAt: new Date(),
|
|
||||||
})
|
|
||||||
.where(eq(pastes.id, id))
|
|
||||||
.returning();
|
|
||||||
|
|
||||||
const updatedFirst = updated[0];
|
|
||||||
|
|
||||||
if (!updatedFirst) {
|
|
||||||
return NextResponse.json({ error: 'Not found' }, { status: 404 });
|
|
||||||
}
|
|
||||||
|
|
||||||
return NextResponse.json(updatedFirst);
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof ZodError) {
|
|
||||||
return NextResponse.json({ error: (error as any).errors }, { status: 400 });
|
|
||||||
}
|
|
||||||
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function DELETE(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
|
||||||
const { id } = await params;
|
|
||||||
await db.delete(pastes).where(eq(pastes.id, id));
|
|
||||||
return new NextResponse(null, { status: 204 });
|
|
||||||
}
|
|
||||||
|
|
@ -1,114 +0,0 @@
|
||||||
import { NextRequest, NextResponse } from 'next/server';
|
|
||||||
import { db } from '@/db';
|
|
||||||
import { pastes, tags, pastesToTags } from '@/db/schema';
|
|
||||||
import { nanoid } from 'nanoid';
|
|
||||||
import { z, ZodError } from 'zod';
|
|
||||||
import { eq, desc, like, and } from 'drizzle-orm';
|
|
||||||
import { auth } from '@/auth';
|
|
||||||
|
|
||||||
const createPasteSchema = z.object({
|
|
||||||
content: z.string().min(1),
|
|
||||||
title: z.string().optional(),
|
|
||||||
tags: z.array(z.string()).optional(),
|
|
||||||
sessionId: z.string().optional(),
|
|
||||||
visibility: z.enum(['public', 'unlisted', 'private']).optional().default('public'),
|
|
||||||
expiresIn: z.number().optional(), // seconds
|
|
||||||
contentType: z.string().optional(),
|
|
||||||
syntax: z.string().optional(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export async function POST(req: NextRequest) {
|
|
||||||
try {
|
|
||||||
const body = await req.json();
|
|
||||||
const session = await auth();
|
|
||||||
|
|
||||||
// API Key Auth for Desktop Client
|
|
||||||
const apiKey = req.headers.get('x-api-key');
|
|
||||||
const isApiAuth = apiKey && apiKey === process.env.KITES_API_KEY;
|
|
||||||
|
|
||||||
if (!session && !isApiAuth) {
|
|
||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const validated = createPasteSchema.parse(body);
|
|
||||||
|
|
||||||
const id = nanoid(10);
|
|
||||||
|
|
||||||
// Calculate expiration
|
|
||||||
let expiresAt = null;
|
|
||||||
if (validated.expiresIn) {
|
|
||||||
// Simple expiration logic (seconds)
|
|
||||||
expiresAt = new Date(Date.now() + validated.expiresIn * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
await db.insert(pastes).values({
|
|
||||||
id,
|
|
||||||
content: validated.content,
|
|
||||||
title: validated.title,
|
|
||||||
sessionId: validated.sessionId,
|
|
||||||
visibility: validated.visibility,
|
|
||||||
expiresAt,
|
|
||||||
contentType: validated.contentType,
|
|
||||||
syntax: validated.syntax,
|
|
||||||
authorId: session?.user?.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (validated.tags && validated.tags.length > 0) {
|
|
||||||
for (const tagName of validated.tags) {
|
|
||||||
// Simple tag handling: create if not exists, then link
|
|
||||||
// In a real app, might want to optimize this
|
|
||||||
let tagId = nanoid(8);
|
|
||||||
|
|
||||||
// Check if tag exists
|
|
||||||
const existingTag = (await db.select().from(tags).where(eq(tags.name, tagName)).limit(1))[0];
|
|
||||||
|
|
||||||
if (existingTag) {
|
|
||||||
tagId = existingTag.id;
|
|
||||||
} else {
|
|
||||||
await db.insert(tags).values({ id: tagId, name: tagName });
|
|
||||||
}
|
|
||||||
|
|
||||||
await db.insert(pastesToTags).values({
|
|
||||||
pasteId: id,
|
|
||||||
tagId: tagId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const created = (await db.select().from(pastes).where(eq(pastes.id, id)).limit(1))[0];
|
|
||||||
|
|
||||||
return NextResponse.json(created, { status: 201 });
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof ZodError) {
|
|
||||||
return NextResponse.json({ error: (error as any).errors }, { status: 400 });
|
|
||||||
}
|
|
||||||
console.error(error);
|
|
||||||
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function GET(req: NextRequest) {
|
|
||||||
const { searchParams } = new URL(req.url);
|
|
||||||
const limit = parseInt(searchParams.get('limit') || '20');
|
|
||||||
const offset = parseInt(searchParams.get('offset') || '0');
|
|
||||||
const sessionId = searchParams.get('session_id');
|
|
||||||
const authorId = searchParams.get('author_id');
|
|
||||||
const q = searchParams.get('q');
|
|
||||||
|
|
||||||
// Basic filtering
|
|
||||||
let conditions = [];
|
|
||||||
if (sessionId) conditions.push(eq(pastes.sessionId, sessionId));
|
|
||||||
if (authorId) conditions.push(eq(pastes.authorId, authorId));
|
|
||||||
if (q) conditions.push(like(pastes.title, `%${q}%`)); // Simple title search
|
|
||||||
|
|
||||||
// TODO: Tag filtering requires join
|
|
||||||
|
|
||||||
const results = await db.select()
|
|
||||||
.from(pastes)
|
|
||||||
.where(and(...conditions))
|
|
||||||
.orderBy(desc(pastes.createdAt))
|
|
||||||
.limit(limit)
|
|
||||||
.offset(offset);
|
|
||||||
|
|
||||||
return NextResponse.json(results);
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
import { NextRequest, NextResponse } from 'next/server';
|
|
||||||
import { db } from '@/db';
|
|
||||||
import { pastes } from '@/db/schema';
|
|
||||||
import { eq, desc } from 'drizzle-orm';
|
|
||||||
|
|
||||||
export async function GET(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
|
||||||
const { id: sessionId } = await params;
|
|
||||||
|
|
||||||
const results = await db.select()
|
|
||||||
.from(pastes)
|
|
||||||
.where(eq(pastes.sessionId, sessionId))
|
|
||||||
.orderBy(desc(pastes.createdAt));
|
|
||||||
|
|
||||||
return NextResponse.json(results);
|
|
||||||
}
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
import { NextRequest, NextResponse } from 'next/server';
|
|
||||||
import { db } from '@/db';
|
|
||||||
import { agentSessions } from '@/db/schema';
|
|
||||||
import { nanoid } from 'nanoid';
|
|
||||||
import { z, ZodError } from 'zod';
|
|
||||||
import { eq } from 'drizzle-orm';
|
|
||||||
import { auth } from '@/auth';
|
|
||||||
|
|
||||||
const createSessionSchema = z.object({
|
|
||||||
title: z.string().optional(),
|
|
||||||
agentName: z.string().optional(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export async function POST(req: NextRequest) {
|
|
||||||
try {
|
|
||||||
const body = await req.json();
|
|
||||||
const session = await auth();
|
|
||||||
const validated = createSessionSchema.parse(body);
|
|
||||||
|
|
||||||
const id = nanoid(12);
|
|
||||||
|
|
||||||
await db.insert(agentSessions).values({
|
|
||||||
id,
|
|
||||||
title: validated.title,
|
|
||||||
agentName: validated.agentName,
|
|
||||||
userId: session?.user?.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
const created = (await db.select().from(agentSessions).where(eq(agentSessions.id, id)).limit(1))[0]; // Re-fetch to get default fields if any
|
|
||||||
|
|
||||||
// Since we inserted, we can just return what we have + id if we trust it, but fetching is safer for timestamps
|
|
||||||
// Actually better-sqlite3 insert doesn't return the row by default unless using returning() which is supported in Drizzle now
|
|
||||||
// Let's use returning() in the insert above if possible, but I used .values().
|
|
||||||
// Drizzle with SQLite supports .returning()
|
|
||||||
|
|
||||||
// Let's refactor to use returning() for cleaner code in next iteration or just re-fetch.
|
|
||||||
// Re-fetching is fine.
|
|
||||||
|
|
||||||
return NextResponse.json(created || { id, ...validated }, { status: 201 });
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof ZodError) {
|
|
||||||
return NextResponse.json({ error: (error as any).errors }, { status: 400 });
|
|
||||||
}
|
|
||||||
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 25 KiB |
|
|
@ -1,100 +0,0 @@
|
||||||
@import "tailwindcss";
|
|
||||||
|
|
||||||
@layer base {
|
|
||||||
:root {
|
|
||||||
--background: 0 0% 100%;
|
|
||||||
--foreground: 222.2 84% 4.9%;
|
|
||||||
|
|
||||||
--card: 0 0% 100%;
|
|
||||||
--card-foreground: 222.2 84% 4.9%;
|
|
||||||
|
|
||||||
--popover: 0 0% 100%;
|
|
||||||
--popover-foreground: 222.2 84% 4.9%;
|
|
||||||
|
|
||||||
--primary: 222.2 47.4% 11.2%;
|
|
||||||
--primary-foreground: 210 40% 98%;
|
|
||||||
|
|
||||||
--secondary: 210 40% 96.1%;
|
|
||||||
--secondary-foreground: 222.2 47.4% 11.2%;
|
|
||||||
|
|
||||||
--muted: 210 40% 96.1%;
|
|
||||||
--muted-foreground: 215.4 16.3% 46.9%;
|
|
||||||
|
|
||||||
--accent: 210 40% 96.1%;
|
|
||||||
--accent-foreground: 222.2 47.4% 11.2%;
|
|
||||||
|
|
||||||
--destructive: 0 84.2% 60.2%;
|
|
||||||
--destructive-foreground: 210 40% 98%;
|
|
||||||
|
|
||||||
--border: 214.3 31.8% 91.4%;
|
|
||||||
--input: 214.3 31.8% 91.4%;
|
|
||||||
--ring: 222.2 84% 4.9%;
|
|
||||||
|
|
||||||
--radius: 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dark {
|
|
||||||
--background: 222.2 84% 4.9%;
|
|
||||||
--foreground: 210 40% 98%;
|
|
||||||
|
|
||||||
--card: 222.2 84% 4.9%;
|
|
||||||
--card-foreground: 210 40% 98%;
|
|
||||||
|
|
||||||
--popover: 222.2 84% 4.9%;
|
|
||||||
--popover-foreground: 210 40% 98%;
|
|
||||||
|
|
||||||
--primary: 210 40% 98%;
|
|
||||||
--primary-foreground: 222.2 47.4% 11.2%;
|
|
||||||
|
|
||||||
--secondary: 217.2 32.6% 17.5%;
|
|
||||||
--secondary-foreground: 210 40% 98%;
|
|
||||||
|
|
||||||
--muted: 217.2 32.6% 17.5%;
|
|
||||||
--muted-foreground: 215 20.2% 65.1%;
|
|
||||||
|
|
||||||
--accent: 217.2 32.6% 17.5%;
|
|
||||||
--accent-foreground: 210 40% 98%;
|
|
||||||
|
|
||||||
--destructive: 0 62.8% 30.6%;
|
|
||||||
--destructive-foreground: 210 40% 98%;
|
|
||||||
|
|
||||||
--border: 217.2 32.6% 17.5%;
|
|
||||||
--input: 217.2 32.6% 17.5%;
|
|
||||||
--ring: 212.7 26.8% 83.9%;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@theme {
|
|
||||||
--color-background: var(--background);
|
|
||||||
--color-foreground: var(--foreground);
|
|
||||||
--color-card: var(--card);
|
|
||||||
--color-card-foreground: var(--card-foreground);
|
|
||||||
--color-popover: var(--popover);
|
|
||||||
--color-popover-foreground: var(--popover-foreground);
|
|
||||||
--color-primary: var(--primary);
|
|
||||||
--color-primary-foreground: var(--primary-foreground);
|
|
||||||
--color-secondary: var(--secondary);
|
|
||||||
--color-secondary-foreground: var(--secondary-foreground);
|
|
||||||
--color-muted: var(--muted);
|
|
||||||
--color-muted-foreground: var(--muted-foreground);
|
|
||||||
--color-accent: var(--accent);
|
|
||||||
--color-accent-foreground: var(--accent-foreground);
|
|
||||||
--color-destructive: var(--destructive);
|
|
||||||
--color-destructive-foreground: var(--destructive-foreground);
|
|
||||||
--color-border: var(--border);
|
|
||||||
--color-input: var(--input);
|
|
||||||
--color-ring: var(--ring);
|
|
||||||
--radius-sm: calc(var(--radius) - 4px);
|
|
||||||
--radius-md: calc(var(--radius) - 2px);
|
|
||||||
--radius-lg: var(--radius);
|
|
||||||
}
|
|
||||||
|
|
||||||
@layer base {
|
|
||||||
* {
|
|
||||||
@apply border-border;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
@apply bg-background text-foreground;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
import type { Metadata } from "next";
|
|
||||||
import { Inter } from "next/font/google";
|
|
||||||
import "./globals.css";
|
|
||||||
import { ThemeProvider } from "@/components/theme-provider";
|
|
||||||
import { Navbar } from "@/components/navbar";
|
|
||||||
import { cn } from "@/lib/utils";
|
|
||||||
|
|
||||||
const inter = Inter({ subsets: ["latin"] });
|
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
|
||||||
title: "Kites - Agentic Pastebin",
|
|
||||||
description: "A clean, agent-native pastebin service.",
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function RootLayout({
|
|
||||||
children,
|
|
||||||
}: Readonly<{
|
|
||||||
children: React.ReactNode;
|
|
||||||
}>) {
|
|
||||||
return (
|
|
||||||
<html lang="en" suppressHydrationWarning>
|
|
||||||
<body className={cn(inter.className, "min-h-screen bg-background font-sans antialiased")}>
|
|
||||||
<ThemeProvider
|
|
||||||
attribute="class"
|
|
||||||
defaultTheme="system"
|
|
||||||
enableSystem
|
|
||||||
disableTransitionOnChange
|
|
||||||
>
|
|
||||||
<div className="relative flex min-h-screen flex-col">
|
|
||||||
<Navbar />
|
|
||||||
<main className="flex-1 container mx-auto px-4 py-6">
|
|
||||||
{children}
|
|
||||||
</main>
|
|
||||||
</div>
|
|
||||||
</ThemeProvider>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
import { PasteForm } from "@/components/paste-form";
|
|
||||||
import Link from "next/link";
|
|
||||||
import { Copy, Terminal, Key } from "lucide-react";
|
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
|
|
||||||
export default function NewPastePage() {
|
|
||||||
return (
|
|
||||||
<div className="max-w-3xl mx-auto p-4 md:p-6">
|
|
||||||
<h1 className="text-4xl font-extrabold tracking-tight mb-4 text-center">Create New Paste</h1>
|
|
||||||
<p className="text-muted-foreground text-center mb-10 max-w-xl mx-auto">
|
|
||||||
Kites helps you manage code snippets, agent outputs, and clipboard history. Create a paste below, or learn how to integrate with your tools.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
{/* Instruction Cards */}
|
|
||||||
<div className="grid md:grid-cols-2 gap-6 mb-12">
|
|
||||||
<div className="bg-card p-6 rounded-lg border flex flex-col items-start space-y-4">
|
|
||||||
<div className="p-3 rounded-full bg-primary/10 text-primary">
|
|
||||||
<Copy className="w-6 h-6" />
|
|
||||||
</div>
|
|
||||||
<h2 className="text-xl font-semibold">For Humans</h2>
|
|
||||||
<p className="text-muted-foreground flex-1">
|
|
||||||
Simply paste your content below. Choose a title, syntax, and visibility. Your paste will be available in your personal feed.
|
|
||||||
</p>
|
|
||||||
<Button variant="outline">
|
|
||||||
<Link href="/">View My Pastes</Link>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
<div className="bg-card p-6 rounded-lg border flex flex-col items-start space-y-4">
|
|
||||||
<div className="p-3 rounded-full bg-green-500/10 text-green-500">
|
|
||||||
<Terminal className="w-6 h-6" />
|
|
||||||
</div>
|
|
||||||
<h2 className="text-xl font-semibold">For Agents & Clients</h2>
|
|
||||||
<p className="text-muted-foreground flex-1">
|
|
||||||
Integrate your LLMs, scripts, or desktop clipboard managers using the Kites API. Generate an API key to securely push data.
|
|
||||||
</p>
|
|
||||||
<Button>
|
|
||||||
<Link href="/settings/api-keys">
|
|
||||||
<Key className="w-4 h-4 mr-2" /> Manage API Keys
|
|
||||||
</Link>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Paste Form */}
|
|
||||||
<h2 className="text-2xl font-bold tracking-tight mb-6">Your Content Here</h2>
|
|
||||||
<PasteForm />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
@ -1,147 +0,0 @@
|
||||||
import Link from "next/link";
|
|
||||||
import { db } from "@/db";
|
|
||||||
import { pastes } from "@/db/schema";
|
|
||||||
import { desc, eq } from "drizzle-orm";
|
|
||||||
import { formatDistanceToNow } from "date-fns";
|
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import { Terminal, Cpu, Share2, Shield, Code, Sparkles } from "lucide-react";
|
|
||||||
import { auth } from "@/auth";
|
|
||||||
import { redirect } from "next/navigation"; // Import redirect
|
|
||||||
|
|
||||||
export const dynamic = 'force-dynamic';
|
|
||||||
|
|
||||||
export default async function Home() {
|
|
||||||
const session = await auth();
|
|
||||||
const userId = session?.user?.id;
|
|
||||||
|
|
||||||
if (userId) { // Redirect if logged in
|
|
||||||
redirect("/dashboard");
|
|
||||||
}
|
|
||||||
|
|
||||||
const recentPastes = await db.select()
|
|
||||||
.from(pastes)
|
|
||||||
.orderBy(desc(pastes.createdAt))
|
|
||||||
.limit(12);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="flex flex-col min-h-screen">
|
|
||||||
{/* Hero Section */}
|
|
||||||
<section className="relative py-24 lg:py-32 overflow-hidden">
|
|
||||||
<div className="container px-4 md:px-6 relative z-10">
|
|
||||||
<div className="flex flex-col items-center text-center space-y-8">
|
|
||||||
<div className="inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 border-transparent bg-primary/10 text-primary hover:bg-primary/20">
|
|
||||||
<Sparkles className="w-3 h-3 mr-1" />
|
|
||||||
v1.0 Public Beta
|
|
||||||
</div>
|
|
||||||
<h1 className="text-4xl font-extrabold tracking-tight lg:text-6xl max-w-3xl bg-clip-text text-transparent bg-gradient-to-r from-foreground to-foreground/70">
|
|
||||||
The Shared Brain for <br/> Humans & AI Agents
|
|
||||||
</h1>
|
|
||||||
<p className="text-xl text-muted-foreground max-w-[42rem]">
|
|
||||||
Stop copy-pasting into the void. Kites is an agent-native clipboard that gives your LLMs a persistent memory and you a unified history.
|
|
||||||
</p>
|
|
||||||
<div className="flex gap-4">
|
|
||||||
<Link href="/new">
|
|
||||||
<Button size="lg" className="h-12 px-8">Start Pasting</Button>
|
|
||||||
</Link>
|
|
||||||
{userId ? ( // Conditional button for logged-in users
|
|
||||||
<Link href="/dashboard">
|
|
||||||
<Button variant="outline" size="lg" className="h-12 px-8">Go to Dashboard</Button>
|
|
||||||
</Link>
|
|
||||||
) : (
|
|
||||||
<Link href="https://github.com/fullsizemalt/kites">
|
|
||||||
<Button variant="outline" size="lg" className="h-12 px-8">View on GitHub</Button>
|
|
||||||
</Link>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Abstract "Network" Background */}
|
|
||||||
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[800px] h-[500px] bg-primary/5 rounded-full blur-3xl -z-10 pointer-events-none" />
|
|
||||||
</section>
|
|
||||||
|
|
||||||
{/* Feature Grid */}
|
|
||||||
<section className="py-12 bg-muted/30 border-y">
|
|
||||||
<div className="container px-4 md:px-6">
|
|
||||||
<div className="grid md:grid-cols-3 gap-8">
|
|
||||||
<div className="flex flex-col items-center text-center p-6 space-y-4 rounded-xl hover:bg-background transition-colors">
|
|
||||||
<div className="p-3 bg-blue-500/10 text-blue-500 rounded-full">
|
|
||||||
<Terminal className="w-8 h-8" />
|
|
||||||
</div>
|
|
||||||
<h3 className="text-xl font-bold">Agent-Native API</h3>
|
|
||||||
<p className="text-muted-foreground">
|
|
||||||
Give your agents a <code>POST /pastes</code> endpoint. Let them save context, code blocks, and logs directly to your view.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div className="flex flex-col items-center text-center p-6 space-y-4 rounded-xl hover:bg-background transition-colors">
|
|
||||||
<div className="p-3 bg-purple-500/10 text-purple-500 rounded-full">
|
|
||||||
<Share2 className="w-8 h-8" />
|
|
||||||
</div>
|
|
||||||
<h3 className="text-xl font-bold">Unified History</h3>
|
|
||||||
<p className="text-muted-foreground">
|
|
||||||
Your desktop clipboard, your agent's output, and your mobile saves—all in one structured, searchable timeline.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div className="flex flex-col items-center text-center p-6 space-y-4 rounded-xl hover:bg-background transition-colors">
|
|
||||||
<div className="p-3 bg-green-500/10 text-green-500 rounded-full">
|
|
||||||
<Shield className="w-8 h-8" />
|
|
||||||
</div>
|
|
||||||
<h3 className="text-xl font-bold">Privacy First</h3>
|
|
||||||
<p className="text-muted-foreground">
|
|
||||||
Self-hostable. Private by default. You control the retention policy and visibility of every snippet.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
{/* Live Feed (Recent Pastes) */}
|
|
||||||
<section className="py-16">
|
|
||||||
<div className="container px-4 md:px-6 space-y-8">
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<div>
|
|
||||||
<h2 className="text-2xl font-bold tracking-tight">{userId ? "My Recent Pastes" : "Live Context Feed"}</h2>
|
|
||||||
<p className="text-muted-foreground">{userId ? "Your latest snippets and agent interactions." : "Recent items from our community."}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
|
||||||
{recentPastes.length === 0 ? (
|
|
||||||
<div className="col-span-full text-center py-12 border-2 border-dashed rounded-xl text-muted-foreground">
|
|
||||||
<div className="mb-2">👻</div>
|
|
||||||
No context yet. Create your first paste!
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
recentPastes.map((paste) => (
|
|
||||||
<Link
|
|
||||||
key={paste.id}
|
|
||||||
href={`/paste/${paste.id}`}
|
|
||||||
className="group block p-5 rounded-lg border bg-card text-card-foreground shadow-sm hover:shadow-md hover:border-primary/50 transition-all"
|
|
||||||
>
|
|
||||||
<div className="flex items-center justify-between mb-3">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
{paste.syntax ? <Code className="w-4 h-4 text-primary" /> : <Cpu className="w-4 h-4 text-muted-foreground" />}
|
|
||||||
<span className="text-xs font-medium text-muted-foreground uppercase">{paste.syntax || 'Text'}</span>
|
|
||||||
</div>
|
|
||||||
<span className="text-xs text-muted-foreground">{formatDistanceToNow(paste.createdAt!, { addSuffix: true })}</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h3 className="font-semibold truncate mb-2 group-hover:text-primary transition-colors">
|
|
||||||
{paste.title || "Untitled Snippet"}
|
|
||||||
</h3>
|
|
||||||
|
|
||||||
<div className="relative">
|
|
||||||
<div className="text-sm text-muted-foreground line-clamp-3 font-mono bg-muted/50 p-3 rounded-md text-xs">
|
|
||||||
{paste.content}
|
|
||||||
</div>
|
|
||||||
<div className="absolute inset-0 bg-gradient-to-b from-transparent to-card/10 group-hover:to-transparent" />
|
|
||||||
</div>
|
|
||||||
</Link>
|
|
||||||
))
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
@ -1,76 +0,0 @@
|
||||||
import { db } from "@/db";
|
|
||||||
import { pastes, tags, pastesToTags } from "@/db/schema";
|
|
||||||
import { eq } from "drizzle-orm";
|
|
||||||
import { notFound } from "next/navigation";
|
|
||||||
import { formatDistanceToNow } from "date-fns";
|
|
||||||
import { CodeViewer } from "@/components/code-viewer";
|
|
||||||
import Link from "next/link";
|
|
||||||
import { Badge } from "@/components/ui/badge"; // We don't have this yet, I'll inline styles or create it
|
|
||||||
|
|
||||||
// Inline simple Badge component for now to avoid creating too many files
|
|
||||||
function SimpleBadge({ children, className }: { children: React.ReactNode, className?: string }) {
|
|
||||||
return (
|
|
||||||
<span className={`inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80 ${className}`}>
|
|
||||||
{children}
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default async function PastePage({ params }: { params: Promise<{ id: string }> }) {
|
|
||||||
const { id } = await params;
|
|
||||||
const paste = (await db.select().from(pastes).where(eq(pastes.id, id)).limit(1))[0];
|
|
||||||
|
|
||||||
if (!paste) {
|
|
||||||
notFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
const pasteTags = await db.select({
|
|
||||||
id: tags.id,
|
|
||||||
name: tags.name,
|
|
||||||
})
|
|
||||||
.from(tags)
|
|
||||||
.innerJoin(pastesToTags, eq(tags.id, pastesToTags.tagId))
|
|
||||||
.where(eq(pastesToTags.pasteId, id));
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="space-y-6">
|
|
||||||
<div className="flex flex-col gap-4 md:flex-row md:items-center md:justify-between">
|
|
||||||
<div className="space-y-1">
|
|
||||||
<h1 className="text-2xl font-bold tracking-tight">{paste.title || "Untitled Paste"}</h1>
|
|
||||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
|
||||||
<span>{formatDistanceToNow(paste.createdAt!, { addSuffix: true })}</span>
|
|
||||||
<span>•</span>
|
|
||||||
<span className="font-mono">{paste.syntax || "text"}</span>
|
|
||||||
<span>•</span>
|
|
||||||
<span className="capitalize">{paste.visibility}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<a
|
|
||||||
href={`/api/v1/pastes/${paste.id}?raw=1`}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background hover:bg-accent hover:text-accent-foreground h-9 px-4 py-2"
|
|
||||||
>
|
|
||||||
Raw
|
|
||||||
</a>
|
|
||||||
{/* Copy button could go here */}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{pasteTags.length > 0 && (
|
|
||||||
<div className="flex flex-wrap gap-2">
|
|
||||||
{pasteTags.map((tag) => (
|
|
||||||
<Link key={tag.id} href={`/tag/${tag.id}`}>
|
|
||||||
<SimpleBadge>#{tag.name}</SimpleBadge>
|
|
||||||
</Link>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="rounded-lg border bg-card text-card-foreground shadow-sm">
|
|
||||||
<CodeViewer code={paste.content} language={paste.syntax || 'text'} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
@ -1,64 +0,0 @@
|
||||||
import Link from "next/link";
|
|
||||||
import { db } from "@/db";
|
|
||||||
import { agentSessions, pastes } from "@/db/schema";
|
|
||||||
import { eq, desc } from "drizzle-orm";
|
|
||||||
import { notFound } from "next/navigation";
|
|
||||||
import { formatDistanceToNow } from "date-fns";
|
|
||||||
|
|
||||||
export default async function SessionPage({ params }: { params: Promise<{ id: string }> }) {
|
|
||||||
const { id } = await params;
|
|
||||||
const session = (await db.select().from(agentSessions).where(eq(agentSessions.id, id)).limit(1))[0];
|
|
||||||
|
|
||||||
if (!session) {
|
|
||||||
notFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
const sessionPastes = await db.select()
|
|
||||||
.from(pastes)
|
|
||||||
.where(eq(pastes.sessionId, session.id))
|
|
||||||
.orderBy(desc(pastes.createdAt));
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="space-y-6">
|
|
||||||
<div className="space-y-1">
|
|
||||||
<h1 className="text-2xl font-bold tracking-tight">{session.title || "Session " + session.id}</h1>
|
|
||||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
|
||||||
<span>{formatDistanceToNow(session.createdAt!, { addSuffix: true })}</span>
|
|
||||||
<span>•</span>
|
|
||||||
<span className="font-mono">{session.agentName || "Unknown Agent"}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid gap-4">
|
|
||||||
{sessionPastes.length === 0 ? (
|
|
||||||
<div className="text-center py-12 text-muted-foreground">
|
|
||||||
No pastes in this session.
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
sessionPastes.map((paste) => (
|
|
||||||
<Link
|
|
||||||
key={paste.id}
|
|
||||||
href={`/paste/${paste.id}`}
|
|
||||||
className="block p-4 rounded-lg border bg-card text-card-foreground shadow-sm hover:shadow-md transition-shadow"
|
|
||||||
>
|
|
||||||
<div className="flex items-center justify-between mb-1">
|
|
||||||
<h3 className="font-medium truncate">
|
|
||||||
{paste.title || "Untitled Paste"}
|
|
||||||
</h3>
|
|
||||||
<span className="text-xs text-muted-foreground font-mono">
|
|
||||||
{paste.syntax || "text"}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div className="text-xs text-muted-foreground line-clamp-2 font-mono bg-muted/50 p-1.5 rounded mb-2">
|
|
||||||
{paste.content}
|
|
||||||
</div>
|
|
||||||
<div className="text-xs text-muted-foreground">
|
|
||||||
{formatDistanceToNow(paste.createdAt!, { addSuffix: true })}
|
|
||||||
</div>
|
|
||||||
</Link>
|
|
||||||
))
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
import Link from "next/link";
|
|
||||||
import { db } from "@/db";
|
|
||||||
import { agentSessions, pastes } from "@/db/schema";
|
|
||||||
import { desc, eq, sql } from "drizzle-orm";
|
|
||||||
import { formatDistanceToNow } from "date-fns";
|
|
||||||
|
|
||||||
export const dynamic = 'force-dynamic';
|
|
||||||
|
|
||||||
export default async function SessionsPage() {
|
|
||||||
// Fetch sessions with paste count
|
|
||||||
const allSessions = await db.select({
|
|
||||||
id: agentSessions.id,
|
|
||||||
title: agentSessions.title,
|
|
||||||
agentName: agentSessions.agentName,
|
|
||||||
createdAt: agentSessions.createdAt,
|
|
||||||
pasteCount: sql<number>`count(${pastes.id})`,
|
|
||||||
})
|
|
||||||
.from(agentSessions)
|
|
||||||
.leftJoin(pastes, eq(agentSessions.id, pastes.sessionId))
|
|
||||||
.groupBy(agentSessions.id)
|
|
||||||
.orderBy(desc(agentSessions.createdAt));
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="space-y-6">
|
|
||||||
<h1 className="text-3xl font-bold tracking-tight">Sessions</h1>
|
|
||||||
|
|
||||||
<div className="grid gap-4">
|
|
||||||
{allSessions.length === 0 ? (
|
|
||||||
<div className="text-center py-12 text-muted-foreground">
|
|
||||||
No sessions found.
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
allSessions.map((session) => (
|
|
||||||
<Link
|
|
||||||
key={session.id}
|
|
||||||
href={`/sessions/${session.id}`}
|
|
||||||
className="block p-6 rounded-lg border bg-card text-card-foreground shadow-sm hover:shadow-md transition-shadow"
|
|
||||||
>
|
|
||||||
<div className="flex items-center justify-between mb-2">
|
|
||||||
<h2 className="font-semibold text-lg">
|
|
||||||
{session.title || session.id}
|
|
||||||
</h2>
|
|
||||||
<span className="text-xs text-muted-foreground font-mono">
|
|
||||||
{session.agentName || "Unknown Agent"}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-4 text-xs text-muted-foreground">
|
|
||||||
<span>{formatDistanceToNow(session.createdAt!, { addSuffix: true })}</span>
|
|
||||||
<span>{session.pasteCount} pastes</span>
|
|
||||||
</div>
|
|
||||||
</Link>
|
|
||||||
))
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
@ -1,75 +0,0 @@
|
||||||
import Link from "next/link";
|
|
||||||
import { db } from "@/db";
|
|
||||||
import { tags, pastes, pastesToTags } from "@/db/schema";
|
|
||||||
import { eq, desc } from "drizzle-orm";
|
|
||||||
import { notFound } from "next/navigation";
|
|
||||||
import { formatDistanceToNow } from "date-fns";
|
|
||||||
import { Badge } from "@/components/ui/badge";
|
|
||||||
|
|
||||||
export default async function TagPage({ params }: { params: Promise<{ id: string }> }) {
|
|
||||||
const { id } = await params;
|
|
||||||
const tag = (await db.select().from(tags).where(eq(tags.id, id)).limit(1))[0];
|
|
||||||
|
|
||||||
if (!tag) {
|
|
||||||
notFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
const taggedPastes = await db.select({
|
|
||||||
id: pastes.id,
|
|
||||||
title: pastes.title,
|
|
||||||
content: pastes.content,
|
|
||||||
syntax: pastes.syntax,
|
|
||||||
createdAt: pastes.createdAt,
|
|
||||||
visibility: pastes.visibility,
|
|
||||||
})
|
|
||||||
.from(pastes)
|
|
||||||
.innerJoin(pastesToTags, eq(pastes.id, pastesToTags.pasteId))
|
|
||||||
.where(eq(pastesToTags.tagId, tag.id))
|
|
||||||
.orderBy(desc(pastes.createdAt))
|
|
||||||
.limit(50);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="space-y-6">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<h1 className="text-2xl font-bold tracking-tight">Tag:</h1>
|
|
||||||
<Badge className="text-lg px-3 py-1">#{tag.name}</Badge>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid gap-4">
|
|
||||||
{taggedPastes.length === 0 ? (
|
|
||||||
<div className="text-center py-12 text-muted-foreground">
|
|
||||||
No pastes found with this tag.
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
taggedPastes.map((paste) => (
|
|
||||||
<Link
|
|
||||||
key={paste.id}
|
|
||||||
href={`/paste/${paste.id}`}
|
|
||||||
className="block p-6 rounded-lg border bg-card text-card-foreground shadow-sm hover:shadow-md transition-shadow"
|
|
||||||
>
|
|
||||||
<div className="flex items-center justify-between mb-2">
|
|
||||||
<h2 className="font-semibold text-lg truncate">
|
|
||||||
{paste.title || "Untitled Paste"}
|
|
||||||
</h2>
|
|
||||||
<span className="text-xs text-muted-foreground font-mono">
|
|
||||||
{paste.syntax || "text"}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div className="text-sm text-muted-foreground line-clamp-2 font-mono bg-muted/50 p-2 rounded">
|
|
||||||
{paste.content}
|
|
||||||
</div>
|
|
||||||
<div className="mt-4 flex items-center gap-4 text-xs text-muted-foreground">
|
|
||||||
<span>{formatDistanceToNow(paste.createdAt!, { addSuffix: true })}</span>
|
|
||||||
{paste.visibility !== 'public' && (
|
|
||||||
<span className="capitalize px-2 py-0.5 rounded-full bg-secondary text-secondary-foreground">
|
|
||||||
{paste.visibility}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</Link>
|
|
||||||
))
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
import NextAuth from "next-auth"
|
|
||||||
import { DrizzleAdapter } from "@auth/drizzle-adapter"
|
|
||||||
import { db } from "@/db"
|
|
||||||
import { accounts, sessions, users, verificationTokens } from "@/db/schema"
|
|
||||||
import Google from "next-auth/providers/google"
|
|
||||||
import GitHub from "next-auth/providers/github"
|
|
||||||
import Apple from "next-auth/providers/apple"
|
|
||||||
|
|
||||||
export const { handlers, auth, signIn, signOut } = NextAuth({
|
|
||||||
adapter: DrizzleAdapter(db, {
|
|
||||||
usersTable: users,
|
|
||||||
accountsTable: accounts,
|
|
||||||
sessionsTable: sessions,
|
|
||||||
verificationTokensTable: verificationTokens,
|
|
||||||
}),
|
|
||||||
providers: [Google, GitHub, Apple],
|
|
||||||
})
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
import { signIn, signOut } from "@/auth"
|
|
||||||
import { Button } from "./ui/button"
|
|
||||||
|
|
||||||
export function SignIn() {
|
|
||||||
return (
|
|
||||||
<form
|
|
||||||
action={async () => {
|
|
||||||
"use server"
|
|
||||||
await signIn()
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Button variant="outline" size="sm">Sign In</Button>
|
|
||||||
</form>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function SignOut() {
|
|
||||||
return (
|
|
||||||
<form
|
|
||||||
action={async () => {
|
|
||||||
"use server"
|
|
||||||
await signOut()
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Button variant="ghost" size="sm" className="w-full justify-start">
|
|
||||||
Sign Out
|
|
||||||
</Button>
|
|
||||||
</form>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
"use client"
|
|
||||||
|
|
||||||
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
|
|
||||||
import { vscDarkPlus, vs } from 'react-syntax-highlighter/dist/esm/styles/prism';
|
|
||||||
import { useTheme } from 'next-themes';
|
|
||||||
import { useEffect, useState } from 'react';
|
|
||||||
|
|
||||||
interface CodeViewerProps {
|
|
||||||
code: string;
|
|
||||||
language: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function CodeViewer({ code, language }: CodeViewerProps) {
|
|
||||||
const { theme } = useTheme();
|
|
||||||
const [mounted, setMounted] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setMounted(true);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
if (!mounted) {
|
|
||||||
return (
|
|
||||||
<pre className="p-4 rounded-md bg-muted overflow-auto">
|
|
||||||
<code>{code}</code>
|
|
||||||
</pre>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<SyntaxHighlighter
|
|
||||||
language={language || 'text'}
|
|
||||||
style={theme === 'dark' ? vscDarkPlus : vs}
|
|
||||||
customStyle={{ margin: 0, borderRadius: '0.5rem', fontSize: '0.875rem' }}
|
|
||||||
showLineNumbers
|
|
||||||
>
|
|
||||||
{code}
|
|
||||||
</SyntaxHighlighter>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
import Link from "next/link"
|
|
||||||
import { ThemeToggle } from "./theme-toggle"
|
|
||||||
import UserButton from "./user-button"
|
|
||||||
|
|
||||||
export function Navbar() {
|
|
||||||
return (
|
|
||||||
<header className="border-b">
|
|
||||||
<div className="container mx-auto px-4 h-16 flex items-center justify-between">
|
|
||||||
<div className="flex items-center gap-6">
|
|
||||||
<Link href="/" className="font-bold text-xl tracking-tight">
|
|
||||||
Kites
|
|
||||||
</Link>
|
|
||||||
<nav className="flex items-center gap-4 text-sm font-medium text-muted-foreground">
|
|
||||||
<Link href="/" className="hover:text-foreground transition-colors">
|
|
||||||
Home
|
|
||||||
</Link>
|
|
||||||
<Link href="/dashboard" className="hover:text-foreground transition-colors">
|
|
||||||
Dashboard
|
|
||||||
</Link>
|
|
||||||
<Link href="/sessions" className="hover:text-foreground transition-colors">
|
|
||||||
Sessions
|
|
||||||
</Link>
|
|
||||||
<Link href="/settings/api-keys" className="hover:text-foreground transition-colors">
|
|
||||||
Settings
|
|
||||||
</Link>
|
|
||||||
</nav>
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-4">
|
|
||||||
<ThemeToggle />
|
|
||||||
<UserButton />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
@ -1,141 +0,0 @@
|
||||||
"use client"
|
|
||||||
|
|
||||||
import { useState } from "react"
|
|
||||||
import { useRouter } from "next/navigation"
|
|
||||||
|
|
||||||
export function PasteForm() {
|
|
||||||
const router = useRouter()
|
|
||||||
const [loading, setLoading] = useState(false)
|
|
||||||
const [error, setError] = useState<string | null>(null)
|
|
||||||
|
|
||||||
async function onSubmit(event: React.FormEvent<HTMLFormElement>) {
|
|
||||||
event.preventDefault()
|
|
||||||
setLoading(true)
|
|
||||||
setError(null)
|
|
||||||
|
|
||||||
const formData = new FormData(event.currentTarget)
|
|
||||||
const data = {
|
|
||||||
title: formData.get("title"),
|
|
||||||
content: formData.get("content"),
|
|
||||||
syntax: formData.get("syntax"),
|
|
||||||
visibility: formData.get("visibility"),
|
|
||||||
tags: formData.get("tags")?.toString().split(",").map(t => t.trim()).filter(Boolean),
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const res = await fetch("/api/v1/pastes", {
|
|
||||||
method: "POST",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!res.ok) {
|
|
||||||
const json = await res.json()
|
|
||||||
throw new Error(JSON.stringify(json.error) || "Failed to create paste")
|
|
||||||
}
|
|
||||||
|
|
||||||
const created = await res.json()
|
|
||||||
router.push(`/paste/${created.id}`)
|
|
||||||
router.refresh()
|
|
||||||
} catch (err) {
|
|
||||||
setError(err instanceof Error ? err.message : "Something went wrong")
|
|
||||||
} finally {
|
|
||||||
setLoading(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<form onSubmit={onSubmit} className="space-y-6">
|
|
||||||
{error && (
|
|
||||||
<div className="p-4 rounded bg-destructive/10 text-destructive text-sm">
|
|
||||||
{error}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="space-y-2">
|
|
||||||
<label htmlFor="title" className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70">
|
|
||||||
Title (Optional)
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
id="title"
|
|
||||||
name="title"
|
|
||||||
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
|
|
||||||
placeholder="My awesome snippet"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid grid-cols-2 gap-4">
|
|
||||||
<div className="space-y-2">
|
|
||||||
<label htmlFor="syntax" className="text-sm font-medium leading-none">
|
|
||||||
Syntax
|
|
||||||
</label>
|
|
||||||
<select
|
|
||||||
id="syntax"
|
|
||||||
name="syntax"
|
|
||||||
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
|
||||||
>
|
|
||||||
<option value="text">Plain Text</option>
|
|
||||||
<option value="javascript">JavaScript</option>
|
|
||||||
<option value="typescript">TypeScript</option>
|
|
||||||
<option value="python">Python</option>
|
|
||||||
<option value="json">JSON</option>
|
|
||||||
<option value="markdown">Markdown</option>
|
|
||||||
<option value="html">HTML</option>
|
|
||||||
<option value="css">CSS</option>
|
|
||||||
<option value="bash">Bash</option>
|
|
||||||
<option value="go">Go</option>
|
|
||||||
<option value="rust">Rust</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-2">
|
|
||||||
<label htmlFor="visibility" className="text-sm font-medium leading-none">
|
|
||||||
Visibility
|
|
||||||
</label>
|
|
||||||
<select
|
|
||||||
id="visibility"
|
|
||||||
name="visibility"
|
|
||||||
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
|
||||||
>
|
|
||||||
<option value="public">Public</option>
|
|
||||||
<option value="unlisted">Unlisted</option>
|
|
||||||
<option value="private">Private</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-2">
|
|
||||||
<label htmlFor="tags" className="text-sm font-medium leading-none">
|
|
||||||
Tags (comma separated)
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
id="tags"
|
|
||||||
name="tags"
|
|
||||||
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
|
||||||
placeholder="bug, feature, wip"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-2">
|
|
||||||
<label htmlFor="content" className="text-sm font-medium leading-none">
|
|
||||||
Content
|
|
||||||
</label>
|
|
||||||
<textarea
|
|
||||||
id="content"
|
|
||||||
name="content"
|
|
||||||
required
|
|
||||||
className="flex min-h-[300px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm font-mono ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
|
|
||||||
placeholder="Paste your code here..."
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
disabled={loading}
|
|
||||||
className="inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2 w-full"
|
|
||||||
>
|
|
||||||
{loading ? "Creating..." : "Create Paste"}
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
"use client"
|
|
||||||
|
|
||||||
import * as React from "react"
|
|
||||||
import { ThemeProvider as NextThemesProvider } from "next-themes"
|
|
||||||
import { type ThemeProviderProps } from "next-themes"
|
|
||||||
|
|
||||||
export function ThemeProvider({ children, ...props }: ThemeProviderProps) {
|
|
||||||
return <NextThemesProvider {...props}>{children}</NextThemesProvider>
|
|
||||||
}
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
"use client"
|
|
||||||
|
|
||||||
import * as React from "react"
|
|
||||||
import { Moon, Sun } from "lucide-react"
|
|
||||||
import { useTheme } from "next-themes"
|
|
||||||
|
|
||||||
export function ThemeToggle() {
|
|
||||||
const { setTheme, theme } = useTheme()
|
|
||||||
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
onClick={() => setTheme(theme === "light" ? "dark" : "light")}
|
|
||||||
className="p-2 rounded-md hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors"
|
|
||||||
aria-label="Toggle theme"
|
|
||||||
>
|
|
||||||
<Sun className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
|
|
||||||
<Moon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100 top-2" />
|
|
||||||
<span className="sr-only">Toggle theme</span>
|
|
||||||
</button>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
import * as React from "react"
|
|
||||||
import { cva, type VariantProps } from "class-variance-authority"
|
|
||||||
import { cn } from "@/lib/utils"
|
|
||||||
|
|
||||||
const badgeVariants = cva(
|
|
||||||
"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
|
|
||||||
{
|
|
||||||
variants: {
|
|
||||||
variant: {
|
|
||||||
default:
|
|
||||||
"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",
|
|
||||||
secondary:
|
|
||||||
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
||||||
destructive:
|
|
||||||
"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
|
|
||||||
outline: "text-foreground",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
defaultVariants: {
|
|
||||||
variant: "default",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
export interface BadgeProps
|
|
||||||
extends React.HTMLAttributes<HTMLDivElement>,
|
|
||||||
VariantProps<typeof badgeVariants> { }
|
|
||||||
|
|
||||||
function Badge({ className, variant, ...props }: BadgeProps) {
|
|
||||||
return (
|
|
||||||
<div className={cn(badgeVariants({ variant }), className)} {...props} />
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export { Badge, badgeVariants }
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
import * as React from "react"
|
|
||||||
import { clsx, type ClassValue } from "clsx"
|
|
||||||
import { twMerge } from "tailwind-merge"
|
|
||||||
|
|
||||||
export function cn(...inputs: ClassValue[]) {
|
|
||||||
return twMerge(clsx(inputs))
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ButtonProps
|
|
||||||
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
||||||
variant?: "default" | "outline" | "ghost"
|
|
||||||
size?: "default" | "sm" | "lg"
|
|
||||||
}
|
|
||||||
|
|
||||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
||||||
({ className, variant = "default", size = "default", ...props }, ref) => {
|
|
||||||
const variants = {
|
|
||||||
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
||||||
outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
|
||||||
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
||||||
}
|
|
||||||
const sizes = {
|
|
||||||
default: "h-10 px-4 py-2",
|
|
||||||
sm: "h-9 rounded-md px-3",
|
|
||||||
lg: "h-11 rounded-md px-8",
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
className={cn(
|
|
||||||
"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
|
||||||
variants[variant],
|
|
||||||
sizes[size],
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
ref={ref}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
Button.displayName = "Button"
|
|
||||||
|
|
||||||
export { Button }
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
import { auth } from "@/auth"
|
|
||||||
import { SignIn, SignOut } from "./auth-components"
|
|
||||||
import { Button } from "./ui/button"
|
|
||||||
|
|
||||||
export default async function UserButton() {
|
|
||||||
const session = await auth()
|
|
||||||
|
|
||||||
if (!session?.user) return <SignIn />
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="flex items-center gap-4">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
{session.user.image ? (
|
|
||||||
<img
|
|
||||||
src={session.user.image}
|
|
||||||
alt={session.user.name || "User"}
|
|
||||||
className="w-8 h-8 rounded-full border border-border"
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<div className="w-8 h-8 rounded-full bg-muted flex items-center justify-center text-xs font-medium">
|
|
||||||
{session.user.name?.[0] || "U"}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<span className="text-sm font-medium hidden md:inline-block">
|
|
||||||
{session.user.name}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<SignOut />
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
import { drizzle } from 'drizzle-orm/node-postgres';
|
|
||||||
import { Pool } from 'pg';
|
|
||||||
import * as schema from './schema';
|
|
||||||
|
|
||||||
const pool = new Pool({
|
|
||||||
connectionString: process.env.DATABASE_URL,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const db = drizzle(pool, { schema });
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
import { migrate } from 'drizzle-orm/node-postgres/migrator';
|
|
||||||
import { db } from './index';
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
console.log('Running migrations...');
|
|
||||||
await migrate(db, { migrationsFolder: 'drizzle' });
|
|
||||||
console.log('Migrations complete!');
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
main().catch((err) => {
|
|
||||||
console.error('Migration failed!', err);
|
|
||||||
process.exit(1);
|
|
||||||
});
|
|
||||||
|
|
@ -1,120 +0,0 @@
|
||||||
import { pgTable, text, integer, timestamp, primaryKey, index, boolean } from 'drizzle-orm/pg-core';
|
|
||||||
import { sql } from 'drizzle-orm';
|
|
||||||
import type { AdapterAccount } from "next-auth/adapters";
|
|
||||||
|
|
||||||
// --- Application Tables ---
|
|
||||||
|
|
||||||
export const pastes = pgTable('pastes', {
|
|
||||||
id: text('id').primaryKey(), // Nanoid
|
|
||||||
title: text('title'),
|
|
||||||
content: text('content').notNull(),
|
|
||||||
contentType: text('content_type').default('text/plain'),
|
|
||||||
syntax: text('syntax'),
|
|
||||||
visibility: text('visibility').default('public'), // 'public', 'unlisted', 'private'
|
|
||||||
authorId: text('author_id').references(() => users.id, { onDelete: 'set null' }), // Linked to User
|
|
||||||
sessionId: text('session_id').references(() => agentSessions.id, { onDelete: 'set null' }),
|
|
||||||
expiresAt: timestamp('expires_at'),
|
|
||||||
createdAt: timestamp('created_at').defaultNow(),
|
|
||||||
updatedAt: timestamp('updated_at').defaultNow(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const tags = pgTable('tags', {
|
|
||||||
id: text('id').primaryKey(),
|
|
||||||
name: text('name').notNull().unique(),
|
|
||||||
color: text('color'),
|
|
||||||
description: text('description'),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const pastesToTags = pgTable('pastes_to_tags', {
|
|
||||||
pasteId: text('paste_id').references(() => pastes.id, { onDelete: 'cascade' }),
|
|
||||||
tagId: text('tag_id').references(() => tags.id, { onDelete: 'cascade' }),
|
|
||||||
}, (t) => ({
|
|
||||||
pk: primaryKey({ columns: [t.pasteId, t.tagId] }),
|
|
||||||
}));
|
|
||||||
|
|
||||||
export const agentSessions = pgTable('agent_sessions', {
|
|
||||||
id: text('id').primaryKey(),
|
|
||||||
title: text('title'),
|
|
||||||
agentName: text('agent_name'),
|
|
||||||
userId: text('user_id').references(() => users.id, { onDelete: 'cascade' }), // Optional owner
|
|
||||||
createdAt: timestamp('created_at').defaultNow(),
|
|
||||||
});
|
|
||||||
|
|
||||||
// --- Auth.js Tables ---
|
|
||||||
|
|
||||||
export const users = pgTable("user", {
|
|
||||||
id: text("id")
|
|
||||||
.primaryKey()
|
|
||||||
.$defaultFn(() => crypto.randomUUID()),
|
|
||||||
name: text("name"),
|
|
||||||
email: text("email").notNull(),
|
|
||||||
emailVerified: timestamp("emailVerified", { mode: "date" }),
|
|
||||||
image: text("image"),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const accounts = pgTable(
|
|
||||||
"account",
|
|
||||||
{
|
|
||||||
userId: text("userId")
|
|
||||||
.notNull()
|
|
||||||
.references(() => users.id, { onDelete: "cascade" }),
|
|
||||||
type: text("type").$type<AdapterAccount["type"]>().notNull(),
|
|
||||||
provider: text("provider").notNull(),
|
|
||||||
providerAccountId: text("providerAccountId").notNull(),
|
|
||||||
refresh_token: text("refresh_token"),
|
|
||||||
access_token: text("access_token"),
|
|
||||||
expires_at: integer("expires_at"),
|
|
||||||
token_type: text("token_type"),
|
|
||||||
scope: text("scope"),
|
|
||||||
id_token: text("id_token"),
|
|
||||||
session_state: text("session_state"),
|
|
||||||
},
|
|
||||||
(account) => ({
|
|
||||||
compoundKey: primaryKey({
|
|
||||||
columns: [account.provider, account.providerAccountId],
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
export const sessions = pgTable("session", {
|
|
||||||
sessionToken: text("sessionToken").primaryKey(),
|
|
||||||
userId: text("userId")
|
|
||||||
.notNull()
|
|
||||||
.references(() => users.id, { onDelete: "cascade" }),
|
|
||||||
expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const verificationTokens = pgTable(
|
|
||||||
"verificationToken",
|
|
||||||
{
|
|
||||||
identifier: text("identifier").notNull(),
|
|
||||||
token: text("token").notNull(),
|
|
||||||
expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
||||||
},
|
|
||||||
(verificationToken) => ({
|
|
||||||
compositePk: primaryKey({
|
|
||||||
columns: [verificationToken.identifier, verificationToken.token],
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
export const authenticators = pgTable(
|
|
||||||
"authenticator",
|
|
||||||
{
|
|
||||||
credentialID: text("credentialID").notNull().unique(),
|
|
||||||
userId: text("userId")
|
|
||||||
.notNull()
|
|
||||||
.references(() => users.id, { onDelete: "cascade" }),
|
|
||||||
providerAccountId: text("providerAccountId").notNull(),
|
|
||||||
credentialPublicKey: text("credentialPublicKey").notNull(),
|
|
||||||
counter: integer("counter").notNull(),
|
|
||||||
credentialDeviceType: text("credentialDeviceType").notNull(),
|
|
||||||
credentialBackedUp: boolean("credentialBackedUp").notNull(),
|
|
||||||
transports: text("transports"),
|
|
||||||
},
|
|
||||||
(authenticator) => ({
|
|
||||||
compositePK: primaryKey({
|
|
||||||
columns: [authenticator.userId, authenticator.credentialID],
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
import { type ClassValue, clsx } from "clsx"
|
|
||||||
import { twMerge } from "tailwind-merge"
|
|
||||||
|
|
||||||
export function cn(...inputs: ClassValue[]) {
|
|
||||||
return twMerge(clsx(inputs))
|
|
||||||
}
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "ES2017",
|
|
||||||
"lib": ["dom", "dom.iterable", "esnext"],
|
|
||||||
"allowJs": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"strict": true,
|
|
||||||
"noEmit": true,
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"module": "esnext",
|
|
||||||
"moduleResolution": "bundler",
|
|
||||||
"resolveJsonModule": true,
|
|
||||||
"isolatedModules": true,
|
|
||||||
"jsx": "react-jsx",
|
|
||||||
"incremental": true,
|
|
||||||
"plugins": [
|
|
||||||
{
|
|
||||||
"name": "next"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"paths": {
|
|
||||||
"@/*": ["./src/*"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"include": [
|
|
||||||
"next-env.d.ts",
|
|
||||||
"**/*.ts",
|
|
||||||
"**/*.tsx",
|
|
||||||
".next/types/**/*.ts",
|
|
||||||
".next/dev/types/**/*.ts",
|
|
||||||
"**/*.mts"
|
|
||||||
],
|
|
||||||
"exclude": ["node_modules"]
|
|
||||||
}
|
|
||||||
|
|
@ -3,7 +3,7 @@ version: '3.8'
|
||||||
services:
|
services:
|
||||||
kites:
|
kites:
|
||||||
build:
|
build:
|
||||||
context: ./apps/web
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
environment:
|
environment:
|
||||||
DATABASE_URL: postgresql://postgres:postgres@db:5432/kites_db?schema=public
|
DATABASE_URL: postgresql://postgres:postgres@db:5432/kites_db?schema=public
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import { defineConfig } from 'drizzle-kit';
|
import type { Config } from 'drizzle-kit';
|
||||||
import 'dotenv/config';
|
import 'dotenv/config';
|
||||||
|
|
||||||
export default defineConfig({
|
export default {
|
||||||
schema: './src/db/schema.ts',
|
schema: './src/db/schema.ts',
|
||||||
out: './drizzle',
|
out: './drizzle',
|
||||||
dialect: 'postgresql',
|
dialect: 'postgresql',
|
||||||
dbCredentials: {
|
dbCredentials: {
|
||||||
url: process.env.DATABASE_URL!,
|
url: process.env.DATABASE_URL!,
|
||||||
},
|
},
|
||||||
});
|
} satisfies Config;
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import type { NextConfig } from "next";
|
import type { NextConfig } from "next";
|
||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
/* config options here */
|
output: "standalone",
|
||||||
};
|
};
|
||||||
|
|
||||||
export default nextConfig;
|
export default nextConfig;
|
||||||
22
package.json
22
package.json
|
|
@ -1,27 +1,32 @@
|
||||||
{
|
{
|
||||||
"name": "kites",
|
"name": "web",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "bun --bun next dev",
|
||||||
"build": "next build",
|
"build": "bun --bun next build",
|
||||||
"start": "next start",
|
"start": "bun --bun next start",
|
||||||
"lint": "eslint"
|
"lint": "bun --bun next lint",
|
||||||
|
"db:push": "bun --bun drizzle-kit push:pg",
|
||||||
|
"db:migrate": "bun --bun drizzle-kit migrate",
|
||||||
|
"db:generate": "bun --bun drizzle-kit generate"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@auth/drizzle-adapter": "^1.11.1",
|
"@auth/drizzle-adapter": "^1.11.1",
|
||||||
"@types/react-syntax-highlighter": "^15.5.13",
|
"@types/react-syntax-highlighter": "^15.5.13",
|
||||||
"better-sqlite3": "^12.4.1",
|
"pg": "^8.13.1",
|
||||||
"class-variance-authority": "^0.7.1",
|
"class-variance-authority": "^0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"date-fns": "^4.1.0",
|
"date-fns": "^4.1.0",
|
||||||
|
"dotenv": "^16.4.5",
|
||||||
"drizzle-orm": "^0.44.7",
|
"drizzle-orm": "^0.44.7",
|
||||||
"lucide-react": "^0.554.0",
|
"lucide-react": "^0.554.0",
|
||||||
"nanoid": "^5.1.6",
|
"nanoid": "^5.1.6",
|
||||||
"next": "16.0.3",
|
"next": "16.0.3",
|
||||||
"next-auth": "^5.0.0-beta.30",
|
"next-auth": "^5.0.0-beta.30",
|
||||||
"next-themes": "^0.4.6",
|
"next-themes": "^0.4.6",
|
||||||
"pg": "^8.16.3",
|
"@radix-ui/react-select": "^2.1.0",
|
||||||
|
"@radix-ui/react-popover": "^1.1.0",
|
||||||
"react": "19.2.0",
|
"react": "19.2.0",
|
||||||
"react-dom": "19.2.0",
|
"react-dom": "19.2.0",
|
||||||
"react-syntax-highlighter": "^16.1.0",
|
"react-syntax-highlighter": "^16.1.0",
|
||||||
|
|
@ -30,9 +35,8 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tailwindcss/postcss": "^4",
|
"@tailwindcss/postcss": "^4",
|
||||||
"@types/better-sqlite3": "^7.6.13",
|
"@types/pg": "^8.11.0",
|
||||||
"@types/node": "^20",
|
"@types/node": "^20",
|
||||||
"@types/pg": "^8.16.0",
|
|
||||||
"@types/react": "^19",
|
"@types/react": "^19",
|
||||||
"@types/react-dom": "^19",
|
"@types/react-dom": "^19",
|
||||||
"drizzle-kit": "^0.31.7",
|
"drizzle-kit": "^0.31.7",
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ export async function GET(req: NextRequest, { params }: { params: Promise<{ id:
|
||||||
const { searchParams } = new URL(req.url);
|
const { searchParams } = new URL(req.url);
|
||||||
const raw = searchParams.get('raw') === '1';
|
const raw = searchParams.get('raw') === '1';
|
||||||
|
|
||||||
const paste = await db.select().from(pastes).where(eq(pastes.id, id)).get();
|
const paste = (await db.select().from(pastes).where(eq(pastes.id, id)).limit(1))[0];
|
||||||
|
|
||||||
if (!paste) {
|
if (!paste) {
|
||||||
return NextResponse.json({ error: 'Not found' }, { status: 404 });
|
return NextResponse.json({ error: 'Not found' }, { status: 404 });
|
||||||
|
|
@ -45,14 +45,15 @@ export async function PATCH(req: NextRequest, { params }: { params: Promise<{ id
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
})
|
})
|
||||||
.where(eq(pastes.id, id))
|
.where(eq(pastes.id, id))
|
||||||
.returning()
|
.returning();
|
||||||
.get();
|
|
||||||
|
const updatedFirst = updated[0];
|
||||||
|
|
||||||
if (!updated) {
|
if (!updatedFirst) {
|
||||||
return NextResponse.json({ error: 'Not found' }, { status: 404 });
|
return NextResponse.json({ error: 'Not found' }, { status: 404 });
|
||||||
}
|
}
|
||||||
|
|
||||||
return NextResponse.json(updated);
|
return NextResponse.json(updatedFirst);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof ZodError) {
|
if (error instanceof ZodError) {
|
||||||
return NextResponse.json({ error: (error as any).errors }, { status: 400 });
|
return NextResponse.json({ error: (error as any).errors }, { status: 400 });
|
||||||
|
|
@ -63,6 +64,6 @@ export async function PATCH(req: NextRequest, { params }: { params: Promise<{ id
|
||||||
|
|
||||||
export async function DELETE(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
export async function DELETE(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
||||||
const { id } = await params;
|
const { id } = await params;
|
||||||
await db.delete(pastes).where(eq(pastes.id, id)).run();
|
await db.delete(pastes).where(eq(pastes.id, id));
|
||||||
return new NextResponse(null, { status: 204 });
|
return new NextResponse(null, { status: 204 });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,15 @@ export async function POST(req: NextRequest) {
|
||||||
try {
|
try {
|
||||||
const body = await req.json();
|
const body = await req.json();
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
|
|
||||||
|
// API Key Auth for Desktop Client
|
||||||
|
const apiKey = req.headers.get('x-api-key');
|
||||||
|
const isApiAuth = apiKey && apiKey === process.env.KITES_API_KEY;
|
||||||
|
|
||||||
|
if (!session && !isApiAuth) {
|
||||||
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
const validated = createPasteSchema.parse(body);
|
const validated = createPasteSchema.parse(body);
|
||||||
|
|
||||||
const id = nanoid(10);
|
const id = nanoid(10);
|
||||||
|
|
@ -51,7 +60,7 @@ export async function POST(req: NextRequest) {
|
||||||
let tagId = nanoid(8);
|
let tagId = nanoid(8);
|
||||||
|
|
||||||
// Check if tag exists
|
// Check if tag exists
|
||||||
const existingTag = await db.select().from(tags).where(eq(tags.name, tagName)).get();
|
const existingTag = (await db.select().from(tags).where(eq(tags.name, tagName)).limit(1))[0];
|
||||||
|
|
||||||
if (existingTag) {
|
if (existingTag) {
|
||||||
tagId = existingTag.id;
|
tagId = existingTag.id;
|
||||||
|
|
@ -66,7 +75,7 @@ export async function POST(req: NextRequest) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const created = await db.select().from(pastes).where(eq(pastes.id, id)).get();
|
const created = (await db.select().from(pastes).where(eq(pastes.id, id)).limit(1))[0];
|
||||||
|
|
||||||
return NextResponse.json(created, { status: 201 });
|
return NextResponse.json(created, { status: 201 });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -99,8 +108,7 @@ export async function GET(req: NextRequest) {
|
||||||
.where(and(...conditions))
|
.where(and(...conditions))
|
||||||
.orderBy(desc(pastes.createdAt))
|
.orderBy(desc(pastes.createdAt))
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset);
|
||||||
.all();
|
|
||||||
|
|
||||||
return NextResponse.json(results);
|
return NextResponse.json(results);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,7 @@ export async function GET(req: NextRequest, { params }: { params: Promise<{ id:
|
||||||
const results = await db.select()
|
const results = await db.select()
|
||||||
.from(pastes)
|
.from(pastes)
|
||||||
.where(eq(pastes.sessionId, sessionId))
|
.where(eq(pastes.sessionId, sessionId))
|
||||||
.orderBy(desc(pastes.createdAt))
|
.orderBy(desc(pastes.createdAt));
|
||||||
.all();
|
|
||||||
|
|
||||||
return NextResponse.json(results);
|
return NextResponse.json(results);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ export async function POST(req: NextRequest) {
|
||||||
userId: session?.user?.id,
|
userId: session?.user?.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
const created = await db.select().from(agentSessions).where(eq(agentSessions.id, id)).get(); // Re-fetch to get default fields if any
|
const created = (await db.select().from(agentSessions).where(eq(agentSessions.id, id)).limit(1))[0]; // Re-fetch to get default fields if any
|
||||||
|
|
||||||
// Since we inserted, we can just return what we have + id if we trust it, but fetching is safer for timestamps
|
// Since we inserted, we can just return what we have + id if we trust it, but fetching is safer for timestamps
|
||||||
// Actually better-sqlite3 insert doesn't return the row by default unless using returning() which is supported in Drizzle now
|
// Actually better-sqlite3 insert doesn't return the row by default unless using returning() which is supported in Drizzle now
|
||||||
|
|
@ -36,7 +36,7 @@ export async function POST(req: NextRequest) {
|
||||||
// Let's refactor to use returning() for cleaner code in next iteration or just re-fetch.
|
// Let's refactor to use returning() for cleaner code in next iteration or just re-fetch.
|
||||||
// Re-fetching is fine.
|
// Re-fetching is fine.
|
||||||
|
|
||||||
return NextResponse.json({ id, ...validated }, { status: 201 });
|
return NextResponse.json(created || { id, ...validated }, { status: 201 });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof ZodError) {
|
if (error instanceof ZodError) {
|
||||||
return NextResponse.json({ error: (error as any).errors }, { status: 400 });
|
return NextResponse.json({ error: (error as any).errors }, { status: 400 });
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,49 @@
|
||||||
import { PasteForm } from "@/components/paste-form";
|
import { PasteForm } from "@/components/paste-form";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { Copy, Terminal, Key } from "lucide-react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
|
||||||
export default function NewPastePage() {
|
export default function NewPastePage() {
|
||||||
return (
|
return (
|
||||||
<div className="max-w-2xl mx-auto">
|
<div className="max-w-3xl mx-auto p-4 md:p-6">
|
||||||
<h1 className="text-3xl font-bold tracking-tight mb-6">Create New Paste</h1>
|
<h1 className="text-4xl font-extrabold tracking-tight mb-4 text-center">Create New Paste</h1>
|
||||||
|
<p className="text-muted-foreground text-center mb-10 max-w-xl mx-auto">
|
||||||
|
Kites helps you manage code snippets, agent outputs, and clipboard history. Create a paste below, or learn how to integrate with your tools.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{/* Instruction Cards */}
|
||||||
|
<div className="grid md:grid-cols-2 gap-6 mb-12">
|
||||||
|
<div className="bg-card p-6 rounded-lg border flex flex-col items-start space-y-4">
|
||||||
|
<div className="p-3 rounded-full bg-primary/10 text-primary">
|
||||||
|
<Copy className="w-6 h-6" />
|
||||||
|
</div>
|
||||||
|
<h2 className="text-xl font-semibold">For Humans</h2>
|
||||||
|
<p className="text-muted-foreground flex-1">
|
||||||
|
Simply paste your content below. Choose a title, syntax, and visibility. Your paste will be available in your personal feed.
|
||||||
|
</p>
|
||||||
|
<Button variant="outline">
|
||||||
|
<Link href="/">View My Pastes</Link>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div className="bg-card p-6 rounded-lg border flex flex-col items-start space-y-4">
|
||||||
|
<div className="p-3 rounded-full bg-green-500/10 text-green-500">
|
||||||
|
<Terminal className="w-6 h-6" />
|
||||||
|
</div>
|
||||||
|
<h2 className="text-xl font-semibold">For Agents & Clients</h2>
|
||||||
|
<p className="text-muted-foreground flex-1">
|
||||||
|
Integrate your LLMs, scripts, or desktop clipboard managers using the Kites API. Generate an API key to securely push data.
|
||||||
|
</p>
|
||||||
|
<Button>
|
||||||
|
<Link href="/settings/api-keys">
|
||||||
|
<Key className="w-4 h-4 mr-2" /> Manage API Keys
|
||||||
|
</Link>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Paste Form */}
|
||||||
|
<h2 className="text-2xl font-bold tracking-tight mb-6">Your Content Here</h2>
|
||||||
<PasteForm />
|
<PasteForm />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
174
src/app/page.tsx
174
src/app/page.tsx
|
|
@ -1,65 +1,147 @@
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { db } from "@/db";
|
import { db } from "@/db";
|
||||||
import { pastes } from "@/db/schema";
|
import { pastes } from "@/db/schema";
|
||||||
import { desc } from "drizzle-orm";
|
import { desc, eq } from "drizzle-orm";
|
||||||
import { formatDistanceToNow } from "date-fns";
|
import { formatDistanceToNow } from "date-fns";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Terminal, Cpu, Share2, Shield, Code, Sparkles } from "lucide-react";
|
||||||
|
import { auth } from "@/auth";
|
||||||
|
import { redirect } from "next/navigation"; // Import redirect
|
||||||
|
|
||||||
export const dynamic = 'force-dynamic';
|
export const dynamic = 'force-dynamic';
|
||||||
|
|
||||||
export default async function Home() {
|
export default async function Home() {
|
||||||
|
const session = await auth();
|
||||||
|
const userId = session?.user?.id;
|
||||||
|
|
||||||
|
if (userId) { // Redirect if logged in
|
||||||
|
redirect("/dashboard");
|
||||||
|
}
|
||||||
|
|
||||||
const recentPastes = await db.select()
|
const recentPastes = await db.select()
|
||||||
.from(pastes)
|
.from(pastes)
|
||||||
.orderBy(desc(pastes.createdAt))
|
.orderBy(desc(pastes.createdAt))
|
||||||
.limit(20)
|
.limit(12);
|
||||||
.all();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="flex flex-col min-h-screen">
|
||||||
<div className="flex items-center justify-between">
|
{/* Hero Section */}
|
||||||
<h1 className="text-3xl font-bold tracking-tight">Recent Pastes</h1>
|
<section className="relative py-24 lg:py-32 overflow-hidden">
|
||||||
<Link
|
<div className="container px-4 md:px-6 relative z-10">
|
||||||
href="/new"
|
<div className="flex flex-col items-center text-center space-y-8">
|
||||||
className="inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2"
|
<div className="inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 border-transparent bg-primary/10 text-primary hover:bg-primary/20">
|
||||||
>
|
<Sparkles className="w-3 h-3 mr-1" />
|
||||||
New Paste
|
v1.0 Public Beta
|
||||||
</Link>
|
</div>
|
||||||
</div>
|
<h1 className="text-4xl font-extrabold tracking-tight lg:text-6xl max-w-3xl bg-clip-text text-transparent bg-gradient-to-r from-foreground to-foreground/70">
|
||||||
|
The Shared Brain for <br/> Humans & AI Agents
|
||||||
<div className="grid gap-4">
|
</h1>
|
||||||
{recentPastes.length === 0 ? (
|
<p className="text-xl text-muted-foreground max-w-[42rem]">
|
||||||
<div className="text-center py-12 text-muted-foreground">
|
Stop copy-pasting into the void. Kites is an agent-native clipboard that gives your LLMs a persistent memory and you a unified history.
|
||||||
No pastes found. Create one to get started.
|
</p>
|
||||||
|
<div className="flex gap-4">
|
||||||
|
<Link href="/new">
|
||||||
|
<Button size="lg" className="h-12 px-8">Start Pasting</Button>
|
||||||
|
</Link>
|
||||||
|
{userId ? ( // Conditional button for logged-in users
|
||||||
|
<Link href="/dashboard">
|
||||||
|
<Button variant="outline" size="lg" className="h-12 px-8">Go to Dashboard</Button>
|
||||||
|
</Link>
|
||||||
|
) : (
|
||||||
|
<Link href="https://github.com/fullsizemalt/kites">
|
||||||
|
<Button variant="outline" size="lg" className="h-12 px-8">View on GitHub</Button>
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
</div>
|
||||||
recentPastes.map((paste) => (
|
|
||||||
<Link
|
{/* Abstract "Network" Background */}
|
||||||
key={paste.id}
|
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[800px] h-[500px] bg-primary/5 rounded-full blur-3xl -z-10 pointer-events-none" />
|
||||||
href={`/paste/${paste.id}`}
|
</section>
|
||||||
className="block p-6 rounded-lg border bg-card text-card-foreground shadow-sm hover:shadow-md transition-shadow"
|
|
||||||
>
|
{/* Feature Grid */}
|
||||||
<div className="flex items-center justify-between mb-2">
|
<section className="py-12 bg-muted/30 border-y">
|
||||||
<h2 className="font-semibold text-lg truncate">
|
<div className="container px-4 md:px-6">
|
||||||
{paste.title || "Untitled Paste"}
|
<div className="grid md:grid-cols-3 gap-8">
|
||||||
</h2>
|
<div className="flex flex-col items-center text-center p-6 space-y-4 rounded-xl hover:bg-background transition-colors">
|
||||||
<span className="text-xs text-muted-foreground font-mono">
|
<div className="p-3 bg-blue-500/10 text-blue-500 rounded-full">
|
||||||
{paste.syntax || "text"}
|
<Terminal className="w-8 h-8" />
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="text-sm text-muted-foreground line-clamp-2 font-mono bg-muted/50 p-2 rounded">
|
<h3 className="text-xl font-bold">Agent-Native API</h3>
|
||||||
{paste.content}
|
<p className="text-muted-foreground">
|
||||||
|
Give your agents a <code>POST /pastes</code> endpoint. Let them save context, code blocks, and logs directly to your view.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col items-center text-center p-6 space-y-4 rounded-xl hover:bg-background transition-colors">
|
||||||
|
<div className="p-3 bg-purple-500/10 text-purple-500 rounded-full">
|
||||||
|
<Share2 className="w-8 h-8" />
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-4 flex items-center gap-4 text-xs text-muted-foreground">
|
<h3 className="text-xl font-bold">Unified History</h3>
|
||||||
<span>{formatDistanceToNow(paste.createdAt!, { addSuffix: true })}</span>
|
<p className="text-muted-foreground">
|
||||||
{paste.visibility !== 'public' && (
|
Your desktop clipboard, your agent's output, and your mobile saves—all in one structured, searchable timeline.
|
||||||
<span className="capitalize px-2 py-0.5 rounded-full bg-secondary text-secondary-foreground">
|
</p>
|
||||||
{paste.visibility}
|
</div>
|
||||||
</span>
|
<div className="flex flex-col items-center text-center p-6 space-y-4 rounded-xl hover:bg-background transition-colors">
|
||||||
)}
|
<div className="p-3 bg-green-500/10 text-green-500 rounded-full">
|
||||||
|
<Shield className="w-8 h-8" />
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
<h3 className="text-xl font-bold">Privacy First</h3>
|
||||||
))
|
<p className="text-muted-foreground">
|
||||||
)}
|
Self-hostable. Private by default. You control the retention policy and visibility of every snippet.
|
||||||
</div>
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{/* Live Feed (Recent Pastes) */}
|
||||||
|
<section className="py-16">
|
||||||
|
<div className="container px-4 md:px-6 space-y-8">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div>
|
||||||
|
<h2 className="text-2xl font-bold tracking-tight">{userId ? "My Recent Pastes" : "Live Context Feed"}</h2>
|
||||||
|
<p className="text-muted-foreground">{userId ? "Your latest snippets and agent interactions." : "Recent items from our community."}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||||
|
{recentPastes.length === 0 ? (
|
||||||
|
<div className="col-span-full text-center py-12 border-2 border-dashed rounded-xl text-muted-foreground">
|
||||||
|
<div className="mb-2">👻</div>
|
||||||
|
No context yet. Create your first paste!
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
recentPastes.map((paste) => (
|
||||||
|
<Link
|
||||||
|
key={paste.id}
|
||||||
|
href={`/paste/${paste.id}`}
|
||||||
|
className="group block p-5 rounded-lg border bg-card text-card-foreground shadow-sm hover:shadow-md hover:border-primary/50 transition-all"
|
||||||
|
>
|
||||||
|
<div className="flex items-center justify-between mb-3">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
{paste.syntax ? <Code className="w-4 h-4 text-primary" /> : <Cpu className="w-4 h-4 text-muted-foreground" />}
|
||||||
|
<span className="text-xs font-medium text-muted-foreground uppercase">{paste.syntax || 'Text'}</span>
|
||||||
|
</div>
|
||||||
|
<span className="text-xs text-muted-foreground">{formatDistanceToNow(paste.createdAt!, { addSuffix: true })}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3 className="font-semibold truncate mb-2 group-hover:text-primary transition-colors">
|
||||||
|
{paste.title || "Untitled Snippet"}
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<div className="relative">
|
||||||
|
<div className="text-sm text-muted-foreground line-clamp-3 font-mono bg-muted/50 p-3 rounded-md text-xs">
|
||||||
|
{paste.content}
|
||||||
|
</div>
|
||||||
|
<div className="absolute inset-0 bg-gradient-to-b from-transparent to-card/10 group-hover:to-transparent" />
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -18,7 +18,7 @@ function SimpleBadge({ children, className }: { children: React.ReactNode, class
|
||||||
|
|
||||||
export default async function PastePage({ params }: { params: Promise<{ id: string }> }) {
|
export default async function PastePage({ params }: { params: Promise<{ id: string }> }) {
|
||||||
const { id } = await params;
|
const { id } = await params;
|
||||||
const paste = await db.select().from(pastes).where(eq(pastes.id, id)).get();
|
const paste = (await db.select().from(pastes).where(eq(pastes.id, id)).limit(1))[0];
|
||||||
|
|
||||||
if (!paste) {
|
if (!paste) {
|
||||||
notFound();
|
notFound();
|
||||||
|
|
@ -30,8 +30,7 @@ export default async function PastePage({ params }: { params: Promise<{ id: stri
|
||||||
})
|
})
|
||||||
.from(tags)
|
.from(tags)
|
||||||
.innerJoin(pastesToTags, eq(tags.id, pastesToTags.tagId))
|
.innerJoin(pastesToTags, eq(tags.id, pastesToTags.tagId))
|
||||||
.where(eq(pastesToTags.pasteId, paste.id))
|
.where(eq(pastesToTags.pasteId, id));
|
||||||
.all();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import { formatDistanceToNow } from "date-fns";
|
||||||
|
|
||||||
export default async function SessionPage({ params }: { params: Promise<{ id: string }> }) {
|
export default async function SessionPage({ params }: { params: Promise<{ id: string }> }) {
|
||||||
const { id } = await params;
|
const { id } = await params;
|
||||||
const session = await db.select().from(agentSessions).where(eq(agentSessions.id, id)).get();
|
const session = (await db.select().from(agentSessions).where(eq(agentSessions.id, id)).limit(1))[0];
|
||||||
|
|
||||||
if (!session) {
|
if (!session) {
|
||||||
notFound();
|
notFound();
|
||||||
|
|
@ -16,8 +16,7 @@ export default async function SessionPage({ params }: { params: Promise<{ id: st
|
||||||
const sessionPastes = await db.select()
|
const sessionPastes = await db.select()
|
||||||
.from(pastes)
|
.from(pastes)
|
||||||
.where(eq(pastes.sessionId, session.id))
|
.where(eq(pastes.sessionId, session.id))
|
||||||
.orderBy(desc(pastes.createdAt))
|
.orderBy(desc(pastes.createdAt));
|
||||||
.all();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,7 @@ export default async function SessionsPage() {
|
||||||
.from(agentSessions)
|
.from(agentSessions)
|
||||||
.leftJoin(pastes, eq(agentSessions.id, pastes.sessionId))
|
.leftJoin(pastes, eq(agentSessions.id, pastes.sessionId))
|
||||||
.groupBy(agentSessions.id)
|
.groupBy(agentSessions.id)
|
||||||
.orderBy(desc(agentSessions.createdAt))
|
.orderBy(desc(agentSessions.createdAt));
|
||||||
.all();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import { Badge } from "@/components/ui/badge";
|
||||||
|
|
||||||
export default async function TagPage({ params }: { params: Promise<{ id: string }> }) {
|
export default async function TagPage({ params }: { params: Promise<{ id: string }> }) {
|
||||||
const { id } = await params;
|
const { id } = await params;
|
||||||
const tag = await db.select().from(tags).where(eq(tags.id, id)).get();
|
const tag = (await db.select().from(tags).where(eq(tags.id, id)).limit(1))[0];
|
||||||
|
|
||||||
if (!tag) {
|
if (!tag) {
|
||||||
notFound();
|
notFound();
|
||||||
|
|
@ -26,7 +26,7 @@ export default async function TagPage({ params }: { params: Promise<{ id: string
|
||||||
.innerJoin(pastesToTags, eq(pastes.id, pastesToTags.pasteId))
|
.innerJoin(pastesToTags, eq(pastes.id, pastesToTags.pasteId))
|
||||||
.where(eq(pastesToTags.tagId, tag.id))
|
.where(eq(pastesToTags.tagId, tag.id))
|
||||||
.orderBy(desc(pastes.createdAt))
|
.orderBy(desc(pastes.createdAt))
|
||||||
.all();
|
.limit(50);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,17 @@ export function Navbar() {
|
||||||
</Link>
|
</Link>
|
||||||
<nav className="flex items-center gap-4 text-sm font-medium text-muted-foreground">
|
<nav className="flex items-center gap-4 text-sm font-medium text-muted-foreground">
|
||||||
<Link href="/" className="hover:text-foreground transition-colors">
|
<Link href="/" className="hover:text-foreground transition-colors">
|
||||||
Pastes
|
Home
|
||||||
|
</Link>
|
||||||
|
<Link href="/dashboard" className="hover:text-foreground transition-colors">
|
||||||
|
Dashboard
|
||||||
</Link>
|
</Link>
|
||||||
<Link href="/sessions" className="hover:text-foreground transition-colors">
|
<Link href="/sessions" className="hover:text-foreground transition-colors">
|
||||||
Sessions
|
Sessions
|
||||||
</Link>
|
</Link>
|
||||||
|
<Link href="/settings/api-keys" className="hover:text-foreground transition-colors">
|
||||||
|
Settings
|
||||||
|
</Link>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-4">
|
<div className="flex items-center gap-4">
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import { sqliteTable, text, integer, index, primaryKey } from 'drizzle-orm/sqlite-core';
|
import { pgTable, text, integer, timestamp, primaryKey, index, boolean } from 'drizzle-orm/pg-core';
|
||||||
import { sql } from 'drizzle-orm';
|
import { sql } from 'drizzle-orm';
|
||||||
import type { AdapterAccount } from "next-auth/adapters";
|
import type { AdapterAccount } from "next-auth/adapters";
|
||||||
|
|
||||||
// --- Application Tables ---
|
// --- Application Tables ---
|
||||||
|
|
||||||
export const pastes = sqliteTable('pastes', {
|
export const pastes = pgTable('pastes', {
|
||||||
id: text('id').primaryKey(), // Nanoid
|
id: text('id').primaryKey(), // Nanoid
|
||||||
title: text('title'),
|
title: text('title'),
|
||||||
content: text('content').notNull(),
|
content: text('content').notNull(),
|
||||||
|
|
@ -12,46 +12,47 @@ export const pastes = sqliteTable('pastes', {
|
||||||
syntax: text('syntax'),
|
syntax: text('syntax'),
|
||||||
visibility: text('visibility').default('public'), // 'public', 'unlisted', 'private'
|
visibility: text('visibility').default('public'), // 'public', 'unlisted', 'private'
|
||||||
authorId: text('author_id').references(() => users.id, { onDelete: 'set null' }), // Linked to User
|
authorId: text('author_id').references(() => users.id, { onDelete: 'set null' }), // Linked to User
|
||||||
sessionId: text('session_id'), // Linked to Agent Session (logical)
|
sessionId: text('session_id').references(() => agentSessions.id, { onDelete: 'set null' }),
|
||||||
expiresAt: integer('expires_at', { mode: 'timestamp' }),
|
expiresAt: timestamp('expires_at'),
|
||||||
createdAt: integer('created_at', { mode: 'timestamp' }).default(sql`CURRENT_TIMESTAMP`),
|
createdAt: timestamp('created_at').defaultNow(),
|
||||||
updatedAt: integer('updated_at', { mode: 'timestamp' }).default(sql`CURRENT_TIMESTAMP`),
|
updatedAt: timestamp('updated_at').defaultNow(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const tags = sqliteTable('tags', {
|
export const tags = pgTable('tags', {
|
||||||
id: text('id').primaryKey(),
|
id: text('id').primaryKey(),
|
||||||
name: text('name').notNull().unique(),
|
name: text('name').notNull().unique(),
|
||||||
color: text('color'),
|
color: text('color'),
|
||||||
description: text('description'),
|
description: text('description'),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const pastesToTags = sqliteTable('pastes_to_tags', {
|
export const pastesToTags = pgTable('pastes_to_tags', {
|
||||||
pasteId: text('paste_id').references(() => pastes.id, { onDelete: 'cascade' }),
|
pasteId: text('paste_id').references(() => pastes.id, { onDelete: 'cascade' }),
|
||||||
tagId: text('tag_id').references(() => tags.id, { onDelete: 'cascade' }),
|
tagId: text('tag_id').references(() => tags.id, { onDelete: 'cascade' }),
|
||||||
}, (t) => ({
|
}, (t) => ({
|
||||||
pk: index('pk').on(t.pasteId, t.tagId),
|
pk: primaryKey({ columns: [t.pasteId, t.tagId] }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Renamed from 'sessions' to 'agent_sessions' to avoid conflict with Auth.js
|
export const agentSessions = pgTable('agent_sessions', {
|
||||||
export const agentSessions = sqliteTable('agent_sessions', {
|
|
||||||
id: text('id').primaryKey(),
|
id: text('id').primaryKey(),
|
||||||
title: text('title'),
|
title: text('title'),
|
||||||
agentName: text('agent_name'),
|
agentName: text('agent_name'),
|
||||||
userId: text('user_id').references(() => users.id, { onDelete: 'cascade' }), // Optional owner
|
userId: text('user_id').references(() => users.id, { onDelete: 'cascade' }), // Optional owner
|
||||||
createdAt: integer('created_at', { mode: 'timestamp' }).default(sql`CURRENT_TIMESTAMP`),
|
createdAt: timestamp('created_at').defaultNow(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// --- Auth.js Tables ---
|
// --- Auth.js Tables ---
|
||||||
|
|
||||||
export const users = sqliteTable("user", {
|
export const users = pgTable("user", {
|
||||||
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
id: text("id")
|
||||||
|
.primaryKey()
|
||||||
|
.$defaultFn(() => crypto.randomUUID()),
|
||||||
name: text("name"),
|
name: text("name"),
|
||||||
email: text("email").notNull(),
|
email: text("email").notNull(),
|
||||||
emailVerified: integer("emailVerified", { mode: "timestamp_ms" }),
|
emailVerified: timestamp("emailVerified", { mode: "date" }),
|
||||||
image: text("image"),
|
image: text("image"),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const accounts = sqliteTable(
|
export const accounts = pgTable(
|
||||||
"account",
|
"account",
|
||||||
{
|
{
|
||||||
userId: text("userId")
|
userId: text("userId")
|
||||||
|
|
@ -75,20 +76,20 @@ export const accounts = sqliteTable(
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
export const sessions = sqliteTable("session", {
|
export const sessions = pgTable("session", {
|
||||||
sessionToken: text("sessionToken").primaryKey(),
|
sessionToken: text("sessionToken").primaryKey(),
|
||||||
userId: text("userId")
|
userId: text("userId")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => users.id, { onDelete: "cascade" }),
|
.references(() => users.id, { onDelete: "cascade" }),
|
||||||
expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
|
expires: timestamp("expires", { mode: "date" }).notNull(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const verificationTokens = sqliteTable(
|
export const verificationTokens = pgTable(
|
||||||
"verificationToken",
|
"verificationToken",
|
||||||
{
|
{
|
||||||
identifier: text("identifier").notNull(),
|
identifier: text("identifier").notNull(),
|
||||||
token: text("token").notNull(),
|
token: text("token").notNull(),
|
||||||
expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
|
expires: timestamp("expires", { mode: "date" }).notNull(),
|
||||||
},
|
},
|
||||||
(verificationToken) => ({
|
(verificationToken) => ({
|
||||||
compositePk: primaryKey({
|
compositePk: primaryKey({
|
||||||
|
|
@ -97,7 +98,7 @@ export const verificationTokens = sqliteTable(
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
export const authenticators = sqliteTable(
|
export const authenticators = pgTable(
|
||||||
"authenticator",
|
"authenticator",
|
||||||
{
|
{
|
||||||
credentialID: text("credentialID").notNull().unique(),
|
credentialID: text("credentialID").notNull().unique(),
|
||||||
|
|
@ -108,7 +109,7 @@ export const authenticators = sqliteTable(
|
||||||
credentialPublicKey: text("credentialPublicKey").notNull(),
|
credentialPublicKey: text("credentialPublicKey").notNull(),
|
||||||
counter: integer("counter").notNull(),
|
counter: integer("counter").notNull(),
|
||||||
credentialDeviceType: text("credentialDeviceType").notNull(),
|
credentialDeviceType: text("credentialDeviceType").notNull(),
|
||||||
credentialBackedUp: integer("credentialBackedUp").notNull(),
|
credentialBackedUp: boolean("credentialBackedUp").notNull(),
|
||||||
transports: text("transports"),
|
transports: text("transports"),
|
||||||
},
|
},
|
||||||
(authenticator) => ({
|
(authenticator) => ({
|
||||||
|
|
@ -116,4 +117,4 @@ export const authenticators = sqliteTable(
|
||||||
columns: [authenticator.userId, authenticator.credentialID],
|
columns: [authenticator.userId, authenticator.credentialID],
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
Loading…
Add table
Reference in a new issue