docker shit
This commit is contained in:
@@ -1 +1,72 @@
|
||||
|
||||
import { NextResponse } from 'next/server';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const postsDirectory = path.join(process.cwd(), 'posts');
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { name, path: folderPath } = body;
|
||||
|
||||
// Create the full path for the new folder
|
||||
const fullPath = path.join(postsDirectory, folderPath, name);
|
||||
|
||||
// Check if folder already exists
|
||||
if (fs.existsSync(fullPath)) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Folder already exists' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Create the folder
|
||||
fs.mkdirSync(fullPath, { recursive: true });
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
console.error('Error creating folder:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Error creating folder' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(request: Request) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { name, path: folderPath } = body;
|
||||
|
||||
// Create the full path for the folder to delete
|
||||
const fullPath = path.join(postsDirectory, folderPath, name);
|
||||
|
||||
// Check if folder exists
|
||||
if (!fs.existsSync(fullPath)) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Folder does not exist' },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
// Check if folder is empty
|
||||
const files = fs.readdirSync(fullPath);
|
||||
if (files.length > 0) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Cannot delete non-empty folder' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Delete the folder
|
||||
fs.rmdirSync(fullPath);
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
console.error('Error deleting folder:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Error deleting folder' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import matter from 'gray-matter';
|
||||
import { remark } from 'remark';
|
||||
import html from 'remark-html';
|
||||
import chokidar from 'chokidar';
|
||||
import type { FSWatcher } from 'chokidar';
|
||||
|
||||
export interface Post {
|
||||
slug: string;
|
||||
@@ -64,12 +65,13 @@ export async function getPostsByTag(tag: string): Promise<Post[]> {
|
||||
const allPosts = await getAllPosts();
|
||||
return allPosts.filter((post) => post.tags.includes(tag));
|
||||
}
|
||||
// File watcher setup
|
||||
let watcher: chokidar.FSWatcher | null = null;
|
||||
let onChangeCallback: (() => void) | null = null;
|
||||
|
||||
export function watchPosts(callback: () => void) {
|
||||
if (watcher) {
|
||||
// File watcher setup
|
||||
let watcher: FSWatcher | null = null;
|
||||
let onChangeCallback: (() => void) | null = null;
|
||||
|
||||
export function watchPosts(callback: () => void) {
|
||||
if (watcher) {
|
||||
watcher.close();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user