Commit c7c109b2 authored by Yannis Barlas's avatar Yannis Barlas
Browse files

refactor(server): let server provide full image urls

parent 21112f34
......@@ -40,7 +40,7 @@ class DropArea extends React.Component {
const file = {
name: values.image.name,
preview: `/uploads/${values.image.url}`,
preview: values.image.url,
url: values.image.url,
}
......
const { transaction } = require('objection')
const clone = require('lodash/clone')
const config = require('config')
const {
CuratorReview,
......@@ -54,6 +55,20 @@ const manuscriptVersions = async (
return restructured
}
const manuscriptVersionImage = async (manuscriptVersion, args, ctx) => {
const { image } = manuscriptVersion
if (image && image.url) {
const serverUrl =
config.has('pubsweet-server.baseUrl') &&
config.get('pubsweet-server.baseUrl')
image.url = `${serverUrl}/uploads${image.url}`
}
return manuscriptVersion.image
}
const manuscriptVersionCuratorReviews = async (
parent,
{ currentUserOnly },
......@@ -207,6 +222,7 @@ const submitManuscript = async (_, { input }, ctx) => {
module.exports = {
manuscriptVersions,
manuscriptVersionCuratorReviews,
manuscriptVersionImage,
saveSubmissionForm,
setSOApproval,
submitDecision,
......
......@@ -25,6 +25,7 @@ const {
const {
manuscriptVersions,
manuscriptVersionCuratorReviews,
manuscriptVersionImage,
saveSubmissionForm,
setSOApproval,
submitDecision,
......@@ -139,6 +140,7 @@ const resolvers = {
},
ManuscriptVersion: {
curatorReviews: manuscriptVersionCuratorReviews,
image: manuscriptVersionImage,
reviews: manuscriptVersionReviews,
teams: teamsForObject,
},
......
......@@ -4,10 +4,11 @@ const fs = require('fs')
const path = require('path')
const { promisify } = require('util')
const JSZip = require('jszip')
const config = require('config')
const logger = require('@pubsweet/logger')
const { ManuscriptVersion } = require('@pubsweet/models')
const HTMLExport = require('./HTML')
const PrintExport = require('./print')
......@@ -104,6 +105,9 @@ const exportEndpoints = app => {
app.get('/api/export/:manuscriptVersionId/print', async (req, res) => {
const { manuscriptVersionId } = req.params
const serverUrl =
config.has('pubsweet-server.baseUrl') &&
config.get('pubsweet-server.baseUrl')
// Get manuscript version
let version
......@@ -116,7 +120,10 @@ const exportEndpoints = app => {
throw new Error(e)
}
const html = PrintExport(version, `/uploads${version.image.url}`)
const html = PrintExport(
version,
`${serverUrl}/uploads${version.image.url}`,
)
res.send(html)
})
}
......
......@@ -79,17 +79,8 @@ const Manuscript = props => {
hasEqualContributionAuthor: previousHasEqualContributionAuthor,
} = transformAuthorData(get(previousVersion, 'authors'))
const imageSource =
image &&
image.url &&
(image.url.match(/^static/) ? image.url : `/uploads/${image.url}`)
const previousImageSource =
previousImage &&
previousImage.url &&
(previousImage.url.match(/^static/)
? previousImage.url
: `/uploads/${previousImage.url}`)
const imageSource = image && image.url
const previousImageSource = previousImage && previousImage.url
const equalContributionValue = hasEqualContributionAuthor
? '<sup>*</sup>These authors contributed equally'
......
......@@ -93,9 +93,12 @@ module.exports = {
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"development"',
}),
new webpack.EnvironmentPlugin([
'NODE_ENV',
'SERVER_PROTOCOL',
'SERVER_HOST',
'SERVER_PORT',
]),
new HtmlWebpackPlugin({
title: 'microPublication',
template: '../app/index.ejs', // Load a custom template
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment