mirror of
https://github.com/strapi/strapi.git
synced 2025-07-25 18:05:07 +00:00
Remove functions from model attributes
This commit is contained in:
parent
3557a00940
commit
c42e3eff8b
@ -62,192 +62,193 @@ module.exports = function (strapi) {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
process.nextTick(function () {
|
manager.on('connect_failed', function () {
|
||||||
manager.on('connect_failed', function () {
|
if (firstConnectionAttempt) {
|
||||||
if (firstConnectionAttempt) {
|
strapi.log.warn('Connection to the Studio server failed!');
|
||||||
strapi.log.warn('Connection to the Studio server failed!');
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
manager.on('reconnect_failed', function () {
|
||||||
|
strapi.log.warn('Reconnection to the Studio server failed!');
|
||||||
|
});
|
||||||
|
|
||||||
|
manager.on('reconnect', function () {
|
||||||
|
strapi.log.info('Connection to the Studio server found, please wait a few seconds...');
|
||||||
|
});
|
||||||
|
|
||||||
|
manager.on('reconnecting', function (number) {
|
||||||
|
strapi.log.warn('Connection error with the Studio server, new attempt in progress... (' + number + ')');
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('connect', function () {
|
||||||
|
firstConnectionAttempt = false;
|
||||||
|
|
||||||
|
strapi.once('bootstrap:done', function () {
|
||||||
|
_self.connectWithStudio(socket);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('error', function (err) {
|
||||||
|
strapi.log.warn(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('disconnect', function () {
|
||||||
|
strapi.log.info('Disconnected from the Studio server.');
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('authorized', function (data) {
|
||||||
|
const decryptedData = strapi.rsa.decryptPublic(data, 'json');
|
||||||
|
|
||||||
|
if (decryptedData.status === 'ok') {
|
||||||
|
if (strapi.config.environment === 'development') {
|
||||||
|
socket.emit('testEncryption', {
|
||||||
|
appId: strapi.config.studio.appId,
|
||||||
|
token: strapi.token,
|
||||||
|
encrypted: strapi.rsa.encrypt({
|
||||||
|
secretKey: strapi.config.studio.secretKey,
|
||||||
|
data: 'ok'
|
||||||
|
})
|
||||||
|
}, function (err) {
|
||||||
|
if (err) {
|
||||||
|
strapi.log.warn(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
strapi.log.info('Connected with the Studio server.');
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
strapi.log.warn('The use of the Studio is restricted to development environment.');
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
manager.on('reconnect_failed', function () {
|
socket.on('todo', function (data, fn) {
|
||||||
strapi.log.warn('Reconnection to the Studio server failed!');
|
if (!data.hasOwnProperty('from') || !data.hasOwnProperty('to')) {
|
||||||
});
|
fn(stringify('Some required attributes are missing', null, 2), null);
|
||||||
|
} else if (data.from === strapi.token) {
|
||||||
|
if (data.hasOwnProperty('files')) {
|
||||||
|
const syncPromise = function (file, index) {
|
||||||
|
const deferred = Promise.defer();
|
||||||
|
|
||||||
manager.on('reconnect', function () {
|
_self.unzipper(file)
|
||||||
strapi.log.info('Connection to the Studio server found, please wait a few seconds...');
|
|
||||||
});
|
|
||||||
|
|
||||||
manager.on('reconnecting', function (number) {
|
|
||||||
strapi.log.warn('Connection error with the Studio server, new attempt in progress... (' + number + ')');
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('connect', function () {
|
|
||||||
firstConnectionAttempt = false;
|
|
||||||
|
|
||||||
strapi.once('bootstrap:done', function () {
|
|
||||||
_self.connectWithStudio(socket);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('error', function (err) {
|
|
||||||
strapi.log.warn(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('disconnect', function () {
|
|
||||||
strapi.log.info('Disconnected from the Studio server.');
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('authorized', function (data) {
|
|
||||||
const decryptedData = strapi.rsa.decryptPublic(data, 'json');
|
|
||||||
|
|
||||||
if (decryptedData.status === 'ok') {
|
|
||||||
if (strapi.config.environment === 'development') {
|
|
||||||
socket.emit('testEncryption', {
|
|
||||||
appId: strapi.config.studio.appId,
|
|
||||||
token: strapi.token,
|
|
||||||
encrypted: strapi.rsa.encrypt({
|
|
||||||
secretKey: strapi.config.studio.secretKey,
|
|
||||||
data: 'ok'
|
|
||||||
})
|
|
||||||
}, function (err) {
|
|
||||||
if (err) {
|
|
||||||
strapi.log.warn(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
strapi.log.info('Connected with the Studio server.');
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
strapi.log.warn('The use of the Studio is restricted to development environment.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('todo', function (data, fn) {
|
|
||||||
if (!data.hasOwnProperty('from') || !data.hasOwnProperty('to')) {
|
|
||||||
fn(stringify('Some required attributes are missing', null, 2), null);
|
|
||||||
} else if (data.from === strapi.token) {
|
|
||||||
if (data.hasOwnProperty('files')) {
|
|
||||||
const syncPromise = function (file, index) {
|
|
||||||
const deferred = Promise.defer();
|
|
||||||
|
|
||||||
_self.unzipper(file)
|
|
||||||
.then(function () {
|
|
||||||
if (!_.isEmpty(data.files[index + 1])) {
|
|
||||||
return syncPromise(data.files[index + 1], index + 1);
|
|
||||||
} else {
|
|
||||||
deferred.resolve();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(function () {
|
|
||||||
deferred.resolve();
|
|
||||||
})
|
|
||||||
.catch(function (err) {
|
|
||||||
deferred.reject(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
return deferred.promise;
|
|
||||||
};
|
|
||||||
|
|
||||||
syncPromise(_.first(data.files), 0)
|
|
||||||
.then(function () {
|
.then(function () {
|
||||||
if (data.hasOwnProperty('action') && _.isFunction(_self[data.action])) {
|
if (!_.isEmpty(data.files[index + 1])) {
|
||||||
_self[data.action](data, function (err, obj) {
|
return syncPromise(data.files[index + 1], index + 1);
|
||||||
if (err) {
|
} else {
|
||||||
fn({
|
deferred.resolve();
|
||||||
appId: strapi.config.studio.appId,
|
}
|
||||||
token: strapi.token,
|
})
|
||||||
encrypted: strapi.rsa.encrypt({
|
.then(function () {
|
||||||
err: stringify(err, null, 2),
|
deferred.resolve();
|
||||||
data: null
|
})
|
||||||
})
|
.catch(function (err) {
|
||||||
});
|
deferred.reject(err);
|
||||||
|
});
|
||||||
|
|
||||||
return false;
|
return deferred.promise;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
syncPromise(_.first(data.files), 0)
|
||||||
|
.then(function () {
|
||||||
|
if (data.hasOwnProperty('action') && _.isFunction(_self[data.action])) {
|
||||||
|
_self[data.action](data, function (err, obj) {
|
||||||
|
|
||||||
|
if (err) {
|
||||||
fn({
|
fn({
|
||||||
appId: strapi.config.studio.appId,
|
appId: strapi.config.studio.appId,
|
||||||
token: strapi.token,
|
token: strapi.token,
|
||||||
encrypted: strapi.rsa.encrypt({
|
encrypted: strapi.rsa.encrypt({
|
||||||
err: null,
|
err: stringify(err, null, 2),
|
||||||
data: stringify(obj, null, 2)
|
data: null
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
|
||||||
} else if (!data.hasOwnProperty('action')) {
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
fn({
|
fn({
|
||||||
appId: strapi.config.studio.appId,
|
appId: strapi.config.studio.appId,
|
||||||
token: strapi.token,
|
token: strapi.token,
|
||||||
encrypted: strapi.rsa.encrypt({
|
encrypted: strapi.rsa.encrypt({
|
||||||
err: null,
|
err: null,
|
||||||
data: stringify(true, null, 2)
|
data: stringify(obj, null, 2)
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
} else {
|
});
|
||||||
fn({
|
} else if (!data.hasOwnProperty('action')) {
|
||||||
appId: strapi.config.studio.appId,
|
|
||||||
token: strapi.token,
|
|
||||||
encrypted: strapi.rsa.encrypt({
|
|
||||||
err: stringify('Unknow action', null, 2),
|
|
||||||
data: null
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(function (err) {
|
|
||||||
fn({
|
fn({
|
||||||
appId: strapi.config.studio.appId,
|
appId: strapi.config.studio.appId,
|
||||||
token: strapi.token,
|
token: strapi.token,
|
||||||
encrypted: strapi.rsa.encrypt({
|
encrypted: strapi.rsa.encrypt({
|
||||||
err: err,
|
err: null,
|
||||||
data: null
|
data: stringify(true, null, 2)
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
} else {
|
||||||
} else if (!data.hasOwnProperty('action')) {
|
|
||||||
fn(strapi.rsa.encrypt(stringify('`action` attribute is missing', null, 2)), strapi.rsa.encryptPrivate(null));
|
|
||||||
} else if (_.isFunction(_self[data.action])) {
|
|
||||||
_self[data.action](data, function (err, obj) {
|
|
||||||
if (err) {
|
|
||||||
fn({
|
fn({
|
||||||
appId: strapi.config.studio.appId,
|
appId: strapi.config.studio.appId,
|
||||||
token: strapi.token,
|
token: strapi.token,
|
||||||
encrypted: strapi.rsa.encrypt({
|
encrypted: strapi.rsa.encrypt({
|
||||||
err: err,
|
err: stringify('Unknow action', null, 2),
|
||||||
data: null
|
data: null
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
fn({
|
fn({
|
||||||
appId: strapi.config.studio.appId,
|
appId: strapi.config.studio.appId,
|
||||||
token: strapi.token,
|
token: strapi.token,
|
||||||
encrypted: strapi.rsa.encrypt({
|
encrypted: strapi.rsa.encrypt({
|
||||||
err: null,
|
err: err,
|
||||||
data: stringify(obj, null, 2)
|
data: null
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else if (!data.hasOwnProperty('action')) {
|
||||||
|
fn(strapi.rsa.encrypt(stringify('`action` attribute is missing', null, 2)), strapi.rsa.encryptPrivate(null));
|
||||||
|
} else if (_.isFunction(_self[data.action])) {
|
||||||
|
_self[data.action](data, function (err, obj) {
|
||||||
|
if (err) {
|
||||||
|
fn({
|
||||||
|
appId: strapi.config.studio.appId,
|
||||||
|
token: strapi.token,
|
||||||
|
encrypted: strapi.rsa.encrypt({
|
||||||
|
err: err,
|
||||||
|
data: null
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn({
|
fn({
|
||||||
appId: strapi.config.studio.appId,
|
appId: strapi.config.studio.appId,
|
||||||
token: strapi.token,
|
token: strapi.token,
|
||||||
encrypted: strapi.rsa.encrypt({
|
encrypted: strapi.rsa.encrypt({
|
||||||
err: stringify('Unknow action', null, 2),
|
err: null,
|
||||||
data: null
|
data: stringify(obj, null, 2)
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
} else {
|
} else {
|
||||||
fn(stringify('Bad user token', null, 2), null);
|
fn({
|
||||||
|
appId: strapi.config.studio.appId,
|
||||||
|
token: strapi.token,
|
||||||
|
encrypted: strapi.rsa.encrypt({
|
||||||
|
err: stringify('Unknow action', null, 2),
|
||||||
|
data: null
|
||||||
|
})
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
fn(stringify('Bad user token', null, 2), null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
socket.on('err', function (data) {
|
socket.on('err', function (data) {
|
||||||
strapi.log.warn(data.text);
|
strapi.log.warn(data.text);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
cb();
|
cb();
|
||||||
@ -318,12 +319,23 @@ module.exports = function (strapi) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
pullServer: function (data, cb) {
|
pullServer: function (data, cb) {
|
||||||
const obj = {};
|
const obj = {
|
||||||
obj.token = strapi.token;
|
token: strapi.token,
|
||||||
obj.config = strapi.config;
|
config: strapi.config,
|
||||||
obj.models = strapi.models;
|
models: _.mapValues(_.cloneDeep(strapi.models), function (model) {
|
||||||
obj.api = strapi.api;
|
model.attributes = _.omit(model.attributes, _.isFunction);
|
||||||
obj.templates = {};
|
|
||||||
|
return model;
|
||||||
|
}),
|
||||||
|
api: _.mapValues(_.cloneDeep(strapi.api), function (api) {
|
||||||
|
return _.mapValues(api.models, function (model) {
|
||||||
|
model.attributes = _.omit(model.attributes, _.isFunction);
|
||||||
|
|
||||||
|
return model;
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
templates: {}
|
||||||
|
};
|
||||||
|
|
||||||
cb(null, obj);
|
cb(null, obj);
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user