forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main'
- Loading branch information
Showing
78 changed files
with
613 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
import { desensitizeUrl } from './desensitizeUrl'; | ||
|
||
describe('desensitizeUrl', () => { | ||
it('should desensitize a URL with a subdomain', () => { | ||
const originalUrl = 'https://api.example.com/v1'; | ||
const result = desensitizeUrl(originalUrl); | ||
expect(result).toBe('https://api.ex****le.com/v1'); | ||
}); | ||
|
||
it('should desensitize a URL without a subdomain', () => { | ||
const originalUrl = 'https://example.com/v1'; | ||
const result = desensitizeUrl(originalUrl); | ||
expect(result).toBe('https://ex****le.com/v1'); | ||
}); | ||
|
||
it('should desensitize a URL without a subdomain less then 5 chartarters', () => { | ||
const originalUrl = 'https://abc.com/v1'; | ||
const result = desensitizeUrl(originalUrl); | ||
expect(result).toBe('https://***.com/v1'); | ||
}); | ||
|
||
it('should desensitize a URL with multiple subdomains', () => { | ||
const originalUrl = 'https://sub.api.example.com/v1'; | ||
const result = desensitizeUrl(originalUrl); | ||
expect(result).toBe('https://sub.api.ex****le.com/v1'); | ||
}); | ||
|
||
it('should desensitize a URL with path and query parameters', () => { | ||
const originalUrl = 'https://api.example.com/v1?query=123'; | ||
const result = desensitizeUrl(originalUrl); | ||
expect(result).toBe('https://api.ex****le.com/v1?query=123'); | ||
}); | ||
|
||
it('should return the original URL if it is invalid', () => { | ||
const originalUrl = 'invalidurl'; | ||
const result = desensitizeUrl(originalUrl); | ||
expect(result).toBe(originalUrl); | ||
}); | ||
|
||
it('should desensitize a URL with a port number', () => { | ||
const originalUrl = 'https://api.example.com:8080/v1'; | ||
const result = desensitizeUrl(originalUrl); | ||
expect(result).toBe('https://api.ex****le.com:****/v1'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export const desensitizeUrl = (url: string) => { | ||
try { | ||
const urlObj = new URL(url); | ||
const hostnameParts = urlObj.hostname.split('.'); | ||
const port = urlObj.port; | ||
|
||
// Desensitize domain only if there are at least two parts (example.com) | ||
if (hostnameParts.length > 1) { | ||
// Desensitize the second level domain (second part from the right) | ||
// Special case for short domain names | ||
const secondLevelDomainIndex = hostnameParts.length - 2; | ||
if (hostnameParts[secondLevelDomainIndex].length < 5) { | ||
hostnameParts[secondLevelDomainIndex] = '***'; | ||
} else { | ||
hostnameParts[secondLevelDomainIndex] = hostnameParts[secondLevelDomainIndex].replace( | ||
/^(.*?)(\w{2})(\w+)(\w{2})$/, | ||
(_, prefix, start, middle, end) => `${prefix}${start}****${end}`, | ||
); | ||
} | ||
} | ||
|
||
// Join the hostname parts back together | ||
const desensitizedHostname = hostnameParts.join('.'); | ||
|
||
// Desensitize port if present | ||
const desensitizedPort = port ? ':****' : ''; | ||
|
||
// Reconstruct the URL with the desensitized parts | ||
return `${urlObj.protocol}//${desensitizedHostname}${desensitizedPort}${urlObj.pathname}${urlObj.search}`; | ||
} catch { | ||
// If the URL is invalid, return the original URL | ||
return url; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...nversation/ChatList/Actions/Assistant.tsx → ...atures/Conversation/Actions/Assistant.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...s/Conversation/ChatList/Actions/Error.tsx → src/features/Conversation/Actions/Error.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
...onversation/ChatList/Actions/Fallback.tsx → ...eatures/Conversation/Actions/Fallback.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
...onversation/ChatList/Actions/Function.tsx → ...eatures/Conversation/Actions/Function.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...es/Conversation/ChatList/Actions/User.tsx → src/features/Conversation/Actions/User.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
3 changes: 1 addition & 2 deletions
3
...es/Conversation/ChatList/Actions/index.ts → src/features/Conversation/Actions/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...onversation/ChatList/Error/OpenAPIKey.tsx → ...eatures/Conversation/Error/OpenAPIKey.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...rsation/ChatList/Error/OpenAiBizError.tsx → ...res/Conversation/Error/OpenAiBizError.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...ion/ChatList/Error/Plugin/PluginError.tsx → ...Conversation/Error/Plugin/PluginError.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...res/Conversation/ChatList/Error/index.tsx → src/features/Conversation/Error/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
3 changes: 1 addition & 2 deletions
3
...res/Conversation/ChatList/Extras/index.ts → src/features/Conversation/Extras/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.