Browse Source

fix(nocodb): move custom url to ee

Ramesh Mane 4 days ago
parent
commit
81aa1e3ad1
  1. 38
      packages/nocodb/src/controllers/custom-urls.controller.ts
  2. 4
      packages/nocodb/src/meta/migrations/XcMigrationSourcev2.ts
  3. 44
      packages/nocodb/src/meta/migrations/v2/nc_068_custom_url.ts
  4. 133
      packages/nocodb/src/models/CustomUrl.ts
  5. 6
      packages/nocodb/src/modules/noco.module.ts
  6. 87
      packages/nocodb/src/schema/swagger-v2.json
  7. 17
      packages/nocodb/src/services/custom-urls.service.ts

38
packages/nocodb/src/controllers/custom-urls.controller.ts

@ -1,38 +0,0 @@
import {
Body,
Controller,
Get,
HttpCode,
Param,
Post,
UseGuards,
} from '@nestjs/common';
import { GlobalGuard } from '~/guards/global/global.guard';
import { MetaApiLimiterGuard } from '~/guards/meta-api-limiter.guard';
import { CustomUrlsService } from 'src/services/custom-urls.service';
@Controller()
@UseGuards(MetaApiLimiterGuard, GlobalGuard)
export class CustomUrlsController {
constructor(protected readonly customUrlsService: CustomUrlsService) {}
@Get([
'/api/v1/db/meta/custom-url/:customPath',
'/api/v2/meta/custom-url/:customPath',
])
async getOriginalPath(@Param('customPath') customPath: string) {
return await this.customUrlsService.getOriginalPath(customPath);
}
@Post(['/api/v1/db/meta/custom-url/check-path', '/api/v2/meta/check-path'])
@HttpCode(200)
async checkAvailability(
@Body()
body: {
id?: string;
custom_path?: string;
},
) {
return await this.customUrlsService.checkAvailability(body);
}
}

4
packages/nocodb/src/meta/migrations/XcMigrationSourcev2.ts

@ -55,7 +55,6 @@ import * as nc_065_encrypt_flag from '~/meta/migrations/v2/nc_065_encrypt_flag';
import * as nc_066_ai_button from '~/meta/migrations/v2/nc_066_ai_button';
import * as nc_067_personal_view from '~/meta/migrations/v2/nc_067_personal_view';
import * as nc_068_user_delete from '~/meta/migrations/v2/nc_068_user_delete';
import * as nc_068_custom_url from '~/meta/migrations/v2/nc_068_custom_url';
// Create a custom migration source class
export default class XcMigrationSourcev2 {
@ -122,7 +121,6 @@ export default class XcMigrationSourcev2 {
'nc_066_ai_button',
'nc_067_personal_view',
'nc_068_user_delete',
'nc_068_custom_url',
]);
}
@ -246,8 +244,6 @@ export default class XcMigrationSourcev2 {
return nc_067_personal_view;
case 'nc_068_user_delete':
return nc_068_user_delete;
case 'nc_068_custom_url':
return nc_068_custom_url;
}
}
}

44
packages/nocodb/src/meta/migrations/v2/nc_068_custom_url.ts

@ -1,44 +0,0 @@
import type { Knex } from 'knex';
import { MetaTable } from '~/utils/globals';
const up = async (knex: Knex) => {
await knex.schema.createTable(MetaTable.CUSTOM_URLS, (table) => {
table.string('id', 20);
table.string('fk_workspace_id', 20);
table.string('base_id', 20);
table.string('fk_model_id', 20);
table.string('view_id', 20);
table.string('original_path');
table.string('custom_path');
table.timestamps(true, true);
});
await knex.schema.alterTable(MetaTable.PROJECT, (table) => {
table.string('fk_custom_url_id', 20).index();
});
await knex.schema.alterTable(MetaTable.VIEWS, (table) => {
table.string('fk_custom_url_id', 20).index();
});
};
const down = async (knex: Knex) => {
await knex.schema.dropTable(MetaTable.CUSTOM_URLS);
await knex.schema.alterTable(MetaTable.PROJECT, (table) => {
table.dropColumn('fk_custom_url_id');
});
await knex.schema.alterTable(MetaTable.VIEWS, (table) => {
table.dropColumn('fk_custom_url_id');
});
};
export { up, down };

133
packages/nocodb/src/models/CustomUrl.ts

@ -1,13 +1,4 @@
import Noco from '~/Noco';
import { extractProps } from '~/helpers/extractProps';
import {
CacheGetType,
CacheScope,
MetaTable,
RootScopes,
} from '~/utils/globals';
import NocoCache from '~/cache/NocoCache';
import { NcError } from 'src/helpers/catchError';
export default class CustomUrl {
id?: string;
@ -26,153 +17,43 @@ export default class CustomUrl {
params: Pick<CustomUrl, 'id' | 'view_id' | 'custom_path'>,
ncMeta = Noco.ncMeta,
) {
const condition = extractProps(params, ['id', 'view_id', 'custom_path']);
const customUrl = await ncMeta.metaGet2(
RootScopes.ROOT,
RootScopes.ROOT,
MetaTable.CUSTOM_URLS,
condition,
);
return customUrl && new CustomUrl(customUrl);
return {} as CustomUrl;
}
public static async getOriginUrlByCustomPath(
customPath: string,
ncMeta = Noco.ncMeta,
) {
let customUrl = await NocoCache.get(
`${CacheScope.CUSTOM_URLS}:${customPath}`,
CacheGetType.TYPE_OBJECT,
);
if (!customUrl) {
customUrl = await ncMeta.metaGet2(
RootScopes.ROOT,
RootScopes.ROOT,
MetaTable.CUSTOM_URLS,
{
custom_path: customPath,
},
);
if (customUrl) {
NocoCache.set(`${CacheScope.CUSTOM_URLS}:${customPath}`, customUrl);
}
}
if (!customUrl) {
NcError.notFound();
}
return customUrl?.original_path;
return '';
}
public static async insert(
customUrl: Partial<CustomUrl>,
ncMeta = Noco.ncMeta,
) {
const insertData = extractProps(customUrl, [
'fk_workspace_id',
'base_id',
'fk_model_id',
'view_id',
'original_path',
'custom_path',
]);
const insertedCustomUrl = await ncMeta.metaInsert2(
RootScopes.ROOT,
RootScopes.ROOT,
MetaTable.CUSTOM_URLS,
insertData,
);
return insertedCustomUrl && new CustomUrl(insertedCustomUrl);
return {} as CustomUrl;
}
public static async list(
params: Pick<CustomUrl, 'fk_workspace_id' | 'base_id' | 'fk_model_id'>,
ncMeta = Noco.ncMeta,
) {
const condition = extractProps(params, [
'fk_workspace_id',
'base_id',
'fk_model_id',
]);
const customUrlList = await ncMeta.metaList2(
RootScopes.ROOT,
RootScopes.ROOT,
MetaTable.CUSTOM_URLS,
{
condition,
},
);
return customUrlList.map((customUrl) => new CustomUrl(customUrl));
return [] as CustomUrl[];
}
public static async update(
id: string,
customUrl: Partial<CustomUrl>,
ncMeta = Noco.ncMeta,
) {
const updateData = extractProps(customUrl, [
'original_path',
'custom_path',
]);
return await ncMeta.metaUpdate(
RootScopes.ROOT,
RootScopes.ROOT,
MetaTable.CUSTOM_URLS,
updateData,
id,
);
}
) {}
public static async checkAvailability(
params: Pick<CustomUrl, 'id' | 'custom_path'>,
ncMeta = Noco.ncMeta,
) {
const condition = extractProps(params, ['custom_path']);
const customUrlList = await ncMeta.metaList2(
RootScopes.ROOT,
RootScopes.ROOT,
MetaTable.CUSTOM_URLS,
{
condition,
xcCondition: params.id
? {
_not: {
id: {
neq: params.id,
},
},
}
: null,
},
);
return !!customUrlList.length;
}
) {}
static async delete(
customUrl: Pick<CustomUrl, 'id' | 'view_id'>,
ncMeta = Noco.ncMeta,
) {
const condition = extractProps(customUrl, ['id', 'view_id']);
const res = await ncMeta.metaDelete(
RootScopes.ROOT,
RootScopes.ROOT,
MetaTable.CUSTOM_URLS,
condition,
);
return res;
}
) {}
}

6
packages/nocodb/src/modules/noco.module.ts

@ -16,8 +16,6 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { TelemetryService } from '~/services/telemetry.service';
import { AppHooksListenerService } from '~/services/app-hooks-listener.service';
import { HookHandlerService } from '~/services/hook-handler.service';
import { CustomUrlsController } from '~/controllers/custom-urls.controller';
import { CustomUrlsService } from '~/services/custom-urls.service';
/* User */
import { UsersController } from '~/controllers/users/users.controller';
@ -147,8 +145,6 @@ export const nocoModuleMetadata = {
controllers: [
...(process.env.NC_WORKER_CONTAINER !== 'true'
? [
CustomUrlsController,
/* Users */
UsersController,
@ -219,7 +215,6 @@ export const nocoModuleMetadata = {
AppHooksListenerService,
TelemetryService,
HookHandlerService,
CustomUrlsService,
/* Users */
UsersService,
@ -282,7 +277,6 @@ export const nocoModuleMetadata = {
TelemetryService,
HookHandlerService,
JwtStrategy,
CustomUrlsService,
/* Users */
UsersService,

87
packages/nocodb/src/schema/swagger-v2.json

@ -12970,93 +12970,6 @@
"$ref": "#/components/parameters/xc-token"
}
]
},
"/api/v2/meta/custom-url/{customPath}": {
"get": {
"summary": "Get original path from custom url path",
"operationId": "get-original-path",
"description": "Get original path from custom url path",
"tags": [
"CustomUrl", "Internal"
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {},
"examples": {
"Example 1": {
"value": "nc/form/957b3e5b-c7fe-4805-bdb2-e4048e974f62"
}
}
}
}
},
"400": {
"$ref": "#/components/responses/BadRequest"
}
}
},
"parameters": [
{
"schema": {
"type": "string"
},
"name": "customPath",
"in": "path",
"required": true,
"description": "Custom url path"
},
{
"$ref": "#/components/parameters/xc-token"
}
]
},
"/api/v2/meta/custom-url/check-path": {
"get": {
"summary": "Check custom url path availability",
"operationId": "check-availability",
"description": "Check custom url path availability",
"tags": [
"CustomUrl", "Internal"
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"status": {
"custom_path": "string"
}
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {},
"examples": {
"Example 1": {
"value": true
}
}
}
}
},
"400": {
"$ref": "#/components/responses/BadRequest"
}
}
}
}
},
"components": {

17
packages/nocodb/src/services/custom-urls.service.ts

@ -1,17 +0,0 @@
import { Injectable } from '@nestjs/common';
import type { NcContext } from '~/interface/config';
import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import CustomUrl from 'src/models/CustomUrl';
@Injectable()
export class CustomUrlsService {
constructor(private readonly appHooksService: AppHooksService) {}
async checkAvailability(params: Pick<CustomUrl, 'id' | 'custom_path'>) {
return await CustomUrl.checkAvailability(params);
}
async getOriginalPath(custom_path: string) {
return await CustomUrl.getOriginUrlByCustomPath(custom_path);
}
}
Loading…
Cancel
Save