You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
2.8 KiB
112 lines
2.8 KiB
'use strict';
|
|
|
|
const Service = require('egg').Service;
|
|
const _ = require("lodash")
|
|
const tencentcloud = require("tencentcloud-sdk-nodejs-ft");
|
|
const { mongoose } = require('../../config/plugin');
|
|
const FtClient = tencentcloud.ft.v20200304.Client;
|
|
class UserService extends Service {
|
|
async index(params) {
|
|
let { ctx } = this
|
|
let modelLocal = ctx.model.User
|
|
let returnData = { hasError: false, msg: "数据错误", list: [] }
|
|
// 请求照片
|
|
let reqCount = 9
|
|
let pngList = []
|
|
for (let i = 1; i < reqCount; i++) {
|
|
let para = {
|
|
img: params.img,
|
|
age: i * 10
|
|
}
|
|
let pngRes = await this.createPng(para)
|
|
if (pngRes.haserror) {
|
|
pngList.push({
|
|
age: i * 10,
|
|
png: "",
|
|
ResultUrl: "",
|
|
RequestId: "",
|
|
})
|
|
} else {
|
|
pngList.push({
|
|
age: i * 10,
|
|
png: `data:image/png;base64,${pngRes.ResultImage}`,
|
|
ResultUrl: pngRes.ResultUrl,
|
|
RequestId: pngRes.RequestId,
|
|
})
|
|
}
|
|
|
|
}
|
|
let paramsLocal = {
|
|
name: params.name,
|
|
age: params.age,
|
|
createImgList: pngList,
|
|
imgbase64: params.img,
|
|
}
|
|
let res = await modelLocal.create(paramsLocal)
|
|
returnData.hasError = false
|
|
returnData.msg = "数据新增成功"
|
|
returnData.list = res
|
|
return returnData
|
|
}
|
|
async createPng(params) {
|
|
let clientConfig = {
|
|
credential: {
|
|
secretId: "AKIDLgwLkIcpoZ6PZht382oUMCC6wdFhMwZ8",//客户端身份标识
|
|
secretKey: "TmvwtkcYWTJ5qkEg3FIB2sokccepOsCO",//客户端身份密钥
|
|
},
|
|
region: "ap-chengdu",
|
|
profile: {
|
|
httpProfile: {
|
|
endpoint: "ft.tencentcloudapi.com",
|
|
},
|
|
},
|
|
};
|
|
// 实例化要请求产品的client对象,clientProfile是可选的
|
|
let client = new FtClient(clientConfig);
|
|
let paramsLocal = {
|
|
AgeInfos: [
|
|
{ Age: params.age },
|
|
],
|
|
Image: params.img
|
|
}
|
|
let resPng = {}
|
|
try {
|
|
console.log(9999, paramsLocal.AgeInfos[0].Age)
|
|
resPng = await client.ChangeAgePic(paramsLocal);
|
|
if (resPng.ResultImage) {
|
|
return resPng
|
|
} else {
|
|
return {
|
|
ResultImage: "",
|
|
ResultUrl: "",
|
|
RequestId: "",
|
|
haserror: true
|
|
}
|
|
}
|
|
} catch (e) {
|
|
return {
|
|
ResultImage: "",
|
|
ResultUrl: "",
|
|
RequestId: "",
|
|
haserror: true
|
|
}
|
|
}
|
|
}
|
|
async downloadPng(params) {
|
|
let { ctx } = this
|
|
let modelLocal = ctx.model.User
|
|
let returnData = { hasError: false, msg: "数据错误", list: [] }
|
|
//查询后下载8张图片
|
|
return returnData
|
|
}
|
|
async getPng(id) {
|
|
let { ctx } = this
|
|
let modelLocal = ctx.model.User
|
|
let res = await modelLocal.find({ _id: id })
|
|
//查询后下载8张图片
|
|
return res
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = UserService;
|
|
|