Browse Source

feat: code snippet

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/1950/head
Pranav C 3 years ago
parent
commit
06ddeff5cf
  1. 118
      packages/nc-gui/components/project/spreadsheet/components/codeSnippet.vue
  2. 11
      packages/nc-gui/components/project/spreadsheet/components/spreadsheetNavDrawer.vue
  3. 766
      packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue
  4. 4
      packages/nocodb/src/lib/noco/meta/api/apiTokenApis.ts
  5. 5
      packages/nocodb/src/lib/noco/meta/api/columnApis.ts
  6. 8
      packages/nocodb/src/lib/noco/meta/api/filterApis.ts
  7. 5
      packages/nocodb/src/lib/noco/meta/api/formViewApis.ts
  8. 2
      packages/nocodb/src/lib/noco/meta/api/formViewColumnApis.ts
  9. 4
      packages/nocodb/src/lib/noco/meta/api/galleryViewApis.ts
  10. 2
      packages/nocodb/src/lib/noco/meta/api/gridViewApis.ts
  11. 3
      packages/nocodb/src/lib/noco/meta/api/gridViewColumnApis.ts
  12. 7
      packages/nocodb/src/lib/noco/meta/api/hookApis.ts
  13. 12
      packages/nocodb/src/lib/noco/meta/api/hookFilterApis.ts
  14. 3
      packages/nocodb/src/lib/noco/meta/api/metaDiffApis.ts
  15. 3
      packages/nocodb/src/lib/noco/meta/api/modelVisibilityApis.ts
  16. 11
      packages/nocodb/src/lib/noco/meta/api/pluginApis.ts
  17. 6
      packages/nocodb/src/lib/noco/meta/api/projectApis.ts
  18. 6
      packages/nocodb/src/lib/noco/meta/api/projectUserApis.ts
  19. 11
      packages/nocodb/src/lib/noco/meta/api/sortApis.ts
  20. 7
      packages/nocodb/src/lib/noco/meta/api/tableApis.ts
  21. 9
      packages/nocodb/src/lib/noco/meta/api/viewApis.ts
  22. 4
      packages/nocodb/src/lib/noco/meta/api/viewColumnApis.ts
  23. 12
      packages/nocodb/src/lib/noco/meta/helpers/apiMetrics.ts

118
packages/nc-gui/components/project/spreadsheet/components/codeSnippet.vue

@ -1,7 +1,7 @@
<template> <template>
<v-dialog :value="true"> <v-dialog v-model="modal">
<v-card style="overflow: hidden"> <v-card style="overflow: hidden">
<v-tabs v-model="tab" height="30"> <v-tabs v-model="tab" height="30" @change="client=null">
<v-tab <v-tab
v-for="{lang} in langs" v-for="{lang} in langs"
:key="lang" :key="lang"
@ -11,17 +11,31 @@
</v-tab> </v-tab>
</v-tabs> </v-tabs>
<div class="nc-snippet-wrapper"> <div class="nc-snippet-wrapper">
<div class="nc-snippet-actions"> <div class="nc-snippet-actions d-flex">
<v-icon>mdi-clipboard</v-icon>sdds <v-btn color="primary" class="rounded caption " @click="copyToClipboard">
<v-select <v-icon small>
mdi-clipboard-outline
</v-icon> Copy To Clipboard
</v-btn>
<div
v-if="langs[tab].clients" v-if="langs[tab].clients"
v-model="client" class=" ml-2 d-flex align-center"
class="nc-snippet-client" >
outlined <v-menu bottom offset-y>
dense <template #activator="{on}">
hide-details <v-btn class="caption" color="primary" v-on="on">
style="max-width: 100px" {{ client || langs[tab].clients[0] }} <v-icon small>
/> mdi-chevron-down
</v-icon>
</v-btn>
</template>
<v-list dense>
<v-list-item v-for="c in langs[tab].clients" :key="c" dense @click="client = c">
<v-list-item-title>{{ c }}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</div>
</div> </div>
<custom-monaco-editor style="min-height:500px;max-width: 100%" :value="code" read-only /> <custom-monaco-editor style="min-height:500px;max-width: 100%" :value="code" read-only />
</div> </div>
@ -32,6 +46,7 @@
<script> <script>
import HTTPSnippet from 'httpsnippet' import HTTPSnippet from 'httpsnippet'
import CustomMonacoEditor from '~/components/monaco/CustomMonacoEditor' import CustomMonacoEditor from '~/components/monaco/CustomMonacoEditor'
import { copyTextToClipboard } from '~/helpers/xutils'
export default { export default {
name: 'CodeSnippet', name: 'CodeSnippet',
components: { CustomMonacoEditor }, components: { CustomMonacoEditor },
@ -40,48 +55,110 @@ export default {
view: Object, view: Object,
filters: [Object, Array], filters: [Object, Array],
sorts: [Object, Array], sorts: [Object, Array],
fileds: [Object, Array] fileds: [Object, Array],
queryParams: Object,
value: Boolean
}, },
data: () => ({ data: () => ({
tab: 0, tab: 0,
client: null, client: null,
langs: [ langs: [
{
lang: 'shell',
clients: ['curl', 'wget']
},
{ {
lang: 'javascript', lang: 'javascript',
clients: ['XMLHttpRequest', 'jQuery.ajax'] clients: ['axios', 'fetch', 'jquery', 'xhr']
}, },
{ {
lang: 'node' lang: 'node',
clients: ['axios', 'fetch', 'request', 'native', 'unirest']
}, },
{ {
lang: 'shell' lang: 'nocodb-sdk',
clients: ['javascript', 'node']
}, },
{ {
lang: 'php' lang: 'php'
}, },
{ {
lang: 'python' lang: 'python',
clients: ['python3',
'requests']
}, },
{ {
lang: 'ruby' lang: 'ruby'
}, },
{
lang: 'java'
},
{ {
lang: 'c' lang: 'c'
} }
] ]
}), }),
computed: { computed: {
modal: {
get() {
return this.value
},
set(v) {
this.$emit('input', v)
}
},
apiUrl() {
return new URL(`/api/v1/db/data/noco/${this.projectId}/${this.meta.title}/views/${this.view.title}`, this.$store.state.project.projectInfo.ncSiteUrl).href
},
snippet() { snippet() {
return new HTTPSnippet({ return new HTTPSnippet({
method: 'GET', method: 'GET',
headers: [ headers: [
{ name: 'xc-auth', value: this.$store.state.users.token, comment: 'JWT Auth token' } { name: 'xc-auth', value: this.$store.state.users.token, comment: 'JWT Auth token' }
], ],
url: new URL(`/api/v1/db/data/noco/${this.projectId}/${this.meta.title}/views/${this.view.title}`, this.$store.state.project.projectInfo.ncSiteUrl).href url: this.apiUrl,
queryString: Object.entries(this.queryParams || {}).map(([name, value]) => {
return {
name, value: String(value)
}
})
}) })
}, },
code() { code() {
return this.snippet.convert(this.langs[this.tab].lang, this.client) if (this.langs[this.tab].lang === 'nocodb-sdk') {
return `${
this.client === 'node'
? 'const { Api } require("nocodb-sdk");'
: 'import { Api } from "nocodb-sdk";'
}
const api = new Api({
baseURL: ${JSON.stringify(this.apiUrl)},
headers: {
"xc-auth": ${JSON.stringify(this.$store.state.users.token)}
}
})
api.dbViewRow.list(
"noco",
${JSON.stringify(this.projectName)},
${JSON.stringify(this.meta.title)},
${JSON.stringify(this.view.title)},
${JSON.stringify(this.queryParams, null, 2)}
).then(function (data) {
console.log(data);
}).catch(function (error) {
console.error(error);
});`
}
return this.snippet.convert(this.langs[this.tab].lang, this.client || (this.langs[this.tab].clients && this.langs[this.tab].clients[0]), {})
}
},
methods: {
copyToClipboard() {
copyTextToClipboard(this.code)
this.$toast.success('Code copied to clipboard successfully.').goAway(3000)
} }
} }
} }
@ -94,6 +171,7 @@ export default {
.nc-snippet-actions{ .nc-snippet-actions{
position: absolute; position: absolute;
right: 10px; right: 10px;
top:40px; bottom:10px;
z-index: 99999;
} }
</style> </style>

11
packages/nc-gui/components/project/spreadsheet/components/spreadsheetNavDrawer.vue

@ -274,7 +274,12 @@
</div> </div>
<div> <div>
<code-snippet :meta="meta" :view="selectedView" /> <v-btn color="primary" class="caption d-100" @click="codeSnippetModal=true">
<v-icon small class="mr-2">
mdi-xml
</v-icon> Get API Snippet
</v-btn>
<code-snippet v-model="codeSnippetModal" :query-params="queryParams" :meta="meta" :view="selectedView" />
</div> </div>
<div <div
@ -549,9 +554,11 @@ export default {
// coverImageField: String, // coverImageField: String,
groupingField: String, groupingField: String,
// showSystemFields: Boolean, // showSystemFields: Boolean,
views: Array views: Array,
queryParams: Object
}, },
data: () => ({ data: () => ({
codeSnippetModal: false,
drag: false, drag: false,
dragOptions: { dragOptions: {
animation: 200, animation: 200,

766
packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue

File diff suppressed because it is too large Load Diff

4
packages/nocodb/src/lib/noco/meta/api/apiTokenApis.ts

@ -2,6 +2,7 @@ import { Request, Response, Router } from 'express';
import ncMetaAclMw from '../helpers/ncMetaAclMw'; import ncMetaAclMw from '../helpers/ncMetaAclMw';
import ApiToken from '../../../noco-models/ApiToken'; import ApiToken from '../../../noco-models/ApiToken';
import { Tele } from 'nc-help'; import { Tele } from 'nc-help';
import { metaApiMetrics } from '../helpers/apiMetrics';
export async function apiTokenList(_req: Request, res: Response) { export async function apiTokenList(_req: Request, res: Response) {
res.json(await ApiToken.list()); res.json(await ApiToken.list());
@ -19,14 +20,17 @@ const router = Router({ mergeParams: true });
router.get( router.get(
'/api/v1/db/meta/projects/:projectId/api-tokens', '/api/v1/db/meta/projects/:projectId/api-tokens',
metaApiMetrics,
ncMetaAclMw(apiTokenList, 'apiTokenList') ncMetaAclMw(apiTokenList, 'apiTokenList')
); );
router.post( router.post(
'/api/v1/db/meta/projects/:projectId/api-tokens', '/api/v1/db/meta/projects/:projectId/api-tokens',
metaApiMetrics,
ncMetaAclMw(apiTokenCreate, 'apiTokenCreate') ncMetaAclMw(apiTokenCreate, 'apiTokenCreate')
); );
router.delete( router.delete(
'/api/v1/db/meta/projects/:projectId/api-tokens/:token', '/api/v1/db/meta/projects/:projectId/api-tokens/:token',
metaApiMetrics,
ncMetaAclMw(apiTokenDelete, 'apiTokenDelete') ncMetaAclMw(apiTokenDelete, 'apiTokenDelete')
); );

5
packages/nocodb/src/lib/noco/meta/api/columnApis.ts

@ -31,6 +31,7 @@ import { NcError } from '../helpers/catchError';
import getColumnPropsFromUIDT from '../helpers/getColumnPropsFromUIDT'; import getColumnPropsFromUIDT from '../helpers/getColumnPropsFromUIDT';
import mapDefaultPrimaryValue from '../helpers/mapDefaultPrimaryValue'; import mapDefaultPrimaryValue from '../helpers/mapDefaultPrimaryValue';
import NcConnectionMgrv2 from '../../common/NcConnectionMgrv2'; import NcConnectionMgrv2 from '../../common/NcConnectionMgrv2';
import { metaApiMetrics } from '../helpers/apiMetrics';
const randomID = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 10); const randomID = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 10);
@ -922,18 +923,22 @@ const deleteHmOrBtRelation = async (
const router = Router({ mergeParams: true }); const router = Router({ mergeParams: true });
router.post( router.post(
'/api/v1/db/meta/tables/:tableId/columns/', '/api/v1/db/meta/tables/:tableId/columns/',
metaApiMetrics,
ncMetaAclMw(columnAdd, 'columnAdd') ncMetaAclMw(columnAdd, 'columnAdd')
); );
router.patch( router.patch(
'/api/v1/db/meta/columns/:columnId', '/api/v1/db/meta/columns/:columnId',
metaApiMetrics,
ncMetaAclMw(columnUpdate, 'columnUpdate') ncMetaAclMw(columnUpdate, 'columnUpdate')
); );
router.delete( router.delete(
'/api/v1/db/meta/columns/:columnId', '/api/v1/db/meta/columns/:columnId',
metaApiMetrics,
ncMetaAclMw(columnDelete, 'columnDelete') ncMetaAclMw(columnDelete, 'columnDelete')
); );
router.post( router.post(
'/api/v1/db/meta/columns/:columnId/primary', '/api/v1/db/meta/columns/:columnId/primary',
metaApiMetrics,
ncMetaAclMw(columnSetAsPrimary, 'columnSetAsPrimary') ncMetaAclMw(columnSetAsPrimary, 'columnSetAsPrimary')
); );
export default router; export default router;

8
packages/nocodb/src/lib/noco/meta/api/filterApis.ts

@ -12,6 +12,7 @@ import Project from '../../../noco-models/Project';
import Filter from '../../../noco-models/Filter'; import Filter from '../../../noco-models/Filter';
import ncMetaAclMw from '../helpers/ncMetaAclMw'; import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { Tele } from 'nc-help'; import { Tele } from 'nc-help';
import { metaApiMetrics } from '../helpers/apiMetrics';
// @ts-ignore // @ts-ignore
export async function filterGet(req: Request, res: Response, next) { export async function filterGet(req: Request, res: Response, next) {
@ -129,10 +130,12 @@ export async function hookFilterCreate(req: Request<any, any, TableReq>, res) {
const router = Router({ mergeParams: true }); const router = Router({ mergeParams: true });
router.get( router.get(
'/api/v1/db/meta/views/:viewId/filters', '/api/v1/db/meta/views/:viewId/filters',
metaApiMetrics,
ncMetaAclMw(filterList, 'filterList') ncMetaAclMw(filterList, 'filterList')
); );
router.post( router.post(
'/api/v1/db/meta/views/:viewId/filters', '/api/v1/db/meta/views/:viewId/filters',
metaApiMetrics,
ncMetaAclMw(filterCreate, 'filterCreate') ncMetaAclMw(filterCreate, 'filterCreate')
); );
@ -142,23 +145,28 @@ router.get(
); );
router.post( router.post(
'/api/v1/db/meta/hooks/:hookId/filters', '/api/v1/db/meta/hooks/:hookId/filters',
metaApiMetrics,
ncMetaAclMw(hookFilterCreate, 'filterCreate') ncMetaAclMw(hookFilterCreate, 'filterCreate')
); );
router.get( router.get(
'/api/v1/db/meta/filters/:filterId', '/api/v1/db/meta/filters/:filterId',
metaApiMetrics,
ncMetaAclMw(filterGet, 'filterGet') ncMetaAclMw(filterGet, 'filterGet')
); );
router.patch( router.patch(
'/api/v1/db/meta/filters/:filterId', '/api/v1/db/meta/filters/:filterId',
metaApiMetrics,
ncMetaAclMw(filterUpdate, 'filterUpdate') ncMetaAclMw(filterUpdate, 'filterUpdate')
); );
router.delete( router.delete(
'/api/v1/db/meta/filters/:filterId', '/api/v1/db/meta/filters/:filterId',
metaApiMetrics,
ncMetaAclMw(filterDelete, 'filterDelete') ncMetaAclMw(filterDelete, 'filterDelete')
); );
router.get( router.get(
'/api/v1/db/meta/filters/:filterParentId/children', '/api/v1/db/meta/filters/:filterParentId/children',
metaApiMetrics,
ncMetaAclMw(filterChildrenRead, 'filterChildrenRead') ncMetaAclMw(filterChildrenRead, 'filterChildrenRead')
); );
export default router; export default router;

5
packages/nocodb/src/lib/noco/meta/api/formViewApis.ts

@ -12,6 +12,7 @@ import View from '../../../noco-models/View';
import FormView from '../../../noco-models/FormView'; import FormView from '../../../noco-models/FormView';
import ncMetaAclMw from '../helpers/ncMetaAclMw'; import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { Tele } from 'nc-help'; import { Tele } from 'nc-help';
import { metaApiMetrics } from '../helpers/apiMetrics';
// @ts-ignore // @ts-ignore
export async function formViewGet(req: Request, res: Response<FormType>) { export async function formViewGet(req: Request, res: Response<FormType>) {
@ -41,18 +42,22 @@ export async function formViewDelete(req: Request, res: Response, next) {}
const router = Router({ mergeParams: true }); const router = Router({ mergeParams: true });
router.post( router.post(
'/api/v1/db/meta/tables/:tableId/forms', '/api/v1/db/meta/tables/:tableId/forms',
metaApiMetrics,
ncMetaAclMw(formViewCreate, 'formViewCreate') ncMetaAclMw(formViewCreate, 'formViewCreate')
); );
router.get( router.get(
'/api/v1/db/meta/forms/:formViewId', '/api/v1/db/meta/forms/:formViewId',
metaApiMetrics,
ncMetaAclMw(formViewGet, 'formViewGet') ncMetaAclMw(formViewGet, 'formViewGet')
); );
router.patch( router.patch(
'/api/v1/db/meta/forms/:formViewId', '/api/v1/db/meta/forms/:formViewId',
metaApiMetrics,
ncMetaAclMw(formViewUpdate, 'formViewUpdate') ncMetaAclMw(formViewUpdate, 'formViewUpdate')
); );
router.delete( router.delete(
'/api/v1/db/meta/forms/:formViewId', '/api/v1/db/meta/forms/:formViewId',
metaApiMetrics,
ncMetaAclMw(formViewDelete, 'formViewDelete') ncMetaAclMw(formViewDelete, 'formViewDelete')
); );
export default router; export default router;

2
packages/nocodb/src/lib/noco/meta/api/formViewColumnApis.ts

@ -2,6 +2,7 @@ import { Request, Response, Router } from 'express';
import FormViewColumn from '../../../noco-models/FormViewColumn'; import FormViewColumn from '../../../noco-models/FormViewColumn';
import ncMetaAclMw from '../helpers/ncMetaAclMw'; import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { Tele } from 'nc-help'; import { Tele } from 'nc-help';
import { metaApiMetrics } from '../helpers/apiMetrics';
export async function columnUpdate(req: Request, res: Response) { export async function columnUpdate(req: Request, res: Response) {
Tele.emit('evt', { evt_type: 'formViewColumn:updated' }); Tele.emit('evt', { evt_type: 'formViewColumn:updated' });
@ -11,6 +12,7 @@ export async function columnUpdate(req: Request, res: Response) {
const router = Router({ mergeParams: true }); const router = Router({ mergeParams: true });
router.patch( router.patch(
'/api/v1/db/meta/form-columns/:formViewColumnId', '/api/v1/db/meta/form-columns/:formViewColumnId',
metaApiMetrics,
ncMetaAclMw(columnUpdate, 'columnUpdate') ncMetaAclMw(columnUpdate, 'columnUpdate')
); );
export default router; export default router;

4
packages/nocodb/src/lib/noco/meta/api/galleryViewApis.ts

@ -4,6 +4,7 @@ import View from '../../../noco-models/View';
import GalleryView from '../../../noco-models/GalleryView'; import GalleryView from '../../../noco-models/GalleryView';
import ncMetaAclMw from '../helpers/ncMetaAclMw'; import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { Tele } from 'nc-help'; import { Tele } from 'nc-help';
import { metaApiMetrics } from '../helpers/apiMetrics';
export async function galleryViewGet(req: Request, res: Response<GalleryType>) { export async function galleryViewGet(req: Request, res: Response<GalleryType>) {
res.json(await GalleryView.get(req.params.galleryViewId)); res.json(await GalleryView.get(req.params.galleryViewId));
} }
@ -27,14 +28,17 @@ export async function galleryViewUpdate(req, res) {
const router = Router({ mergeParams: true }); const router = Router({ mergeParams: true });
router.post( router.post(
'/api/v1/db/meta/tables/:tableId/galleries', '/api/v1/db/meta/tables/:tableId/galleries',
metaApiMetrics,
ncMetaAclMw(galleryViewCreate, 'galleryViewCreate') ncMetaAclMw(galleryViewCreate, 'galleryViewCreate')
); );
router.patch( router.patch(
'/api/v1/db/meta/galleries/:galleryViewId', '/api/v1/db/meta/galleries/:galleryViewId',
metaApiMetrics,
ncMetaAclMw(galleryViewUpdate, 'galleryViewUpdate') ncMetaAclMw(galleryViewUpdate, 'galleryViewUpdate')
); );
router.get( router.get(
'/api/v1/db/meta/galleries/:galleryViewId', '/api/v1/db/meta/galleries/:galleryViewId',
metaApiMetrics,
ncMetaAclMw(galleryViewGet, 'galleryViewGet') ncMetaAclMw(galleryViewGet, 'galleryViewGet')
); );
export default router; export default router;

2
packages/nocodb/src/lib/noco/meta/api/gridViewApis.ts

@ -11,6 +11,7 @@ import Project from '../../../noco-models/Project';
import View from '../../../noco-models/View'; import View from '../../../noco-models/View';
import ncMetaAclMw from '../helpers/ncMetaAclMw'; import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { Tele } from 'nc-help'; import { Tele } from 'nc-help';
import { metaApiMetrics } from '../helpers/apiMetrics';
// @ts-ignore // @ts-ignore
export async function gridViewCreate(req: Request<any, any>, res) { export async function gridViewCreate(req: Request<any, any>, res) {
@ -27,6 +28,7 @@ export async function gridViewCreate(req: Request<any, any>, res) {
const router = Router({ mergeParams: true }); const router = Router({ mergeParams: true });
router.post( router.post(
'/api/v1/db/meta/tables/:tableId/grids/', '/api/v1/db/meta/tables/:tableId/grids/',
metaApiMetrics,
ncMetaAclMw(gridViewCreate, 'gridViewCreate') ncMetaAclMw(gridViewCreate, 'gridViewCreate')
); );
export default router; export default router;

3
packages/nocodb/src/lib/noco/meta/api/gridViewColumnApis.ts

@ -2,6 +2,7 @@ import { Request, Response, Router } from 'express';
import GridViewColumn from '../../../noco-models/GridViewColumn'; import GridViewColumn from '../../../noco-models/GridViewColumn';
import ncMetaAclMw from '../helpers/ncMetaAclMw'; import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { Tele } from 'nc-help'; import { Tele } from 'nc-help';
import { metaApiMetrics } from '../helpers/apiMetrics';
export async function columnList(req: Request, res: Response) { export async function columnList(req: Request, res: Response) {
res.json(await GridViewColumn.list(req.params.gridViewId)); res.json(await GridViewColumn.list(req.params.gridViewId));
@ -15,10 +16,12 @@ export async function gridColumnUpdate(req: Request, res: Response) {
const router = Router({ mergeParams: true }); const router = Router({ mergeParams: true });
router.get( router.get(
'/api/v1/db/meta/grids/:gridViewId/grid-columns', '/api/v1/db/meta/grids/:gridViewId/grid-columns',
metaApiMetrics,
ncMetaAclMw(columnList, 'columnList') ncMetaAclMw(columnList, 'columnList')
); );
router.patch( router.patch(
'/api/v1/db/meta/grid-columns/:gridViewColumnId', '/api/v1/db/meta/grid-columns/:gridViewColumnId',
metaApiMetrics,
ncMetaAclMw(gridColumnUpdate, 'gridColumnUpdate') ncMetaAclMw(gridColumnUpdate, 'gridColumnUpdate')
); );
export default router; export default router;

7
packages/nocodb/src/lib/noco/meta/api/hookApis.ts

@ -8,6 +8,7 @@ import Model from '../../../noco-models/Model';
import populateSamplePayload from '../helpers/populateSamplePayload'; import populateSamplePayload from '../helpers/populateSamplePayload';
import ncMetaAclMw from '../helpers/ncMetaAclMw'; import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { Tele } from 'nc-help'; import { Tele } from 'nc-help';
import { metaApiMetrics } from '../helpers/apiMetrics';
export async function hookList( export async function hookList(
req: Request<any, any, any>, req: Request<any, any, any>,
@ -77,26 +78,32 @@ export async function tableSampleData(req: Request, res: Response) {
const router = Router({ mergeParams: true }); const router = Router({ mergeParams: true });
router.get( router.get(
'/api/v1/db/meta/tables/:tableId/hooks', '/api/v1/db/meta/tables/:tableId/hooks',
metaApiMetrics,
ncMetaAclMw(hookList, 'hookList') ncMetaAclMw(hookList, 'hookList')
); );
router.post( router.post(
'/api/v1/db/meta/tables/:tableId/hooks/test', '/api/v1/db/meta/tables/:tableId/hooks/test',
metaApiMetrics,
ncMetaAclMw(hookTest, 'hookTest') ncMetaAclMw(hookTest, 'hookTest')
); );
router.post( router.post(
'/api/v1/db/meta/tables/:tableId/hooks', '/api/v1/db/meta/tables/:tableId/hooks',
metaApiMetrics,
ncMetaAclMw(hookCreate, 'hookCreate') ncMetaAclMw(hookCreate, 'hookCreate')
); );
router.delete( router.delete(
'/api/v1/db/meta/hooks/:hookId', '/api/v1/db/meta/hooks/:hookId',
metaApiMetrics,
ncMetaAclMw(hookDelete, 'hookDelete') ncMetaAclMw(hookDelete, 'hookDelete')
); );
router.patch( router.patch(
'/api/v1/db/meta/hooks/:hookId', '/api/v1/db/meta/hooks/:hookId',
metaApiMetrics,
ncMetaAclMw(hookUpdate, 'hookUpdate') ncMetaAclMw(hookUpdate, 'hookUpdate')
); );
router.get( router.get(
'/api/v1/db/meta/tables/:tableId/hooks/samplePayload/:operation', '/api/v1/db/meta/tables/:tableId/hooks/samplePayload/:operation',
metaApiMetrics,
catchError(tableSampleData) catchError(tableSampleData)
); );
export default router; export default router;

12
packages/nocodb/src/lib/noco/meta/api/hookFilterApis.ts

@ -12,6 +12,7 @@ import Project from '../../../noco-models/Project';
import Filter from '../../../noco-models/Filter'; import Filter from '../../../noco-models/Filter';
import ncMetaAclMw from '../helpers/ncMetaAclMw'; import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { Tele } from 'nc-help'; import { Tele } from 'nc-help';
import { metaApiMetrics } from '../helpers/apiMetrics';
// @ts-ignore // @ts-ignore
export async function filterGet(req: Request, res: Response, next) { export async function filterGet(req: Request, res: Response, next) {
@ -108,25 +109,34 @@ export async function filterDelete(req: Request, res: Response, next) {
} }
const router = Router({ mergeParams: true }); const router = Router({ mergeParams: true });
router.get('/hooks/:hookId/filters/', ncMetaAclMw(filterList, 'filterList')); router.get(
'/hooks/:hookId/filters/',
metaApiMetrics,
ncMetaAclMw(filterList, 'filterList')
);
router.post( router.post(
'/hooks/:hookId/filters/', '/hooks/:hookId/filters/',
metaApiMetrics,
ncMetaAclMw(filterCreate, 'filterCreate') ncMetaAclMw(filterCreate, 'filterCreate')
); );
router.get( router.get(
'/hooks/:hookId/filters/:filterId', '/hooks/:hookId/filters/:filterId',
metaApiMetrics,
ncMetaAclMw(filterGet, 'filterGet') ncMetaAclMw(filterGet, 'filterGet')
); );
router.patch( router.patch(
'/hooks/:hookId/filters/:filterId', '/hooks/:hookId/filters/:filterId',
metaApiMetrics,
ncMetaAclMw(filterUpdate, 'filterUpdate') ncMetaAclMw(filterUpdate, 'filterUpdate')
); );
router.delete( router.delete(
'/hooks/:hookId/filters/:filterId', '/hooks/:hookId/filters/:filterId',
metaApiMetrics,
ncMetaAclMw(filterDelete, 'filterDelete') ncMetaAclMw(filterDelete, 'filterDelete')
); );
router.get( router.get(
'/hooks/:hookId/filters/:filterParentId/children', '/hooks/:hookId/filters/:filterParentId/children',
metaApiMetrics,
ncMetaAclMw(filterChildrenRead, 'filterChildrenRead') ncMetaAclMw(filterChildrenRead, 'filterChildrenRead')
); );
export default router; export default router;

3
packages/nocodb/src/lib/noco/meta/api/metaDiffApis.ts

@ -16,6 +16,7 @@ import getTableNameAlias, { getColumnNameAlias } from '../helpers/getTableName';
import mapDefaultPrimaryValue from '../helpers/mapDefaultPrimaryValue'; import mapDefaultPrimaryValue from '../helpers/mapDefaultPrimaryValue';
import { Tele } from 'nc-help'; import { Tele } from 'nc-help';
import getColumnUiType from '../helpers/getColumnUiType'; import getColumnUiType from '../helpers/getColumnUiType';
import { metaApiMetrics } from '../helpers/apiMetrics';
export enum MetaDiffType { export enum MetaDiffType {
TABLE_NEW = 'TABLE_NEW', TABLE_NEW = 'TABLE_NEW',
@ -849,10 +850,12 @@ export async function extractAndGenerateManyToManyRelations(
const router = Router(); const router = Router();
router.get( router.get(
'/api/v1/db/meta/projects/:projectId/meta-diff', '/api/v1/db/meta/projects/:projectId/meta-diff',
metaApiMetrics,
ncMetaAclMw(metaDiff, 'metaDiff') ncMetaAclMw(metaDiff, 'metaDiff')
); );
router.post( router.post(
'/api/v1/db/meta/projects/:projectId/meta-diff', '/api/v1/db/meta/projects/:projectId/meta-diff',
metaApiMetrics,
ncMetaAclMw(metaDiffSync, 'metaDiffSync') ncMetaAclMw(metaDiffSync, 'metaDiffSync')
); );
export default router; export default router;

3
packages/nocodb/src/lib/noco/meta/api/modelVisibilityApis.ts

@ -4,6 +4,7 @@ import { Router } from 'express';
import ncMetaAclMw from '../helpers/ncMetaAclMw'; import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { Tele } from 'nc-help'; import { Tele } from 'nc-help';
import Project from '../../../noco-models/Project'; import Project from '../../../noco-models/Project';
import { metaApiMetrics } from '../helpers/apiMetrics';
async function xcVisibilityMetaSetAll(req, res) { async function xcVisibilityMetaSetAll(req, res) {
Tele.emit('evt', { evt_type: 'uiAcl:updated' }); Tele.emit('evt', { evt_type: 'uiAcl:updated' });
for (const d of req.body) { for (const d of req.body) {
@ -108,6 +109,7 @@ export async function xcVisibilityMetaGet(
const router = Router({ mergeParams: true }); const router = Router({ mergeParams: true });
router.get( router.get(
'/api/v1/db/meta/projects/:projectId/visibility-rules', '/api/v1/db/meta/projects/:projectId/visibility-rules',
metaApiMetrics,
ncMetaAclMw(async (req, res) => { ncMetaAclMw(async (req, res) => {
res.json( res.json(
await xcVisibilityMetaGet( await xcVisibilityMetaGet(
@ -120,6 +122,7 @@ router.get(
); );
router.post( router.post(
'/api/v1/db/meta/projects/:projectId/visibility-rules', '/api/v1/db/meta/projects/:projectId/visibility-rules',
metaApiMetrics,
ncMetaAclMw(xcVisibilityMetaSetAll, 'modelVisibilitySet') ncMetaAclMw(xcVisibilityMetaSetAll, 'modelVisibilitySet')
); );
export default router; export default router;

11
packages/nocodb/src/lib/noco/meta/api/pluginApis.ts

@ -5,6 +5,7 @@ import { PluginType } from 'nocodb-sdk';
import NcPluginMgrv2 from '../helpers/NcPluginMgrv2'; import NcPluginMgrv2 from '../helpers/NcPluginMgrv2';
import ncMetaAclMw from '../helpers/ncMetaAclMw'; import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { Tele } from 'nc-help'; import { Tele } from 'nc-help';
import { metaApiMetrics } from '../helpers/apiMetrics';
export async function pluginList(_req: Request, res: Response) { export async function pluginList(_req: Request, res: Response) {
res.json(new PagedResponseImpl(await Plugin.list())); res.json(new PagedResponseImpl(await Plugin.list()));
@ -34,21 +35,29 @@ export async function isPluginActive(req: Request, res: Response) {
} }
const router = Router({ mergeParams: true }); const router = Router({ mergeParams: true });
router.get('/api/v1/db/meta/plugins', ncMetaAclMw(pluginList, 'pluginList')); router.get(
'/api/v1/db/meta/plugins',
metaApiMetrics,
ncMetaAclMw(pluginList, 'pluginList')
);
router.post( router.post(
'/api/v1/db/meta/plugins/test', '/api/v1/db/meta/plugins/test',
metaApiMetrics,
ncMetaAclMw(pluginTest, 'pluginTest') ncMetaAclMw(pluginTest, 'pluginTest')
); );
router.get( router.get(
'/api/v1/db/meta/plugins/:pluginId', '/api/v1/db/meta/plugins/:pluginId',
metaApiMetrics,
ncMetaAclMw(pluginRead, 'pluginRead') ncMetaAclMw(pluginRead, 'pluginRead')
); );
router.patch( router.patch(
'/api/v1/db/meta/plugins/:pluginId', '/api/v1/db/meta/plugins/:pluginId',
metaApiMetrics,
ncMetaAclMw(pluginUpdate, 'pluginUpdate') ncMetaAclMw(pluginUpdate, 'pluginUpdate')
); );
router.get( router.get(
'/api/v1/db/meta/plugins/:pluginTitle/status', '/api/v1/db/meta/plugins/:pluginTitle/status',
metaApiMetrics,
ncMetaAclMw(isPluginActive, 'isPluginActive') ncMetaAclMw(isPluginActive, 'isPluginActive')
); );
export default router; export default router;

6
packages/nocodb/src/lib/noco/meta/api/projectApis.ts

@ -22,6 +22,7 @@ import { NcError } from '../helpers/catchError';
import getColumnUiType from '../helpers/getColumnUiType'; import getColumnUiType from '../helpers/getColumnUiType';
import mapDefaultPrimaryValue from '../helpers/mapDefaultPrimaryValue'; import mapDefaultPrimaryValue from '../helpers/mapDefaultPrimaryValue';
import { extractAndGenerateManyToManyRelations } from './metaDiffApis'; import { extractAndGenerateManyToManyRelations } from './metaDiffApis';
import { metaApiMetrics } from '../helpers/apiMetrics';
const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 4); const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 4);
@ -392,22 +393,27 @@ export async function projectInfoGet(req, res) {
export default router => { export default router => {
router.get( router.get(
'/api/v1/db/meta/projects/:projectId/info', '/api/v1/db/meta/projects/:projectId/info',
metaApiMetrics,
ncMetaAclMw(projectInfoGet, 'projectInfoGet') ncMetaAclMw(projectInfoGet, 'projectInfoGet')
); );
router.get( router.get(
'/api/v1/db/meta/projects/:projectId', '/api/v1/db/meta/projects/:projectId',
metaApiMetrics,
ncMetaAclMw(projectGet, 'projectGet') ncMetaAclMw(projectGet, 'projectGet')
); );
router.delete( router.delete(
'/api/v1/db/meta/projects/:projectId', '/api/v1/db/meta/projects/:projectId',
metaApiMetrics,
ncMetaAclMw(projectDelete, 'projectDelete') ncMetaAclMw(projectDelete, 'projectDelete')
); );
router.post( router.post(
'/api/v1/db/meta/projects', '/api/v1/db/meta/projects',
metaApiMetrics,
ncMetaAclMw(projectCreate, 'projectCreate') ncMetaAclMw(projectCreate, 'projectCreate')
); );
router.get( router.get(
'/api/v1/db/meta/projects', '/api/v1/db/meta/projects',
metaApiMetrics,
ncMetaAclMw(projectList, 'projectList') ncMetaAclMw(projectList, 'projectList')
); );
}; };

6
packages/nocodb/src/lib/noco/meta/api/projectUserApis.ts

@ -14,6 +14,7 @@ import * as ejs from 'ejs';
import NcPluginMgrv2 from '../helpers/NcPluginMgrv2'; import NcPluginMgrv2 from '../helpers/NcPluginMgrv2';
import Noco from '../../Noco'; import Noco from '../../Noco';
import { PluginCategory } from 'nocodb-sdk'; import { PluginCategory } from 'nocodb-sdk';
import { metaApiMetrics } from '../helpers/apiMetrics';
async function userList(req, res) { async function userList(req, res) {
res.json({ res.json({
@ -297,22 +298,27 @@ async function sendInviteEmail(
const router = Router({ mergeParams: true }); const router = Router({ mergeParams: true });
router.get( router.get(
'/api/v1/db/meta/projects/:projectId/users', '/api/v1/db/meta/projects/:projectId/users',
metaApiMetrics,
ncMetaAclMw(userList, 'userList') ncMetaAclMw(userList, 'userList')
); );
router.post( router.post(
'/api/v1/db/meta/projects/:projectId/users', '/api/v1/db/meta/projects/:projectId/users',
metaApiMetrics,
ncMetaAclMw(userInvite, 'userInvite') ncMetaAclMw(userInvite, 'userInvite')
); );
router.patch( router.patch(
'/api/v1/db/meta/projects/:projectId/users/:userId', '/api/v1/db/meta/projects/:projectId/users/:userId',
metaApiMetrics,
ncMetaAclMw(projectUserUpdate, 'projectUserUpdate') ncMetaAclMw(projectUserUpdate, 'projectUserUpdate')
); );
router.delete( router.delete(
'/api/v1/db/meta/projects/:projectId/users/:userId', '/api/v1/db/meta/projects/:projectId/users/:userId',
metaApiMetrics,
ncMetaAclMw(projectUserDelete, 'projectUserDelete') ncMetaAclMw(projectUserDelete, 'projectUserDelete')
); );
router.post( router.post(
'/api/v1/db/meta/projects/:projectId/users/:userId/resend-invite', '/api/v1/db/meta/projects/:projectId/users/:userId/resend-invite',
metaApiMetrics,
ncMetaAclMw(projectUserInviteResend, 'projectUserInviteResend') ncMetaAclMw(projectUserInviteResend, 'projectUserInviteResend')
); );
export default router; export default router;

11
packages/nocodb/src/lib/noco/meta/api/sortApis.ts

@ -11,6 +11,7 @@ import Project from '../../../noco-models/Project';
import Sort from '../../../noco-models/Sort'; import Sort from '../../../noco-models/Sort';
import ncMetaAclMw from '../helpers/ncMetaAclMw'; import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { Tele } from 'nc-help'; import { Tele } from 'nc-help';
import { metaApiMetrics } from '../helpers/apiMetrics';
// @ts-ignore // @ts-ignore
export async function sortGet(req: Request, res: Response<TableType>) {} export async function sortGet(req: Request, res: Response<TableType>) {}
@ -51,19 +52,27 @@ export async function sortDelete(req: Request, res: Response) {
const router = Router({ mergeParams: true }); const router = Router({ mergeParams: true });
router.get( router.get(
'/api/v1/db/meta/views/:viewId/sorts/', '/api/v1/db/meta/views/:viewId/sorts/',
metaApiMetrics,
ncMetaAclMw(sortList, 'sortList') ncMetaAclMw(sortList, 'sortList')
); );
router.post( router.post(
'/api/v1/db/meta/views/:viewId/sorts/', '/api/v1/db/meta/views/:viewId/sorts/',
metaApiMetrics,
ncMetaAclMw(sortCreate, 'sortCreate') ncMetaAclMw(sortCreate, 'sortCreate')
); );
router.get('/api/v1/db/meta/sorts/:sortId', ncMetaAclMw(sortGet, 'sortGet')); router.get(
'/api/v1/db/meta/sorts/:sortId',
metaApiMetrics,
ncMetaAclMw(sortGet, 'sortGet')
);
router.patch( router.patch(
'/api/v1/db/meta/sorts/:sortId', '/api/v1/db/meta/sorts/:sortId',
metaApiMetrics,
ncMetaAclMw(sortUpdate, 'sortUpdate') ncMetaAclMw(sortUpdate, 'sortUpdate')
); );
router.delete( router.delete(
'/api/v1/db/meta/sorts/:sortId', '/api/v1/db/meta/sorts/:sortId',
metaApiMetrics,
ncMetaAclMw(sortDelete, 'sortDelete') ncMetaAclMw(sortDelete, 'sortDelete')
); );
export default router; export default router;

7
packages/nocodb/src/lib/noco/meta/api/tableApis.ts

@ -26,6 +26,7 @@ import Column from '../../../noco-models/Column';
import NcConnectionMgrv2 from '../../common/NcConnectionMgrv2'; import NcConnectionMgrv2 from '../../common/NcConnectionMgrv2';
import getColumnUiType from '../helpers/getColumnUiType'; import getColumnUiType from '../helpers/getColumnUiType';
import LinkToAnotherRecordColumn from '../../../noco-models/LinkToAnotherRecordColumn'; import LinkToAnotherRecordColumn from '../../../noco-models/LinkToAnotherRecordColumn';
import { metaApiMetrics } from '../helpers/apiMetrics';
export async function tableGet(req: Request, res: Response<TableType>) { export async function tableGet(req: Request, res: Response<TableType>) {
const table = await Model.getWithInfo({ const table = await Model.getWithInfo({
id: req.params.tableId id: req.params.tableId
@ -264,26 +265,32 @@ export async function tableDelete(req: Request, res: Response) {
const router = Router({ mergeParams: true }); const router = Router({ mergeParams: true });
router.get( router.get(
'/api/v1/db/meta/projects/:projectId/tables', '/api/v1/db/meta/projects/:projectId/tables',
metaApiMetrics,
ncMetaAclMw(tableList, 'tableList') ncMetaAclMw(tableList, 'tableList')
); );
router.post( router.post(
'/api/v1/db/meta/projects/:projectId/tables', '/api/v1/db/meta/projects/:projectId/tables',
metaApiMetrics,
ncMetaAclMw(tableCreate, 'tableCreate') ncMetaAclMw(tableCreate, 'tableCreate')
); );
router.get( router.get(
'/api/v1/db/meta/tables/:tableId', '/api/v1/db/meta/tables/:tableId',
metaApiMetrics,
ncMetaAclMw(tableGet, 'tableGet') ncMetaAclMw(tableGet, 'tableGet')
); );
router.patch( router.patch(
'/api/v1/db/meta/tables/:tableId', '/api/v1/db/meta/tables/:tableId',
metaApiMetrics,
ncMetaAclMw(tableUpdate, 'tableUpdate') ncMetaAclMw(tableUpdate, 'tableUpdate')
); );
router.delete( router.delete(
'/api/v1/db/meta/tables/:tableId', '/api/v1/db/meta/tables/:tableId',
metaApiMetrics,
ncMetaAclMw(tableDelete, 'tableDelete') ncMetaAclMw(tableDelete, 'tableDelete')
); );
router.post( router.post(
'/api/v1/db/meta/tables/:tableId/reorder', '/api/v1/db/meta/tables/:tableId/reorder',
metaApiMetrics,
ncMetaAclMw(tableReorder, 'tableReorder') ncMetaAclMw(tableReorder, 'tableReorder')
); );
export default router; export default router;

9
packages/nocodb/src/lib/noco/meta/api/viewApis.ts

@ -13,6 +13,7 @@ import View from '../../../noco-models/View';
import ncMetaAclMw from '../helpers/ncMetaAclMw'; import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { xcVisibilityMetaGet } from './modelVisibilityApis'; import { xcVisibilityMetaGet } from './modelVisibilityApis';
import { Tele } from 'nc-help'; import { Tele } from 'nc-help';
import { metaApiMetrics } from '../helpers/apiMetrics';
// @ts-ignore // @ts-ignore
export async function viewGet(req: Request, res: Response<Table>) {} export async function viewGet(req: Request, res: Response<Table>) {}
@ -103,27 +104,33 @@ async function shareViewList(req: Request<any, any>, res) {
const router = Router({ mergeParams: true }); const router = Router({ mergeParams: true });
router.get( router.get(
'/api/v1/db/meta/tables/:tableId/views', '/api/v1/db/meta/tables/:tableId/views',
metaApiMetrics,
ncMetaAclMw(viewList, 'viewList') ncMetaAclMw(viewList, 'viewList')
); );
router.patch( router.patch(
'/api/v1/db/meta/views/:viewId', '/api/v1/db/meta/views/:viewId',
metaApiMetrics,
ncMetaAclMw(viewUpdate, 'viewUpdate') ncMetaAclMw(viewUpdate, 'viewUpdate')
); );
router.delete( router.delete(
'/api/v1/db/meta/views/:viewId', '/api/v1/db/meta/views/:viewId',
metaApiMetrics,
ncMetaAclMw(viewDelete, 'viewDelete') ncMetaAclMw(viewDelete, 'viewDelete')
); );
router.post( router.post(
'/api/v1/db/meta/views/:viewId/show-all', '/api/v1/db/meta/views/:viewId/show-all',
metaApiMetrics,
ncMetaAclMw(showAllColumns, 'showAllColumns') ncMetaAclMw(showAllColumns, 'showAllColumns')
); );
router.post( router.post(
'/api/v1/db/meta/views/:viewId/hide-all', '/api/v1/db/meta/views/:viewId/hide-all',
metaApiMetrics,
ncMetaAclMw(hideAllColumns, 'hideAllColumns') ncMetaAclMw(hideAllColumns, 'hideAllColumns')
); );
router.get( router.get(
'/api/v1/db/meta/tables/:tableId/share', '/api/v1/db/meta/tables/:tableId/share',
metaApiMetrics,
ncMetaAclMw(shareViewList, 'shareViewList') ncMetaAclMw(shareViewList, 'shareViewList')
); );
router.post( router.post(
@ -132,10 +139,12 @@ router.post(
); );
router.patch( router.patch(
'/api/v1/db/meta/views/:viewId/share', '/api/v1/db/meta/views/:viewId/share',
metaApiMetrics,
ncMetaAclMw(shareViewPasswordUpdate, 'shareViewPasswordUpdate') ncMetaAclMw(shareViewPasswordUpdate, 'shareViewPasswordUpdate')
); );
router.delete( router.delete(
'/api/v1/db/meta/views/:viewId/share', '/api/v1/db/meta/views/:viewId/share',
metaApiMetrics,
ncMetaAclMw(shareViewDelete, 'shareViewDelete') ncMetaAclMw(shareViewDelete, 'shareViewDelete')
); );

4
packages/nocodb/src/lib/noco/meta/api/viewColumnApis.ts

@ -2,6 +2,7 @@ import { Request, Response, Router } from 'express';
import View from '../../../noco-models/View'; import View from '../../../noco-models/View';
import ncMetaAclMw from '../helpers/ncMetaAclMw'; import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { Tele } from 'nc-help'; import { Tele } from 'nc-help';
import { metaApiMetrics } from '../helpers/apiMetrics';
export async function columnList(req: Request, res: Response) { export async function columnList(req: Request, res: Response) {
res.json(await View.getColumns(req.params.viewId)); res.json(await View.getColumns(req.params.viewId));
@ -33,14 +34,17 @@ export async function columnUpdate(req: Request, res: Response) {
const router = Router({ mergeParams: true }); const router = Router({ mergeParams: true });
router.get( router.get(
'/api/v1/db/meta/views/:viewId/columns/', '/api/v1/db/meta/views/:viewId/columns/',
metaApiMetrics,
ncMetaAclMw(columnList, 'columnList') ncMetaAclMw(columnList, 'columnList')
); );
router.post( router.post(
'/api/v1/db/meta/views/:viewId/columns/', '/api/v1/db/meta/views/:viewId/columns/',
metaApiMetrics,
ncMetaAclMw(columnAdd, 'columnAdd') ncMetaAclMw(columnAdd, 'columnAdd')
); );
router.patch( router.patch(
'/api/v1/db/meta/views/:viewId/columns/:columnId', '/api/v1/db/meta/views/:viewId/columns/:columnId',
metaApiMetrics,
ncMetaAclMw(columnUpdate, 'viewColumnUpdate') ncMetaAclMw(columnUpdate, 'viewColumnUpdate')
); );
export default router; export default router;

12
packages/nocodb/src/lib/noco/meta/helpers/apiMetrics.ts

@ -3,17 +3,23 @@ import { Tele } from 'nc-help';
const countMap = {}; const countMap = {};
const metrics = async (req: Request) => { const metrics = async (req: Request, c = 50) => {
if (!req?.route?.path) return; if (!req?.route?.path) return;
const event = `a:api:${req.route.path}:${req.method}`; const event = `a:api:${req.route.path}:${req.method}`;
countMap[event] = (countMap[event] || 0) + 1; countMap[event] = (countMap[event] || 0) + 1;
if (countMap[event] >= 50) { if (countMap[event] >= c) {
Tele.event({ event }); Tele.event({ event });
countMap[event] = 0; countMap[event] = 0;
} }
}; };
export default async (req: Request, _res, next) => { const metaApiMetrics = (req: Request, _res, next) => {
metrics(req, 10).then(() => {});
next();
};
export default (req: Request, _res, next) => {
metrics(req).then(() => {}); metrics(req).then(() => {});
next(); next();
}; };
export { metaApiMetrics };

Loading…
Cancel
Save