mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 16:29:34 +00:00
Add content-type kind property
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
a8f909f4e3
commit
86312ecbaf
@ -66,20 +66,20 @@ module.exports = {
|
||||
|
||||
const contentTypeService = strapi.plugins['content-type-builder'].services.contenttypes;
|
||||
|
||||
const component = await contentTypeService.createContentType({
|
||||
const contentType = await contentTypeService.createContentType({
|
||||
contentType: body.contentType,
|
||||
components: body.components,
|
||||
});
|
||||
|
||||
if (_.isEmpty(strapi.api)) {
|
||||
await strapi.telemetry.send('didCreateFirstContentType');
|
||||
await strapi.telemetry.send('didCreateFirstContentType', { kind: contentType.kind });
|
||||
} else {
|
||||
await strapi.telemetry.send('didCreateContentType');
|
||||
await strapi.telemetry.send('didCreateContentType', { kind: contentType.kind });
|
||||
}
|
||||
|
||||
setImmediate(() => strapi.reload());
|
||||
|
||||
ctx.send({ data: { uid: component.uid } }, 201);
|
||||
ctx.send({ data: { uid: contentType.uid } }, 201);
|
||||
} catch (error) {
|
||||
strapi.log.error(error);
|
||||
await strapi.telemetry.send('didNotCreateContentType', { error: error.message });
|
||||
|
@ -41,7 +41,7 @@ const createComponent = async ({ component, components = [] }) => {
|
||||
const uidMap = builder.createNewComponentUIDMap(components);
|
||||
const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);
|
||||
|
||||
const newComponent = builder.createComponent(replaceTmpUIDs(component));
|
||||
const newComponent = await builder.createComponent(replaceTmpUIDs(component));
|
||||
|
||||
components.forEach(component => {
|
||||
if (!_.has(component, 'uid')) {
|
||||
|
@ -30,7 +30,7 @@ module.exports = function createComponentBuilder() {
|
||||
/**
|
||||
* create a component in the tmpComponent map
|
||||
*/
|
||||
async createComponent(infos) {
|
||||
createComponent(infos) {
|
||||
const uid = this.createComponentUID(infos);
|
||||
|
||||
if (this.components.has(uid)) {
|
||||
|
@ -43,6 +43,10 @@ module.exports = function createSchemaHandler(infos) {
|
||||
return initialState.category;
|
||||
},
|
||||
|
||||
get kind() {
|
||||
return _.get(state.schema, 'kind', 'collectionType');
|
||||
},
|
||||
|
||||
get uid() {
|
||||
return state.uid;
|
||||
},
|
||||
@ -162,9 +166,7 @@ module.exports = function createSchemaHandler(infos) {
|
||||
Array.isArray(attr.components) &&
|
||||
attr.components.includes(uid)
|
||||
) {
|
||||
const updatedComponentList = attributes[key].components.filter(
|
||||
val => val !== uid
|
||||
);
|
||||
const updatedComponentList = attributes[key].components.filter(val => val !== uid);
|
||||
this.set(['attributes', key, 'components'], updatedComponentList);
|
||||
}
|
||||
});
|
||||
@ -187,9 +189,7 @@ module.exports = function createSchemaHandler(infos) {
|
||||
Array.isArray(attr.components) &&
|
||||
attr.components.includes(uid)
|
||||
) {
|
||||
const updatedComponentList = attr.components.map(val =>
|
||||
val === uid ? newUID : val
|
||||
);
|
||||
const updatedComponentList = attr.components.map(val => (val === uid ? newUID : val));
|
||||
|
||||
this.set(['attributes', key, 'components'], updatedComponentList);
|
||||
}
|
||||
|
@ -11,18 +11,8 @@ const fetch = require('node-fetch');
|
||||
const ciEnv = require('ci-info');
|
||||
const { scheduleJob } = require('node-schedule');
|
||||
|
||||
const isTruthyEnvVar = val => {
|
||||
if (val === null || val === undefined) return false;
|
||||
|
||||
if (val === true) return true;
|
||||
|
||||
if (val.toString().toLowerCase() === 'true') return true;
|
||||
if (val.toString().toLowerCase() === 'false') return false;
|
||||
|
||||
if (val === 1) return true;
|
||||
|
||||
return false;
|
||||
};
|
||||
const createMiddleware = require('./middleware');
|
||||
const isTruthyEnvVar = require('./truthy-var');
|
||||
|
||||
const createTelemetryInstance = strapi => {
|
||||
const uuid = strapi.config.uuid;
|
||||
@ -68,52 +58,18 @@ const createTelemetryInstance = strapi => {
|
||||
}
|
||||
};
|
||||
|
||||
const _state = {
|
||||
currentDay: null,
|
||||
counter: 0,
|
||||
};
|
||||
|
||||
return {
|
||||
initPing() {
|
||||
const initPing = () => {
|
||||
if (isDisabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
scheduleJob('0 0 12 * * *', () => sendEvent('ping'));
|
||||
},
|
||||
middleware: async (ctx, next) => {
|
||||
if (isDisabled) {
|
||||
return next();
|
||||
}
|
||||
};
|
||||
|
||||
const { url, method } = ctx.request;
|
||||
|
||||
if (!url.includes('.') && ['GET', 'PUT', 'POST', 'DELETE'].includes(method)) {
|
||||
const dayOfMonth = new Date().getDate();
|
||||
|
||||
if (dayOfMonth !== _state.currentDay) {
|
||||
_state.currentDay = dayOfMonth;
|
||||
_state.counter = 0;
|
||||
}
|
||||
|
||||
// Send max. 1000 events per day.
|
||||
if (_state.counter < 1000) {
|
||||
await sendEvent('didReceiveRequest', { url: ctx.request.url });
|
||||
|
||||
// Increase counter.
|
||||
_state.counter++;
|
||||
}
|
||||
}
|
||||
|
||||
await next();
|
||||
},
|
||||
async send(event, properties) {
|
||||
if (isDisabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
await sendEvent(event, properties);
|
||||
},
|
||||
return {
|
||||
initPing,
|
||||
send: sendEvent,
|
||||
middleware: createMiddleware({ sendEvent, isDisabled }),
|
||||
};
|
||||
};
|
||||
|
||||
|
37
packages/strapi-telemetry/lib/middleware.js
Normal file
37
packages/strapi-telemetry/lib/middleware.js
Normal file
@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
|
||||
const createMiddleware = ({ sendEvent, isDisabled }) => {
|
||||
const _state = {
|
||||
currentDay: null,
|
||||
counter: 0,
|
||||
};
|
||||
|
||||
return async (ctx, next) => {
|
||||
if (isDisabled) {
|
||||
return next();
|
||||
}
|
||||
|
||||
const { url, method } = ctx.request;
|
||||
|
||||
if (!url.includes('.') && ['GET', 'PUT', 'POST', 'DELETE'].includes(method)) {
|
||||
const dayOfMonth = new Date().getDate();
|
||||
|
||||
if (dayOfMonth !== _state.currentDay) {
|
||||
_state.currentDay = dayOfMonth;
|
||||
_state.counter = 0;
|
||||
}
|
||||
|
||||
// Send max. 1000 events per day.
|
||||
if (_state.counter < 1000) {
|
||||
await sendEvent('didReceiveRequest', { url: ctx.request.url });
|
||||
|
||||
// Increase counter.
|
||||
_state.counter++;
|
||||
}
|
||||
}
|
||||
|
||||
await next();
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = createMiddleware;
|
16
packages/strapi-telemetry/lib/truthy-var.js
Normal file
16
packages/strapi-telemetry/lib/truthy-var.js
Normal file
@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
const isTruthyEnvVar = val => {
|
||||
if (val === null || val === undefined) return false;
|
||||
|
||||
if (val === true) return true;
|
||||
|
||||
if (val.toString().toLowerCase() === 'true') return true;
|
||||
if (val.toString().toLowerCase() === 'false') return false;
|
||||
|
||||
if (val === 1) return true;
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
module.exports = isTruthyEnvVar;
|
Loading…
x
Reference in New Issue
Block a user