Skip to content

Commit b07b32c

Browse files
fix: cappasity - allow to upload files of types other than cappasity … (#41)
* fix: cappasity - allow to upload files of types other than cappasity models * add separate typemap for cappasity
1 parent e08c17c commit b07b32c

4 files changed

Lines changed: 30 additions & 16 deletions

File tree

src/constant.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,10 @@ exports.FIELDS_TO_STRINGIFY = [
5757
exports.FILES_CONTROLS_FIELD,
5858
exports.FILES_BACKGROUND_IMAGE_FIELD,
5959
];
60+
61+
exports.CAPPASITY_TYPE_MAP = {
62+
'c-preview': 'preview',
63+
'c-bin': 'model',
64+
'c-texture': 'texture',
65+
'c-archive': 'archive',
66+
};

src/custom/cappasity-process-pre.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
const Promise = require('bluebird');
2-
const { FILES_OWNER_FIELD } = require('../constant.js');
2+
const { FILES_OWNER_FIELD, CAPPASITY_TYPE_MAP } = require('../constant.js');
33
const { HttpStatusError } = require('common-errors');
44

5-
const TYPE_MAP = {
6-
'c-preview': 'preview',
7-
'c-bin': 'model',
8-
'c-texture': 'texture',
9-
'c-archive': 'archive',
10-
};
11-
125
function parseMeta(data) {
136
const parsedFiles = typeof data.files === 'string' ? JSON.parse(data.files) : data.files;
147
const output = {};
158

169
let textures = 0;
1710
parsedFiles.forEach(({ type, filename }) => {
18-
const responsibility = TYPE_MAP[type];
11+
const responsibility = CAPPASITY_TYPE_MAP[type];
1912
if (responsibility === 'texture') {
2013
output[`texture_${textures}`] = filename;
2114
textures += 1;

src/custom/cappasity-upload-pre.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const Errors = require('common-errors');
22
const Promise = require('bluebird');
33
const assert = require('assert');
4+
const isCappasityUpload = require('../utils/isCappasityUpload');
45

56
module.exports = function extractMetadata({ files, meta, temp }) {
67
let sourceSHA;
@@ -26,13 +27,15 @@ module.exports = function extractMetadata({ files, meta, temp }) {
2627
}
2728
});
2829

29-
// assert constraints
30-
if (differentFileTypes === 1) {
31-
assert.equal(fileTypes['c-preview'], 1, 'must contain exactly one preview');
32-
} else {
33-
// must always be true if it's not a simple preview upload
34-
assert.equal(fileTypes['c-bin'], 1, 'must contain exactly one binary upload');
35-
meta.sourceSHA = sourceSHA;
30+
if (isCappasityUpload(Object.keys(fileTypes))) {
31+
// assert constraints
32+
if (differentFileTypes === 1) {
33+
assert.equal(fileTypes['c-preview'], 1, 'must contain exactly one preview');
34+
} else {
35+
// must always be true if it's not a simple preview upload
36+
assert.equal(fileTypes['c-bin'], 1, 'must contain exactly one binary upload');
37+
meta.sourceSHA = sourceSHA;
38+
}
3639
}
3740

3841
if (meta.export && !temp) {

src/utils/isCappasityUpload.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const intersectionBy = require('lodash/intersectionBy');
2+
const lowerCase = require('lodash/lowerCase');
3+
const { CAPPASITY_TYPE_MAP } = require('../constant');
4+
5+
const CAPPASITY_FILES = Object.keys(CAPPASITY_TYPE_MAP);
6+
7+
module.exports = function isCappasityUpload(types) {
8+
const cappasityFiles = intersectionBy(types, CAPPASITY_FILES, lowerCase);
9+
10+
return cappasityFiles.length > 0;
11+
};

0 commit comments

Comments
 (0)