線上預覽cad
阿新 • • 發佈:2021-01-31
官方node demo
以下是自己手動改的 記錄以下萬一以後用到
async objects(msg){
// tiken client 獲取
await setMsg(this.app)
const token = await getInternalToken();
msg.oauth_token = token;
msg.oauth_client = getClient();
// 讀oss檔案寫到本地檔案
let file = await this.app.updateOssRedis (msg.url);
console.log('file :>> ', file);
// const file = 'https://cdn.tjssy.cn/ssy/2021-01-29/1611897895988b.dwg';
file = 'http://cdn.tjssy.cn/ssy/2021-01-29/1611897895988b.dwg'
const fileData = await this.ctx.curl(file);
const parseUrl = url.parse(file).pathname;
console.log(parseUrl)
const fileExtName = path.extname(parseUrl);
await mkdir('./app/public/cad' + parseUrl.replace(RegExp(path.basename(parseUrl, path.extname(parseUrl)) + fileExtName, 'g'), ''));
fs.writeFileSync('./app/public/cad' + parseUrl, fileData.data, 'binary');
// 讀本地檔案上傳autodesk
let oldfileMsg = { }
let data = fs.readFileSync('./app/public/cad' + parseUrl);
oldfileMsg = await new ObjectsApi().uploadObject(msg.bucketKey, 'parseUrl6.dwg', data.length, data, {}, msg.oauth_client, msg.oauth_token);
let job = new JobPayload();
job.input = new JobPayloadInput();
job.input.urn = Buffer.from(oldfileMsg.body.objectId).toString('base64');
job.output = new JobPayloadOutput([
new JobSvfOutputPayload()
]);
job.output.formats[0].type = 'svf';
job.output.formats[0].views = ['2d', '3d'];
const result = await new DerivativesApi().translate(job, {}, msg.oauth_client, msg.oauth_token);
console.log('result :>> ', result);
return {
token: msg.oauth_token,
msg: result,
};
}