* feat: Add settings modal with GitHub PAT and filter toggle - Add GeneralSettingsModal with General and GitHub tabs - Create GitHub PAT input field that saves to .env as GITHUB_TOKEN - Add animated toggle component for SAVE_FILTER setting - Create API endpoints for settings management - Add Input and Toggle UI components - Implement smooth animations for toggle interactions - Add proper error handling and user feedback * feat: Add filter persistence with settings integration - Add filter persistence system that saves user filter preferences to .env - Create FILTERS variable in .env to store complete filter state as JSON - Add SAVE_FILTER toggle in settings to enable/disable persistence - Implement auto-save functionality with 500ms debounce - Add loading states and visual feedback for filter restoration - Create API endpoints for managing saved filters - Add filter management UI in settings modal - Support for search query, type filters, sort order, and updatable status - Seamless integration across all script tabs (Available, Downloaded, Installed) - Auto-clear saved filters when persistence is disabled
76 lines
2.2 KiB
TypeScript
76 lines
2.2 KiB
TypeScript
import type { NextRequest } from 'next/server';
|
|
import { NextResponse } from 'next/server';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const { token } = await request.json();
|
|
|
|
if (!token || typeof token !== 'string') {
|
|
return NextResponse.json(
|
|
{ error: 'Token is required and must be a string' },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
// Path to the .env file
|
|
const envPath = path.join(process.cwd(), '.env');
|
|
|
|
// Read existing .env file
|
|
let envContent = '';
|
|
if (fs.existsSync(envPath)) {
|
|
envContent = fs.readFileSync(envPath, 'utf8');
|
|
}
|
|
|
|
// Check if GITHUB_TOKEN already exists
|
|
const githubTokenRegex = /^GITHUB_TOKEN=.*$/m;
|
|
const githubTokenMatch = githubTokenRegex.exec(envContent);
|
|
|
|
if (githubTokenMatch) {
|
|
// Replace existing GITHUB_TOKEN
|
|
envContent = envContent.replace(githubTokenRegex, `GITHUB_TOKEN=${token}`);
|
|
} else {
|
|
// Add new GITHUB_TOKEN
|
|
envContent += (envContent.endsWith('\n') ? '' : '\n') + `GITHUB_TOKEN=${token}\n`;
|
|
}
|
|
|
|
// Write back to .env file
|
|
fs.writeFileSync(envPath, envContent);
|
|
|
|
return NextResponse.json({ success: true, message: 'GitHub token saved successfully' });
|
|
} catch (error) {
|
|
console.error('Error saving GitHub token:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to save GitHub token' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|
|
|
|
export async function GET() {
|
|
try {
|
|
// Path to the .env file
|
|
const envPath = path.join(process.cwd(), '.env');
|
|
|
|
if (!fs.existsSync(envPath)) {
|
|
return NextResponse.json({ token: null });
|
|
}
|
|
|
|
// Read .env file and extract GITHUB_TOKEN
|
|
const envContent = fs.readFileSync(envPath, 'utf8');
|
|
const githubTokenRegex = /^GITHUB_TOKEN=(.*)$/m;
|
|
const githubTokenMatch = githubTokenRegex.exec(envContent);
|
|
|
|
const token = githubTokenMatch ? githubTokenMatch[1] : null;
|
|
|
|
return NextResponse.json({ token });
|
|
} catch (error) {
|
|
console.error('Error reading GitHub token:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to read GitHub token' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|