emoji
This commit is contained in:
@@ -47,15 +47,29 @@ export async function POST(request: Request) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET(request: Request) {
|
||||
// Return the current pinned.json object
|
||||
try {
|
||||
const pinnedPath = path.join(postsDirectory, 'pinned.json');
|
||||
let pinnedData = { pinned: [], folderEmojis: {} };
|
||||
if (fs.existsSync(pinnedPath)) {
|
||||
pinnedData = JSON.parse(fs.readFileSync(pinnedPath, 'utf8'));
|
||||
}
|
||||
return NextResponse.json(pinnedData);
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: 'Error reading pinned.json' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export async function PATCH(request: Request) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { pinned } = body; // expects an array of slugs
|
||||
if (!Array.isArray(pinned)) {
|
||||
return NextResponse.json({ error: 'Invalid pinned data' }, { status: 400 });
|
||||
const { pinned, folderEmojis } = body; // expects pinned (array) and folderEmojis (object)
|
||||
if (!Array.isArray(pinned) || typeof folderEmojis !== 'object') {
|
||||
return NextResponse.json({ error: 'Invalid pinned or folderEmojis data' }, { status: 400 });
|
||||
}
|
||||
const pinnedPath = path.join(postsDirectory, 'pinned.json');
|
||||
fs.writeFileSync(pinnedPath, JSON.stringify(pinned, null, 2), 'utf8');
|
||||
fs.writeFileSync(pinnedPath, JSON.stringify({ pinned, folderEmojis }, null, 2), 'utf8');
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
console.error('Error updating pinned.json:', error);
|
||||
|
||||
Reference in New Issue
Block a user