Notes
Notes - notes.io |
// const { access_token } = await service.getInternalToken();
// try {
// const props = await modelDerivativeClient.metadata.getModelProperties({
// urn,
// guid,
// accessToken: access_token,
// });
// return props.data?.collection || [];
// } catch (err) {
// console.error(
// "Error fetching raw properties:",
// err?.axiosError?.response?.data || err.message
// );
// throw new Error("Failed to fetch raw properties: " + (err.message || ""));
// }
// },
// getRawProperties: async (urn, guid) => {
// const token = await service.getInternalToken();
// const modelDerivativeClient = new ForgeSDK.DerivativesApi();
// try {
// const response = await modelDerivativeClient.getProperties(urn, guid, {
// accessToken: token,
// });
// return response.data.collection;
// } catch (err) {
// console.error("Error fetching raw properties:", err.message);
// throw new Error(err.message || "Failed to fetch raw properties");
// }
// },
//end code
// getDerivativeDownloadUrl: async (urn, derivativeUrn) => {
// const { access_token } = await service.getInternalToken();
// const encodedUrn = encodeURIComponent(urn);
// const encodedDerivative = encodeURIComponent(derivativeUrn);
// const signedCookiesEndpoint = `https://developer.api.autodesk.com/modelderivative/v2/designdata/${encodedUrn}/manifest/${encodedDerivative}/signedcookies`;
// const resp = await axios.get(signedCookiesEndpoint, {
// headers: { Authorization: `Bearer ${access_token}` },
// validateStatus: (s) => s >= 200 && s < 400,
// });
// console.log(resp.data, "znmbxcvnbmnxcbvnb");
// const body = resp.data;
// const rawSetCookie = (resp.headers["set-cookie"] || []).join("; ");
// const cookieParts = rawSetCookie.split("; ").map((c) => c.trim());
// const map = {};
// cookieParts.forEach((part) => {
// if (part.startsWith("CloudFront-Policy="))
// map.Policy = part.split("=")[1];
// if (part.startsWith("CloudFront-Key-Pair-Id="))
// map["Key-Pair-Id"] = part.split("=")[1];
// if (part.startsWith("CloudFront-Signature="))
// map.Signature = part.split("=")[1];
// });
// let downloadUrl = body.url;
// const qs = new URLSearchParams();
// if (map["Key-Pair-Id"]) qs.append("Key-Pair-Id", map["Key-Pair-Id"]);
// if (map.Signature) qs.append("Signature", map.Signature);
// if (map.Policy) qs.append("Policy", map.Policy);
// const finalUrl = `${downloadUrl}${
// qs.toString() ? "?" + qs.toString() : ""
// }`;
// return { downloadUrl: finalUrl };
// },
// getDerivativeDownloadUrl: async (urn, derivativeUrn) => {
// const { access_token } = await service.getInternalToken();
// const encodedUrn = encodeURIComponent(urn);
// const encodedDerivative = encodeURIComponent(derivativeUrn);
// const endpoint = `https://developer.api.autodesk.com/modelderivative/v2/designdata/${encodedUrn}/manifest/${encodedDerivative}/signedcookies`;
// const resp = await axios.get(endpoint, {
// headers: { Authorization: `Bearer ${access_token}` },
// validateStatus: (s) => s >= 200 && s < 500,
// });
// if (resp.status !== 200) {
// throw new Error(
// `Forge returned ${resp.status}: ${JSON.stringify(resp.data)}`
// );
// }
// const body = resp.data;
// const rawSetCookie = (resp.headers["set-cookie"] || []).join("; ");
// const cookieParts = rawSetCookie.split("; ").map((c) => c.trim());
// const map = {};
// cookieParts.forEach((part) => {
// if (part.startsWith("CloudFront-Policy="))
// map.Policy = part.split("=")[1];
// if (part.startsWith("CloudFront-Key-Pair-Id="))
// map["Key-Pair-Id"] = part.split("=")[1];
// if (part.startsWith("CloudFront-Signature="))
// map.Signature = part.split("=")[1];
// });
// const qs = new URLSearchParams();
// if (map["Key-Pair-Id"]) qs.append("Key-Pair-Id", map["Key-Pair-Id"]);
// if (map.Signature) qs.append("Signature", map.Signature);
// if (map.Policy) qs.append("Policy", map.Policy);
// return { downloadUrl: `${body.url}?${qs.toString()}` };
// },
// getDerivativeDownloadUrl: async (urn, derivativeUrn) => {
// const { access_token } = await service.getInternalToken(); // must include data:read
// console.log(access_token, "accress_token");
// const encodedUrn = encodeURIComponent(urn);
// const encodedDerivative = encodeURIComponent(derivativeUrn);
// console.log("new url", encodedUrn);
// console.log("new deririvateovbe", encodedDerivative);
// const endpoint = `https://developer.api.autodesk.com/modelderivative/v2/designdata/${encodedUrn}/manifest/${encodedDerivative}/signedcookies`;
// const resp = await axios.get(endpoint, {
// headers: { Authorization: `Bearer ${access_token}` },
// validateStatus: (s) => s >= 200 && s < 500,
// });
// if (resp.status !== 200) {
// console.error(resp.data);
// throw new Error(
// `Forge returned ${resp.status}: ${JSON.stringify(resp.data)}`
// );
// }
// const body = resp.data;
// const rawSetCookie = (resp.headers["set-cookie"] || []).join("; ");
// const cookieParts = rawSetCookie.split("; ").map((c) => c.trim());
// const map = {};
// cookieParts.forEach((part) => {
// if (part.startsWith("CloudFront-Policy="))
// map.Policy = part.split("=")[1];
// if (part.startsWith("CloudFront-Key-Pair-Id="))
// map["Key-Pair-Id"] = part.split("=")[1];
// if (part.startsWith("CloudFront-Signature="))
// map.Signature = part.split("=")[1];
// });
// const qs = new URLSearchParams();
// if (map["Key-Pair-Id"]) qs.append("Key-Pair-Id", map["Key-Pair-Id"]);
// if (map.Signature) qs.append("Signature", map.Signature);
// if (map.Policy) qs.append("Policy", map.Policy);
// return { downloadUrl: `${body.url}?${qs.toString()}` };
// },
constructPdfUrl: (derivativeUrn) => {
return `https://developer.api.autodesk.com/model-derivative/v2/viewers/7.*/output/Resource/${
derivativeUrn.split(":")[2]
}`;
},
getFileNameFromUrn: (urn) => {
const parts = urn.split("/");
return parts[parts.length - 1] || "download.pdf";
},
// fresh new code
// getMetadata: async (urn) => {
// const { access_token } = await service.getInternalToken();
// try {
// const metadata = await modelDerivativeClient.getMetadata({
// urn,
// accessToken: access_token,
// });
// return metadata;
// } catch (err) {
// console.error(
// "Error fetching metadata:",
// err?.axiosError?.response?.data || err.message
// );
// throw new Error("Failed to fetch metadata: " + (err.message || ""));
// }
// },
getRawProperties: async (urn, guid) => {
const { access_token } = await service.getInternalToken();
try {
const props = await modelDerivativeClient.getModelProperties({
urn,
guid,
accessToken: access_token,
});
return props.data?.collection || [];
} catch (err) {
console.error(
"Error fetching properties:",
err?.axiosError?.response?.data || err.message
);
throw new Error("Failed to fetch raw properties: " + (err.message || ""));
}
},
extractMaterialsFromProperties: async (urn) => {
const metadata = await service.getMetadata(urn);
if (!metadata?.data?.metadata || metadata.data.metadata.length === 0) {
throw new Error("No metadata found. Model may not be translated yet.");
}
const guid = metadata.data.metadata[0].guid;
if (!guid) {
throw new Error("No GUID found in metadata");
}
const collection = await service.getRawProperties(urn, guid);
const materials = [];
for (const item of collection) {
const { properties, name, externalId } = item;
if (!properties) continue;
for (const categoryKey of Object.keys(properties)) {
const props = properties[categoryKey];
if (!props || typeof props !== "object") continue;
const materialName =
props["Material"] ??
props["Material Name"] ??
props["Finish"] ??
props["Render Material"] ??
null;
if (materialName) {
materials.push({
material: materialName,
category: categoryKey,
element: name,
externalId,
});
}
}
}
return materials;
},
getMetadata: async (urn) => {
const { access_token } = await service.getInternalToken();
try {
const response = await modelDerivativeClient.getManifest(
access_token,
urn
);
const derivative = response.body.derivatives?.[0];
if (!derivative) throw new Error("No derivatives found.");
return {
status: response.body.status,
derivativeUrn: derivative.urn,
children: derivative.children || [],
};
} catch (error) {
console.error("Error fetching metadata:", error.message);
throw new Error(`Failed to fetch metadata: ${error.message}`);
}
},
//endcode
urnify: (id) => Buffer.from(id).toString("base64").replace(/=/g, ""),
};
export default service;
![]() |
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
