feat: add container page api
This commit is contained in:
parent
99f6f58f52
commit
0571863839
@ -45,6 +45,7 @@
|
||||
"sequelize": "^6.37.3",
|
||||
"socket.io": "^4.7.5",
|
||||
"strip-ansi": "^7.1.0",
|
||||
"uuid": "^10.0.0",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
110
pnpm-lock.yaml
generated
110
pnpm-lock.yaml
generated
@ -26,9 +26,6 @@ importers:
|
||||
dayjs:
|
||||
specifier: ^1.11.13
|
||||
version: 1.11.13
|
||||
dts-bundle:
|
||||
specifier: ^0.7.3
|
||||
version: 0.7.3
|
||||
dts-bundle-generator:
|
||||
specifier: ^9.5.1
|
||||
version: 9.5.1
|
||||
@ -56,6 +53,9 @@ importers:
|
||||
strip-ansi:
|
||||
specifier: ^7.1.0
|
||||
version: 7.1.0
|
||||
uuid:
|
||||
specifier: ^10.0.0
|
||||
version: 10.0.0
|
||||
zod:
|
||||
specifier: ^3.23.8
|
||||
version: 3.23.8
|
||||
@ -63,9 +63,6 @@ importers:
|
||||
'@types/crypto-js':
|
||||
specifier: ^4.2.2
|
||||
version: 4.2.2
|
||||
'@types/dts-bundle':
|
||||
specifier: ^0.0.35
|
||||
version: 0.0.35
|
||||
'@types/jest':
|
||||
specifier: ^29.5.13
|
||||
version: 29.5.13
|
||||
@ -919,18 +916,9 @@ packages:
|
||||
'@types/debug@4.1.12':
|
||||
resolution: {integrity: sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ==}
|
||||
|
||||
'@types/detect-indent@0.1.30':
|
||||
resolution: {integrity: sha512-AUmj9JHuHTD94slY1WR1VulFxRGC6D1pcNCN0MCulKFyiihvV/28lLS8oRHgfmc2Cxq954J8Vmosa8qzm7PLGQ==}
|
||||
|
||||
'@types/dts-bundle@0.0.35':
|
||||
resolution: {integrity: sha512-TZCP4CIDR3R3K2ij5UqXzKfkiAcnVBSUudPOq0zUk42hl8PirN/4q0dPiidBP3s7hZJuB7OQULxR3I2ZQsnLig==}
|
||||
|
||||
'@types/estree@1.0.5':
|
||||
resolution: {integrity: sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==}
|
||||
|
||||
'@types/glob@5.0.30':
|
||||
resolution: {integrity: sha512-ZM05wDByI+WA153sfirJyEHoYYoIuZ7lA2dB/Gl8ymmpMTR78fNRtDMqa7Z6SdH4fZdLWZNRE6mZpx3XqBOrHw==}
|
||||
|
||||
'@types/graceful-fs@4.1.9':
|
||||
resolution: {integrity: sha512-olP3sd1qOEe5dXTSaFvQG+02VdRXcdytWLAZsAq1PecU8uqQAhkrnbli7DagjtXKW/Bl7YJbUsa8MPcuc8LHEQ==}
|
||||
|
||||
@ -961,21 +949,12 @@ packages:
|
||||
'@types/methods@1.1.4':
|
||||
resolution: {integrity: sha512-ymXWVrDiCxTBE3+RIrrP533E70eA+9qu7zdWoHuOmGujkYtzf4HQF96b8nwHLqhuf4ykX61IGRIB38CC6/sImQ==}
|
||||
|
||||
'@types/minimatch@5.1.2':
|
||||
resolution: {integrity: sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==}
|
||||
|
||||
'@types/mkdirp@0.3.29':
|
||||
resolution: {integrity: sha512-QRLQpFsIQGO2k8pupga9abfei85GKotAtQ+F6xuQmSGomUt6C52TyMiTFpP8kUwuPKr00gNtu3itLlC6gvI/NA==}
|
||||
|
||||
'@types/ms@0.7.34':
|
||||
resolution: {integrity: sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==}
|
||||
|
||||
'@types/node@22.5.5':
|
||||
resolution: {integrity: sha512-Xjs4y5UPO/CLdzpgR6GirZJx36yScjh73+2NlLlkFRSoQN8B0DpfXPdZGnvVmLRLOsqDpOfTNv7D9trgGhmOIA==}
|
||||
|
||||
'@types/node@8.0.0':
|
||||
resolution: {integrity: sha512-j2tekvJCO7j22cs+LO6i0kRPhmQ9MXaPZ55TzOc1lzkN5b6BWqq4AFjl04s1oRRQ1v5rSe+KEvnLUSTonuls/A==}
|
||||
|
||||
'@types/stack-utils@2.0.3':
|
||||
resolution: {integrity: sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==}
|
||||
|
||||
@ -1420,11 +1399,6 @@ packages:
|
||||
resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==}
|
||||
engines: {node: '>=0.4.0'}
|
||||
|
||||
detect-indent@0.2.0:
|
||||
resolution: {integrity: sha512-C6jyrDu/eGH4KT0ZxAzijiH+ts5YLy7DqGFoDuHGxZjMOdjzRltp3jByySnpFBVIy4Em0ZkLN8tIV6mcREdw5A==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
hasBin: true
|
||||
|
||||
detect-newline@3.1.0:
|
||||
resolution: {integrity: sha512-TLz+x/vEXm/Y7P7wn1EJFNLxYpUD4TgMosxY6fAVJUnJMbupHBOncxyWUG9OpTaH9EBD7uFI5LfEgmMOc54DsA==}
|
||||
engines: {node: '>=8'}
|
||||
@ -1448,11 +1422,6 @@ packages:
|
||||
engines: {node: '>=14.0.0'}
|
||||
hasBin: true
|
||||
|
||||
dts-bundle@0.7.3:
|
||||
resolution: {integrity: sha512-EEAEuPRk8QyKhoN90NHTh+spSQujkkvOnKWUfuzpmC/fgryiWopL1SegSktx0UsoPfNidIGVDN7/AXpBDBv0WQ==}
|
||||
engines: {node: '>= 0.10.0'}
|
||||
hasBin: true
|
||||
|
||||
ecdsa-sig-formatter@1.0.11:
|
||||
resolution: {integrity: sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==}
|
||||
|
||||
@ -1644,10 +1613,6 @@ packages:
|
||||
resolution: {integrity: sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==}
|
||||
engines: {node: '>=8.0.0'}
|
||||
|
||||
get-stdin@0.1.0:
|
||||
resolution: {integrity: sha512-/WBu3IaQZxE3bs3BhBmR10ipDY4pjN+U4EZgXULa1eqKA0B/Lka/MVoAqhTVYBkkRlCrEGDOU9itrzIgm9Ksng==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
get-stream@6.0.1:
|
||||
resolution: {integrity: sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==}
|
||||
engines: {node: '>=10'}
|
||||
@ -1663,10 +1628,6 @@ packages:
|
||||
glob-to-regexp@0.4.1:
|
||||
resolution: {integrity: sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==}
|
||||
|
||||
glob@6.0.4:
|
||||
resolution: {integrity: sha512-MKZeRNyYZAVVVG1oZeLaWie1uweH40m9AZwIwxyPbTSX4hHrVYSzLg0Ro5Z5R7XKkIX+Cc6oD1rqeDJnwsB8/A==}
|
||||
deprecated: Glob versions prior to v9 are no longer supported
|
||||
|
||||
glob@7.2.3:
|
||||
resolution: {integrity: sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==}
|
||||
deprecated: Glob versions prior to v9 are no longer supported
|
||||
@ -2121,16 +2082,6 @@ packages:
|
||||
resolution: {integrity: sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==}
|
||||
engines: {node: '>=10'}
|
||||
|
||||
minimist@0.1.0:
|
||||
resolution: {integrity: sha512-wR5Ipl99t0mTGwLjQJnBjrP/O7zBbLZqvA3aw32DmLx+nXHfWctUjzDjnDx09pX1Po86WFQazF9xUzfMea3Cnw==}
|
||||
|
||||
minimist@1.2.8:
|
||||
resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==}
|
||||
|
||||
mkdirp@0.5.6:
|
||||
resolution: {integrity: sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==}
|
||||
hasBin: true
|
||||
|
||||
moment-timezone@0.5.45:
|
||||
resolution: {integrity: sha512-HIWmqA86KcmCAhnMAN0wuDOARV/525R2+lOLotuGFzn4HO+FH+/645z2wx0Dt3iDv6/p61SIvKnDstISainhLQ==}
|
||||
|
||||
@ -2745,6 +2696,10 @@ packages:
|
||||
uri-js@4.4.1:
|
||||
resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==}
|
||||
|
||||
uuid@10.0.0:
|
||||
resolution: {integrity: sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==}
|
||||
hasBin: true
|
||||
|
||||
uuid@8.3.2:
|
||||
resolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==}
|
||||
hasBin: true
|
||||
@ -3969,17 +3924,8 @@ snapshots:
|
||||
dependencies:
|
||||
'@types/ms': 0.7.34
|
||||
|
||||
'@types/detect-indent@0.1.30': {}
|
||||
|
||||
'@types/dts-bundle@0.0.35': {}
|
||||
|
||||
'@types/estree@1.0.5': {}
|
||||
|
||||
'@types/glob@5.0.30':
|
||||
dependencies:
|
||||
'@types/minimatch': 5.1.2
|
||||
'@types/node': 22.5.5
|
||||
|
||||
'@types/graceful-fs@4.1.9':
|
||||
dependencies:
|
||||
'@types/node': 22.5.5
|
||||
@ -4013,18 +3959,12 @@ snapshots:
|
||||
|
||||
'@types/methods@1.1.4': {}
|
||||
|
||||
'@types/minimatch@5.1.2': {}
|
||||
|
||||
'@types/mkdirp@0.3.29': {}
|
||||
|
||||
'@types/ms@0.7.34': {}
|
||||
|
||||
'@types/node@22.5.5':
|
||||
dependencies:
|
||||
undici-types: 6.19.8
|
||||
|
||||
'@types/node@8.0.0': {}
|
||||
|
||||
'@types/stack-utils@2.0.3': {}
|
||||
|
||||
'@types/superagent@8.1.9':
|
||||
@ -4520,11 +4460,6 @@ snapshots:
|
||||
|
||||
delayed-stream@1.0.0: {}
|
||||
|
||||
detect-indent@0.2.0:
|
||||
dependencies:
|
||||
get-stdin: 0.1.0
|
||||
minimist: 0.1.0
|
||||
|
||||
detect-newline@3.1.0: {}
|
||||
|
||||
dezalgo@1.0.4:
|
||||
@ -4543,17 +4478,6 @@ snapshots:
|
||||
typescript: 5.6.2
|
||||
yargs: 17.7.2
|
||||
|
||||
dts-bundle@0.7.3:
|
||||
dependencies:
|
||||
'@types/detect-indent': 0.1.30
|
||||
'@types/glob': 5.0.30
|
||||
'@types/mkdirp': 0.3.29
|
||||
'@types/node': 8.0.0
|
||||
commander: 2.20.3
|
||||
detect-indent: 0.2.0
|
||||
glob: 6.0.4
|
||||
mkdirp: 0.5.6
|
||||
|
||||
ecdsa-sig-formatter@1.0.11:
|
||||
dependencies:
|
||||
safe-buffer: 5.2.1
|
||||
@ -4752,8 +4676,6 @@ snapshots:
|
||||
|
||||
get-package-type@0.1.0: {}
|
||||
|
||||
get-stdin@0.1.0: {}
|
||||
|
||||
get-stream@6.0.1: {}
|
||||
|
||||
glob-parent@5.1.2:
|
||||
@ -4766,14 +4688,6 @@ snapshots:
|
||||
|
||||
glob-to-regexp@0.4.1: {}
|
||||
|
||||
glob@6.0.4:
|
||||
dependencies:
|
||||
inflight: 1.0.6
|
||||
inherits: 2.0.4
|
||||
minimatch: 3.1.2
|
||||
once: 1.4.0
|
||||
path-is-absolute: 1.0.1
|
||||
|
||||
glob@7.2.3:
|
||||
dependencies:
|
||||
fs.realpath: 1.0.0
|
||||
@ -5380,14 +5294,6 @@ snapshots:
|
||||
dependencies:
|
||||
brace-expansion: 2.0.1
|
||||
|
||||
minimist@0.1.0: {}
|
||||
|
||||
minimist@1.2.8: {}
|
||||
|
||||
mkdirp@0.5.6:
|
||||
dependencies:
|
||||
minimist: 1.2.8
|
||||
|
||||
moment-timezone@0.5.45:
|
||||
dependencies:
|
||||
moment: 2.30.1
|
||||
@ -5949,6 +5855,8 @@ snapshots:
|
||||
dependencies:
|
||||
punycode: 2.3.1
|
||||
|
||||
uuid@10.0.0: {}
|
||||
|
||||
uuid@8.3.2: {}
|
||||
|
||||
v8-compile-cache-lib@3.0.1: {}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { CustomError } from '@abearxiong/router';
|
||||
import { app } from '../../app.ts';
|
||||
import { ContainerModel, ContainerData, Container } from './models/index.ts';
|
||||
|
||||
@ -13,6 +14,21 @@ list.run = async (ctx) => {
|
||||
|
||||
list.addTo(app);
|
||||
|
||||
app
|
||||
.route({
|
||||
path: 'container',
|
||||
key: 'get',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const id = ctx.query.id;
|
||||
if (!id) {
|
||||
throw new CustomError('id is required');
|
||||
}
|
||||
ctx.body = await ContainerModel.findByPk(id);
|
||||
return ctx;
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
const add = app.route({
|
||||
path: 'container',
|
||||
key: 'update',
|
||||
@ -46,8 +62,7 @@ add.run = async (ctx) => {
|
||||
containerModel.save();
|
||||
}
|
||||
} else {
|
||||
try{
|
||||
|
||||
try {
|
||||
containerModel = await ContainerModel.create({
|
||||
...container,
|
||||
});
|
||||
|
@ -1 +1,3 @@
|
||||
import './container/index.ts';
|
||||
import './container/index.ts';
|
||||
|
||||
import './page/index.ts';
|
@ -1,5 +1,29 @@
|
||||
import { CustomError } from '@abearxiong/router';
|
||||
import { app } from '../../app.ts';
|
||||
import { PageModel } from './models/index.ts';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { ContainerModel } from '../container/models/index.ts';
|
||||
import { Op } from 'sequelize';
|
||||
|
||||
app
|
||||
.route({
|
||||
path: 'page',
|
||||
key: 'get',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const id = ctx.query.id;
|
||||
if (!id) {
|
||||
throw new CustomError('id is required');
|
||||
}
|
||||
try {
|
||||
const page = await PageModel.findByPk(id);
|
||||
ctx.body = page;
|
||||
} catch (e) {
|
||||
console.log('error', e);
|
||||
throw new CustomError(e.message || 'get error');
|
||||
}
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
app
|
||||
.route({
|
||||
@ -15,13 +39,20 @@ app
|
||||
app
|
||||
.route({
|
||||
path: 'page',
|
||||
key: 'add',
|
||||
key: 'update',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const data = ctx.query;
|
||||
const page = await PageModel.create(data);
|
||||
ctx.body = page;
|
||||
return ctx;
|
||||
const { data, id, ...rest } = ctx.query.data;
|
||||
if (id) {
|
||||
const page = await PageModel.findByPk(id);
|
||||
if (page) {
|
||||
const newPage = await page.update({ data: data, ...rest });
|
||||
ctx.body = newPage;
|
||||
}
|
||||
} else if (data) {
|
||||
const page = await PageModel.create({ data, ...rest });
|
||||
ctx.body = page;
|
||||
}
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
@ -40,3 +71,148 @@ app
|
||||
return ctx;
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
app
|
||||
.route({
|
||||
path: 'page',
|
||||
key: 'addDemo',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const id = uuidv4();
|
||||
const data = {
|
||||
// id: 'container-1',
|
||||
id,
|
||||
title: 'demo',
|
||||
description: 'demo',
|
||||
type: 'conainer',
|
||||
data: {
|
||||
edges: [
|
||||
{
|
||||
id: 'e1',
|
||||
// source: 'container-1',
|
||||
source: id,
|
||||
target: 'container-2',
|
||||
},
|
||||
{
|
||||
id: 'e2',
|
||||
// source: 'container-1',
|
||||
source: id,
|
||||
target: 'container-3',
|
||||
},
|
||||
{
|
||||
id: 'e3',
|
||||
source: 'container-2',
|
||||
target: 'container-4',
|
||||
},
|
||||
],
|
||||
nodes: [
|
||||
{
|
||||
// id: 'container-1',
|
||||
id,
|
||||
type: 'container',
|
||||
data: {
|
||||
label: '开始',
|
||||
title: 'demo-hello-world',
|
||||
cid: 'a6652ce0-82fb-432a-a6b0-2033a655b02c',
|
||||
root: true,
|
||||
},
|
||||
position: {
|
||||
x: 50,
|
||||
y: 125,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'container-2',
|
||||
type: 'container',
|
||||
data: {
|
||||
label: '容器',
|
||||
title: 'demo-child-01',
|
||||
cid: '67e5b2ff-98dc-43ab-8ad9-9b062096f8eb',
|
||||
},
|
||||
position: {
|
||||
x: 350,
|
||||
y: 125,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'container-3',
|
||||
type: 'container',
|
||||
data: {
|
||||
label: '容器',
|
||||
title: 'demo-child-03',
|
||||
cid: '208c3e36-dc7d-46af-b2f0-81d5f43c974d',
|
||||
},
|
||||
position: {
|
||||
x: 350,
|
||||
y: 325,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'container-4',
|
||||
type: 'container',
|
||||
data: {
|
||||
label: '容器',
|
||||
title: 'demo-child-04',
|
||||
cid: '170c0b55-8c13-4d6e-bf35-3f935d979a0d',
|
||||
},
|
||||
position: {
|
||||
x: 650,
|
||||
y: 125,
|
||||
},
|
||||
},
|
||||
],
|
||||
viewport: {},
|
||||
},
|
||||
};
|
||||
try {
|
||||
const page = await PageModel.create(data);
|
||||
ctx.body = page;
|
||||
} catch (e) {
|
||||
console.log('error', e);
|
||||
throw new CustomError('addDemo error');
|
||||
}
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
app
|
||||
.route({
|
||||
path: 'page',
|
||||
key: 'getDeck',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const id = ctx.query.id;
|
||||
if (!id) {
|
||||
throw new CustomError('id is required');
|
||||
}
|
||||
|
||||
try {
|
||||
const page = await PageModel.findByPk(id);
|
||||
if (!page) {
|
||||
throw new CustomError(404, 'panel not found');
|
||||
}
|
||||
const { data } = page;
|
||||
const { nodes = [], edges } = data;
|
||||
const containerList = nodes
|
||||
.map((item) => {
|
||||
const { data } = item;
|
||||
return data?.cid;
|
||||
})
|
||||
.filter((item) => item);
|
||||
const quchong = Array.from(new Set(containerList));
|
||||
const containers = await ContainerModel.findAll({
|
||||
where: {
|
||||
id: {
|
||||
[Op.in]: quchong,
|
||||
},
|
||||
},
|
||||
});
|
||||
ctx.body = {
|
||||
page,
|
||||
containerList: containers,
|
||||
};
|
||||
} catch (e) {
|
||||
console.log('error', e);
|
||||
throw new CustomError(e.message || 'get error');
|
||||
}
|
||||
})
|
||||
.addTo(app);
|
||||
|
@ -27,7 +27,7 @@ PageModel.init(
|
||||
defaultValue: '',
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.STRING,
|
||||
type: DataTypes.TEXT,
|
||||
defaultValue: '',
|
||||
},
|
||||
type: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user