|
|
@ -437,9 +437,9 @@ export default class NcMetaMgr { |
|
|
|
await this.xcMetaTablesReset(args); |
|
|
|
await this.xcMetaTablesReset(args); |
|
|
|
|
|
|
|
|
|
|
|
for (const tn of META_TABLES[this.config.projectType.toLowerCase()]) { |
|
|
|
for (const tn of META_TABLES[this.config.projectType.toLowerCase()]) { |
|
|
|
if (fs.existsSync(path.join(metaFolder, `${tn}.json`))) { |
|
|
|
if (await promisify(fs.exists)(path.join(metaFolder, `${tn}.json`))) { |
|
|
|
const data = JSON.parse( |
|
|
|
const data = JSON.parse( |
|
|
|
fs.readFileSync(path.join(metaFolder, `${tn}.json`), 'utf8') |
|
|
|
await promisify(fs.readFile)(path.join(metaFolder, `${tn}.json`), 'utf8') |
|
|
|
); |
|
|
|
); |
|
|
|
for (const row of data) { |
|
|
|
for (const row of data) { |
|
|
|
delete row.id; |
|
|
|
delete row.id; |
|
|
@ -488,14 +488,14 @@ export default class NcMetaMgr { |
|
|
|
}, |
|
|
|
}, |
|
|
|
}); |
|
|
|
}); |
|
|
|
// delete temporary upload file
|
|
|
|
// delete temporary upload file
|
|
|
|
fs.unlinkSync(file.path); |
|
|
|
await promisify(fs.unlink)(file.path); |
|
|
|
|
|
|
|
|
|
|
|
let projectId = this.getProjectId(args); |
|
|
|
let projectId = this.getProjectId(args); |
|
|
|
if (!projectConfigPath) { |
|
|
|
if (!projectConfigPath) { |
|
|
|
throw new Error('Missing project config file'); |
|
|
|
throw new Error('Missing project config file'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const projectDetailsJSON: any = fs.readFileSync( |
|
|
|
const projectDetailsJSON: any = await promisify(fs.readFile)( |
|
|
|
path.join(this.config.toolDir, 'uploads', projectConfigPath), |
|
|
|
path.join(this.config.toolDir, 'uploads', projectConfigPath), |
|
|
|
'utf8' |
|
|
|
'utf8' |
|
|
|
); |
|
|
|
); |
|
|
@ -519,7 +519,7 @@ export default class NcMetaMgr { |
|
|
|
|
|
|
|
|
|
|
|
if (projectConfig?.prefix) { |
|
|
|
if (projectConfig?.prefix) { |
|
|
|
const metaProjConfig = |
|
|
|
const metaProjConfig = |
|
|
|
NcConfigFactory.makeProjectConfigFromConnection( |
|
|
|
await NcConfigFactory.makeProjectConfigFromConnection( |
|
|
|
this.config?.meta?.db, |
|
|
|
this.config?.meta?.db, |
|
|
|
args.args.projectType |
|
|
|
args.args.projectType |
|
|
|
); |
|
|
|
); |
|
|
@ -614,11 +614,11 @@ export default class NcMetaMgr { |
|
|
|
}, |
|
|
|
}, |
|
|
|
}); |
|
|
|
}); |
|
|
|
// delete temporary upload file
|
|
|
|
// delete temporary upload file
|
|
|
|
fs.unlinkSync(file.path); |
|
|
|
await promisify(fs.unlink)(file.path); |
|
|
|
|
|
|
|
|
|
|
|
if (projectConfigPath) { |
|
|
|
if (projectConfigPath) { |
|
|
|
// read project config and extract project id
|
|
|
|
// read project config and extract project id
|
|
|
|
let projectConfig: any = fs.readFileSync( |
|
|
|
let projectConfig: any = await promisify(fs.readFile)( |
|
|
|
path.join(this.config?.toolDir, projectConfigPath), |
|
|
|
path.join(this.config?.toolDir, projectConfigPath), |
|
|
|
'utf8' |
|
|
|
'utf8' |
|
|
|
); |
|
|
|
); |
|
|
@ -702,14 +702,14 @@ export default class NcMetaMgr { |
|
|
|
'meta' |
|
|
|
'meta' |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
mkdirp.sync(metaFolder); |
|
|
|
await mkdirp(metaFolder); |
|
|
|
|
|
|
|
|
|
|
|
// const client = await this.projectGetSqlClient(args);
|
|
|
|
// const client = await this.projectGetSqlClient(args);
|
|
|
|
const dbAlias = this.getDbAlias(args); |
|
|
|
const dbAlias = this.getDbAlias(args); |
|
|
|
for (const tn of META_TABLES[this.config.projectType.toLowerCase()]) { |
|
|
|
for (const tn of META_TABLES[this.config.projectType.toLowerCase()]) { |
|
|
|
// const metaData = await client.knex(tn).select();
|
|
|
|
// const metaData = await client.knex(tn).select();
|
|
|
|
const metaData = await this.xcMeta.metaList(projectId, dbAlias, tn); |
|
|
|
const metaData = await this.xcMeta.metaList(projectId, dbAlias, tn); |
|
|
|
fs.writeFileSync( |
|
|
|
await promisify(fs.writeFile)( |
|
|
|
path.join(metaFolder, `${tn}.json`), |
|
|
|
path.join(metaFolder, `${tn}.json`), |
|
|
|
JSON.stringify(metaData, null, 2) |
|
|
|
JSON.stringify(metaData, null, 2) |
|
|
|
); |
|
|
|
); |
|
|
@ -720,7 +720,7 @@ export default class NcMetaMgr { |
|
|
|
true |
|
|
|
true |
|
|
|
); |
|
|
|
); |
|
|
|
projectMetaData.key = this.config?.auth?.jwt?.secret; |
|
|
|
projectMetaData.key = this.config?.auth?.jwt?.secret; |
|
|
|
fs.writeFileSync( |
|
|
|
await promisify(fs.writeFile)( |
|
|
|
path.join(metaFolder, `nc_project.json`), |
|
|
|
path.join(metaFolder, `nc_project.json`), |
|
|
|
JSON.stringify(projectMetaData, null, 2) |
|
|
|
JSON.stringify(projectMetaData, null, 2) |
|
|
|
); |
|
|
|
); |
|
|
@ -1551,7 +1551,7 @@ export default class NcMetaMgr { |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'testConnection': |
|
|
|
case 'testConnection': |
|
|
|
result = await SqlClientFactory.create(args.args).testConnection(); |
|
|
|
result = await (await SqlClientFactory.create(args.args)).testConnection(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'xcProjectGetConfig': |
|
|
|
case 'xcProjectGetConfig': |
|
|
|
result = await this.xcMeta.projectGetById(this.getProjectId(args)); |
|
|
|
result = await this.xcMeta.projectGetById(this.getProjectId(args)); |
|
|
@ -1602,7 +1602,7 @@ export default class NcMetaMgr { |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'projectCreateByOneClick': |
|
|
|
case 'projectCreateByOneClick': |
|
|
|
{ |
|
|
|
{ |
|
|
|
const config = NcConfigFactory.makeProjectConfigFromUrl( |
|
|
|
const config = await NcConfigFactory.makeProjectConfigFromUrl( |
|
|
|
process.env.NC_DB, |
|
|
|
process.env.NC_DB, |
|
|
|
args.args.projectType |
|
|
|
args.args.projectType |
|
|
|
); |
|
|
|
); |
|
|
@ -1635,7 +1635,7 @@ export default class NcMetaMgr { |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'projectCreateByWebWithXCDB': { |
|
|
|
case 'projectCreateByWebWithXCDB': { |
|
|
|
await this.checkIsUserAllowedToCreateProject(req); |
|
|
|
await this.checkIsUserAllowedToCreateProject(req); |
|
|
|
const config = NcConfigFactory.makeProjectConfigFromConnection( |
|
|
|
const config = await NcConfigFactory.makeProjectConfigFromConnection( |
|
|
|
this.config?.meta?.db, |
|
|
|
this.config?.meta?.db, |
|
|
|
args.args.projectType |
|
|
|
args.args.projectType |
|
|
|
); |
|
|
|
); |
|
|
@ -2904,7 +2904,7 @@ export default class NcMetaMgr { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected projectGetSqlClient(args) { |
|
|
|
protected async projectGetSqlClient(args): Promise<any> { |
|
|
|
const builder = this.getBuilder(args); |
|
|
|
const builder = this.getBuilder(args); |
|
|
|
return builder?.getSqlClient(); |
|
|
|
return builder?.getSqlClient(); |
|
|
|
} |
|
|
|
} |
|
|
@ -3440,7 +3440,7 @@ export default class NcMetaMgr { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
protected getSqlClient(project_id: string, dbAlias: string) { |
|
|
|
protected async getSqlClient(project_id: string, dbAlias: string) { |
|
|
|
return this.app?.projectBuilders |
|
|
|
return this.app?.projectBuilders |
|
|
|
?.find((pb) => pb?.id === project_id) |
|
|
|
?.find((pb) => pb?.id === project_id) |
|
|
|
?.apiBuilders?.find((builder) => builder.dbAlias === dbAlias) |
|
|
|
?.apiBuilders?.find((builder) => builder.dbAlias === dbAlias) |
|
|
@ -4250,7 +4250,7 @@ export default class NcMetaMgr { |
|
|
|
return { data: { list: columns } }; |
|
|
|
return { data: { list: columns } }; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return this.projectGetSqlClient(args).columnList(args.args); |
|
|
|
return (await this.projectGetSqlClient(args)).columnList(args.args); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
throw e; |
|
|
|
throw e; |
|
|
|
} |
|
|
|
} |
|
|
@ -4595,7 +4595,7 @@ export default class NcMetaMgr { |
|
|
|
{} |
|
|
|
{} |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const sqlClient = this.projectGetSqlClient(args); |
|
|
|
const sqlClient = await this.projectGetSqlClient(args); |
|
|
|
|
|
|
|
|
|
|
|
switch (args.args.type) { |
|
|
|
switch (args.args.type) { |
|
|
|
case 'table': |
|
|
|
case 'table': |
|
|
|