Skip to content

Commit 7756e55

Browse files
liiil825sunnywx
authored andcommitted
fix: Attachment image not display when forward request (#568)
1 parent 3c14060 commit 7756e55

File tree

4 files changed

+18
-22
lines changed

4 files changed

+18
-22
lines changed

server/routes/page.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
const Router = require('koa-router');
2+
const agent = require('lib/request').default;
23
const auth = require('../middleware/auth');
34
const gzip = require('../middleware/gzip');
45

56
const router = new Router();
67

8+
router.get('/attachments/:id', async ctx => {
9+
const { apiServer } = ctx.store;
10+
const apiUrl = `${apiServer.split('/v')[0]}/attachments/${ctx.params.id}/raw`;
11+
12+
ctx.body = await agent.send('get', apiUrl);
13+
});
14+
715
router.get('/:page(/?.*)', auth, gzip, async (ctx, next) => {
816
try {
917
await next();

src/components/Base/Image/index.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import classnames from 'classnames';
44

5+
import { startsWith } from 'lodash';
6+
57
import styles from './index.scss';
68

79
export default class Image extends React.Component {
@@ -47,6 +49,7 @@ export default class Image extends React.Component {
4749
src, iconLetter, className, iconSize, ...rest
4850
} = this.props;
4951
const { failed } = this.state;
52+
const imgStr = src && startsWith(src, 'att-') ? `/attachments/${src}` : src;
5053

5154
if (failed) {
5255
const style = {
@@ -73,7 +76,7 @@ export default class Image extends React.Component {
7376
return (
7477
<img
7578
src="/none.svg"
76-
data-origin-url={src}
79+
data-origin-url={imgStr}
7780
style={style}
7881
className={classnames(styles.img, className)}
7982
{...rest}
@@ -83,8 +86,8 @@ export default class Image extends React.Component {
8386

8487
return (
8588
<img
86-
src={src}
87-
data-origin-url={src}
89+
src={imgStr}
90+
data-origin-url={imgStr}
8891
className={classnames(styles.img, className)}
8992
ref={c => {
9093
this.img = c;

src/pages/Dashboard/Apps/Card/index.jsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
33
import classnames from 'classnames';
44
import { withRouter } from 'react-router';
5-
import _ from 'lodash';
65

76
import Status from 'components/Status';
87
import { Image } from 'components/Base';
@@ -13,16 +12,13 @@ import styles from './index.scss';
1312
@withRouter
1413
export default class AppCard extends Component {
1514
static propTypes = {
16-
apiServer: PropTypes.string,
1715
children: PropTypes.node,
1816
className: PropTypes.string,
1917
data: PropTypes.object
2018
};
2119

2220
render() {
23-
const {
24-
apiServer, className, data, t
25-
} = this.props;
21+
const { className, data, t } = this.props;
2622
const {
2723
app_id,
2824
icon,
@@ -32,10 +28,6 @@ export default class AppCard extends Component {
3228
status_time,
3329
app_version_types
3430
} = data;
35-
let imgStr = icon;
36-
if (icon && _.startsWith(icon, 'att-')) {
37-
imgStr = `${apiServer.split('/v')[0]}/attachments/${icon}/raw`;
38-
}
3931
const versions = app_version_types.split(',');
4032
return (
4133
<div
@@ -48,7 +40,7 @@ export default class AppCard extends Component {
4840
<Image
4941
className={styles.icon}
5042
iconLetter={name}
51-
src={imgStr}
43+
src={icon}
5244
iconSize={48}
5345
alt="logo"
5446
/>

src/pages/Dashboard/Apps/MyApps/index.jsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default class Apps extends Component {
8989
}
9090

9191
render() {
92-
const { t, appStore, rootStore } = this.props;
92+
const { t, appStore } = this.props;
9393
const { apps, searchWord } = appStore;
9494

9595
const { pageLoading } = this.state;
@@ -102,14 +102,7 @@ export default class Apps extends Component {
102102
<Loading className={styles.page} isLoading={pageLoading}>
103103
{this.renderHeader()}
104104
<div className={styles.cards}>
105-
{apps.map(item => (
106-
<Card
107-
apiServer={rootStore.apiServer}
108-
key={item.app_id}
109-
t={t}
110-
data={item}
111-
/>
112-
))}
105+
{apps.map(item => <Card key={item.app_id} t={t} data={item} />)}
113106
</div>
114107
{this.renderSearchEmpty()}
115108
</Loading>

0 commit comments

Comments
 (0)