@lobehub/chat 0.51.0 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/package.json +1 -1
- package/src/features/AvatarWithUpload/index.tsx +34 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
## [Version 0.52.0](https://github.com/lobehub/lobe-chat/compare/v0.51.0...v0.52.0)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2023-08-15**</sup>
|
|
8
|
+
|
|
9
|
+
#### ✨ Features
|
|
10
|
+
|
|
11
|
+
- **misc**: Add avatar compress.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's improved
|
|
19
|
+
|
|
20
|
+
- **misc**: Add avatar compress ([1325b40](https://github.com/lobehub/lobe-chat/commit/1325b40))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
5
30
|
## [Version 0.51.0](https://github.com/lobehub/lobe-chat/compare/v0.50.0...v0.51.0)
|
|
6
31
|
|
|
7
32
|
<sup>Released on **2023-08-15**</sup>
|
package/package.json
CHANGED
|
@@ -23,15 +23,47 @@ const useStyle = createStyles(
|
|
|
23
23
|
);
|
|
24
24
|
|
|
25
25
|
interface AvatarWithUploadProps {
|
|
26
|
+
compressSize?: number;
|
|
26
27
|
size?: number;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
const AvatarWithUpload = memo<AvatarWithUploadProps>(({ size = 40 }) => {
|
|
30
|
+
const AvatarWithUpload = memo<AvatarWithUploadProps>(({ size = 40, compressSize = 128 }) => {
|
|
30
31
|
const [avatar, setSettings] = useGlobalStore((st) => [st.settings.avatar, st.setSettings]);
|
|
31
32
|
const { styles } = useStyle();
|
|
32
33
|
|
|
33
34
|
const handleUploadAvatar = createUploadImageHandler((avatar) => {
|
|
34
|
-
|
|
35
|
+
const img = new Image();
|
|
36
|
+
img.src = avatar;
|
|
37
|
+
img.addEventListener('load', () => {
|
|
38
|
+
const canvas = document.createElement('canvas');
|
|
39
|
+
const ctx = canvas.getContext('2d') as CanvasRenderingContext2D;
|
|
40
|
+
let startX = 0;
|
|
41
|
+
let startY = 0;
|
|
42
|
+
|
|
43
|
+
if (img.width > img.height) {
|
|
44
|
+
startX = (img.width - img.height) / 2;
|
|
45
|
+
} else {
|
|
46
|
+
startY = (img.height - img.width) / 2;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
canvas.width = compressSize;
|
|
50
|
+
canvas.height = compressSize;
|
|
51
|
+
|
|
52
|
+
ctx.drawImage(
|
|
53
|
+
img,
|
|
54
|
+
startX,
|
|
55
|
+
startY,
|
|
56
|
+
Math.min(img.width, img.height),
|
|
57
|
+
Math.min(img.width, img.height),
|
|
58
|
+
0,
|
|
59
|
+
0,
|
|
60
|
+
compressSize,
|
|
61
|
+
compressSize,
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const webpBase64 = canvas.toDataURL('image/webp');
|
|
65
|
+
setSettings({ avatar: webpBase64 });
|
|
66
|
+
});
|
|
35
67
|
});
|
|
36
68
|
|
|
37
69
|
return (
|