feat: implement owner check functionality and update file action components
This commit is contained in:
		
							parent
							
								
									b368473216
								
							
						
					
					
						commit
						036f23b777
					
				| @ -93,12 +93,12 @@ export function FileActionsContainer({ | ||||
|           console.error(err); | ||||
|         } | ||||
|         }} | ||||
|         className="flex items-center justify-center rounded-full bg-gray-500 p-2 hover:bg-gray-600" | ||||
|         className="flex items-center justify-center rounded-full bg-gray-500 p-2 hover:bg-gray-600 transition-all duration-300" | ||||
|       > | ||||
|         <img | ||||
|         src={isPublic ? "/icons/public.svg" : "/icons/private.svg"} | ||||
|         alt={isPublic ? "Public" : "Private"} | ||||
|         className="h-6 w-6" | ||||
|         className={`h-6 w-6 transition-transform duration-300 ${isPublic ? 'rotate-360' : 'rotate-0'}`} | ||||
|         /> | ||||
|       </button> | ||||
|       )} | ||||
|  | ||||
| @ -7,6 +7,7 @@ import { env } from "~/env.js"; | ||||
| import { FilePreview } from "~/app/_components/FilePreview"; | ||||
| import { useFileActions } from "~/app/_components/FileActions"; | ||||
| import { FileActionsContainer } from "./ActionButtons"; | ||||
| import { checkOwner } from "~/utils/checkOwner"; // Import the client component
 | ||||
| 
 | ||||
| interface FileDetails { | ||||
|   id: string; | ||||
|  | ||||
| @ -25,10 +25,11 @@ export async function GET(req: Request) { | ||||
|       name: file.name, | ||||
|       size: file.size, | ||||
|       owner: file.uploadedBy?.name ?? null, | ||||
|       ownerId: file.uploadedBy?.id ?? null, | ||||
|       ownerAvatar: file.uploadedBy?.image ?? null, | ||||
|       uploadDate: file.uploadDate, | ||||
|       id: file.id, | ||||
|       isOwner: session?.user?.id === file.uploadedById, | ||||
|       isOwner: null, | ||||
|       type: file.extension, | ||||
|       url: file.url, | ||||
|       description: file.description, | ||||
|  | ||||
| @ -10,6 +10,7 @@ interface FileDetails { | ||||
|   name: string; | ||||
|   size: number; | ||||
|   owner: string; | ||||
|   ownerId: string; | ||||
|   ownerAvatar: string | null; | ||||
|   uploadDate: string; | ||||
|   id: string; | ||||
| @ -107,7 +108,7 @@ export default function SearchFile() { | ||||
|                     fileId={file.id} | ||||
|                     fileName={file.name} | ||||
|                     fileUrl={file.url} | ||||
|                     isOwner={false} // Check if the user is the owner
 | ||||
|                     isOwner={false} | ||||
|                     isPublic={file.isPublic} // Check if the file is public
 | ||||
|                   /> | ||||
|                 </div> | ||||
|  | ||||
| @ -7,11 +7,14 @@ import { | ||||
|   FileDescriptionContainer, | ||||
| } from "~/app/_components/ActionButtons"; // Import the client component
 | ||||
| import type { Metadata } from "next"; | ||||
| import { checkOwner } from "~/utils/checkOwner"; // Import the client component
 | ||||
| import { auth } from "~/server/auth"; | ||||
| 
 | ||||
| interface FileDetails { | ||||
|   name: string; | ||||
|   size: number; | ||||
|   owner: string; | ||||
|   ownerId: string; | ||||
|   ownerAvatar: string | null; | ||||
|   uploadDate: string; | ||||
|   id: string; | ||||
| @ -96,6 +99,7 @@ export default async function FilePreviewContainer({ | ||||
|   } | ||||
| 
 | ||||
|   const fileDetails = await fetchFileDetails(fileId); | ||||
|   const session = await auth(); | ||||
| 
 | ||||
|   if (!fileDetails) { | ||||
|     return ( | ||||
| @ -167,7 +171,7 @@ export default async function FilePreviewContainer({ | ||||
|               fileId={fileDetails.id} | ||||
|               fileName={fileDetails.name} | ||||
|               fileUrl={fileDetails.url} | ||||
|               isOwner={true} | ||||
|               isOwner={session?.user?.id ? await checkOwner(fileDetails.ownerId, session.user.id) : false} | ||||
|               isPublic={fileDetails.isPublic} | ||||
|             /> | ||||
|           </div> | ||||
|  | ||||
							
								
								
									
										12
									
								
								src/utils/checkOwner.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/utils/checkOwner.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | ||||
| import type { Session } from "next-auth"; | ||||
| 
 | ||||
| export const checkOwner = async (id: string , session: string) => { | ||||
|   console.log("Session:", session); | ||||
|   console.log("File ID:", id); | ||||
|   if (session) { | ||||
|     console.log("Session User ID:", session); | ||||
|     console.log("File Owner ID:", id); | ||||
|     return id === session; | ||||
|   } | ||||
|   return false; | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user