@alipay/faas-biz-web-sdk
Advanced tools
Comparing version 0.0.1-alpha.6 to 0.0.1-alpha.7
@@ -16,2 +16,4 @@ "use strict"; | ||
getTaskUrl; | ||
getUploadUrlEndpoint; | ||
getDownloadUrlEndpoint; | ||
additionalHeaders; | ||
@@ -24,3 +26,3 @@ constructor(config) { | ||
this.environment = config.environment || "hz"; | ||
this.useHttps = config.useHttps || true; | ||
this.useHttps = config.useHttps ?? true; | ||
const schema = this.useHttps ? "https" : "http"; | ||
@@ -31,6 +33,8 @@ if (this.environment === "offline") { | ||
else { | ||
this.endpoint = `${schema}://biz.api-${this.environment}.cloudbasefunction.cn`; | ||
this.endpoint = `${schema}://env-00jxgirz4op0.api-${this.environment}.cloudbasefunction.cn`; | ||
} | ||
this.image2imageUrl = `${this.endpoint}/api/v1/aigc/image2image`; | ||
this.getTaskUrl = `${this.endpoint}/api/v1/aigc/task/`; | ||
this.getUploadUrlEndpoint = `${this.endpoint}/api/v1/storage/file/uploadUrl`; | ||
this.getDownloadUrlEndpoint = `${this.endpoint}/api/v1/storage/file/downloadUrl`; | ||
} | ||
@@ -61,2 +65,3 @@ async image2image(service, input, parameters) { | ||
const taskInfo = await this.image2image(service, input, parameters); | ||
console.log('taskInfo:' + JSON.stringify(taskInfo)); | ||
const taskId = taskInfo.output?.taskId; | ||
@@ -67,3 +72,4 @@ const startTime = Date.now(); | ||
const taskResult = await this.getTaskResult(taskId); | ||
if (taskResult.output?.taskStatus === 'SUCCESS' || taskResult.output?.taskStatus === 'FAILED') { | ||
console.log('taskResult:' + JSON.stringify(taskResult)); | ||
if (taskResult.output?.taskStatus === 'SUCCEEDED' || taskResult.output?.taskStatus === 'FAILED') { | ||
return taskResult; | ||
@@ -81,4 +87,4 @@ } | ||
try { | ||
this.getTaskUrl += taskId; | ||
const response = await (0, httpRequest_1.sendRequest)(this.getTaskUrl, "GET", {}, this.additionalHeaders); | ||
const taskUrl = this.getTaskUrl + taskId; | ||
const response = await (0, httpRequest_1.sendRequest)(taskUrl, "GET", {}, this.additionalHeaders); | ||
if (response.success) { | ||
@@ -96,2 +102,40 @@ const respData = response.data; | ||
} | ||
async getUploadUrl(fileName) { | ||
try { | ||
const body = { | ||
fileName | ||
}; | ||
const response = await (0, httpRequest_1.sendRequest)(this.getUploadUrlEndpoint, "POST", body, this.additionalHeaders); | ||
if (response.success) { | ||
const respData = response.data; | ||
return this.buildUploadUrlGetResponse(respData); | ||
; | ||
} | ||
else { | ||
throw new Error(response.errorCode + "," + response.resultMsg); | ||
} | ||
} | ||
catch (error) { | ||
throw new Error(`getUploadUrl failed: ${error.message}`); | ||
} | ||
} | ||
async getDownloadUrl(fileName) { | ||
try { | ||
const body = { | ||
fileName | ||
}; | ||
const response = await (0, httpRequest_1.sendRequest)(this.getDownloadUrlEndpoint, "POST", body, this.additionalHeaders); | ||
if (response.success) { | ||
const respData = response.data; | ||
return this.buildDownloadUrlGetResponse(respData); | ||
; | ||
} | ||
else { | ||
throw new Error(response.errorCode + "," + response.resultMsg); | ||
} | ||
} | ||
catch (error) { | ||
throw new Error(`getDownloadUrl failed: ${error.message}`); | ||
} | ||
} | ||
buildImage2ImageResponse(respData) { | ||
@@ -114,3 +158,15 @@ const response = new Image2ImageResponse_1.Image2ImageResponse(); | ||
} | ||
buildUploadUrlGetResponse(respData) { | ||
return { | ||
url: respData.url, | ||
expireTs: respData.expireTs, | ||
}; | ||
} | ||
buildDownloadUrlGetResponse(respData) { | ||
return { | ||
url: respData.url, | ||
expireTs: respData.expireTs, | ||
}; | ||
} | ||
} | ||
exports.CloudAI = CloudAI; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TaskResultResponse = exports.Image2ImageResponse = exports.TaskResult = exports.TaskInfo = exports.Image2ImageInput = exports.CloudAI = exports.LoginState = exports.User = exports.Auth = void 0; | ||
exports.DownloadUrlGetResponse = exports.UploadUrlGetResponse = exports.TaskResultResponse = exports.Image2ImageResponse = exports.TaskResult = exports.TaskInfo = exports.Image2ImageInput = exports.CloudAI = exports.LoginState = exports.User = exports.Auth = void 0; | ||
const Auth_1 = require("./Auth"); | ||
@@ -22,1 +22,5 @@ Object.defineProperty(exports, "Auth", { enumerable: true, get: function () { return Auth_1.Auth; } }); | ||
Object.defineProperty(exports, "TaskResultResponse", { enumerable: true, get: function () { return TaskResultResponse_1.TaskResultResponse; } }); | ||
const UploadUrlGetResponse_1 = require("./models/storage/UploadUrlGetResponse"); | ||
Object.defineProperty(exports, "UploadUrlGetResponse", { enumerable: true, get: function () { return UploadUrlGetResponse_1.UploadUrlGetResponse; } }); | ||
const DownloadUrlGetResponse_1 = require("./models/storage/DownloadUrlGetResponse"); | ||
Object.defineProperty(exports, "DownloadUrlGetResponse", { enumerable: true, get: function () { return DownloadUrlGetResponse_1.DownloadUrlGetResponse; } }); |
{ | ||
"name": "@alipay/faas-biz-web-sdk", | ||
"version": "0.0.1-alpha.6", | ||
"version": "0.0.1-alpha.7", | ||
"description": "支付宝云开发业务扩展web端 SDK", | ||
@@ -11,2 +11,3 @@ "main": "dist/index.js", | ||
"build": "tsc", | ||
"compile": "./node_modules/.bin/esbuild main.js --bundle --outfile=dist/faas-biz-web-sdk-bundle.js", | ||
"prepublishOnly": "npm run build" | ||
@@ -13,0 +14,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31278
17
723