feat: improoved the code

This commit is contained in:
Maxim Grigorev 2025-05-16 20:35:04 +07:00
commit 2b0f178fe0
2 changed files with 14 additions and 8 deletions

View file

@ -52,11 +52,16 @@ export default ({
useEffect(() => {
const loadSplashText = async () => {
if (appConfig?.splashText && isRemoteSplashText(appConfig.splashText)) {
const text = await loadRemoteSplashText(appConfig.splashText)
setSplashText(text)
} else {
setSplashText(appConfig?.splashText || '')
try {
if (appConfig?.splashText && isRemoteSplashText(appConfig.splashText)) {
const text = await loadRemoteSplashText(appConfig.splashText)
setSplashText(text)
} else {
setSplashText(appConfig?.splashText || '')
}
} catch (error) {
console.error('Failed to load splash text:', error)
setSplashText('Error loading splash text')
}
}
void loadSplashText()

View file

@ -1,5 +1,5 @@
const MAX_WORDS = 5
const HTTPS_REGEX = /^https?:\/\//
const HTTPS_REGEX = /^https?:\/\/[-\w@:%.+~#=]{1,256}\.[a-zA-Z\d()]{1,6}\b([-\w()@:%+.~#?&/=]*)$/
const limitWords = (text: string): string => {
const words = text.split(/\s+/)
@ -19,6 +19,8 @@ export const loadRemoteSplashText = async (url: string): Promise<string> => {
if (!response.ok) {
throw new Error(`Failed to fetch splash text: ${response.statusText}`)
}
const clonedResponse = response.clone()
try {
const json = await response.json()
@ -32,8 +34,7 @@ export const loadRemoteSplashText = async (url: string): Promise<string> => {
return limitWords(String(json))
} catch (jsonError) {
const text = await response.text()
const text = await clonedResponse.text()
return limitWords(text.trim())
}
} catch (error) {