Skip to content

Commit

Permalink
Update createZip.js
Browse files Browse the repository at this point in the history
  • Loading branch information
halfmanbear authored Aug 30, 2024
1 parent 232980f commit e83bb5f
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/pages/Generator/createZip.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
import JSZip from "jszip";

function addFile(zip, type, file) {
// Add "-OpenNept4une" to the file name before the .json extension
let path = `${type}/${file.name}-OpenNept4une.json`;
console.log(`Adding file to zip: ${path} with content:`, file.content);
zip.file(path, JSON.stringify(file.content)); // Minified JSON output
}

function generateBundleStructure(printer_profiles, filament_profiles, process_profiles) {
const currentDateTime = new Date().toISOString().replace(/[-:.TZ]/g, '').slice(0, 14);

console.log(`Adding file to zip: ${path} with content:`, file.content); // Log file content to verify it is not empty
zip.file(path, JSON.stringify(file.content, null, 2)); // Ensure content is correctly stringified
return {
bundle_id: `offline_${printer_profiles[0].name}-OpenNept4une_${currentDateTime}`,
bundle_type: "printer config bundle",
filament_config: filament_profiles.map(file => `filament/${file.name}-OpenNept4une.json`),
printer_config: printer_profiles.map(file => `printer/${file.name}-OpenNept4une.json`),
printer_preset_name: `${printer_profiles[0].name}-OpenNept4une`,
process_config: process_profiles.map(file => `process/${file.name}-OpenNept4une.json`),
version: "" // You can set a version if required
};
}

export const createZip = async (printer_profiles, filament_profiles, process_profiles) => {
const zip = new JSZip();

printer_profiles.forEach((profile) => {
const file = { name: profile.name, content: profile };
printer_profiles.forEach((file) => {
addFile(zip, "printers", file);
});

filament_profiles.forEach((profile) => {
const file = { name: profile.name, content: profile };
filament_profiles.forEach((file) => {
addFile(zip, "filaments", file);
});

process_profiles.forEach((profile) => {
const file = { name: profile.name, content: profile };
process_profiles.forEach((file) => {
addFile(zip, "processes", file);
});

const bundleStructure = generateBundleStructure(printer_profiles, filament_profiles, process_profiles);
zip.file("bundle_structure.json", JSON.stringify(bundleStructure)); // Minified JSON output

return zip.generateAsync({ type: "blob" });
};

0 comments on commit e83bb5f

Please sign in to comment.