-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
232980f
commit e83bb5f
Showing
1 changed file
with
21 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }); | ||
}; |