generated from Jeff-Tian/egg-passport-citi
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
53 lines (47 loc) · 2.08 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import {Application, Context} from 'egg'
import RPCClient from '@alicloud/pop-core'
// tslint:disable-next-line:no-var-requires
const ROAClient = require('@alicloud/pop-core').ROAClient
import uuidV1 = require('uuid/v1')
import assert = require('assert')
export default (app: Application) => {
const config = app.config.aliyunOpenApi
assert(config.key)
assert(config.secret)
assert(config.mount)
Object.keys(config.mount).forEach(key => {
if (key === 'vod') {
app.get(config.mount[key], async (ctx: Context) => {
const client = new RPCClient({
accessKeyId: config.key,
accessKeySecret: config.secret,
endpoint: `https://${key}.${config.regionId}.aliyuncs.com`,
apiVersion: config.apiVersion,
})
ctx.body = await client.request(ctx.query.action, {
VideoId: ctx.query.videoId,
PlayConfig: ctx.query.playConfig || (config.vod ? JSON.stringify(config.vod.playConfig) : undefined),
})
})
} else {
const subRouter = app.router.namespace(config.mount[key])
subRouter.post('/text/scan', async (ctx: Context) => {
const client = new ROAClient({
accessKeyId: config.key,
accessKeySecret: config.secret,
endpoint: `https://${key}.${config.regionId}.aliyuncs.com`,
apiVersion: config.apiVersion,
})
ctx.body = await client.request(ctx.method, '/green/text/scan', ctx.queries, JSON.stringify({
scenes: ['antispam'], ...ctx.request.body,
tasks: [...(ctx.request.body.tasks || []).map((t: { dataId?: string, content: string }) => ({
dataId: t.dataId || uuidV1(),
content: t.content,
}))],
}), {
'Content-Type': 'application/json', ...ctx.headers,
})
})
}
})
}