Skip to content
This repository has been archived by the owner on Oct 22, 2020. It is now read-only.

Commit

Permalink
refactor(submission): move the uploadProgress subscription of elife-xpub
Browse files Browse the repository at this point in the history
re #312
  • Loading branch information
mihaildu committed Aug 17, 2018
1 parent 96132aa commit 4633086
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions server/xpub/entities/manuscript/resolvers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const config = require('config')
const User = require('../user')
const { pubsubs } = require('pubsweet-server/src/graphql/pubsubs')
const { pubsub, asyncIterators } = require('pubsweet-server/src/graphql/pubsub')
const mailer = require('@pubsweet/component-send-email')
const logger = require('@pubsweet/logger')
const request = require('request-promise-native')
Expand All @@ -11,7 +11,7 @@ const path = require('path')
const crypto = require('crypto')
const Joi = require('joi')

const ON_UPLOAD_PROGRESS = 'uploadProgress'
const { ON_UPLOAD_PROGRESS } = asyncIterators

const parseString = promisify(xml2js.parseString)
const randomBytes = promisify(crypto.randomBytes)
Expand Down Expand Up @@ -141,7 +141,9 @@ const resolvers = {
stream.on('data', chunk => {
uploadedSize += chunk.length
const uploadProgress = Math.floor(uploadedSize * 100 / fileSize)
pubsubs[context.user].publish(ON_UPLOAD_PROGRESS, { uploadProgress })
pubsub.publish(`${ON_UPLOAD_PROGRESS}.${context.user}`, {
uploadProgress,
})
})
const saveFilePromise = new Promise((resolve, reject) => {
saveFileStream.on('finish', () => resolve(true))
Expand Down Expand Up @@ -195,11 +197,6 @@ const resolvers = {
return manuscript
},
},
Subscription: {
uploadProgress: {
subscribe: (_, vars, context) => pubsubs[context.user].asyncIterator(ON_UPLOAD_PROGRESS),
},
},

Manuscript: {
async author(manuscript) {
Expand Down

0 comments on commit 4633086

Please sign in to comment.