mirror of
https://github.com/Kizuren/uLinkShortener.git
synced 2025-12-21 21:16:17 +01:00
fixed errors
This commit is contained in:
parent
71bdd08da9
commit
9cf0a294ad
10 changed files with 35 additions and 37 deletions
|
|
@ -7,7 +7,7 @@ import logger from '@/lib/logger';
|
|||
|
||||
export async function POST(
|
||||
req: NextRequest,
|
||||
{ params }: { params: { accountId: string } }
|
||||
{ params }: { params: Promise<{ accountId: string }> }
|
||||
) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
|
@ -19,7 +19,7 @@ export async function POST(
|
|||
}, { status: 401 });
|
||||
}
|
||||
|
||||
const { accountId } = params;
|
||||
const { accountId } = await params;
|
||||
|
||||
if (!accountId) {
|
||||
return NextResponse.json({
|
||||
|
|
@ -58,7 +58,7 @@ export async function POST(
|
|||
success: true,
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Error toggling admin status:', { error });
|
||||
logger.error('Error toggling admin status:', error);
|
||||
return NextResponse.json({
|
||||
message: "Failed to toggle admin status",
|
||||
success: false,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import logger from '@/lib/logger';
|
|||
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
{ params }: { params: { accountId: string, shortId: string } }
|
||||
{ params }: { params: Promise<{ accountId: string, shortId: string }> }
|
||||
) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
|
@ -51,7 +51,7 @@ export async function GET(
|
|||
success: true,
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Error getting analytics:', { error, accountId: params.accountId, shortId: params.shortId });
|
||||
logger.error('Error getting analytics:', { error, accountId: (await params).accountId, shortId: (await params).shortId });
|
||||
return NextResponse.json({
|
||||
message: "Failed to retrieve analytics",
|
||||
success: false,
|
||||
|
|
@ -61,7 +61,7 @@ export async function GET(
|
|||
|
||||
export async function DELETE(
|
||||
req: NextRequest,
|
||||
{ params }: { params: { accountId: string, shortId: string } }
|
||||
{ params }: { params: Promise<{ accountId: string, shortId: string }> }
|
||||
) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
|
@ -107,7 +107,7 @@ export async function DELETE(
|
|||
success: false,
|
||||
}, { status: 400 });
|
||||
} catch (error) {
|
||||
logger.error('Error deleting analytics:', { error, accountId: params.accountId, shortId: params.shortId });
|
||||
logger.error('Error deleting analytics:', { error, accountId: (await params).accountId, shortId: (await params).shortId });
|
||||
return NextResponse.json({
|
||||
message: "Failed to delete analytics",
|
||||
success: false,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import logger from '@/lib/logger';
|
|||
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
{ params }: { params: { accountId: string, shortId: string } }
|
||||
{ params }: { params: Promise<{ accountId: string, shortId: string }> }
|
||||
) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
|
@ -42,7 +42,7 @@ export async function GET(
|
|||
success: true,
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Error getting link details:', { error, accountId: params.accountId, shortId: params.shortId });
|
||||
logger.error('Error getting link details:', { error, accountId: (await params).accountId, shortId: (await params).shortId });
|
||||
return NextResponse.json({
|
||||
message: "Failed to retrieve link details",
|
||||
success: false,
|
||||
|
|
@ -52,7 +52,7 @@ export async function GET(
|
|||
|
||||
export async function PATCH(
|
||||
req: NextRequest,
|
||||
{ params }: { params: { accountId: string, shortId: string } }
|
||||
{ params }: { params: Promise<{ accountId: string, shortId: string }> }
|
||||
) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
|
@ -90,7 +90,7 @@ export async function PATCH(
|
|||
success: result.success,
|
||||
}, { status: result.success ? 200 : 400 });
|
||||
} catch (error) {
|
||||
logger.error('Error updating link:', { error, accountId: params.accountId, shortId: params.shortId });
|
||||
logger.error('Error updating link:', { error, accountId: (await params).accountId, shortId: (await params).shortId });
|
||||
return NextResponse.json({
|
||||
message: "Failed to update link",
|
||||
success: false,
|
||||
|
|
@ -100,7 +100,7 @@ export async function PATCH(
|
|||
|
||||
export async function DELETE(
|
||||
req: NextRequest,
|
||||
{ params }: { params: { accountId: string, shortId: string } }
|
||||
{ params }: { params: Promise<{ accountId: string, shortId: string }> }
|
||||
) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
|
@ -128,7 +128,7 @@ export async function DELETE(
|
|||
success: result.success,
|
||||
}, { status: result.success ? 200 : 400 });
|
||||
} catch (error) {
|
||||
logger.error('Error deleting link:', { error, accountId: params.accountId, shortId: params.shortId });
|
||||
logger.error('Error deleting link:', { error, accountId: (await params).accountId, shortId: (await params).shortId });
|
||||
return NextResponse.json({
|
||||
message: "Failed to delete link",
|
||||
success: false,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import logger from '@/lib/logger';
|
|||
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
{ params }: { params: { accountId: string } }
|
||||
{ params }: { params: Promise<{ accountId: string }> }
|
||||
) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
|
@ -36,7 +36,7 @@ export async function GET(
|
|||
success: true,
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Error getting user links:', { error });
|
||||
logger.error('Error getting user links:', error);
|
||||
return NextResponse.json({
|
||||
message: "Failed to retrieve user links",
|
||||
success: false,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { sanitizeMongoDocument } from '@/lib/utils';
|
|||
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
{ params }: { params: { accountId: string } }
|
||||
{ params }: { params: Promise<{ accountId: string }> }
|
||||
) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import logger from '@/lib/logger';
|
|||
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
{ params }: { params: { accountId: string } }
|
||||
{ params }: { params: Promise<{ accountId: string }> }
|
||||
) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
|
@ -38,7 +38,7 @@ export async function GET(
|
|||
success: true,
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Error getting user sessions:', { error });
|
||||
logger.error('Error getting user sessions:', error);
|
||||
return NextResponse.json({
|
||||
message: "Failed to retrieve user sessions",
|
||||
success: false,
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@ import { useState, useEffect, useRef } from 'react';
|
|||
import { useParams, useRouter } from 'next/navigation';
|
||||
import Link from 'next/link';
|
||||
import { useToast } from '@/contexts/ToastContext';
|
||||
import Graph, { StatItem } from '@/components/ui/Graph';
|
||||
import Graph from '@/components/ui/Graph';
|
||||
import ConfirmModal from '@/components/ui/ConfirmModal';
|
||||
import AnalyticsTable from '@/components/ui/dashboard/link/AnalyticsTable';
|
||||
import styles from './LinkDetail.module.css';
|
||||
import { Analytics } from '@/types/analytics';
|
||||
import { Link as LinkType } from '@/types/link';
|
||||
import type { Link as LinkType } from '@/types/link';
|
||||
import type { StatItem } from '@/types/statistics';
|
||||
|
||||
export default function LinkDetailPage() {
|
||||
const params = useParams();
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import logger from '@/lib/logger';
|
|||
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
{ params }: { params: { shortId: string } }
|
||||
{ params }: { params: Promise<{ shortId: string }> }
|
||||
) {
|
||||
try {
|
||||
const { shortId } = await params;
|
||||
|
|
@ -30,7 +30,7 @@ export async function GET(
|
|||
|
||||
return NextResponse.redirect(new URL(link.target_url));
|
||||
} catch (error) {
|
||||
logger.error('Link redirection error', { error });
|
||||
logger.error('Link redirection error', error);
|
||||
return NextResponse.redirect(new URL('/error', req.url));
|
||||
}
|
||||
}
|
||||
|
|
@ -265,7 +265,7 @@ export default function Graph({
|
|||
data={getBarData()}
|
||||
options={getOptions()}
|
||||
ref={(ref) => {
|
||||
if (ref) chartRef.current = ref.chartInstance;
|
||||
if (ref) chartRef.current = ref;
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
|
@ -274,7 +274,7 @@ export default function Graph({
|
|||
data={getLineData()}
|
||||
options={getOptions()}
|
||||
ref={(ref) => {
|
||||
if (ref) chartRef.current = ref.chartInstance;
|
||||
if (ref) chartRef.current = ref;
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
|
@ -283,7 +283,7 @@ export default function Graph({
|
|||
data={getDoughnutData()}
|
||||
options={getOptions()}
|
||||
ref={(ref) => {
|
||||
if (ref) chartRef.current = ref.chartInstance;
|
||||
if (ref) chartRef.current = ref;
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,5 @@
|
|||
import { Db, MongoClient, ObjectId } from "mongodb";
|
||||
|
||||
const uri = process.env.MONGO_URI!;
|
||||
const dbName = process.env.MONGO_DB_NAME!;
|
||||
|
||||
if (!process.env.MONGO_URI) {
|
||||
throw new Error('Please add your MongoDB URI to .env');
|
||||
}
|
||||
if (!process.env.MONGO_DB_NAME) {
|
||||
throw new Error('Please add your MongoDB DB name to .env');
|
||||
}
|
||||
|
||||
let client: MongoClient;
|
||||
let db: Db;
|
||||
|
||||
|
|
@ -27,9 +17,16 @@ export async function getMongo(): Promise<{ client: MongoClient; db: Db }> {
|
|||
return { client, db };
|
||||
}
|
||||
|
||||
client = new MongoClient(uri);
|
||||
if (!process.env.MONGO_URI) {
|
||||
throw new Error('Please add your MongoDB URI to .env');
|
||||
}
|
||||
if (!process.env.MONGO_DB_NAME) {
|
||||
throw new Error('Please add your MongoDB DB name to .env');
|
||||
}
|
||||
|
||||
client = new MongoClient(process.env.MONGO_URI);
|
||||
await client.connect();
|
||||
db = client.db(dbName);
|
||||
db = client.db(process.env.MONGO_DB_NAME);
|
||||
|
||||
return { client, db };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue