Simplify web service entity

This commit is contained in:
Romein van Buren 2022-07-13 11:27:21 +02:00
parent 4f65212152
commit 58dec27b0e
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49

View File

@ -4,8 +4,8 @@ const { makeId } = require('core/makeid');
const states = { const states = {
concept: 'concept', concept: 'concept',
online: 'online', enabled: 'enabled',
offline: 'offline', disabled: 'disabled',
}; };
module.exports = { module.exports = {
@ -18,7 +18,7 @@ module.exports = {
forms: ({ settings }) => ({ forms: ({ settings }) => ({
default: { default: {
pages: [ pages: [
{ label: 'meta', { label: 'about',
sections: [ sections: [
'id', 'id',
'name', 'name',
@ -27,25 +27,18 @@ module.exports = {
'cluster', 'cluster',
'tags', 'tags',
'channels', 'channels',
],
},
{ label: 'description',
sections: [
'summary', 'summary',
'visual',
'body',
], ],
}, },
{ label: 'auto testing', { label: 'auto testing',
sections: [ sections: [
'autotestEnabled',
'autotestInterval', 'autotestInterval',
'lastChecked',
'autotest', 'autotest',
], ],
}, },
{ label: 'statistics', { label: 'statistics',
sections: [ sections: [
'lastChecked',
'outageStats', 'outageStats',
'outageTable', 'outageTable',
], ],
@ -87,7 +80,7 @@ module.exports = {
}, },
public: { public: {
label: 'is public?', label: 'publish?',
hint: 'If checked, this service will be shown on the status dashboard.', hint: 'If checked, this service will be shown on the status dashboard.',
fields: [ fields: [
{ key: 'public', { key: 'public',
@ -134,6 +127,7 @@ module.exports = {
summary: { summary: {
label: 'summary', label: 'summary',
hint: 'A short summary of what this web service is about.',
fields: [ fields: [
{ key: 'summary', { key: 'summary',
editor: 'text', editor: 'text',
@ -142,28 +136,6 @@ module.exports = {
], ],
}, },
body: {
label: 'body',
fields: [
{ key: 'body',
editor: 'text',
type: 'string',
localized: true,
markup: true,
},
],
},
visual: {
label: 'visual',
fields: [
{ key: 'visual',
editor: 'file',
accept: [ 'image/*' ],
},
],
},
lastChecked: { lastChecked: {
label: 'status last checked on', label: 'status last checked on',
fields: [ fields: [
@ -213,15 +185,6 @@ module.exports = {
], ],
}, },
autotestEnabled: {
label: 'autotesting enabled?',
fields: [
{ key: 'autotestEnabled',
editor: 'checkbox',
},
],
},
autotest: { autotest: {
label: 'endpoint requirements', label: 'endpoint requirements',
fields: [ fields: [
@ -381,60 +344,10 @@ module.exports = {
default: '', default: '',
}, },
body: {
type: 'stringset',
default: '',
filter: {
title: 'message contains',
match: '[a-z0-9A-Z]*',
localized: true,
},
},
autotest: { autotest: {
default: [], default: [],
}, },
visual: {
type: 'array',
of: [ 'string' ],
default: [],
skip: true,
onDataValid: async ({ newValues, storage, user }) => {
newValues.visual = newValues.visual || [];
for (let i = 0; i < newValues.visual.length; i++) {
if (newValues.visual[i].data) {
if (storage) {
// If storage is available, insert the new file into storage and collect id
const result = await storage({ user }).bucket('webdesq/media').insert({
id: makeId(6),
filename: newValues.visual[i].name,
metadata: {
contentType: newValues.visual[i].type,
},
}, newValues.visual[i].data)
.catch(error => {
if (error.code !== 'DUPLICATE_FILE') {
throw error;
}
newValues.visual[i] = error.file.id;
});
if (result) {
newValues.visual[i] = result.id;
}
}
else {
// If no storage is available, remove slot by setting it to null
newValues.visual[i] = null;
}
}
// remove empty slots in photo array
newValues.visual = newValues.visual.filter(i => i != null);
newValues.visual = [ ...new Set(newValues.visual) ];
}
},
},
outages: { outages: {
type: 'computed', type: 'computed',
default: 0, default: 0,