balibabu
		
	commited on
		
		
					Commit 
							
							·
						
						17c457d
	
1
								Parent(s):
							
							01c2a31
								
feat: Dynamically change the background image on the search homepage every day #2247 (#2338)
Browse files### 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)
- docker/nginx/ragflow.conf +6 -2
- web/.umirc.ts +8 -1
- web/src/pages/search/hooks.ts +26 -1
- web/src/pages/search/index.less +1 -2
- web/src/pages/search/index.tsx +6 -5
    	
        docker/nginx/ragflow.conf
    CHANGED
    
    | @@ -11,8 +11,12 @@ server { | |
| 11 | 
             
                gzip_disable "MSIE [1-6]\.";
         | 
| 12 |  | 
| 13 | 
             
                location /v1 {
         | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
|  | |
|  | |
|  | |
|  | |
| 16 | 
             
                }
         | 
| 17 |  | 
| 18 | 
             
                location / {
         | 
|  | |
| 11 | 
             
                gzip_disable "MSIE [1-6]\.";
         | 
| 12 |  | 
| 13 | 
             
                location /v1 {
         | 
| 14 | 
            +
                    proxy_pass http://ragflow:9380;
         | 
| 15 | 
            +
                    include proxy.conf;
         | 
| 16 | 
            +
                }
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                location /HPImageArchive {
         | 
| 19 | 
            +
                    proxy_pass https://cn.bing.com;
         | 
| 20 | 
             
                }
         | 
| 21 |  | 
| 22 | 
             
                location / {
         | 
    	
        web/.umirc.ts
    CHANGED
    
    | @@ -30,7 +30,14 @@ export default defineConfig({ | |
| 30 | 
             
              copy: ['src/conf.json'],
         | 
| 31 | 
             
              proxy: {
         | 
| 32 | 
             
                '/v1': {
         | 
| 33 | 
            -
                  target: 'http:// | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 34 | 
             
                  changeOrigin: true,
         | 
| 35 | 
             
                  ws: true,
         | 
| 36 | 
             
                  logger: console,
         | 
|  | |
| 30 | 
             
              copy: ['src/conf.json'],
         | 
| 31 | 
             
              proxy: {
         | 
| 32 | 
             
                '/v1': {
         | 
| 33 | 
            +
                  target: 'http://123.60.95.134:9380/',
         | 
| 34 | 
            +
                  changeOrigin: true,
         | 
| 35 | 
            +
                  ws: true,
         | 
| 36 | 
            +
                  logger: console,
         | 
| 37 | 
            +
                  // pathRewrite: { '^/v1': '/v1' },
         | 
| 38 | 
            +
                },
         | 
| 39 | 
            +
                '/HPImageArchive': {
         | 
| 40 | 
            +
                  target: 'https://cn.bing.com/',
         | 
| 41 | 
             
                  changeOrigin: true,
         | 
| 42 | 
             
                  ws: true,
         | 
| 43 | 
             
                  logger: console,
         | 
    	
        web/src/pages/search/hooks.ts
    CHANGED
    
    | @@ -3,7 +3,7 @@ import { useTestChunkRetrieval } from '@/hooks/knowledge-hooks'; | |
| 3 | 
             
            import { useSendMessageWithSse } from '@/hooks/logic-hooks';
         | 
| 4 | 
             
            import { IAnswer } from '@/interfaces/database/chat';
         | 
| 5 | 
             
            import api from '@/utils/api';
         | 
| 6 | 
            -
            import { isEmpty, trim } from 'lodash';
         | 
| 7 | 
             
            import { ChangeEventHandler, useCallback, useEffect, useState } from 'react';
         | 
| 8 |  | 
| 9 | 
             
            export const useSendQuestion = (kbIds: string[]) => {
         | 
| @@ -99,3 +99,28 @@ export const useSendQuestion = (kbIds: string[]) => { | |
| 99 | 
             
                isFirstRender,
         | 
| 100 | 
             
              };
         | 
| 101 | 
             
            };
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 3 | 
             
            import { useSendMessageWithSse } from '@/hooks/logic-hooks';
         | 
| 4 | 
             
            import { IAnswer } from '@/interfaces/database/chat';
         | 
| 5 | 
             
            import api from '@/utils/api';
         | 
| 6 | 
            +
            import { get, isEmpty, trim } from 'lodash';
         | 
| 7 | 
             
            import { ChangeEventHandler, useCallback, useEffect, useState } from 'react';
         | 
| 8 |  | 
| 9 | 
             
            export const useSendQuestion = (kbIds: string[]) => {
         | 
|  | |
| 99 | 
             
                isFirstRender,
         | 
| 100 | 
             
              };
         | 
| 101 | 
             
            };
         | 
| 102 | 
            +
             | 
| 103 | 
            +
            export const useFetchBackgroundImage = () => {
         | 
| 104 | 
            +
              const [imgUrl, setImgUrl] = useState<string>('');
         | 
| 105 | 
            +
             | 
| 106 | 
            +
              const fetchImage = useCallback(async () => {
         | 
| 107 | 
            +
                try {
         | 
| 108 | 
            +
                  const res = await fetch(
         | 
| 109 | 
            +
                    '/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN',
         | 
| 110 | 
            +
                  );
         | 
| 111 | 
            +
                  const ret = await res.json();
         | 
| 112 | 
            +
                  const url = get(ret, 'images.0.url');
         | 
| 113 | 
            +
                  if (url) {
         | 
| 114 | 
            +
                    setImgUrl(url);
         | 
| 115 | 
            +
                  }
         | 
| 116 | 
            +
                } catch (error) {
         | 
| 117 | 
            +
                  console.log('🚀 ~ fetchImage ~ error:', error);
         | 
| 118 | 
            +
                }
         | 
| 119 | 
            +
              }, []);
         | 
| 120 | 
            +
             | 
| 121 | 
            +
              useEffect(() => {
         | 
| 122 | 
            +
                fetchImage();
         | 
| 123 | 
            +
              }, [fetchImage]);
         | 
| 124 | 
            +
             | 
| 125 | 
            +
              return `https://cn.bing.com${imgUrl}`;
         | 
| 126 | 
            +
            };
         | 
    	
        web/src/pages/search/index.less
    CHANGED
    
    | @@ -51,7 +51,6 @@ | |
| 51 |  | 
| 52 | 
             
            .firstRenderContent {
         | 
| 53 | 
             
              height: 100%;
         | 
| 54 | 
            -
              background-image: url(https://www.bing.com/th?id=OHR.IguazuRainbow_ZH-CN6524347982_1920x1080.webp&qlt=50);
         | 
| 55 | 
             
              background-position: center;
         | 
| 56 | 
             
              background-size: cover;
         | 
| 57 | 
             
            }
         | 
| @@ -122,7 +121,7 @@ | |
| 122 | 
             
              font-weight: 600;
         | 
| 123 | 
             
              line-height: 20px;
         | 
| 124 |  | 
| 125 | 
            -
              background: linear-gradient(to right, #095fab 10%, #25abe8 50%, # | 
| 126 | 
             
              background-size: auto auto;
         | 
| 127 | 
             
              background-clip: border-box;
         | 
| 128 | 
             
              background-size: 200% auto;
         | 
|  | |
| 51 |  | 
| 52 | 
             
            .firstRenderContent {
         | 
| 53 | 
             
              height: 100%;
         | 
|  | |
| 54 | 
             
              background-position: center;
         | 
| 55 | 
             
              background-size: cover;
         | 
| 56 | 
             
            }
         | 
|  | |
| 121 | 
             
              font-weight: 600;
         | 
| 122 | 
             
              line-height: 20px;
         | 
| 123 |  | 
| 124 | 
            +
              background: linear-gradient(to right, #095fab 10%, #25abe8 50%, #55c8dd 60%);
         | 
| 125 | 
             
              background-size: auto auto;
         | 
| 126 | 
             
              background-clip: border-box;
         | 
| 127 | 
             
              background-size: 200% auto;
         | 
    	
        web/src/pages/search/index.tsx
    CHANGED
    
    | @@ -16,13 +16,12 @@ import { | |
| 16 | 
             
            } from 'antd';
         | 
| 17 | 
             
            import { useState } from 'react';
         | 
| 18 | 
             
            import MarkdownContent from '../chat/markdown-content';
         | 
| 19 | 
            -
            import { useSendQuestion } from './hooks';
         | 
| 20 | 
             
            import SearchSidebar from './sidebar';
         | 
| 21 |  | 
| 22 | 
             
            import PdfDrawer from '@/components/pdf-drawer';
         | 
| 23 | 
             
            import { useClickDrawer } from '@/components/pdf-drawer/hooks';
         | 
| 24 | 
             
            import RetrievalDocuments from '@/components/retrieval-documents';
         | 
| 25 | 
            -
            import { useFetchAppConf } from '@/hooks/logic-hooks';
         | 
| 26 | 
             
            import { useTranslation } from 'react-i18next';
         | 
| 27 | 
             
            import styles from './index.less';
         | 
| 28 |  | 
| @@ -33,7 +32,7 @@ const SearchPage = () => { | |
| 33 | 
             
              const { t } = useTranslation();
         | 
| 34 | 
             
              const [checkedList, setCheckedList] = useState<string[]>([]);
         | 
| 35 | 
             
              const list = useSelectTestingResult();
         | 
| 36 | 
            -
              const appConf = useFetchAppConf();
         | 
| 37 | 
             
              const {
         | 
| 38 | 
             
                sendQuestion,
         | 
| 39 | 
             
                handleClickRelatedQuestion,
         | 
| @@ -50,6 +49,7 @@ const SearchPage = () => { | |
| 50 | 
             
              } = useSendQuestion(checkedList);
         | 
| 51 | 
             
              const { visible, hideModal, documentId, selectedChunk, clickDocumentButton } =
         | 
| 52 | 
             
                useClickDrawer();
         | 
|  | |
| 53 |  | 
| 54 | 
             
              const InputSearch = (
         | 
| 55 | 
             
                <Search
         | 
| @@ -80,12 +80,13 @@ const SearchPage = () => { | |
| 80 | 
             
                            justify="center"
         | 
| 81 | 
             
                            align="center"
         | 
| 82 | 
             
                            className={styles.firstRenderContent}
         | 
|  | |
| 83 | 
             
                          >
         | 
| 84 | 
             
                            <Flex vertical align="center" gap={'large'}>
         | 
| 85 | 
            -
                              <Space size={30}>
         | 
| 86 | 
             
                                <img src="/logo.svg" alt="" className={styles.appIcon} />
         | 
| 87 | 
             
                                <span className={styles.appName}>{appConf.appName}</span>
         | 
| 88 | 
            -
                              </Space>
         | 
| 89 | 
             
                              {InputSearch}
         | 
| 90 | 
             
                            </Flex>
         | 
| 91 | 
             
                          </Flex>
         | 
|  | |
| 16 | 
             
            } from 'antd';
         | 
| 17 | 
             
            import { useState } from 'react';
         | 
| 18 | 
             
            import MarkdownContent from '../chat/markdown-content';
         | 
| 19 | 
            +
            import { useFetchBackgroundImage, useSendQuestion } from './hooks';
         | 
| 20 | 
             
            import SearchSidebar from './sidebar';
         | 
| 21 |  | 
| 22 | 
             
            import PdfDrawer from '@/components/pdf-drawer';
         | 
| 23 | 
             
            import { useClickDrawer } from '@/components/pdf-drawer/hooks';
         | 
| 24 | 
             
            import RetrievalDocuments from '@/components/retrieval-documents';
         | 
|  | |
| 25 | 
             
            import { useTranslation } from 'react-i18next';
         | 
| 26 | 
             
            import styles from './index.less';
         | 
| 27 |  | 
|  | |
| 32 | 
             
              const { t } = useTranslation();
         | 
| 33 | 
             
              const [checkedList, setCheckedList] = useState<string[]>([]);
         | 
| 34 | 
             
              const list = useSelectTestingResult();
         | 
| 35 | 
            +
              // const appConf = useFetchAppConf();
         | 
| 36 | 
             
              const {
         | 
| 37 | 
             
                sendQuestion,
         | 
| 38 | 
             
                handleClickRelatedQuestion,
         | 
|  | |
| 49 | 
             
              } = useSendQuestion(checkedList);
         | 
| 50 | 
             
              const { visible, hideModal, documentId, selectedChunk, clickDocumentButton } =
         | 
| 51 | 
             
                useClickDrawer();
         | 
| 52 | 
            +
              const imgUrl = useFetchBackgroundImage();
         | 
| 53 |  | 
| 54 | 
             
              const InputSearch = (
         | 
| 55 | 
             
                <Search
         | 
|  | |
| 80 | 
             
                            justify="center"
         | 
| 81 | 
             
                            align="center"
         | 
| 82 | 
             
                            className={styles.firstRenderContent}
         | 
| 83 | 
            +
                            style={{ backgroundImage: `url(${imgUrl})` }}
         | 
| 84 | 
             
                          >
         | 
| 85 | 
             
                            <Flex vertical align="center" gap={'large'}>
         | 
| 86 | 
            +
                              {/* <Space size={30}>
         | 
| 87 | 
             
                                <img src="/logo.svg" alt="" className={styles.appIcon} />
         | 
| 88 | 
             
                                <span className={styles.appName}>{appConf.appName}</span>
         | 
| 89 | 
            +
                              </Space> */}
         | 
| 90 | 
             
                              {InputSearch}
         | 
| 91 | 
             
                            </Flex>
         | 
| 92 | 
             
                          </Flex>
         |