Skip to content

Commit

Permalink
update avatar folder + base62 service
Browse files Browse the repository at this point in the history
  • Loading branch information
robertotcestari committed Aug 14, 2024
1 parent bc1c82b commit 1ff2849
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"dependencies": {
"@aws-sdk/client-s3": "^3.623.0",
"@aws-sdk/lib-storage": "^3.623.0",
"@sindresorhus/base62": "^0.1.0",
"@types/fluent-ffmpeg": "^2.1.25",
"axios": "^1.7.3",
"base62str": "^1.0.10",
"fluent-ffmpeg": "^2.1.3",
"hono": "^4.5.3",
"nanoid": "^5.0.7",
Expand Down
12 changes: 8 additions & 4 deletions src/routes/upload-avatar-image.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Hono } from 'hono';
import sharp from 'sharp';
import { S3 } from '../lib/s3';
import base62 from '@sindresorhus/base62';
import { nanoid } from 'nanoid';
import Base62Str from 'base62str';

const app = new Hono();

Expand All @@ -19,10 +20,13 @@ app.post('/', async (c) => {
}

// encode in base62 from '@sindresorhus/base62'
const encodedEmail = base62.encodeString(email);
const base62 = Base62Str.createInstance();
const encodedEmail = base62.encodeStr(email);

const smImgPath = `user-avatars/${encodedEmail}.avif`;
const lgImgPath = `user-avatars/${encodedEmail}-lg.avif`;
const strRandom = nanoid(10);

const smImgPath = `user-avatars/${encodedEmail}/${strRandom}.avif`;
const lgImgPath = `user-avatars/${encodedEmail}/${strRandom}-lg.avif`;

const res = await fetch(avatarUrl);
const buffer = Buffer.from(await res.arrayBuffer());
Expand Down

0 comments on commit 1ff2849

Please sign in to comment.