Skip to content

Commit

Permalink
feat: Dynamically change the background image on the search homepage …
Browse files Browse the repository at this point in the history
…every day infiniflow#2247 (infiniflow#2338)

### What problem does this PR solve?

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

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
  • Loading branch information
cike8899 authored Sep 10, 2024
1 parent 280027b commit ce2b528
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 11 deletions.
8 changes: 6 additions & 2 deletions docker/nginx/ragflow.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ server {
gzip_disable "MSIE [1-6]\.";

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 / {
Expand Down
9 changes: 8 additions & 1 deletion web/.umirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ export default defineConfig({
copy: ['src/conf.json'],
proxy: {
'/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,
ws: true,
logger: console,
Expand Down
27 changes: 26 additions & 1 deletion web/src/pages/search/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useTestChunkRetrieval } from '@/hooks/knowledge-hooks';
import { useSendMessageWithSse } from '@/hooks/logic-hooks';
import { IAnswer } from '@/interfaces/database/chat';
import api from '@/utils/api';
import { isEmpty, trim } from 'lodash';
import { get, isEmpty, trim } from 'lodash';
import { ChangeEventHandler, useCallback, useEffect, useState } from 'react';

export const useSendQuestion = (kbIds: string[]) => {
Expand Down Expand Up @@ -99,3 +99,28 @@ export const useSendQuestion = (kbIds: string[]) => {
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}`;
};
3 changes: 1 addition & 2 deletions web/src/pages/search/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@

.firstRenderContent {
height: 100%;
background-image: url(https://www.bing.com/th?id=OHR.IguazuRainbow_ZH-CN6524347982_1920x1080.webp&qlt=50);
background-position: center;
background-size: cover;
}
Expand Down Expand Up @@ -122,7 +121,7 @@
font-weight: 600;
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-clip: border-box;
background-size: 200% auto;
Expand Down
11 changes: 6 additions & 5 deletions web/src/pages/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ import {
} from 'antd';
import { useState } from 'react';
import MarkdownContent from '../chat/markdown-content';
import { useSendQuestion } from './hooks';
import { useFetchBackgroundImage, useSendQuestion } from './hooks';
import SearchSidebar from './sidebar';

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

Expand All @@ -33,7 +32,7 @@ const SearchPage = () => {
const { t } = useTranslation();
const [checkedList, setCheckedList] = useState<string[]>([]);
const list = useSelectTestingResult();
const appConf = useFetchAppConf();
// const appConf = useFetchAppConf();
const {
sendQuestion,
handleClickRelatedQuestion,
Expand All @@ -50,6 +49,7 @@ const SearchPage = () => {
} = useSendQuestion(checkedList);
const { visible, hideModal, documentId, selectedChunk, clickDocumentButton } =
useClickDrawer();
const imgUrl = useFetchBackgroundImage();

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

0 comments on commit ce2b528

Please sign in to comment.