|
|
|
@ -2,6 +2,11 @@
|
|
|
|
|
import { Request, Response } from 'express'; |
|
|
|
|
|
|
|
|
|
import { packageVersion } from 'nc-help'; |
|
|
|
|
import { ViewTypes } from 'nocodb-sdk'; |
|
|
|
|
import Project from '../../models/Project'; |
|
|
|
|
import Noco from '../../Noco'; |
|
|
|
|
import NcConnectionMgrv2 from '../../utils/common/NcConnectionMgrv2'; |
|
|
|
|
import { MetaTable } from '../../utils/globals'; |
|
|
|
|
import ncMetaAclMw from '../helpers/ncMetaAclMw'; |
|
|
|
|
import SqlMgrv2 from '../../db/sql-mgr/v2/SqlMgrv2'; |
|
|
|
|
import NcConfigFactory, { |
|
|
|
@ -19,6 +24,7 @@ const versionCache = {
|
|
|
|
|
export async function testConnection(req: Request, res: Response) { |
|
|
|
|
res.json(await SqlMgrv2.testConnection(req.body)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export async function appInfo(req: Request, res: Response) { |
|
|
|
|
const projectHasAdmin = !(await User.isFirst()); |
|
|
|
|
const result = { |
|
|
|
@ -171,14 +177,172 @@ export async function axiosRequestMake(req: Request, res: Response) {
|
|
|
|
|
export async function urlToDbConfig(req: Request, res: Response) { |
|
|
|
|
const { url } = req.body; |
|
|
|
|
try { |
|
|
|
|
let connectionConfig; |
|
|
|
|
connectionConfig = NcConfigFactory.extractXcUrlFromJdbc(url, true); |
|
|
|
|
const connectionConfig = NcConfigFactory.extractXcUrlFromJdbc(url, true); |
|
|
|
|
return res.json(connectionConfig); |
|
|
|
|
} catch (error) { |
|
|
|
|
return res.sendStatus(500); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
interface AllMeta { |
|
|
|
|
projectCount: number; |
|
|
|
|
projects: { |
|
|
|
|
tableCount: { |
|
|
|
|
table: number; |
|
|
|
|
view: number; |
|
|
|
|
}; |
|
|
|
|
viewCount: { |
|
|
|
|
formCount: number; |
|
|
|
|
gridCount: number; |
|
|
|
|
galleryCount: number; |
|
|
|
|
kanbanCount: number; |
|
|
|
|
total: number; |
|
|
|
|
sharedFormCount: number; |
|
|
|
|
sharedGridCount: number; |
|
|
|
|
sharedGalleryCount: number; |
|
|
|
|
sharedKanbanCount: number; |
|
|
|
|
sharedTotal: number; |
|
|
|
|
sharedPasswordProtected: number; |
|
|
|
|
}; |
|
|
|
|
webhookCount: number; |
|
|
|
|
filterCount: number; |
|
|
|
|
sortCount: number; |
|
|
|
|
rowCount: { totalRecords: number }[]; |
|
|
|
|
userCount: number; |
|
|
|
|
}[]; |
|
|
|
|
userCount: number; |
|
|
|
|
sharedBaseCount: number; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export async function allMeta(_req: Request, res: Response) { |
|
|
|
|
const result: AllMeta = { |
|
|
|
|
projectCount: 0, |
|
|
|
|
projects: [], |
|
|
|
|
userCount: await Noco.ncMeta.metaCount(null, null, MetaTable.USERS), |
|
|
|
|
sharedBaseCount: 0, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const projects = await Project.list({}); |
|
|
|
|
const userCount = await User.count(); |
|
|
|
|
result.projectCount = projects.length; |
|
|
|
|
result.userCount = userCount; |
|
|
|
|
for (const project of projects) { |
|
|
|
|
if (project.uuid) result.sharedBaseCount++; |
|
|
|
|
const tableCount = await Noco.ncMeta.metaCount( |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
MetaTable.MODELS, |
|
|
|
|
{ |
|
|
|
|
condition: { |
|
|
|
|
project_id: project.id, |
|
|
|
|
type: 'table', |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const dbViewCount = await Noco.ncMeta.metaCount( |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
MetaTable.MODELS, |
|
|
|
|
{ |
|
|
|
|
condition: { |
|
|
|
|
project_id: project.id, |
|
|
|
|
type: 'view', |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
const views = await Noco.ncMeta.metaList2(null, null, MetaTable.VIEWS); |
|
|
|
|
const viewCount = views.reduce<AllMeta['projects'][number]['viewCount']>( |
|
|
|
|
(out, view) => { |
|
|
|
|
out.total++; |
|
|
|
|
|
|
|
|
|
switch (view.type) { |
|
|
|
|
case ViewTypes.GRID: |
|
|
|
|
out.gridCount++; |
|
|
|
|
if (view.uuid) out.sharedGridCount++; |
|
|
|
|
break; |
|
|
|
|
case ViewTypes.FORM: |
|
|
|
|
out.formCount++; |
|
|
|
|
if (view.uuid) out.sharedFormCount++; |
|
|
|
|
break; |
|
|
|
|
case ViewTypes.GALLERY: |
|
|
|
|
out.galleryCount++; |
|
|
|
|
if (view.uuid) out.sharedGalleryCount++; |
|
|
|
|
break; |
|
|
|
|
case ViewTypes.KANBAN: |
|
|
|
|
out.kanbanCount++; |
|
|
|
|
if (view.uuid) out.sharedKanbanCount++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (view.uuid && view.password) out.sharedPasswordProtected++; |
|
|
|
|
|
|
|
|
|
return out; |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
formCount: 0, |
|
|
|
|
gridCount: 0, |
|
|
|
|
galleryCount: 0, |
|
|
|
|
kanbanCount: 0, |
|
|
|
|
total: 0, |
|
|
|
|
sharedFormCount: 0, |
|
|
|
|
sharedGridCount: 0, |
|
|
|
|
sharedGalleryCount: 0, |
|
|
|
|
sharedKanbanCount: 0, |
|
|
|
|
sharedTotal: 0, |
|
|
|
|
sharedPasswordProtected: 0, |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
result.projects.push({ |
|
|
|
|
tableCount: { table: tableCount, view: dbViewCount }, |
|
|
|
|
|
|
|
|
|
viewCount, |
|
|
|
|
webhookCount: await Noco.ncMeta.metaCount(null, null, MetaTable.HOOKS, { |
|
|
|
|
condition: { |
|
|
|
|
project_id: project.id, |
|
|
|
|
}, |
|
|
|
|
}), |
|
|
|
|
filterCount: await Noco.ncMeta.metaCount( |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
MetaTable.FILTER_EXP, |
|
|
|
|
{ |
|
|
|
|
condition: { |
|
|
|
|
project_id: project.id, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
), |
|
|
|
|
sortCount: await Noco.ncMeta.metaCount(null, null, MetaTable.SORT, { |
|
|
|
|
condition: { |
|
|
|
|
project_id: project.id, |
|
|
|
|
}, |
|
|
|
|
}), |
|
|
|
|
rowCount: await project.getBases().then((bases) => { |
|
|
|
|
return Promise.all( |
|
|
|
|
bases.map((base) => |
|
|
|
|
NcConnectionMgrv2.getSqlClient(base) |
|
|
|
|
.totalRecords?.() |
|
|
|
|
?.then((result) => result?.data) |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
}), |
|
|
|
|
userCount: await Noco.ncMeta.metaCount( |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
MetaTable.PROJECT_USERS, |
|
|
|
|
{ |
|
|
|
|
condition: { |
|
|
|
|
project_id: project.id, |
|
|
|
|
}, |
|
|
|
|
aggField: '*', |
|
|
|
|
} |
|
|
|
|
), |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
res.json(result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export default (router) => { |
|
|
|
|
router.post( |
|
|
|
|
'/api/v1/db/meta/connection/test', |
|
|
|
@ -190,4 +354,5 @@ export default (router) => {
|
|
|
|
|
router.get('/api/v1/health', catchError(appHealth)); |
|
|
|
|
router.get('/api/v1/feedback_form', catchError(feedbackFormGet)); |
|
|
|
|
router.post('/api/v1/url_to_config', catchError(urlToDbConfig)); |
|
|
|
|
router.get('/api/v1/all_meta', catchError(allMeta)); |
|
|
|
|
}; |
|
|
|
|