pull/712/head
huoyong.msb 5 years ago
parent 12ee098a63
commit 0c0be4ad93

@ -18,6 +18,7 @@ import nanoid = require('nanoid')
import { LOG_SEPERATOR, LOG_SUB_SEPERATOR } from '../models/bo/historyLog'
import { ENTITY_TYPE } from './utils/const'
import { IPager } from '../types'
import * as JSON5 from 'json5'
router.get('/app/get', async (ctx, next) => {
let data: any = {}
@ -1115,13 +1116,22 @@ router.post('/repository/import', isLoggedIn, async (ctx) => {
ctx.body = Consts.COMMON_ERROR_RES.ACCESS_DENY
return
}
const result = await MigrateService.importRepoFromRAP1DocUrl(orgId, ctx.session.id, docUrl, +version, projectData)
ctx.body = {
isOk: result,
message: result ? '导入成功' : '导入失败',
repository: {
id: 1,
let success = false
let message = ''
try {
if (+version === 3) {
await MigrateService.importRepoFromJSON(JSON5.parse(projectData).data, ctx.session.id, true, orgId)
success = true
} else {
success = await MigrateService.importRepoFromRAP1DocUrl(orgId, ctx.session.id, docUrl, +version, projectData)
}
} catch (ex) {
success = false
message = ex.message
}
ctx.body = {
isOk: success,
message: success ? '导入成功' : `导入失败:${message}`,
}
})

@ -29,18 +29,6 @@ export class AccessUtils {
if (inTestMode) {
return true
}
// 内网全可读
const {
ORGANIZATION_GET,
REPOSITORY_GET,
MODULE_GET,
INTERFACE_GET,
PROPERTY_GET,
} = ACCESS_TYPE
const GET_TYPES = [ORGANIZATION_GET, REPOSITORY_GET, MODULE_GET, INTERFACE_GET, PROPERTY_GET]
if (GET_TYPES.includes(accessType)) {
return true
}
// 无 session 且无 toeken 时拒绝访问
if (!curUserId && !token) {

@ -8,7 +8,7 @@ const start = () => {
let open = false
console.log('----------------------------------------')
app.listen(port, () => {
console.log(`rap2-dolores is running as ${url}`)
console.log(`rap2-delos is running as ${url}`)
if (!open) return
try {
execSync(`osascript openChrome.applescript ${url}`, { cwd: __dirname, stdio: 'ignore' })

@ -2,9 +2,7 @@ import * as nodemailer from 'nodemailer'
import config from '../config'
export default class MailService {
public static async sendMail(mailOptions: any) {
public static async sendMail(mailOptions: nodemailer.SendMailOptions) {
const transporter = nodemailer.createTransport(config.mail)
return new Promise((resolve, reject) => {
@ -25,7 +23,6 @@ export default class MailService {
}
public static send(to: string | string[], subject: string, html: string) {
const transporter = nodemailer.createTransport(config.mail)
const mailOptions = {
@ -266,4 +263,4 @@ public static mailFindpwdTemp = `<head>
}
</style>
</body>`
}
}

@ -1,4 +1,4 @@
import { Repository, Module, Interface, Property, QueryInclude, User } from '../models'
import { Repository, Module, Interface, Property, User, QueryInclude } from '../models'
import { SCOPES } from '../models/bo/property'
import Tree from '../routes/utils/tree'
import * as JSON5 from 'json5'
@ -8,10 +8,8 @@ import { Op } from 'sequelize'
import RedisService, { CACHE_KEY } from './redis'
import MailService from './mail'
import * as md5 from 'md5'
// import DingPushService from './ding.push'
// import sequelize from '../models/sequelize'
import * as _ from 'lodash'
const isMd5 = require('is-md5')
import * as _ from 'lodash'
const safeEval = require('notevil')
@ -429,7 +427,6 @@ export default class MigrateService {
let description = []
if (p.name) description.push(p.name)
if (p.remark && remarkWithoutMock) description.push(remarkWithoutMock)
const pCreated = await Property.create({
scope,
name,
@ -739,7 +736,6 @@ export default class MigrateService {
} else {
mod = repository.modules[findIndex]
}
for (const action in paths) {
const apiObj = paths[action][Object.keys(paths[action])[0]]
const method = Object.keys(paths[action])[0]
@ -1176,7 +1172,7 @@ export default class MigrateService {
}
/** 可以直接让用户把自己本地的 data 数据导入到 RAP 中 */
public static async importRepoFromJSON(data: JsonData, curUserId: number) {
public static async importRepoFromJSON(data: JsonData, curUserId: number, createRepo: boolean = false, orgId?: number) {
function parseJSON(str: string) {
try {
const data = JSON5.parse(str)
@ -1186,6 +1182,21 @@ export default class MigrateService {
}
}
if (createRepo) {
if (orgId === undefined) {
throw new Error("orgId is essential while createRepo = true")
}
const repo = await Repository.create({
name: data.name,
description: data.description,
visibility: true,
ownerId: curUserId,
creatorId: curUserId,
organizationId: orgId,
})
data.id = repo.id
}
const repositoryId = data.id
await Promise.all(
data.modules.map(async (modData, index) => {
@ -1248,6 +1259,7 @@ export default class MigrateService {
value: pData.value,
type: pData.type,
description: pData.description,
pos: pData.pos,
priority: index + 1,
interfaceId: itf.id,
creatorId: curUserId,
@ -1304,6 +1316,8 @@ interface JsonData {
* repo id
*/
id: number
name?: string
description?: string
modules: {
name: string
description?: string

Loading…
Cancel
Save