diff --git a/src/custom/cappasity-postprocess.js b/src/custom/cappasity-postprocess.js index 74a5da39..25abd88d 100644 --- a/src/custom/cappasity-postprocess.js +++ b/src/custom/cappasity-postprocess.js @@ -1,6 +1,4 @@ const Promise = require('bluebird'); -const Errors = require('common-errors'); -const { FILES_PROCESS_ERROR_FIELD, FILES_DATA } = require('../constant.js'); const TYPE_MAP = { 'c-preview': 'preview', @@ -10,59 +8,20 @@ const TYPE_MAP = { }; module.exports = function extractMetadata(data) { - const { amqp, config, redis } = this; - const { users: { audience, getMetadata, updateMetadata } } = config; - const username = data.owner; - - return amqp - .publishAndWait(getMetadata, { username, audience }) - .get(audience) - .then(metadata => { - if (metadata.roles && metadata.roles.indexOf('admin') >= 0) { - return null; + return Promise.try(function parseMeta() { + const files = JSON.parse(data.files); + const output = {}; + + let textures = 0; + files.forEach(({ type, filename }) => { + const responsibility = TYPE_MAP[type]; + if (responsibility === 'texture') { + output[`texture_${textures++}`] = filename; + } else { + output[responsibility] = filename; } + }); - const message = { - username, - audience, - metadata: { - $incr: { - models: -1, - }, - }, - }; - - return amqp - .publishAndWait(updateMetadata, message, { timeout: 5000 }) - .then(result => { - if (result.$incr.models >= 0) { - return null; - } - - // revert back - message.metadata.$incr.models = 1; - - // publish - return amqp - .publish(updateMetadata, message) - .then(() => redis.hset(`${FILES_DATA}:${data.uploadId}`, FILES_PROCESS_ERROR_FIELD, '402')) - .throw(new Errors.HttpStatusError(402, 'no more models are available')); - }); - }) - .then(() => Promise.try(function parseMeta() { - const files = JSON.parse(data.files); - const output = {}; - - let textures = 0; - files.forEach(({ type, filename }) => { - const responsibility = TYPE_MAP[type]; - if (responsibility === 'texture') { - output[`texture_${textures++}`] = filename; - } else { - output[responsibility] = filename; - } - }); - - return output; - })); + return output; + }); }; diff --git a/src/custom/cappasity-upload-pre.js b/src/custom/cappasity-upload-pre.js index d8a650e2..659fe5c4 100644 --- a/src/custom/cappasity-upload-pre.js +++ b/src/custom/cappasity-upload-pre.js @@ -1,11 +1,7 @@ const Promise = require('bluebird'); -const Errors = require('common-errors'); const assert = require('assert'); -module.exports = function extractMetadata(files, username) { - const { amqp, config } = this; - const { users: { audience, getMetadata } } = config; - +module.exports = function extractMetadata(files) { return Promise .try(function verifyUploadData() { const fileTypes = {}; @@ -15,15 +11,8 @@ module.exports = function extractMetadata(files, username) { assert.equal(fileTypes['c-bin'], 1, 'must contain exactly one binary upload'); assert.equal(fileTypes['c-preview'], 1, 'must contain preview'); - assert.equal(fileTypes['c-archive'], 1, 'must contain prepared archive'); + assert.ok(fileTypes['c-archive'] <= 1, 'must contain not more than 1 prepared archive'); assert.ok(fileTypes['c-texture'] >= 1, 'must contain at least one texture'); }) - .then(() => amqp.publishAndWait(getMetadata, { username, audience })) - .get(audience) - .then(({ models = 0, roles = [] }) => { - if (models <= 0 && roles.indexOf('admin') === -1) { - throw new Errors.HttpStatusError(402, 'no more models are available'); - } - }) .return(files); };