goodstech-20191230/main.tea (391 lines of code) (raw):

/** * */ import Util; import OSS; import OpenPlatform; import OSSUtil; import FileForm; import OpenApi; import OpenApiUtil; import EndpointUtil; extends OpenApi; init(config: OpenApi.Config){ super(config); @endpointRule = 'regional'; checkConfig(config); @endpoint = getEndpoint('goodstech', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint); } function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{ if (!Util.empty(endpoint)) { return endpoint; } if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) { return endpointMap[regionId]; } return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix); } model ClassifyCommodityRequest { imageURL?: string(name='ImageURL'), } model ClassifyCommodityAdvanceRequest { imageURLObject?: readable(name='ImageURL'), } model ClassifyCommodityResponseBody = { data?: { categories?: [ { categoryId?: string(name='CategoryId'), categoryName?: string(name='CategoryName'), score?: float(name='Score'), } ](name='Categories'), }(name='Data'), requestId?: string(name='RequestId'), } model ClassifyCommodityResponse = { headers: map[string]string(name='headers'), statusCode: int32(name='statusCode'), body: ClassifyCommodityResponseBody(name='body'), } async function classifyCommodityWithOptions(request: ClassifyCommodityRequest, runtime: Util.RuntimeOptions): ClassifyCommodityResponse { Util.validateModel(request); var query = {}; if (!Util.isUnset(request.imageURL)) { query['ImageURL'] = request.imageURL; } var req = new OpenApi.OpenApiRequest{ query = OpenApiUtil.query(query), }; var params = new OpenApi.Params{ action = 'ClassifyCommodity', version = '2019-12-30', protocol = 'HTTPS', pathname = '/', method = 'POST', authType = 'AK', style = 'RPC', reqBodyType = 'formData', bodyType = 'json', }; return callApi(params, req, runtime); } async function classifyCommodity(request: ClassifyCommodityRequest): ClassifyCommodityResponse { var runtime = new Util.RuntimeOptions{}; return classifyCommodityWithOptions(request, runtime); } async function classifyCommodityAdvance(request: ClassifyCommodityAdvanceRequest, runtime: Util.RuntimeOptions): ClassifyCommodityResponse { // Step 0: init client var accessKeyId = @credential.getAccessKeyId(); var accessKeySecret = @credential.getAccessKeySecret(); var securityToken = @credential.getSecurityToken(); var credentialType = @credential.getType(); var openPlatformEndpoint = @openPlatformEndpoint; if(Util.isUnset(openPlatformEndpoint)) { openPlatformEndpoint ='openplatform.aliyuncs.com'; } if(Util.isUnset(credentialType)) { credentialType ='access_key'; } var authConfig = new OpenApi.Config{ accessKeyId = accessKeyId, accessKeySecret = accessKeySecret, securityToken = securityToken, type = credentialType, endpoint = openPlatformEndpoint, protocol = @protocol, regionId = @regionId, }; var authClient = new OpenPlatform(authConfig); var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{ product = 'goodstech', regionId = @regionId, }; var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{}; var ossConfig = new OSS.Config{ accessKeySecret = accessKeySecret, type = 'access_key', protocol = @protocol, regionId = @regionId, }; var ossClient : OSS = null; var fileObj = new FileForm.FileField{}; var ossHeader = new OSS.PostObjectRequest.header{}; var uploadRequest = new OSS.PostObjectRequest{}; var ossRuntime = new OSSUtil.RuntimeOptions{}; OpenApiUtil.convert(runtime, ossRuntime); var classifyCommodityReq = new ClassifyCommodityRequest{}; OpenApiUtil.convert(request, classifyCommodityReq); if(!Util.isUnset(request.imageURLObject)) { authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime); ossConfig.accessKeyId = authResponse.body.accessKeyId; ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType); ossClient = new OSS(ossConfig); fileObj = new FileForm.FileField{ filename = authResponse.body.objectKey, content = request.imageURLObject, contentType = '', }; ossHeader = new OSS.PostObjectRequest.header{ accessKeyId = authResponse.body.accessKeyId, policy = authResponse.body.encodedPolicy, signature = authResponse.body.signature, key = authResponse.body.objectKey, file = fileObj, successActionStatus = '201', }; uploadRequest = new OSS.PostObjectRequest{ bucketName = authResponse.body.bucket, header = ossHeader, }; ossClient.postObject(uploadRequest, ossRuntime); classifyCommodityReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`; } var classifyCommodityResp = classifyCommodityWithOptions(classifyCommodityReq, runtime); return classifyCommodityResp; } model RecognizeFurnitureAttributeRequest { imageURL?: string(name='ImageURL'), } model RecognizeFurnitureAttributeAdvanceRequest { imageURLObject?: readable(name='ImageURL'), } model RecognizeFurnitureAttributeResponseBody = { data?: { predProbability?: float(name='PredProbability'), predStyle?: string(name='PredStyle'), predStyleId?: string(name='PredStyleId'), }(name='Data'), requestId?: string(name='RequestId'), } model RecognizeFurnitureAttributeResponse = { headers: map[string]string(name='headers'), statusCode: int32(name='statusCode'), body: RecognizeFurnitureAttributeResponseBody(name='body'), } async function recognizeFurnitureAttributeWithOptions(request: RecognizeFurnitureAttributeRequest, runtime: Util.RuntimeOptions): RecognizeFurnitureAttributeResponse { Util.validateModel(request); var body : map[string]any = {}; if (!Util.isUnset(request.imageURL)) { body['ImageURL'] = request.imageURL; } var req = new OpenApi.OpenApiRequest{ body = OpenApiUtil.parseToMap(body), }; var params = new OpenApi.Params{ action = 'RecognizeFurnitureAttribute', version = '2019-12-30', protocol = 'HTTPS', pathname = '/', method = 'POST', authType = 'AK', style = 'RPC', reqBodyType = 'formData', bodyType = 'json', }; return callApi(params, req, runtime); } async function recognizeFurnitureAttribute(request: RecognizeFurnitureAttributeRequest): RecognizeFurnitureAttributeResponse { var runtime = new Util.RuntimeOptions{}; return recognizeFurnitureAttributeWithOptions(request, runtime); } async function recognizeFurnitureAttributeAdvance(request: RecognizeFurnitureAttributeAdvanceRequest, runtime: Util.RuntimeOptions): RecognizeFurnitureAttributeResponse { // Step 0: init client var accessKeyId = @credential.getAccessKeyId(); var accessKeySecret = @credential.getAccessKeySecret(); var securityToken = @credential.getSecurityToken(); var credentialType = @credential.getType(); var openPlatformEndpoint = @openPlatformEndpoint; if(Util.isUnset(openPlatformEndpoint)) { openPlatformEndpoint ='openplatform.aliyuncs.com'; } if(Util.isUnset(credentialType)) { credentialType ='access_key'; } var authConfig = new OpenApi.Config{ accessKeyId = accessKeyId, accessKeySecret = accessKeySecret, securityToken = securityToken, type = credentialType, endpoint = openPlatformEndpoint, protocol = @protocol, regionId = @regionId, }; var authClient = new OpenPlatform(authConfig); var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{ product = 'goodstech', regionId = @regionId, }; var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{}; var ossConfig = new OSS.Config{ accessKeySecret = accessKeySecret, type = 'access_key', protocol = @protocol, regionId = @regionId, }; var ossClient : OSS = null; var fileObj = new FileForm.FileField{}; var ossHeader = new OSS.PostObjectRequest.header{}; var uploadRequest = new OSS.PostObjectRequest{}; var ossRuntime = new OSSUtil.RuntimeOptions{}; OpenApiUtil.convert(runtime, ossRuntime); var recognizeFurnitureAttributeReq = new RecognizeFurnitureAttributeRequest{}; OpenApiUtil.convert(request, recognizeFurnitureAttributeReq); if(!Util.isUnset(request.imageURLObject)) { authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime); ossConfig.accessKeyId = authResponse.body.accessKeyId; ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType); ossClient = new OSS(ossConfig); fileObj = new FileForm.FileField{ filename = authResponse.body.objectKey, content = request.imageURLObject, contentType = '', }; ossHeader = new OSS.PostObjectRequest.header{ accessKeyId = authResponse.body.accessKeyId, policy = authResponse.body.encodedPolicy, signature = authResponse.body.signature, key = authResponse.body.objectKey, file = fileObj, successActionStatus = '201', }; uploadRequest = new OSS.PostObjectRequest{ bucketName = authResponse.body.bucket, header = ossHeader, }; ossClient.postObject(uploadRequest, ossRuntime); recognizeFurnitureAttributeReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`; } var recognizeFurnitureAttributeResp = recognizeFurnitureAttributeWithOptions(recognizeFurnitureAttributeReq, runtime); return recognizeFurnitureAttributeResp; } model RecognizeFurnitureSpuRequest { imageURL?: string(name='ImageURL'), XLength?: float(name='XLength'), YLength?: float(name='YLength'), ZLength?: float(name='ZLength'), } model RecognizeFurnitureSpuAdvanceRequest { imageURLObject?: readable(name='ImageURL'), XLength?: float(name='XLength'), YLength?: float(name='YLength'), ZLength?: float(name='ZLength'), } model RecognizeFurnitureSpuResponseBody = { data?: { predCate?: string(name='PredCate'), predCateId?: string(name='PredCateId'), predProbability?: float(name='PredProbability'), }(name='Data'), requestId?: string(name='RequestId'), } model RecognizeFurnitureSpuResponse = { headers: map[string]string(name='headers'), statusCode: int32(name='statusCode'), body: RecognizeFurnitureSpuResponseBody(name='body'), } async function recognizeFurnitureSpuWithOptions(request: RecognizeFurnitureSpuRequest, runtime: Util.RuntimeOptions): RecognizeFurnitureSpuResponse { Util.validateModel(request); var body : map[string]any = {}; if (!Util.isUnset(request.imageURL)) { body['ImageURL'] = request.imageURL; } if (!Util.isUnset(request.XLength)) { body['XLength'] = request.XLength; } if (!Util.isUnset(request.YLength)) { body['YLength'] = request.YLength; } if (!Util.isUnset(request.ZLength)) { body['ZLength'] = request.ZLength; } var req = new OpenApi.OpenApiRequest{ body = OpenApiUtil.parseToMap(body), }; var params = new OpenApi.Params{ action = 'RecognizeFurnitureSpu', version = '2019-12-30', protocol = 'HTTPS', pathname = '/', method = 'POST', authType = 'AK', style = 'RPC', reqBodyType = 'formData', bodyType = 'json', }; return callApi(params, req, runtime); } async function recognizeFurnitureSpu(request: RecognizeFurnitureSpuRequest): RecognizeFurnitureSpuResponse { var runtime = new Util.RuntimeOptions{}; return recognizeFurnitureSpuWithOptions(request, runtime); } async function recognizeFurnitureSpuAdvance(request: RecognizeFurnitureSpuAdvanceRequest, runtime: Util.RuntimeOptions): RecognizeFurnitureSpuResponse { // Step 0: init client var accessKeyId = @credential.getAccessKeyId(); var accessKeySecret = @credential.getAccessKeySecret(); var securityToken = @credential.getSecurityToken(); var credentialType = @credential.getType(); var openPlatformEndpoint = @openPlatformEndpoint; if(Util.isUnset(openPlatformEndpoint)) { openPlatformEndpoint ='openplatform.aliyuncs.com'; } if(Util.isUnset(credentialType)) { credentialType ='access_key'; } var authConfig = new OpenApi.Config{ accessKeyId = accessKeyId, accessKeySecret = accessKeySecret, securityToken = securityToken, type = credentialType, endpoint = openPlatformEndpoint, protocol = @protocol, regionId = @regionId, }; var authClient = new OpenPlatform(authConfig); var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{ product = 'goodstech', regionId = @regionId, }; var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{}; var ossConfig = new OSS.Config{ accessKeySecret = accessKeySecret, type = 'access_key', protocol = @protocol, regionId = @regionId, }; var ossClient : OSS = null; var fileObj = new FileForm.FileField{}; var ossHeader = new OSS.PostObjectRequest.header{}; var uploadRequest = new OSS.PostObjectRequest{}; var ossRuntime = new OSSUtil.RuntimeOptions{}; OpenApiUtil.convert(runtime, ossRuntime); var recognizeFurnitureSpuReq = new RecognizeFurnitureSpuRequest{}; OpenApiUtil.convert(request, recognizeFurnitureSpuReq); if(!Util.isUnset(request.imageURLObject)) { authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime); ossConfig.accessKeyId = authResponse.body.accessKeyId; ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType); ossClient = new OSS(ossConfig); fileObj = new FileForm.FileField{ filename = authResponse.body.objectKey, content = request.imageURLObject, contentType = '', }; ossHeader = new OSS.PostObjectRequest.header{ accessKeyId = authResponse.body.accessKeyId, policy = authResponse.body.encodedPolicy, signature = authResponse.body.signature, key = authResponse.body.objectKey, file = fileObj, successActionStatus = '201', }; uploadRequest = new OSS.PostObjectRequest{ bucketName = authResponse.body.bucket, header = ossHeader, }; ossClient.postObject(uploadRequest, ossRuntime); recognizeFurnitureSpuReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`; } var recognizeFurnitureSpuResp = recognizeFurnitureSpuWithOptions(recognizeFurnitureSpuReq, runtime); return recognizeFurnitureSpuResp; }