Merge branch 'gitlink_ssr_head' into pre_gitlink_ssr

This commit is contained in:
黄心宇 2025-06-20 09:24:41 +08:00
commit 7ecaae2c58
14 changed files with 247 additions and 33 deletions

View File

@ -53,4 +53,5 @@ module.exports = {
appNodeModules: resolveApp('node_modules'),
publicUrl: getPublicUrl(resolveApp('package.json')),
servedPath: getServedPath(resolveApp('package.json')),
};
proxySetup: resolveApp('src/setupProxy.js'),
};

View File

@ -5,6 +5,7 @@ const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMi
const ignoredFiles = require('react-dev-utils/ignoredFiles');
const config = require('./webpack.config.dev');
const paths = require('./paths');
const fs = require('fs');
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
const host = process.env.HOST || '0.0.0.0';
@ -90,6 +91,9 @@ module.exports = function(proxy, allowedHost) {
// it used the same host and port.
// https://github.com/facebookincubator/create-react-app/issues/2272#issuecomment-302832432
app.use(noopServiceWorkerMiddleware());
if (fs.existsSync(paths.proxySetup)) {
require(paths.proxySetup)(app);
}
},
};
};

View File

@ -202,7 +202,6 @@
"eslintConfig": {
"extends": "react-app"
},
"proxy": "https://testforgeplus.trustie.net",
"port": "3007",
"devDependencies": {
"@babel/core": "^7.23.6",

View File

@ -135,6 +135,10 @@ const Wiki = Loadable({
loader: () => import('../Wiki/page/index'),
loading: Loading,
});
const WikiHisList = Loadable({
loader: () => import('../Wiki/page/historyList'),
loading: Loading,
});
const WikiEdit = Loadable({
loader: () => import('../Wiki/page/edit'),
loading: Loading,
@ -817,6 +821,12 @@ class Detail extends Component {
() => (<WikiEdit {...this.props} {...this.state} {...common} />)
}
></Route>
{/* wiki历史列表 */}
<Route path="/:owner/:projectsId/wiki/history"
render={
() => (<WikiHisList {...this.props} {...this.state} {...common} />)
}
></Route>
{/* wiki */}
<Route path="/:owner/:projectsId/wiki"
render={

View File

@ -19,6 +19,24 @@ export function getWiki(params) {
});
}
// 获取wiki历史版本列表
export function getWikiRevisions(params) {
return fetch({
url: '/api/wiki/open/getWikiRevisions',
method: 'get',
params
});
}
// 获取wiki历史版本页面内容
export function getPreviousWiki(params) {
return fetch({
url: '/api/wiki/open/getPreviousWiki',
method: 'get',
params
});
}
//新增wiki
export function addWiki(repoInfo, title, content){
return fetch({

View File

@ -1,7 +1,7 @@
import javaFetch from '../javaFetch';
let settings = JSON.parse(localStorage.chromesetting);
let actionUrl = settings && settings.common.wiki;
let actionUrl = window.location.hostname !== "localhost" ? settings && settings.common.wiki : '';
const service = javaFetch(actionUrl);
export const httpUrl = actionUrl;

View File

@ -1,7 +1,7 @@
import React, { useEffect, useState } from "react";
import { Form, Icon, Input, Button, Spin, message, Radio } from "antd";
import './index.scss';
import { addChildrenByKey, addWiki, editMenuTitleByKey, findSamaNameWiki, getMenuListAndSidebarData, getWiki, treeToMd, updateSidebar, updateWiki } from "../api";
import { addChildrenByKey, addWiki, editMenuTitleByKey, findSamaNameWiki, getMenuListAndSidebarData, getWiki, treeToMd, updateSidebar, updateWiki, getPreviousWiki } from "../api";
import { template } from "../config";
import DelModal from "../components/ModalFun";
import { Base64 } from "js-base64";
@ -20,6 +20,7 @@ export default Form.create()((props) => {
const {getFieldDecorator, validateFields, getFieldValue} = form;
const wikiParams = {owner, repo: repoIdentifier, projectId: project_id};
let editType = pathname.split("/").pop(); //wikiaddWiki addWikiBy${key} edit)
const sha = searchParams.get("sha") || '';
const [loading, setLoading] = useState(false);
const [wikiPageInitDetail, setWikiPageInitDetail] = useState({})
@ -42,9 +43,11 @@ export default Form.create()((props) => {
const wikiName = searchParams.get("wiki")
const sameNameWiki = findSamaNameWiki(wikiPages, wikiName)
document.title = `${titleByEditType[editType]}${sameNameWiki.title}-维基-${projectAuthor && projectAuthor.name}/${projectName}`;
getWiki({
const func = sha ? getPreviousWiki : getWiki
func({
...wikiParams,
pageName: sameNameWiki.sub_url
pageName: sameNameWiki.sub_url,
sha
}).then(res=>{
if(res && res.code === 200){
res.data.content = Base64.decode(res.data.content_base64)

View File

@ -0,0 +1,115 @@
import React, { useEffect, useState } from "react";
import { Button, Table } from "antd";
import { getWikiRevisions } from "../api";
import './index.scss';
export default (props) => {
const {project_id, match:{params:{owner, projectsId: repoIdentifier}}, projectDetail, history, location} = props;
const search = new URLSearchParams(location.search);
const pageName = search.get("wiki") || '';
const title_sub = search.get("str") || '';
const wikiParams = {owner, repo: repoIdentifier, projectId: project_id, pageName: title_sub};
const permission = projectDetail && projectDetail.permission && projectDetail.permission !== "Reporter";
const { author: projectAuthor, name: projectName} = projectDetail || {};
const [reload, setReload] = useState();
const [loading, setLoading] = useState();
const [ historyList, setHistoryList ] = useState([]);
//
useEffect(()=>{
if(!project_id) return
document.title = `${pageName}历史版本-维基-${projectAuthor && projectAuthor.name}/${projectName}`;
getList()
// setWikiPageInitDetail({})
// // wiki sidebar
// getMenuListAndSidebarData(wikiParams).then(res=>{
// setWikiPageInitDetail(res);
// })
}, [project_id, reload])
function refush(){
setReload(Math.random())
}
const getList = () => {
setLoading(true)
getWikiRevisions(wikiParams).then(res=>{
setLoading(false)
if(res?.code === 200){
setHistoryList(res.data?.commits);
}
})
}
const columns = [
{
title: '修改时间',
dataIndex: ['author','date'],
},
{
title: '修改记录',
dataIndex: 'message',
key: "message",
ellipsis: true,
},
{
title: '修改人',
dataIndex: 'author',
key: "author",
ellipsis: true,
render:(value)=>{
return(
<div className="alignCenter">
<img src={`/${value?.image_url}`} style={{width:26,height:26,borderRadius:"50%",marginRight:8}}/>
<span>{value?.name}</span>
</div>
)
}
},
{
title: '操作',
dataIndex: 'sha',
key: 'sha',
render: (text, record) => {
return <div>
<Button type='link' onClick={()=>{
const currentSearchParams = new URLSearchParams(search)
currentSearchParams.set('sha', text)
currentSearchParams.set('name', repoIdentifier)
history.push(`/${owner}/${repoIdentifier}/${project_id}/wiki/preview?${currentSearchParams.toString()}`)}
}
>预览</Button>
<div className="divider"></div>
<Button type='link' onClick={()=>{
const currentSearchParams = new URLSearchParams(search)
currentSearchParams.set('sha', text)
history.push(`/${owner}/${repoIdentifier}/wiki/edit?${currentSearchParams.toString()}`)
}}>使用此版本</Button>
</div>
}
}
];
return <div className="history wiki-main">
<div className="wiki-head">
<div className='wiki-title'>历史版本</div>
<Button type='primary' style={{width: 70}} onClick={()=>{
history.push(`/${owner}/${repoIdentifier}/wiki`)
}}>返回</Button>
</div>
<div className="wiki-body">
<Table
pagination={false}
columns={columns}
dataSource={historyList}
rowKey={(record) => record.id}
loading={loading}
></Table>
</div>
</div >
}

View File

@ -126,6 +126,7 @@ export default (props) => {
{wikiDetail.userName}
</Link>
上次修改于{wikiDetail.last_commit ? timeAgo(wikiDetail.last_commit.author.date) : '刚刚'}
<Link className='color-blue ml10' to={`/${owner}/${repoIdentifier}/wiki/history?wiki=${encodeURIComponent(wikiDetail.title)}&key=${selectNodeDetail.key}&str=${ encodeURIComponent(selectNodeDetail.title_sub) }`}>历史版本</Link>
</div>
</div>
{permission && <div>

View File

@ -112,7 +112,7 @@
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 12rem 0 2rem;
padding: 0 2rem 0 2rem;
width: 100%;
height: 8vh;
background: rgb(39, 47, 76);
@ -125,4 +125,26 @@
flex:none
}
}
}
.history {
.wiki-title {
font-weight: 700;
color: #202d40;
font-size: 17px;
}
.ant-table-thead > tr > th{
background-color: #fff;
}
.ant-table-column-title {
color: #202d40;
font-size: 16px;
}
.divider {
opacity: 24%;
width: 0px;
height: 7px;
border-right: 1px solid;
border-color: #72748e;
display: inline-block;
}
}

View File

@ -1,8 +1,8 @@
import React, { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
import { Base64 } from 'js-base64';
import { Divider } from 'antd';
import { getWiki, getMenuListAndSidebarData, findNodeByFirstOrContrastName, } from '../api';
import { Divider, Button } from 'antd';
import { getWiki, getMenuListAndSidebarData, findNodeByFirstOrContrastName, getPreviousWiki } from '../api';
import RenderHtml from '../../../components/render-html';
import TreeByWikiSidebar from '../components/treeByWikiSidebar';
import Clone from '../components/clone';
@ -15,6 +15,8 @@ export default (props) => {
const search = new URLSearchParams(location.search);
const projectName = search.get("name") || '';
const wikiBySearch = search.get("wiki") || '';
const sha = search.get("sha") || '';
const str = search.get("str") || '';
const [wikiPageInitDetail, setWikiPageInitDetail] = useState({})
const [checkItem, setCheckItem] = useState({});
@ -24,12 +26,13 @@ export default (props) => {
useEffect(()=>{
if(checkItem && checkItem.name){
document.title = `${checkItem.name}-维基预览`
document.title = `${checkItem.name || wikiBySearch}-维基预览`
}
}, [checkItem])
useEffect(()=>{
if (sha) return
// wiki sidebar
getMenuListAndSidebarData(wikiParams).then(res=>{
setWikiPageInitDetail(res);
@ -49,11 +52,13 @@ export default (props) => {
setCheckItem(node);
}, [menuList, wikiBySearch])
useEffect(() => {
document.title = `${checkItem && checkItem.titleStr}-维基预览`
checkItem.title_sub && getWiki({
useEffect(() => {
document.title = `${checkItem && checkItem.titleStr || wikiBySearch}-维基预览`
const func = sha ? getPreviousWiki : getWiki
func({
...wikiParams,
pageName: checkItem.title_sub
pageName: str,
sha
}).then(res => {
if(res && res.code === 200){
setItemDetail(res.data);
@ -71,23 +76,35 @@ export default (props) => {
<span className="ml10">{projectName}</span>
</Link>
<div className="preview-head-right">
<div className="font-16 copy-desc mr10">克隆地址</div>
<Clone wikiPages={wikiPages}/>
<Download wikiParams={wikiParams} projectName={projectName}/>
{
sha ? <Button type='primary' className="ml10" style={{width: 70}} onClick={()=>{
// 退
const currentSearchParams = new URLSearchParams(search)
currentSearchParams.delete('sha')
currentSearchParams.delete('name')
history.push(`/${owner}/${proIdentity}/wiki/history?${ currentSearchParams.toString() }`)
}}>返回</Button> : <>
<div className="font-16 copy-desc mr10">克隆地址</div>
<Clone wikiPages={wikiPages}/>
<Download wikiParams={wikiParams} projectName={projectName}/>
</>
}
</div>
</div>
<div className="wiki-body">
<div className="wiki-nav previewWiki mt20">
{/* 读sidebar转换成目录树 */}
<TreeByWikiSidebar wikiParams={wikiParams} hasPermission={false} hasSearch={false} wikiPageInitDetail={wikiPageInitDetail} clickNode={(node)=>{
history.push(`${location.pathname}?name=${projectName}&wiki=${encodeURIComponent(node.titleStr)}`)
}}/>
</div>
{
!sha && <div className="wiki-nav previewWiki mt20">
{/* 读sidebar转换成目录树 */}
<TreeByWikiSidebar wikiParams={wikiParams} hasPermission={false} hasSearch={false} wikiPageInitDetail={wikiPageInitDetail} clickNode={(node)=>{
history.push(`${location.pathname}?name=${projectName}&wiki=${encodeURIComponent(node.titleStr)}`)
}}/>
</div>
}
<div className="wiki-content padding20">
<h3>{checkItem.titleStr}</h3>
<h3>{itemDetail.title}</h3>
<Divider/>
{itemDetail && itemDetail.content_base64 && <RenderHtml className="wiki-content-detail editor-content-panel markdown-body" value={Base64.decode(itemDetail.content_base64)} url={history.location}/>}
</div>

View File

@ -15,13 +15,13 @@ const axiosInstance = axios.create({
});
axiosInstance.interceptors.request.use(
config => {
if (window.location.port === "3007") {
if (config.url.indexOf('?') === -1) {
config.url = `${config.url}?debug=admin`;
} else {
config.url = `${config.url}&debug=admin`;
}
}
// if (window.location.port === "3007") {
// if (config.url.indexOf('?') === -1) {
// config.url = `${config.url}?debug=admin`;
// } else {
// config.url = `${config.url}&debug=admin`;
// }
// }
return config;
},
err => {

24
src/setupProxy.js Normal file
View File

@ -0,0 +1,24 @@
// src/setupProxy.js
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) {
app.use(
'/api/wiki',
createProxyMiddleware({
target: 'http://testgetway.trustie.net/',
changeOrigin: true,
logLevel: 'debug', // 开启 http-proxy-middleware 的日志
// pathRewrite: { '^/api/wiki': '' }, // 根据需要取消注释和修改
})
);
app.use(
'/api',
createProxyMiddleware({
target: 'http://testforgeplus.trustie.net/',
changeOrigin: true,
logLevel: 'debug', // 开启 http-proxy-middleware 的日志
// pathRewrite: { '^/api': '' }, // 根据需要取消注释和修改
})
);
};

View File

@ -1,4 +1,4 @@
export const url = process.env.NODE_ENV === 'production' ? 'https://www.gitlink.org.cn' : 'https://testforgeplus.trustie.net'
export const url = process.env.NODE_ENV === 'production' ? 'https://www.gitlink.org.cn' : 'https://testforgeplus.trustie.net'
export const zoneUrl = process.env.NODE_ENV === 'production' ? 'https://gateway.gitlink.org.cn' : 'https://testgetway.trustie.net'
export const host = process.env.NODE_ENV === 'production' ? 'www.gitlink.org.cn' : 'testforgeplus.trustie.net'