Skip to content

Commit

Permalink
fix: Attachment image not display when forward request (#568)
Browse files Browse the repository at this point in the history
  • Loading branch information
liiil825 authored and sunnywx committed Dec 6, 2018
1 parent 3c14060 commit 7756e55
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
8 changes: 8 additions & 0 deletions server/routes/page.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
const Router = require('koa-router');
const agent = require('lib/request').default;
const auth = require('../middleware/auth');
const gzip = require('../middleware/gzip');

const router = new Router();

router.get('/attachments/:id', async ctx => {
const { apiServer } = ctx.store;
const apiUrl = `${apiServer.split('/v')[0]}/attachments/${ctx.params.id}/raw`;

ctx.body = await agent.send('get', apiUrl);
});

router.get('/:page(/?.*)', auth, gzip, async (ctx, next) => {
try {
await next();
Expand Down
9 changes: 6 additions & 3 deletions src/components/Base/Image/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';

import { startsWith } from 'lodash';

import styles from './index.scss';

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

if (failed) {
const style = {
Expand All @@ -73,7 +76,7 @@ export default class Image extends React.Component {
return (
<img
src="/none.svg"
data-origin-url={src}
data-origin-url={imgStr}
style={style}
className={classnames(styles.img, className)}
{...rest}
Expand All @@ -83,8 +86,8 @@ export default class Image extends React.Component {

return (
<img
src={src}
data-origin-url={src}
src={imgStr}
data-origin-url={imgStr}
className={classnames(styles.img, className)}
ref={c => {
this.img = c;
Expand Down
12 changes: 2 additions & 10 deletions src/pages/Dashboard/Apps/Card/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { withRouter } from 'react-router';
import _ from 'lodash';

import Status from 'components/Status';
import { Image } from 'components/Base';
Expand All @@ -13,16 +12,13 @@ import styles from './index.scss';
@withRouter
export default class AppCard extends Component {
static propTypes = {
apiServer: PropTypes.string,
children: PropTypes.node,
className: PropTypes.string,
data: PropTypes.object
};

render() {
const {
apiServer, className, data, t
} = this.props;
const { className, data, t } = this.props;
const {
app_id,
icon,
Expand All @@ -32,10 +28,6 @@ export default class AppCard extends Component {
status_time,
app_version_types
} = data;
let imgStr = icon;
if (icon && _.startsWith(icon, 'att-')) {
imgStr = `${apiServer.split('/v')[0]}/attachments/${icon}/raw`;
}
const versions = app_version_types.split(',');
return (
<div
Expand All @@ -48,7 +40,7 @@ export default class AppCard extends Component {
<Image
className={styles.icon}
iconLetter={name}
src={imgStr}
src={icon}
iconSize={48}
alt="logo"
/>
Expand Down
11 changes: 2 additions & 9 deletions src/pages/Dashboard/Apps/MyApps/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default class Apps extends Component {
}

render() {
const { t, appStore, rootStore } = this.props;
const { t, appStore } = this.props;
const { apps, searchWord } = appStore;

const { pageLoading } = this.state;
Expand All @@ -102,14 +102,7 @@ export default class Apps extends Component {
<Loading className={styles.page} isLoading={pageLoading}>
{this.renderHeader()}
<div className={styles.cards}>
{apps.map(item => (
<Card
apiServer={rootStore.apiServer}
key={item.app_id}
t={t}
data={item}
/>
))}
{apps.map(item => <Card key={item.app_id} t={t} data={item} />)}
</div>
{this.renderSearchEmpty()}
</Loading>
Expand Down

0 comments on commit 7756e55

Please sign in to comment.