REFACTOR(repo): simplify project structure

- Move services/nextjs to nextjs/
- Move deploy/docker/Dockerfile.prod to Dockerfile
- Add GitHub Actions workflows (ci.yml, build.yml)
- Remove deploy/, services/, scripts/ folders
This commit is contained in:
2026-01-05 02:29:10 +09:00
commit e82ea71c22
205 changed files with 21304 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
import { NextRequest, NextResponse } from 'next/server'
import { db } from '@/shared/lib/db'
// GET /api/documents/[id]/public - Get a public document (no auth required)
export async function GET(req: NextRequest) {
try {
const url = new URL(req.url)
const id = url.pathname.split('/')[3] // Extract ID from /api/documents/[id]/public
if (!id) {
return NextResponse.json(
{ error: 'Document ID is required' },
{ status: 400 }
)
}
// 공개된 문서만 조회 (인증 없이)
const document = await db.document.findFirst({
where: {
id,
isPublished: true, // 공개된 문서만
isArchived: false,
},
include: {
user: {
select: {
name: true,
email: true,
}
}
}
})
if (!document) {
return NextResponse.json(
{ error: 'Document not found or not published' },
{ status: 404 }
)
}
return NextResponse.json(document)
} catch (error) {
console.error('Error fetching public document:', error)
return NextResponse.json(
{ error: 'Failed to fetch document' },
{ status: 500 }
)
}
}

View File

@@ -0,0 +1,202 @@
import { NextRequest, NextResponse } from 'next/server'
import { withAuth } from '@/shared/lib/middleware'
import { db } from '@/shared/lib/db'
import { deleteFile } from '@/shared/lib/s3'
// GET /api/documents/[id] - Get a specific document
export const GET = withAuth(async (req: NextRequest, userId: string) => {
try {
const url = new URL(req.url)
const id = url.pathname.split('/').pop()
if (!id) {
return NextResponse.json(
{ error: 'Document ID is required' },
{ status: 400 }
)
}
// Allow viewing both archived and non-archived documents
const document = await db.document.findFirst({
where: {
id,
userId,
},
})
if (!document) {
return NextResponse.json(
{ error: 'Document not found' },
{ status: 404 }
)
}
return NextResponse.json(document)
} catch (error) {
console.error('Error fetching document:', error)
return NextResponse.json(
{ error: 'Failed to fetch document' },
{ status: 500 }
)
}
})
// PUT /api/documents/[id] - Update a specific document
export const PUT = withAuth(async (req: NextRequest, userId: string) => {
try {
const url = new URL(req.url)
const id = url.pathname.split('/').pop()
const { title, content, icon, cover, isPublished } = await req.json()
if (!id) {
return NextResponse.json(
{ error: 'Document ID is required' },
{ status: 400 }
)
}
// Check if document exists and belongs to user
const existingDocument = await db.document.findFirst({
where: {
id,
userId,
isArchived: false,
},
})
if (!existingDocument) {
return NextResponse.json(
{ error: 'Document not found' },
{ status: 404 }
)
}
const document = await db.document.update({
where: { id },
data: {
...(title && { title }),
...(content && { content }),
...(icon !== undefined && { icon }),
...(cover !== undefined && { cover }),
...(isPublished !== undefined && { isPublished }),
updatedAt: new Date(),
},
})
return NextResponse.json(document)
} catch (error) {
console.error('Error updating document:', error)
return NextResponse.json(
{ error: 'Failed to update document' },
{ status: 500 }
)
}
})
// Helper function to extract image paths from document content
async function extractImagePaths(content: any): Promise<string[]> {
if (!content) return [];
const paths: string[] = [];
try {
const parsed = typeof content === 'string' ? JSON.parse(content) : content;
// Recursive function to traverse the document structure
const traverse = (node: any) => {
if (!node) return;
// Check if this is an imageUpload node with a path
if (node.type === 'imageUpload' && node.attrs?.path) {
paths.push(node.attrs.path);
}
// Recursively check content and children
if (node.content && Array.isArray(node.content)) {
node.content.forEach(traverse);
}
if (node.children && Array.isArray(node.children)) {
node.children.forEach(traverse);
}
};
// Check if parsed is an object with content
if (parsed.content) {
traverse(parsed);
} else if (Array.isArray(parsed)) {
parsed.forEach(traverse);
} else if (parsed.type) {
traverse(parsed);
}
} catch (error) {
console.error('Error parsing document content:', error);
}
return paths;
}
// DELETE /api/documents/[id] - Archive a specific document
export const DELETE = withAuth(async (req: NextRequest, userId: string) => {
try {
const url = new URL(req.url)
const id = url.pathname.split('/').pop()
if (!id) {
return NextResponse.json(
{ error: 'Document ID is required' },
{ status: 400 }
)
}
// Check if document exists and belongs to user
const existingDocument = await db.document.findFirst({
where: {
id,
userId,
isArchived: false,
},
})
if (!existingDocument) {
return NextResponse.json(
{ error: 'Document not found' },
{ status: 404 }
)
}
// Extract and delete all image files from the document
const imagePaths = await extractImagePaths(existingDocument.content);
if (imagePaths.length > 0) {
console.log(`Deleting ${imagePaths.length} image files from document ${id}`);
// Delete all image files
await Promise.allSettled(
imagePaths.map(path => {
try {
return deleteFile(path);
} catch (error) {
console.error(`Failed to delete image file ${path}:`, error);
return Promise.resolve();
}
})
);
}
// Archive the document instead of deleting it
const document = await db.document.update({
where: { id },
data: {
isArchived: true,
updatedAt: new Date(),
},
})
return NextResponse.json({ message: 'Document archived successfully' })
} catch (error) {
console.error('Error archiving document:', error)
return NextResponse.json(
{ error: 'Failed to archive document' },
{ status: 500 }
)
}
})

View File

@@ -0,0 +1,84 @@
import { NextRequest, NextResponse } from 'next/server'
import { withAuth } from '@/shared/lib/middleware'
import { db } from '@/shared/lib/db'
// GET /api/documents - Get all documents for the authenticated user
export const GET = withAuth(async (req: NextRequest, userId: string) => {
try {
const url = new URL(req.url)
const folderId = url.searchParams.get('folderId')
const documents = await db.document.findMany({
where: {
userId,
isArchived: false,
...(folderId && { folderId }),
},
include: {
folder: {
select: {
id: true,
name: true,
icon: true,
},
},
},
orderBy: {
createdAt: 'desc',
},
})
return NextResponse.json(documents)
} catch (error) {
console.error('Error fetching documents:', error)
return NextResponse.json(
{ error: 'Failed to fetch documents' },
{ status: 500 }
)
}
})
// POST /api/documents - Create a new document
export const POST = withAuth(async (req: NextRequest, userId: string) => {
try {
const { title, parentId, folderId } = await req.json()
if (!title) {
return NextResponse.json(
{ error: 'Title is required' },
{ status: 400 }
)
}
const document = await db.document.create({
data: {
title,
userId,
parentId: parentId || null,
folderId: folderId || null,
content: {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'Start writing...',
},
],
},
],
},
},
})
return NextResponse.json(document, { status: 201 })
} catch (error) {
console.error('Error creating document:', error)
return NextResponse.json(
{ error: 'Failed to create document' },
{ status: 500 }
)
}
})