Browse Source

feat: Dynamically change the background image on the search homepage every day #2247 (#2338)

### What problem does this PR solve?

feat: Dynamically change the background image on the search homepage
every day #2247

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
tags/v0.11.0
balibabu 1 year ago
parent
commit
f1ad778250
No account linked to committer's email address

+ 6
- 2
docker/nginx/ragflow.conf View File

gzip_disable "MSIE [1-6]\."; gzip_disable "MSIE [1-6]\.";


location /v1 { location /v1 {
proxy_pass http://ragflow:9380;
include proxy.conf;
proxy_pass http://ragflow:9380;
include proxy.conf;
}

location /HPImageArchive {
proxy_pass https://cn.bing.com;
} }


location / { location / {

+ 8
- 1
web/.umirc.ts View File

copy: ['src/conf.json'], copy: ['src/conf.json'],
proxy: { proxy: {
'/v1': { '/v1': {
target: 'http://localhost:9380/',
target: 'http://123.60.95.134:9380/',
changeOrigin: true,
ws: true,
logger: console,
// pathRewrite: { '^/v1': '/v1' },
},
'/HPImageArchive': {
target: 'https://cn.bing.com/',
changeOrigin: true, changeOrigin: true,
ws: true, ws: true,
logger: console, logger: console,

+ 26
- 1
web/src/pages/search/hooks.ts View File

import { useSendMessageWithSse } from '@/hooks/logic-hooks'; import { useSendMessageWithSse } from '@/hooks/logic-hooks';
import { IAnswer } from '@/interfaces/database/chat'; import { IAnswer } from '@/interfaces/database/chat';
import api from '@/utils/api'; import api from '@/utils/api';
import { isEmpty, trim } from 'lodash';
import { get, isEmpty, trim } from 'lodash';
import { ChangeEventHandler, useCallback, useEffect, useState } from 'react'; import { ChangeEventHandler, useCallback, useEffect, useState } from 'react';


export const useSendQuestion = (kbIds: string[]) => { export const useSendQuestion = (kbIds: string[]) => {
isFirstRender, isFirstRender,
}; };
}; };

export const useFetchBackgroundImage = () => {
const [imgUrl, setImgUrl] = useState<string>('');

const fetchImage = useCallback(async () => {
try {
const res = await fetch(
'/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN',
);
const ret = await res.json();
const url = get(ret, 'images.0.url');
if (url) {
setImgUrl(url);
}
} catch (error) {
console.log('🚀 ~ fetchImage ~ error:', error);
}
}, []);

useEffect(() => {
fetchImage();
}, [fetchImage]);

return `https://cn.bing.com${imgUrl}`;
};

+ 1
- 2
web/src/pages/search/index.less View File



.firstRenderContent { .firstRenderContent {
height: 100%; height: 100%;
background-image: url(https://www.bing.com/th?id=OHR.IguazuRainbow_ZH-CN6524347982_1920x1080.webp&qlt=50);
background-position: center; background-position: center;
background-size: cover; background-size: cover;
} }
font-weight: 600; font-weight: 600;
line-height: 20px; line-height: 20px;


background: linear-gradient(to right, #095fab 10%, #25abe8 50%, #57d75b 60%);
background: linear-gradient(to right, #095fab 10%, #25abe8 50%, #55c8dd 60%);
background-size: auto auto; background-size: auto auto;
background-clip: border-box; background-clip: border-box;
background-size: 200% auto; background-size: 200% auto;

+ 6
- 5
web/src/pages/search/index.tsx View File

} from 'antd'; } from 'antd';
import { useState } from 'react'; import { useState } from 'react';
import MarkdownContent from '../chat/markdown-content'; import MarkdownContent from '../chat/markdown-content';
import { useSendQuestion } from './hooks';
import { useFetchBackgroundImage, useSendQuestion } from './hooks';
import SearchSidebar from './sidebar'; import SearchSidebar from './sidebar';


import PdfDrawer from '@/components/pdf-drawer'; import PdfDrawer from '@/components/pdf-drawer';
import { useClickDrawer } from '@/components/pdf-drawer/hooks'; import { useClickDrawer } from '@/components/pdf-drawer/hooks';
import RetrievalDocuments from '@/components/retrieval-documents'; import RetrievalDocuments from '@/components/retrieval-documents';
import { useFetchAppConf } from '@/hooks/logic-hooks';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import styles from './index.less'; import styles from './index.less';


const { t } = useTranslation(); const { t } = useTranslation();
const [checkedList, setCheckedList] = useState<string[]>([]); const [checkedList, setCheckedList] = useState<string[]>([]);
const list = useSelectTestingResult(); const list = useSelectTestingResult();
const appConf = useFetchAppConf();
// const appConf = useFetchAppConf();
const { const {
sendQuestion, sendQuestion,
handleClickRelatedQuestion, handleClickRelatedQuestion,
} = useSendQuestion(checkedList); } = useSendQuestion(checkedList);
const { visible, hideModal, documentId, selectedChunk, clickDocumentButton } = const { visible, hideModal, documentId, selectedChunk, clickDocumentButton } =
useClickDrawer(); useClickDrawer();
const imgUrl = useFetchBackgroundImage();


const InputSearch = ( const InputSearch = (
<Search <Search
justify="center" justify="center"
align="center" align="center"
className={styles.firstRenderContent} className={styles.firstRenderContent}
style={{ backgroundImage: `url(${imgUrl})` }}
> >
<Flex vertical align="center" gap={'large'}> <Flex vertical align="center" gap={'large'}>
<Space size={30}>
{/* <Space size={30}>
<img src="/logo.svg" alt="" className={styles.appIcon} /> <img src="/logo.svg" alt="" className={styles.appIcon} />
<span className={styles.appName}>{appConf.appName}</span> <span className={styles.appName}>{appConf.appName}</span>
</Space>
</Space> */}
{InputSearch} {InputSearch}
</Flex> </Flex>
</Flex> </Flex>

Loading…
Cancel
Save