MCPcopy Create free account
hub / github.com/AstroPrint/AstroBox / designs

Function designs

src/astroprint/api/cloud.py:104–168  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

102@api.route("/astroprint/print-files", methods=["GET"])
103@restricted_access
104def designs():
105 forceSyncCloud = request.args.get('forceSyncCloud')
106 cloud_files = None
107 cloudInstance = astroprintCloud()
108 if not cloudInstance.fleetId:
109 cloud_files = json.loads(cloudInstance.print_files(forceSyncCloud))
110 local_files = list(printerManager().fileManager.getAllFileData())
111
112 if cloud_files:
113 for p in cloud_files:
114 p['local_filename'] = None
115 p['last_print'] = None
116 p['uploaded_on'] = None
117 for i in range(len(local_files)):
118 cloud_id = local_files[i].get("cloud_id")
119 if cloud_id and p['id'] == cloud_id:
120 local_file = local_files[i]
121 p['local_filename'] = local_file['name']
122 p['local_only'] = False
123 p['uploaded_on'] = local_file['date']
124 gcodeAnalysis = local_file.get("gcodeAnalysis")
125 if gcodeAnalysis:
126 p["info"] = gcodeAnalysis
127
128 if 'prints' in local_file \
129 and 'last' in local_file['prints'] \
130 and local_file['prints']['last'] \
131 and 'date' in local_file['prints']['last']:
132 p['last_print'] = local_file['prints']['last']['date']
133
134 del local_files[i]
135
136 break
137
138 cloud_files = sorted(cloud_files, key=lambda e: e['local_filename'] is None)
139
140 else:
141 cloud_files = []
142
143 if local_files:
144 for p in local_files:
145 p['id'] = uuid.uuid4().hex
146 p['local_filename'] = p['name']
147 p['local_only'] = True
148 p['last_print'] = None
149 p['uploaded_on'] = p['date']
150 if 'gcodeAnalysis' in p:
151 p['info'] = p['gcodeAnalysis']
152 del p['gcodeAnalysis']
153 else:
154 p['info'] = None
155
156 if 'prints' in p \
157 and 'last' in p['prints'] \
158 and p['prints']['last'] \
159 and 'date' in p['prints']['last']:
160 p['last_print'] = p['prints']['last']['date']
161 del p['prints']

Callers

nothing calls this directly

Calls 5

astroprintCloudFunction · 0.90
printerManagerFunction · 0.90
print_filesMethod · 0.80
getAllFileDataMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected