mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
[FIX] (profile) - error in local upload (#4)
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
import {Avatar, AvatarFallback, AvatarImage} from "@/components/ui/avatar";
|
||||||
import { UploadIcon } from "lucide-react";
|
import {UploadIcon} from "lucide-react";
|
||||||
import { toast } from "sonner";
|
import {toast} from "sonner";
|
||||||
import { uploadImageAction } from "@/features/upload/public/upload.action";
|
import {uploadImageAction} from "@/features/upload/public/upload.action";
|
||||||
import { useMutation } from "@tanstack/react-query";
|
import {useMutation} from "@tanstack/react-query";
|
||||||
import { updateImageUserAction } from "@/components/wrappers/dashboard/profile/actions/avatar.action";
|
import {updateImageUserAction} from "@/components/wrappers/dashboard/profile/actions/avatar.action";
|
||||||
import { useRouter } from "next/navigation";
|
import {useRouter} from "next/navigation";
|
||||||
import { User } from "@/db/schema/02_user";
|
import {User} from "@/db/schema/02_user";
|
||||||
import React, {ChangeEvent} from "react";
|
import React, {ChangeEvent} from "react";
|
||||||
|
|
||||||
export type AvatarWithUploadProps = {
|
export type AvatarWithUploadProps = {
|
||||||
@@ -55,12 +55,11 @@ export const AvatarWithUpload = (props: AvatarWithUploadProps) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative ">
|
<div className="relative ">
|
||||||
|
|
||||||
<Avatar className="w-24 h-24 lg:w-32 lg:h-32 border-4 border-muted/20">
|
<Avatar className="w-24 h-24 lg:w-32 lg:h-32 border-4 border-muted/20">
|
||||||
<AvatarImage src={user.image || undefined}/>
|
<AvatarImage className="object-cover" src={user.image || undefined}/>
|
||||||
<AvatarFallback className="text-3xl">{user.name.charAt(0)}</AvatarFallback>
|
<AvatarFallback className="text-3xl">{user.name.charAt(0)}</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
|
|
||||||
@@ -75,7 +74,7 @@ export const AvatarWithUpload = (props: AvatarWithUploadProps) => {
|
|||||||
}}
|
}}
|
||||||
className="cursor-pointer absolute inset-0 flex justify-center items-center opacity-0 transition-opacity hover:opacity-100 hover:bg-gray-500 hover:bg-opacity-50 rounded-full w-24 h-24 lg:w-32 lg:h-32"
|
className="cursor-pointer absolute inset-0 flex justify-center items-center opacity-0 transition-opacity hover:opacity-100 hover:bg-gray-500 hover:bg-opacity-50 rounded-full w-24 h-24 lg:w-32 lg:h-32"
|
||||||
>
|
>
|
||||||
<UploadIcon className="w-12 h-12 lg:w-16 lg:h-16 text-primary" />
|
<UploadIcon className="w-12 h-12 lg:w-16 lg:h-16 text-primary"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {Setting} from "@/db/schema/01_setting";
|
|||||||
import * as drizzleDb from "@/db";
|
import * as drizzleDb from "@/db";
|
||||||
|
|
||||||
|
|
||||||
const privateS3ImageDir = "images/";
|
const imageDir = "images/";
|
||||||
|
|
||||||
|
|
||||||
export const uploadImageAction = userAction
|
export const uploadImageAction = userAction
|
||||||
@@ -39,10 +39,10 @@ export const uploadImageAction = userAction
|
|||||||
let result: void | UploadedObjectInfo;
|
let result: void | UploadedObjectInfo;
|
||||||
|
|
||||||
if (settings.storage === "local") {
|
if (settings.storage === "local") {
|
||||||
fileName = `${uuid}.${fileFormat}`;
|
fileName = `${imageDir}${uuid}.${fileFormat}`;
|
||||||
result = await uploadLocal(fileName, buffer);
|
result = await uploadLocal(fileName, buffer);
|
||||||
} else if (settings.storage === "s3") {
|
} else if (settings.storage === "s3") {
|
||||||
fileName = `${privateS3ImageDir}${uuid}.${fileFormat}`;
|
fileName = `${imageDir}${uuid}.${fileFormat}`;
|
||||||
result = await uploadS3Compatible(env.S3_BUCKET_NAME ?? "", fileName, buffer);
|
result = await uploadS3Compatible(env.S3_BUCKET_NAME ?? "", fileName, buffer);
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Unsupported storage type: ${settings.storage}`);
|
throw new Error(`Unsupported storage type: ${settings.storage}`);
|
||||||
@@ -54,7 +54,7 @@ export const uploadImageAction = userAction
|
|||||||
|
|
||||||
|
|
||||||
async function uploadLocal(fileName: string, buffer: any) {
|
async function uploadLocal(fileName: string, buffer: any) {
|
||||||
const localDir = "private/uploads/images/";
|
const localDir = "private/uploads/";
|
||||||
try {
|
try {
|
||||||
await mkdir(path.join(process.cwd(), localDir), {recursive: true});
|
await mkdir(path.join(process.cwd(), localDir), {recursive: true});
|
||||||
return await writeFile(path.join(process.cwd(), localDir + fileName), buffer);
|
return await writeFile(path.join(process.cwd(), localDir + fileName), buffer);
|
||||||
|
|||||||
Reference in New Issue
Block a user