chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
60158935f4
commit
6519682885
15831 files changed
+3063428
No files matched your search
@@ -0,0 +1,36 @@
|
||||
// user-code.ts — input normalisation + validation for the RFC 8628
|
||||
// 8-character user_code format the CLI prints to stderr.
|
||||
//
|
||||
// Format: XXXX-XXXX, uppercase, reduced alphabet (no 0/O, 1/I/l, 2/Z). Low
|
||||
// entropy by design — humans type it — so the server-side rate-limit + TTL +
|
||||
// single-use properties are what defend it, not the alphabet.
|
||||
|
||||
const USER_CODE_ALPHABET = 'ABCDEFGHJKLMNPQRSTUVWXY3456789' // excludes 0 O 1 I L 2 Z
|
||||
|
||||
/**
|
||||
* normaliseUserCodeInput prepares raw input for display in the code field:
|
||||
* strips non-alphanumerics, uppercases, drops disallowed characters, and
|
||||
* inserts the hyphen after the fourth accepted char.
|
||||
*
|
||||
* Returns at most 9 chars ("XXXX-XXXX"); longer input is truncated.
|
||||
*/
|
||||
export function normaliseUserCodeInput(raw: string): string {
|
||||
const cleaned: string[] = []
|
||||
for (const ch of raw.toUpperCase()) {
|
||||
if (USER_CODE_ALPHABET.includes(ch)) cleaned.push(ch)
|
||||
if (cleaned.length === 8) break
|
||||
}
|
||||
if (cleaned.length <= 4) return cleaned.join('')
|
||||
return `${cleaned.slice(0, 4).join('')}-${cleaned.slice(4).join('')}`
|
||||
}
|
||||
|
||||
/**
|
||||
* isValidUserCode tests whether the normalised form is a complete XXXX-XXXX
|
||||
* token suitable for submission to /openapi/v1/oauth/device/lookup.
|
||||
*/
|
||||
export function isValidUserCode(normalised: string): boolean {
|
||||
return (
|
||||
/^[A-Z0-9]{4}-[A-Z0-9]{4}$/.test(normalised) &&
|
||||
[...normalised.replace('-', '')].every((c) => USER_CODE_ALPHABET.includes(c))
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user