add importer

dev
Bosn 7 years ago
parent 59485dc09d
commit 25e5c430eb

@ -49,6 +49,8 @@
"path-to-regexp": "^2.1.0",
"redis": "^2.8.0",
"reflect-metadata": "^0.1.10",
"request": "^2.85.0",
"request-promise": "^4.2.2",
"sequelize": "^4.28.6",
"sequelize-typescript": "^0.6.4",
"svg-captcha": "^1.3.11",
@ -70,6 +72,8 @@
"@types/mockjs": "^1.0.0",
"@types/node": "^8.5.2",
"@types/redis": "^2.8.6",
"@types/request": "^2.47.0",
"@types/request-promise": "^4.1.41",
"@types/sequelize": "^4.27.12",
"@types/underscore": "^1.8.8",
"babel-eslint": "^7.2.3",

@ -5,9 +5,10 @@ import Pagination from './utils/pagination'
import { User, Organization, Repository, Module, Interface, Property, QueryInclude, Logger } from '../models'
import { Sequelize } from 'sequelize-typescript'
import Tree from './utils/tree'
import { AccessUtils, ACCESS_TYPE } from './utils/access';
import { AccessUtils, ACCESS_TYPE } from './utils/access'
import * as Consts from './utils/const'
import RedisService, { CACHE_KEY } from '../service/redis'
import MigrateService from '../service/migrate';
const { initRepository, initModule } = require('./utils/helper')
const Op = Sequelize.Op
@ -760,3 +761,22 @@ router.get('/property/remove', async (ctx) => {
}),
}
})
router.post('/repository/import', async (ctx) => {
if (!ctx.session || !ctx.session.id) {
ctx.body = {
isOk: false,
message: 'NOT LOGIN'
}
return
}
const { docUrl, orgId } = ctx.request.body
const result = await MigrateService.importRepoFromRAP1DocUrl(orgId, ctx.session.id, docUrl)
ctx.body = {
isOk: result,
message: result ? '导入成功' : '导入失败',
repository: {
id: 1,
}
}
})

@ -2,6 +2,8 @@ import { Repository, Module, Interface, Property, User } from "../models";
import { SCOPES, TYPES } from "../models/bo/property";
import * as md5 from 'md5'
const isMd5 = require('is-md5')
import * as querystring from 'querystring'
import * as rp from 'request-promise'
export default class MigrateService {
public static async importRepoFromRAP1ProjectData(orgId: number, curUserId: number, projectData: any): Promise<boolean> {
@ -46,9 +48,9 @@ export default class MigrateService {
async function processParam(p: any, scope: SCOPES, parentId?: number) {
const pCreated = await Property.create({
scope,
name: p.name,
name: p.identifier,
type: getTypeFromRAP1DataType(p.dataType),
description: `${p.remark}`,
description: `${p.remark}${p.name ? ', ' + p.name : ''}`,
priority: pCounter++,
interfaceId: itf.id,
creatorId: curUserId,
@ -85,6 +87,21 @@ export default class MigrateService {
}
}
}
public static async importRepoFromRAP1DocUrl(orgId: number, curUserId: number, docUrl: string): Promise<boolean> {
const { projectId } = querystring.parse(docUrl.substring(docUrl.indexOf('?') + 1))
let domain = docUrl
if (domain.indexOf('http') === -1) {
domain = 'http://' + domain
}
domain = domain.substring(0, domain.indexOf('/', domain.indexOf('.')))
const result = await rp(`${domain}/api/queryRAPModel.do?projectId=${projectId}`, {
json: true,
})
let json = result.modelJSON
const projectData = JSON.parse(json)
return await this.importRepoFromRAP1ProjectData(orgId, curUserId, projectData)
}
}
function getMethodFromRAP1RequestType(type: number) {

Loading…
Cancel
Save