Skip to content

Commit 2adb42e

Browse files
committed
fix: file upload
1 parent 971d6b8 commit 2adb42e

File tree

3 files changed

+4
-39
lines changed

3 files changed

+4
-39
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ DOCKER_MINIO_USERNAME="minioadmin"
1212
DOCKER_MINIO_PASSWORD="minioadmin"
1313

1414
# S3
15-
S3_ENDPOINT="http://127.0.0.1:${DOCKER_MINIO_FORWARD_PORT}"
15+
S3_ENDPOINT="http://127.0.0.1:${DOCKER_MINIO_API_PORT}"
1616
S3_BUCKET_NAME="start-ui-bucket"
1717
S3_ACCESS_KEY_ID="startui-access-key"
1818
S3_SECRET_ACCESS_KEY="startui-secret-key"

src/features/account/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ export type FormFieldsAccountUpdateProfilePicture = z.infer<
1515
>;
1616
export const zFormFieldsAccountUpdateProfilePicture = () =>
1717
z.object({
18-
avatarFileId: zu.string.nonEmpty(z.string()),
18+
avatarFileId: zu.fieldText.required(),
1919
});

src/server/routers/account.ts

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import { DeleteObjectCommand } from '@aws-sdk/client-s3';
21
import { z } from 'zod';
32

4-
import { s3client } from '@/lib/s3';
5-
6-
import { envServer } from '@/env/server';
73
import { zFormFieldsOnboarding } from '@/features/auth/schema';
84
import { zUser } from '@/features/user/schema';
95
import { protectedProcedure } from '@/server/orpc';
@@ -50,42 +46,11 @@ export default {
5046
.handler(async ({ context, input }) => {
5147
context.logger.info('Update user');
5248

53-
// If profilePictureId is defined, check to delete the old one
54-
if (input.avatarFileId) {
55-
// Remove old file if there was one
56-
const deleteCommand = new DeleteObjectCommand({
57-
Bucket: envServer.S3_BUCKET_NAME,
58-
Key: context.user.avatarFileId,
59-
});
60-
try {
61-
await s3client.send(deleteCommand);
62-
} catch (error) {
63-
context.logger.warn('Fail to delete user profile picture', {
64-
profilePictureId: context.user.avatarFileId,
65-
error,
66-
});
67-
}
68-
69-
try {
70-
await context.db.user.update({
71-
where: { id: context.user.id },
72-
data: {
73-
avatarFileId: input.avatarFileId,
74-
},
75-
});
76-
} catch (error) {
77-
context.logger.warn('Fail to save user profile picture', {
78-
profilePictureId: context.user.avatarFileId,
79-
error,
80-
});
81-
}
82-
return;
83-
}
84-
8549
await context.db.user.update({
8650
where: { id: context.user.id },
8751
data: {
88-
name: input.name ?? '',
52+
name: input.name ?? context.user.name,
53+
avatarFileId: input.avatarFileId ?? context.user.avatarFileId,
8954
},
9055
});
9156
}),

0 commit comments

Comments
 (0)