Skip to content

Commit

Permalink
fix: timeout issue for apis
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalkondle-dev committed Jul 1, 2024
1 parent c46ea19 commit aa14cb0
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 13 deletions.
18 changes: 9 additions & 9 deletions app/(private)/drive/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
IconFolderSymlink,
IconTrash,
} from '@tabler/icons-react';
import { useParams, useRouter, useSearchParams } from 'next/navigation';
import { useRouter, useSearchParams } from 'next/navigation';
import { useEffect, useRef, useState } from 'react';
import Breadcrumbs from '@/components/Breadcrumbs';
import FileTable from '@/components/Drive/FileTable';
Expand All @@ -33,9 +33,9 @@ import { apiCall, failure, openModal } from '@/lib/client_functions';

const DrivePage = () => {
const searchParams = useSearchParams();
const params = useParams();
const currentFolder = searchParams.get('_id') ?? '';
const { data, refetch } = useFetchData(
`/api/drive/files${searchParams.get('_id') ? `?parent=${searchParams.get('_id')}` : ''}`
`/api/drive/files${currentFolder ? `?parent=${currentFolder}` : ''}`
);

const [openMoveDialog, setOpenMoveDialog] = useState(false);
Expand All @@ -49,7 +49,7 @@ const DrivePage = () => {
const ref = useRef<HTMLButtonElement>(null);

const handleNewFolder = async () => {
await apiCall('/api/drive/files', { name: folderName, parent: params.path }, 'POST');
await apiCall('/api/drive/files', { name: folderName, parent: currentFolder }, 'POST');
close();
setFolderName('Untitled folder');
refetch();
Expand Down Expand Up @@ -77,12 +77,8 @@ const DrivePage = () => {
try {
const formData = new FormData();
value.forEach((file) => formData.append('file', file, file.name));
formData.append('parent', '');
formData.append('parent', currentFolder ?? '');
await apiCall('/api/drive/files/upload', formData, 'POST');
} catch (err) {
failure('Error uploading file');
} finally {
setValue([]);
refetch();
notifications.update({
id,
Expand All @@ -92,6 +88,10 @@ const DrivePage = () => {
loading: false,
autoClose: 2000,
});
} catch (err) {
failure('Error uploading file');
} finally {
setValue([]);
}
};

Expand Down
3 changes: 3 additions & 0 deletions app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import NextAuth from 'next-auth/next';
import { authOptions } from './authOptions';

export const maxDuration = 60;
export const dynamic = 'force-dynamic';

const authHandler = NextAuth(authOptions);

export { authHandler as GET, authHandler as POST };
3 changes: 3 additions & 0 deletions app/api/documents/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import Document from '@/models/Document';
import { authOptions } from '../auth/[...nextauth]/authOptions';
import { UserDataTypes } from '../auth/[...nextauth]/next-auth.interfaces';

export const maxDuration = 60;
export const dynamic = 'force-dynamic';

export async function GET(req: NextRequest) {
try {
const session: UserDataTypes | null = await getServerSession(authOptions);
Expand Down
9 changes: 6 additions & 3 deletions app/api/drive/files/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import File from '@/models/File';
import { authOptions } from '../../auth/[...nextauth]/authOptions';
import { UserDataTypes } from '../../auth/[...nextauth]/next-auth.interfaces';

export const maxDuration = 60;
export const dynamic = 'force-dynamic';

const s3Client = new S3Client({
region: process.env.AWS_REGION as string,
credentials: {
Expand Down Expand Up @@ -52,8 +55,8 @@ export async function GET(req: NextRequest) {
let test: Types.ObjectId | null = currentFile?.parent;
let path = [currentFile];

while (test !== null) {
const parentFile: any = await File.findById(parent).select('name parent');
while (test) {
const parentFile: any = await File.findById(test).select('name parent');
test = parentFile?.parent;
path = [parentFile, ...path];
}
Expand Down Expand Up @@ -101,7 +104,7 @@ export async function PUT(req: NextRequest) {
await s3Client.send(new CopyObjectCommand(input));
await s3Client.send(new DeleteObjectCommand({ Bucket: 'dream-by-vishal', Key: fl.link }));
}
const input = { parent: body?.parent || null, link: Key };
const input = { parent: body?.parent || null, link: fl?.link ? Key : undefined };
await fl?.updateOne(input);
response = [...response, fl];
})
Expand Down
3 changes: 3 additions & 0 deletions app/api/drive/get-path/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import File from '@/models/File';
import { authOptions } from '../../auth/[...nextauth]/authOptions';
import { UserDataTypes } from '../../auth/[...nextauth]/next-auth.interfaces';

export const maxDuration = 60;
export const dynamic = 'force-dynamic';

export async function GET(req: NextRequest) {
try {
const session: UserDataTypes | null = await getServerSession(authOptions);
Expand Down
3 changes: 3 additions & 0 deletions app/api/list/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import TodoList from '@/models/TodoList';
import { authOptions } from '../auth/[...nextauth]/authOptions';
import { UserDataTypes } from '../auth/[...nextauth]/next-auth.interfaces';

export const maxDuration = 60;
export const dynamic = 'force-dynamic';

export async function GET(req: NextRequest) {
try {
const session: UserDataTypes | null = await getServerSession(authOptions);
Expand Down
3 changes: 3 additions & 0 deletions app/api/notes/archived/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import Note from '@/models/Note';
import { authOptions } from '../../auth/[...nextauth]/authOptions';
import { UserDataTypes } from '../../auth/[...nextauth]/next-auth.interfaces';

export const maxDuration = 60;
export const dynamic = 'force-dynamic';

export async function GET() {
try {
const session: UserDataTypes | null = await getServerSession(authOptions);
Expand Down
3 changes: 3 additions & 0 deletions app/api/notes/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import Note from '@/models/Note';
import { authOptions } from '../auth/[...nextauth]/authOptions';
import { UserDataTypes } from '../auth/[...nextauth]/next-auth.interfaces';

export const maxDuration = 60;
export const dynamic = 'force-dynamic';

export async function GET() {
try {
const session: UserDataTypes | null = await getServerSession(authOptions);
Expand Down
3 changes: 3 additions & 0 deletions app/api/notes/trashed/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import Note from '@/models/Note';
import { authOptions } from '../../auth/[...nextauth]/authOptions';
import { UserDataTypes } from '../../auth/[...nextauth]/next-auth.interfaces';

export const maxDuration = 60;
export const dynamic = 'force-dynamic';

export async function GET() {
try {
const session: UserDataTypes | null = await getServerSession(authOptions);
Expand Down
3 changes: 3 additions & 0 deletions app/api/spotlight/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { authOptions } from '../auth/[...nextauth]/authOptions';
import { UserDataTypes } from '../auth/[...nextauth]/next-auth.interfaces';
import Document from '@/models/Document';

export const maxDuration = 60;
export const dynamic = 'force-dynamic';

export async function GET() {
try {
const session: UserDataTypes | null = await getServerSession(authOptions);
Expand Down
3 changes: 3 additions & 0 deletions app/api/todos/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import {
} from '@/lib/functions';
import '@/models/TodoList';

export const maxDuration = 60;
export const dynamic = 'force-dynamic';

export async function GET(req: NextRequest) {
try {
const session: UserDataTypes | null = await getServerSession(authOptions);
Expand Down
3 changes: 3 additions & 0 deletions app/api/todos/todo-list/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { authOptions } from '../../auth/[...nextauth]/authOptions';
import { UserDataTypes } from '../../auth/[...nextauth]/next-auth.interfaces';
import Todo from '@/models/Todo';

export const maxDuration = 60;
export const dynamic = 'force-dynamic';

export async function GET() {
try {
const session: UserDataTypes | null = await getServerSession(authOptions);
Expand Down
3 changes: 3 additions & 0 deletions app/api/users/register/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import startDb from '@/lib/db';
import User from '@/models/User';
import { sendMail, verificationMessage } from '@/lib/functions';

export const maxDuration = 60;
export const dynamic = 'force-dynamic';

export async function POST(req: Request) {
try {
const body = await req.json();
Expand Down
3 changes: 3 additions & 0 deletions app/verify/[secret]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import startDb from '@/lib/db';
import User from '@/models/User';
import { sendMail } from '@/lib/functions';

export const maxDuration = 60;
export const dynamic = 'force-dynamic';

export async function GET(req: Request, { params }: { params: { secret: string } }) {
try {
await startDb();
Expand Down
2 changes: 1 addition & 1 deletion components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export default function Layout({ children }: { children: React.ReactNode }) {
<Group gap={0}>
{isLoggedIn && (
<Group gap="xs">
<SpotLight />
{/* <SpotLight /> */}
<Popover
opened={opened}
onChange={setOpened}
Expand Down

0 comments on commit aa14cb0

Please sign in to comment.