Skip to content

Commit 687520f

Browse files
authored
Refactor fetch_node_contents for clarity and efficiency
1 parent ea98868 commit 687520f

1 file changed

Lines changed: 49 additions & 43 deletions

File tree

.github/workflows/ssg-node.yml

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ jobs:
7373
print(f" SAVED: {filepath}")
7474
7575
def fetch_node_contents(node_code, output_dir):
76-
url = f"{API_URL}/contents/node/code/{node_code}?fillValues=true&payloadOnly=true&withFiles=true"
76+
# Utiliser payloadOnly=false pour avoir les métadonnées
77+
url = f"{API_URL}/contents/node/code/{node_code}?fillValues=true&withFiles=true"
7778
print(f"Fetching contents for node: {node_code}")
7879
print(f"Calling: {url}")
7980
@@ -90,49 +91,54 @@ jobs:
9091
print(f"Found {len(contents)} content(s)")
9192
9293
for item in contents:
93-
if isinstance(item, dict):
94-
ssg = item.get('ssg', True)
95-
if ssg is False or ssg == 'false':
96-
print(f" SKIP: {item.get('code', 'unknown')} (ssg=false)")
97-
continue
98-
99-
content_type = item.get('type', '')
100-
payload = item.get('payload')
101-
file_name = item.get('fileName')
102-
code = item.get('code', '')
103-
104-
if not payload:
105-
print(f" SKIP: no payload for {code}")
106-
continue
107-
108-
if content_type in ['FILE', 'PICTURE'] and isinstance(payload, str):
109-
try:
110-
file_data = base64.b64decode(payload)
111-
filename = file_name if file_name else f"{code}.bin"
112-
filepath = os.path.join(output_dir, filename)
113-
os.makedirs(os.path.dirname(filepath) if os.path.dirname(filepath) else output_dir, exist_ok=True)
114-
with open(filepath, 'wb') as f:
115-
f.write(file_data)
116-
print(f" SAVED FILE: {filepath}")
117-
except Exception as e:
118-
print(f" ERROR decoding: {e}")
119-
continue
120-
121-
if file_name:
122-
filename = file_name
123-
else:
124-
ext = content_type.lower()
125-
if ext == 'style':
126-
ext = 'css'
127-
elif ext == 'script':
128-
ext = 'js'
129-
else:
130-
ext = ext.lower()
131-
filename = f"{code}.{ext}"
132-
133-
save_content(payload, output_dir, filename)
94+
if not isinstance(item, dict):
95+
print(f" SKIP: not a dict")
96+
continue
97+
98+
# Vérifier ssg
99+
ssg = item.get('ssg', True)
100+
if ssg is False or ssg == 'false':
101+
print(f" SKIP: {item.get('code', 'unknown')} (ssg=false)")
102+
continue
103+
104+
content_type = item.get('type', '')
105+
payload = item.get('payload')
106+
file_name = item.get('fileName')
107+
code = item.get('code', '')
108+
109+
if not payload:
110+
print(f" SKIP: no payload for {code}")
111+
continue
112+
113+
# Gestion des fichiers binaires (FILE, PICTURE)
114+
if content_type in ['FILE', 'PICTURE'] and isinstance(payload, str):
115+
try:
116+
file_data = base64.b64decode(payload)
117+
filename = file_name if file_name else f"{code}.bin"
118+
filepath = os.path.join(output_dir, filename)
119+
os.makedirs(os.path.dirname(filepath) if os.path.dirname(filepath) else output_dir, exist_ok=True)
120+
with open(filepath, 'wb') as f:
121+
f.write(file_data)
122+
print(f" SAVED FILE: {filepath}")
123+
except Exception as e:
124+
print(f" ERROR decoding: {e}")
125+
continue
126+
127+
# Déterminer le nom du fichier
128+
if file_name:
129+
filename = file_name
134130
else:
135-
print(f" SKIP: raw content not supported without metadata")
131+
ext = content_type.lower()
132+
if ext == 'style':
133+
ext = 'css'
134+
elif ext == 'script':
135+
ext = 'js'
136+
else:
137+
ext = ext.lower()
138+
filename = f"{code}.{ext}"
139+
140+
save_content(payload, output_dir, filename)
141+
136142
except json.JSONDecodeError as e:
137143
print(f"Error parsing contents: {e}")
138144

0 commit comments

Comments
 (0)