@lobehub/lobehub 2.0.0-next.184 → 2.0.0-next.186
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 +50 -0
- package/changelog/v1.json +18 -0
- package/e2e/src/support/webServer.ts +0 -1
- package/locales/ar/auth.json +1 -0
- package/locales/ar/models.json +40 -0
- package/locales/ar/setting.json +1 -0
- package/locales/ar/subscription.json +13 -0
- package/locales/bg-BG/auth.json +1 -0
- package/locales/bg-BG/models.json +22 -0
- package/locales/bg-BG/setting.json +1 -0
- package/locales/bg-BG/subscription.json +13 -0
- package/locales/de-DE/auth.json +1 -0
- package/locales/de-DE/models.json +37 -0
- package/locales/de-DE/setting.json +1 -0
- package/locales/de-DE/subscription.json +13 -0
- package/locales/en-US/auth.json +1 -0
- package/locales/en-US/setting.json +1 -1
- package/locales/es-ES/auth.json +1 -0
- package/locales/es-ES/models.json +30 -0
- package/locales/es-ES/setting.json +1 -0
- package/locales/es-ES/subscription.json +13 -0
- package/locales/fa-IR/auth.json +1 -0
- package/locales/fa-IR/models.json +31 -0
- package/locales/fa-IR/setting.json +1 -0
- package/locales/fa-IR/subscription.json +13 -0
- package/locales/fr-FR/auth.json +1 -0
- package/locales/fr-FR/models.json +17 -0
- package/locales/fr-FR/setting.json +1 -0
- package/locales/fr-FR/subscription.json +13 -0
- package/locales/it-IT/auth.json +1 -0
- package/locales/it-IT/models.json +31 -0
- package/locales/it-IT/setting.json +1 -0
- package/locales/it-IT/subscription.json +13 -0
- package/locales/ja-JP/auth.json +1 -0
- package/locales/ja-JP/models.json +1 -0
- package/locales/ja-JP/setting.json +1 -0
- package/locales/ja-JP/subscription.json +13 -0
- package/locales/ko-KR/auth.json +1 -0
- package/locales/ko-KR/models.json +39 -0
- package/locales/ko-KR/setting.json +1 -0
- package/locales/ko-KR/subscription.json +13 -0
- package/locales/nl-NL/auth.json +1 -0
- package/locales/nl-NL/models.json +35 -0
- package/locales/nl-NL/setting.json +1 -0
- package/locales/nl-NL/subscription.json +13 -0
- package/locales/pl-PL/auth.json +1 -0
- package/locales/pl-PL/models.json +12 -0
- package/locales/pl-PL/setting.json +1 -0
- package/locales/pl-PL/subscription.json +13 -0
- package/locales/pt-BR/auth.json +1 -0
- package/locales/pt-BR/models.json +1 -0
- package/locales/pt-BR/setting.json +1 -0
- package/locales/pt-BR/subscription.json +13 -0
- package/locales/ru-RU/auth.json +1 -0
- package/locales/ru-RU/models.json +32 -0
- package/locales/ru-RU/setting.json +1 -0
- package/locales/ru-RU/subscription.json +13 -0
- package/locales/tr-TR/auth.json +1 -0
- package/locales/tr-TR/models.json +20 -0
- package/locales/tr-TR/setting.json +1 -0
- package/locales/tr-TR/subscription.json +13 -0
- package/locales/vi-VN/auth.json +1 -0
- package/locales/vi-VN/models.json +39 -0
- package/locales/vi-VN/setting.json +1 -0
- package/locales/vi-VN/subscription.json +13 -0
- package/locales/zh-CN/auth.json +1 -0
- package/locales/zh-CN/models.json +49 -0
- package/locales/zh-CN/setting.json +1 -1
- package/locales/zh-TW/auth.json +1 -0
- package/locales/zh-TW/models.json +23 -0
- package/locales/zh-TW/setting.json +1 -0
- package/locales/zh-TW/subscription.json +13 -0
- package/next.config.ts +14 -1
- package/package.json +2 -1
- package/packages/types/src/message/common/base.ts +1 -1
- package/packages/types/src/message/ui/chat.ts +3 -3
- package/packages/types/src/message/ui/extra.ts +2 -2
- package/packages/types/src/openai/plugin.ts +1 -1
- package/packages/types/src/session/agentSession.ts +1 -1
- package/packages/types/src/user/settings/index.ts +1 -1
- package/src/app/(backend)/oidc/[...oidc]/route.ts +2 -2
- package/src/app/[variants]/(auth)/oauth/consent/[uid]/page.tsx +2 -2
- package/src/envs/auth.ts +2 -0
- package/src/libs/next/config/define-config.ts +19 -10
- package/src/libs/next/proxy/define-config.ts +4 -5
- package/src/libs/trpc/lambda/context.ts +9 -11
- package/src/server/services/oidc/oidcProvider.ts +2 -2
- package/src/store/image/utils/size.test.ts +245 -0
- package/vercel.json +1 -1
- package/src/envs/oidc.ts +0 -18
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { adaptSizeToRatio, parseRatio } from './size';
|
|
4
|
+
|
|
5
|
+
describe('size utils', () => {
|
|
6
|
+
describe('parseRatio', () => {
|
|
7
|
+
it('should parse valid ratio string correctly', () => {
|
|
8
|
+
expect(parseRatio('16:9')).toBe(16 / 9);
|
|
9
|
+
expect(parseRatio('4:3')).toBe(4 / 3);
|
|
10
|
+
expect(parseRatio('1:1')).toBe(1);
|
|
11
|
+
expect(parseRatio('21:9')).toBe(21 / 9);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('should handle square ratio correctly', () => {
|
|
15
|
+
expect(parseRatio('1:1')).toBe(1);
|
|
16
|
+
expect(parseRatio('100:100')).toBe(1);
|
|
17
|
+
expect(parseRatio('512:512')).toBe(1);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should handle wide ratios correctly', () => {
|
|
21
|
+
expect(parseRatio('16:9')).toBeCloseTo(16 / 9, 6);
|
|
22
|
+
expect(parseRatio('2:1')).toBe(2);
|
|
23
|
+
expect(parseRatio('3:1')).toBe(3);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should handle tall ratios correctly', () => {
|
|
27
|
+
expect(parseRatio('9:16')).toBeCloseTo(0.5625, 4);
|
|
28
|
+
expect(parseRatio('1:2')).toBe(0.5);
|
|
29
|
+
expect(parseRatio('3:4')).toBe(0.75);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should handle decimal values in ratio string', () => {
|
|
33
|
+
expect(parseRatio('1.5:1')).toBe(1.5);
|
|
34
|
+
expect(parseRatio('16.5:9.5')).toBeCloseTo(16.5 / 9.5, 6);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should return 1 for invalid ratio string formats', () => {
|
|
38
|
+
expect(parseRatio('16')).toBe(1); // Missing colon
|
|
39
|
+
expect(parseRatio('16-9')).toBe(1); // Wrong separator
|
|
40
|
+
expect(parseRatio('16:9:1')).toBe(1); // Too many parts
|
|
41
|
+
expect(parseRatio('')).toBe(1); // Empty string
|
|
42
|
+
expect(parseRatio(':')).toBe(1); // Only separator
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should return 1 for invalid input types', () => {
|
|
46
|
+
// @ts-expect-error - testing runtime behavior with invalid types
|
|
47
|
+
expect(parseRatio(null)).toBe(1);
|
|
48
|
+
// @ts-expect-error - testing runtime behavior with invalid types
|
|
49
|
+
expect(parseRatio(undefined)).toBe(1);
|
|
50
|
+
// @ts-expect-error - testing runtime behavior with invalid types
|
|
51
|
+
expect(parseRatio(123)).toBe(1);
|
|
52
|
+
// @ts-expect-error - testing runtime behavior with invalid types
|
|
53
|
+
expect(parseRatio({})).toBe(1);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should return 1 for non-numeric ratio parts', () => {
|
|
57
|
+
expect(parseRatio('abc:def')).toBe(1);
|
|
58
|
+
expect(parseRatio('16:abc')).toBe(1);
|
|
59
|
+
expect(parseRatio('abc:9')).toBe(1);
|
|
60
|
+
expect(parseRatio('NaN:9')).toBe(1);
|
|
61
|
+
expect(parseRatio('16:NaN')).toBe(1);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should return 1 for zero or negative values', () => {
|
|
65
|
+
expect(parseRatio('0:9')).toBe(1);
|
|
66
|
+
expect(parseRatio('16:0')).toBe(1);
|
|
67
|
+
expect(parseRatio('0:0')).toBe(1);
|
|
68
|
+
expect(parseRatio('-16:9')).toBe(1);
|
|
69
|
+
expect(parseRatio('16:-9')).toBe(1);
|
|
70
|
+
expect(parseRatio('-16:-9')).toBe(1);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should return 1 for Infinity values', () => {
|
|
74
|
+
expect(parseRatio('Infinity:9')).toBe(1);
|
|
75
|
+
expect(parseRatio('16:Infinity')).toBe(1);
|
|
76
|
+
expect(parseRatio('Infinity:Infinity')).toBe(1);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('adaptSizeToRatio', () => {
|
|
81
|
+
describe('valid inputs', () => {
|
|
82
|
+
it('should keep width and adjust height when target ratio is wider', () => {
|
|
83
|
+
// 16:9 (1.777) is wider than 4:3 (1.333)
|
|
84
|
+
const result = adaptSizeToRatio(16 / 9, 800, 600);
|
|
85
|
+
expect(result).toEqual({ width: 800, height: 450 });
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should keep height and adjust width when target ratio is taller', () => {
|
|
89
|
+
// 4:3 (1.333) is taller than 16:9 (1.777)
|
|
90
|
+
const result = adaptSizeToRatio(4 / 3, 800, 450);
|
|
91
|
+
expect(result).toEqual({ width: 600, height: 450 });
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('should maintain dimensions when ratio matches current ratio', () => {
|
|
95
|
+
// 16:9 matches 1920:1080
|
|
96
|
+
const result = adaptSizeToRatio(16 / 9, 1920, 1080);
|
|
97
|
+
expect(result).toEqual({ width: 1920, height: 1080 });
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('should handle square ratio (1:1) correctly', () => {
|
|
101
|
+
// Current ratio: 800/600 = 1.333, target ratio: 1
|
|
102
|
+
// Since 1 < 1.333, keeps height (600), adjusts width to 600
|
|
103
|
+
const result = adaptSizeToRatio(1, 800, 600);
|
|
104
|
+
expect(result).toEqual({ width: 600, height: 600 });
|
|
105
|
+
|
|
106
|
+
// Current ratio: 600/800 = 0.75, target ratio: 1
|
|
107
|
+
// Since 1 > 0.75, keeps width (600), adjusts height to 600
|
|
108
|
+
const result2 = adaptSizeToRatio(1, 600, 800);
|
|
109
|
+
expect(result2).toEqual({ width: 600, height: 600 });
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('should round dimensions to nearest integer', () => {
|
|
113
|
+
// Current ratio: 1000/800 = 1.25, target ratio: 1.5
|
|
114
|
+
// Since 1.5 > 1.25, keeps width (1000), adjusts height to 1000/1.5 = 666.67 -> 667
|
|
115
|
+
const result = adaptSizeToRatio(1.5, 1000, 800);
|
|
116
|
+
expect(result.width).toBe(1000);
|
|
117
|
+
expect(result.height).toBe(667);
|
|
118
|
+
expect(Number.isInteger(result.width)).toBe(true);
|
|
119
|
+
expect(Number.isInteger(result.height)).toBe(true);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('should handle very wide ratios correctly', () => {
|
|
123
|
+
const result = adaptSizeToRatio(3, 1200, 800);
|
|
124
|
+
expect(result).toEqual({ width: 1200, height: 400 });
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('should handle very tall ratios correctly', () => {
|
|
128
|
+
const result = adaptSizeToRatio(1 / 3, 1200, 800);
|
|
129
|
+
expect(result).toEqual({ width: 267, height: 800 });
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should handle small dimensions', () => {
|
|
133
|
+
const result = adaptSizeToRatio(16 / 9, 320, 240);
|
|
134
|
+
expect(result).toEqual({ width: 320, height: 180 });
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('should handle large dimensions', () => {
|
|
138
|
+
const result = adaptSizeToRatio(16 / 9, 3840, 2880);
|
|
139
|
+
expect(result).toEqual({ width: 3840, height: 2160 });
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('should handle decimal ratio values', () => {
|
|
143
|
+
const result = adaptSizeToRatio(1.5, 900, 600);
|
|
144
|
+
expect(result).toEqual({ width: 900, height: 600 });
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe('error handling - invalid ratio', () => {
|
|
149
|
+
it('should throw error for zero ratio', () => {
|
|
150
|
+
expect(() => adaptSizeToRatio(0, 800, 600)).toThrow(
|
|
151
|
+
'Invalid ratio: must be a positive finite number',
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('should throw error for negative ratio', () => {
|
|
156
|
+
expect(() => adaptSizeToRatio(-1.5, 800, 600)).toThrow(
|
|
157
|
+
'Invalid ratio: must be a positive finite number',
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('should throw error for NaN ratio', () => {
|
|
162
|
+
expect(() => adaptSizeToRatio(NaN, 800, 600)).toThrow(
|
|
163
|
+
'Invalid ratio: must be a positive finite number',
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('should throw error for Infinity ratio', () => {
|
|
168
|
+
expect(() => adaptSizeToRatio(Infinity, 800, 600)).toThrow(
|
|
169
|
+
'Invalid ratio: must be a positive finite number',
|
|
170
|
+
);
|
|
171
|
+
expect(() => adaptSizeToRatio(-Infinity, 800, 600)).toThrow(
|
|
172
|
+
'Invalid ratio: must be a positive finite number',
|
|
173
|
+
);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
describe('error handling - invalid defaultWidth', () => {
|
|
178
|
+
it('should throw error for zero defaultWidth', () => {
|
|
179
|
+
expect(() => adaptSizeToRatio(16 / 9, 0, 600)).toThrow(
|
|
180
|
+
'Invalid defaultWidth: must be a positive finite number',
|
|
181
|
+
);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('should throw error for negative defaultWidth', () => {
|
|
185
|
+
expect(() => adaptSizeToRatio(16 / 9, -800, 600)).toThrow(
|
|
186
|
+
'Invalid defaultWidth: must be a positive finite number',
|
|
187
|
+
);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('should throw error for NaN defaultWidth', () => {
|
|
191
|
+
expect(() => adaptSizeToRatio(16 / 9, NaN, 600)).toThrow(
|
|
192
|
+
'Invalid defaultWidth: must be a positive finite number',
|
|
193
|
+
);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('should throw error for Infinity defaultWidth', () => {
|
|
197
|
+
expect(() => adaptSizeToRatio(16 / 9, Infinity, 600)).toThrow(
|
|
198
|
+
'Invalid defaultWidth: must be a positive finite number',
|
|
199
|
+
);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
describe('error handling - invalid defaultHeight', () => {
|
|
204
|
+
it('should throw error for zero defaultHeight', () => {
|
|
205
|
+
expect(() => adaptSizeToRatio(16 / 9, 800, 0)).toThrow(
|
|
206
|
+
'Invalid defaultHeight: must be a positive finite number',
|
|
207
|
+
);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('should throw error for negative defaultHeight', () => {
|
|
211
|
+
expect(() => adaptSizeToRatio(16 / 9, 800, -600)).toThrow(
|
|
212
|
+
'Invalid defaultHeight: must be a positive finite number',
|
|
213
|
+
);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('should throw error for NaN defaultHeight', () => {
|
|
217
|
+
expect(() => adaptSizeToRatio(16 / 9, 800, NaN)).toThrow(
|
|
218
|
+
'Invalid defaultHeight: must be a positive finite number',
|
|
219
|
+
);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('should throw error for Infinity defaultHeight', () => {
|
|
223
|
+
expect(() => adaptSizeToRatio(16 / 9, 800, Infinity)).toThrow(
|
|
224
|
+
'Invalid defaultHeight: must be a positive finite number',
|
|
225
|
+
);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
describe('error handling - multiple invalid parameters', () => {
|
|
230
|
+
it('should validate ratio first before other parameters', () => {
|
|
231
|
+
// When multiple params are invalid, ratio is checked first
|
|
232
|
+
expect(() => adaptSizeToRatio(0, 0, 0)).toThrow(
|
|
233
|
+
'Invalid ratio: must be a positive finite number',
|
|
234
|
+
);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('should validate defaultWidth before defaultHeight', () => {
|
|
238
|
+
// When ratio is valid but width and height are invalid
|
|
239
|
+
expect(() => adaptSizeToRatio(1.5, 0, 0)).toThrow(
|
|
240
|
+
'Invalid defaultWidth: must be a positive finite number',
|
|
241
|
+
);
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
});
|
package/vercel.json
CHANGED
package/src/envs/oidc.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { createEnv } from '@t3-oss/env-nextjs';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
|
|
4
|
-
export const oidcEnv = createEnv({
|
|
5
|
-
client: {},
|
|
6
|
-
runtimeEnv: {
|
|
7
|
-
ENABLE_OIDC: process.env.ENABLE_OIDC === '1',
|
|
8
|
-
OIDC_JWKS_KEY: process.env.OIDC_JWKS_KEY,
|
|
9
|
-
},
|
|
10
|
-
server: {
|
|
11
|
-
// 是否启用 OIDC
|
|
12
|
-
ENABLE_OIDC: z.boolean().optional().default(false),
|
|
13
|
-
// OIDC 签名密钥
|
|
14
|
-
// 必须是一个包含私钥的 JWKS (JSON Web Key Set) 格式的 JSON 字符串。
|
|
15
|
-
// 可以使用 `node scripts/generate-oidc-jwk.mjs` 命令生成。
|
|
16
|
-
OIDC_JWKS_KEY: z.string().optional(),
|
|
17
|
-
},
|
|
18
|
-
});
|