Notes
Notes - notes.io |
import axios from "axios";
import { v4 as uuidv4 } from "uuid";
const JOBS = new Map();
export const GetAutoDeskToken = async (req, res, next) => {
try {
res.json(await service.getPublicToken());
} catch (err) {
next(err);
}
};
export const UploadFile = async (req, res, next) => {
try {
// const validatedData = await validation.parseAsync(req.body);
const file = req.files.fileToUpload;
if (!file) {
return res.status(400).json({ error: "File is required!" });
}
const obj = await service.uploadObject(
file.name,
file.path,
req.fields.bucketKey
);
await service.translateObject(
service.urnify(obj.objectId),
req.fields["model-zip-entrypoint"]
);
res.json({
name: obj.objectKey,
urn: service.urnify(obj.objectId),
});
} catch (err) {
next(err);
}
};
export const GetAutoDeskModelBuckets = async (req, res, next) => {
try {
const bucket_name = req.query.id;
if (!bucket_name || bucket_name === "#") {
const buckets = await service.listBuckets();
res.json(
buckets.map((bucket) => {
return {
id: bucket.bucketKey,
text: bucket.bucketKey,
type: "bucket",
children: true,
};
})
);
} else {
const objects = await service.listObjects(bucket_name);
res.json(
objects.map((object) => {
return {
id: Buffer.from(object.objectId).toString("base64"),
text: object.objectKey,
type: "object",
children: false,
};
})
);
}
} catch (err) {
next(err);
}
};
export const GetAutoDeskManiFest = async (req, res, next) => {
try {
const urn = req.query.urn;
res.json(await service.getManifest(urn));
} catch (err) {
next(err);
}
};
// export const GetAutoDeskMetadata = async (req, res, next) => {
// try {
// const urn = req.query.urn;
// res.json(await service.getMetadata(urn));
// } catch (err) {
// next(err);
// }
// };
// export const ConvertRvtToPdf = async (req, res, next) => {
// // try {
// // const urn = req.fields.urn;
// // // const base64EncodedUrn = Buffer.from(urn).toString("base64");
// // // console.log(base64EncodedUrn, "nvbmxbczvbnbmn");
// // // const decodedUrn = Buffer.from(urn, "base64").toString("utf-8");
// // const rootFilename = req.fields.rootFilename;
// // if (!urn || !rootFilename) {
// // return res.status(400).json({ error: "URN and fileName are required!" });
// // }
// // const translationJob = await service.translateObject(urn, rootFilename);
// // res.json({ message: "Converting started successfully.", translationJob });
// // } catch (err) {
// // next(err);
// // }
// try {
// const urn = req.fields.urn;
// const rootFilename = req.fields.rootFilename;
// if (!urn || !rootFilename) {
// return res.status(400).json({ error: "URN and fileName are required!" });
// }
// const translationJob = await service.translateObject(urn, rootFilename);
// const statusCheckInterval = setInterval(async () => {
// try {
// const manifestResponse = await service.checkTranslationStatus(urn);
// console.log(manifestResponse, "ncxznmxzcbn");
// if (manifestResponse.status === "completed") {
// clearInterval(statusCheckInterval);
// return res.json({
// message: "Translation completed successfully.",
// result: manifestResponse,
// });
// } else if (manifestResponse.status === "failed") {
// clearInterval(statusCheckInterval);
// return res.status(400).json({
// error: "Translation failed.",
// messages: manifestResponse.messages.map((m) => m.message),
// });
// }
// console.log(`Translation status: ${manifestResponse.status}`);
// } catch (err) {
// clearInterval(statusCheckInterval);
// next(err);
// }
// }, 5000); // Check every 5 seconds
// res.json({ message: "Converting started successfully.", translationJob });
// } catch (err) {
// next(err);
// }
// };
export const convertRVTorDWGToPDF = async (req, res, next) => {
try {
const urn = req.fields.urn;
const rootFilename = req.fields.rootFilename || "root";
if (!urn || !rootFilename) {
return res.status(400).json({ error: "urn and rootFilename required" });
}
const job = await service.translateToPdf(urn, rootFilename);
return res.json({
message: "Translation job started",
job,
urn:
typeof urn === "string" && (urn.includes("urn:") || urn.includes("/"))
? toUrlSafeBase64(urn)
: urn,
statusCheck: `/convert-to-pdf/translation/status?urn=${encodeURIComponent(
typeof urn === "string" && (urn.includes("urn:") || urn.includes("/"))
? toUrlSafeBase64(urn)
: urn
)}`,
});
} catch (err) {
next(err);
}
};
export const translationPDFStatus = async (req, res, next) => {
try {
const urn = req.query.urn;
if (!urn) return res.status(400).json({ error: "urn required" });
const manifest = await service.getManifest(urn);
if (!manifest) return res.status(404).json({ status: "not_found" });
const status =
manifest.result?.status ||
manifest.status ||
manifest.derivatives?.[0]?.status ||
"unknown";
res.json({ status, manifest });
} catch (err) {
next(err);
}
};
export const listPdfDerivatives = async (req, res, next) => {
try {
const urn = req.query.urn;
if (!urn) return res.status(400).json({ error: "urn required" });
const pdfs = await service.listPdfDerivatives(urn);
res.json({ pdfs });
} catch (err) {
next(err);
}
};
// export const downloadPdf = async (req, res, next) => {
// try {
// const { urn, derivativeUrn } = req.query;
// if (!urn || !derivativeUrn)
// return res.status(400).json({ error: "urn and derivativeUrn required" });
// const { downloadUrl } = await service.getDerivativeDownloadUrl(
// urn,
// derivativeUrn
// );
// console.log("bvnbvbnvbnvbnvnbvnbvbnv");
// // Option A: Redirect client to the signed download URL (fast)
// // return res.redirect(downloadUrl);
// // Option B: Fetch and stream through your server to client (uncomment if you want server-proxy)
// const streamResp = await axios.get(downloadUrl, { responseType: "stream" });
// res.setHeader(
// "Content-Disposition",
// `attachment; filename="${path.basename(derivativeUrn)}"`
// );
// streamResp.data.pipe(res);
// } catch (err) {
// next(err);
// }
// };
export const downloadPdf = async (req, res, next) => {
try {
const downloadFile = await service.download(
req.fields.bucketKey,
req.fields.urn,
req.fields.derivativeUrn
);
res.json({ downloadFile });
// const { access_token } = await service.downloadAsStream();
// async function download() {
// await ossClient.downloadObject(bucketKey, objectKey, filePath);
// }
// async function downloadAsStream() {
// let fileStream = new Stream();
// fileStream = await ossClient.downloadObject(bucketKey, objectKey);
// }
// const { derivativeUrn } = req.query;
// if (!derivativeUrn) {
// return res.status(400).json({ error: "derivativeUrn is required" });
// }
// const { access_token } = await service.getInternalToken();
// const pdfUrl = service.constructPdfUrl(derivativeUrn);
// const pdfResponse = await axios({
// method: "get",
// url: pdfUrl,
// responseType: "arraybuffer",
// headers: {
// Authorization: `Bearer ${access_token}`,
// },
// });
// res.set({
// "Content-Type": "application/pdf",
// "Content-Disposition": `attachment; filename="${service.getFileNameFromUrn(
// derivativeUrn
// )}"`,
// "Content-Length": pdfResponse.data.length,
// });
// res.send(pdfResponse.data);
} catch (err) {
console.error("Error downloading PDF:", err);
res
.status(500)
.json({ error: "An error occurred while downloading the PDF." });
}
};
// new fresh code for materails exatraction
// export const startMaterialExtraction = async (req, res, next) => {
// try {
// const { urn } = req.body;
// if (!urn) {
// return res.status(400).json({ error: "urn is required" });
// }
// const jobId = uuidv4();
// const job = {
// jobId,
// urn,
// status: "queued",
// result: null,
// error: null,
// createdAt: new Date(),
// };
// JOBS.set(jobId, job);
// (async () => {
// try {
// job.status = "started";
// JOBS.set(jobId, job);
// const materials = await service.extractMaterialsFromProperties(urn);
// job.status = "completed";
// job.result = {
// materials,
// count: materials.length,
// };
// } catch (err) {
// job.status = "failed";
// job.error = err.message || String(err);
// console.error("Material extraction job failed:", err);
// } finally {
// JOBS.set(jobId, job);
// }
// })();
// return res.json({ jobId, status: job.status });
// } catch (outerErr) {
// console.error("startMaterialExtraction error:", outerErr);
// return res.status(500).json({ error: "Internal server error" });
// }
// };
// maertials code old
// export const startMaterialExtraction = async (req, res, next) => {
// try {
// const { urn } = req.body;
// if (!urn) {
// return res.status(400).json({ error: "urn is required" });
// }
// const jobId = uuidv4();
// const job = {
// jobId,
// urn,
// status: "queued",
// result: null,
// error: null,
// createdAt: new Date(),
// };
// JOBS.set(jobId, job);
// (async () => {
// try {
// job.status = "started";
// JOBS.set(jobId, job);
// const materials = await service.extractMaterialsFromProperties(urn);
// job.status = "completed";
// job.result = {
// materials,
// count: materials.length,
// };
// } catch (err) {
// job.status = "failed";
// job.error = err.message || String(err);
// console.error("Material extraction job failed:", err);
// } finally {
// JOBS.set(jobId, job);
// }
// })();
// return res.json({ jobId, status: job.status });
// } catch (outerErr) {
// console.error("startMaterialExtraction error:", outerErr);
// return res.status(500).json({ error: "Internal server error" });
// }
// };
// export const getMaterialJobStatus = (req, res, next) => {
// console.log(req.query.jobId, "cxnv,mxcv,mnm,");
// const jobId = req.query.jobId;
// if (!jobId) return res.status(400).json({ error: "jobId is required" });
// const job = JOBS.get(jobId);
// if (!job) return res.status(404).json({ error: "Job not found" });
// return res.json(job);
// };
// export const getMaterialResult = (req, res) => {
// const job = JOBS.get(req.query.jobId);
// if (!job) return res.status(404).json({ error: "job not found" });
// if (job.status !== "completed") return res.status(202).json(job);
// res.json(job.result);
// };
// export const getMaterialsLive = async (req, res) => {
// try {
// const urn = req.params.urn;
// const materials = await service.extractMaterialsFromProperties(urn);
// res.json({ count: materials.length, materials });
// } catch (err) {
// res.status(500).json({ error: err.message });
// }
// };
// export const getModelMetadata = async (req, res) => {
// try {
// const data = await service.getMetadata(req.params.urn);
// res.json(data);
// } catch (err) {
// res.status(500).json({ error: err.message });
// }
// };
// export const getRawPropertyTree = async (req, res) => {
// try {
// const { urn, guid } = req.params;
// const collection = await service.getRawProperties(urn, guid);
// res.json({ count: collection.length, collection });
// } catch (err) {
// res.status(500).json({ error: err.message });
// }
// };
//end code
//fresh code for materials
export const startMaterialExtraction = async (req, res, next) => {
try {
const { urn } = req.body;
if (!urn) {
return res.status(400).json({ error: "urn is required" });
}
const jobId = uuidv4();
const job = {
jobId,
urn,
status: "queued",
result: null,
error: null,
createdAt: new Date(),
};
JOBS.set(jobId, job);
(async () => {
try {
job.status = "started";
JOBS.set(jobId, job);
const materials = await service.extractMaterialsFromProperties(urn);
job.status = "completed";
job.result = {
materials,
count: materials.length,
};
} catch (err) {
job.status = "failed";
job.error = err.message || String(err);
console.error("Material extraction job failed:", err);
} finally {
JOBS.set(jobId, job);
}
})();
return res.json({ jobId, status: job.status });
} catch (outerErr) {
console.error("startMaterialExtraction error:", outerErr);
return res.status(500).json({ error: "Internal server error" });
}
};
// export const getMaterialJobStatus = (req, res) => {
// const jobId = req.query.jobId;
// if (!jobId) {
// return res.status(400).json({ error: "jobId is required" });
// }
// const job = JOBS.get(jobId);
// if (!job) {
// return res.status(404).json({ error: "Job not found" });
// }
// return res.json(job);
// };
export const getMaterialJobStatus = async (req, res) => {
try {
const { jobId, urn } = req.fields;
if (!jobId) return res.status(400).json({ error: "jobId is required" });
if (!urn) return res.status(400).json({ error: "urn is required" });
const metadata = await service.getMetadata(urn);
res.json({
jobId,
urn,
status: metadata.status,
result: metadata,
createdAt: new Date().toISOString(),
});
} catch (err) {
res.json({
jobId: req.query.jobId,
urn: req.query.urn,
status: "failed",
result: null,
error: err.message,
createdAt: new Date().toISOString(),
});
}
};
export const getMaterialResult = (req, res) => {
const jobId = req.query.jobId;
const job = JOBS.get(jobId);
if (!job) {
return res.status(404).json({ error: "job not found" });
}
if (job.status !== "completed") {
return res.status(202).json(job); // still processing or failed
}
return res.json(job.result);
};
export const getMaterialsLive = async (req, res, next) => {
try {
const urn = req.params.urn;
const mats = await service.extractMaterialsFromProperties(urn);
return res.json({ count: mats.length, materials: mats });
} catch (err) {
next(err);
}
};
export const getModelMetadata = async (req, res, next) => {
try {
const urn = req.params.urn;
const md = await service.getMetadata(urn);
return res.json(md);
} catch (err) {
next(err);
}
};
export const getRawPropertyTree = async (req, res, next) => {
try {
const { urn, guid } = req.params;
const coll = await service.getRawProperties(urn, guid);
return res.json({ count: coll.length, collection: coll });
} catch (err) {
next(err);
}
};
//endcode
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team
