reportflow-mcp bot commited on
Commit
147e016
·
1 Parent(s): 04eeb91

Sync Space from reportflow-mcp@dc2e990

Browse files
Files changed (2) hide show
  1. app.py +6 -6
  2. workspace.py +9 -9
app.py CHANGED
@@ -39,8 +39,8 @@ from workspace import (
39
  design_choices,
40
  design_parameters,
41
  empty_params_template,
42
- ensure_pdf_filename,
43
  filename_from_choice_label,
 
44
  list_designs,
45
  parse_design_choice,
46
  render_document,
@@ -224,7 +224,7 @@ def _empty_workspace(
224
  gr.update(choices=[], value=None),
225
  "Sign in, then pick one of your designs. The fields below become the form.",
226
  "{}",
227
- "document.pdf",
228
  "",
229
  )
230
 
@@ -284,7 +284,7 @@ def _workspace_form(session_id: str, prefer: str | None = None):
284
  gr.update(choices=[], value=None),
285
  "This workspace has no designs yet. Copy a public slug from the gallery above (once).",
286
  "{}",
287
- "document.pdf",
288
  "",
289
  )
290
  selected = choices[0][1]
@@ -352,7 +352,7 @@ def load_selected_design(
352
  choice: str, visitor_key: str | None, request: gr.Request
353
  ) -> tuple[str, str, str]:
354
  _, _, label = (choice or "").partition("::")
355
- suggested = filename_from_choice_label(label) if label else "document.pdf"
356
  try:
357
  guide, template = _schema_for_choice(_bound(request, visitor_key), choice)
358
  except OAuthError as err:
@@ -392,7 +392,7 @@ def render_my_document(
392
  design_id,
393
  version,
394
  params,
395
- ensure_pdf_filename(file_name),
396
  )
397
  except (OAuthError, ValueError, json.JSONDecodeError) as err:
398
  return str(err)
@@ -489,7 +489,7 @@ workspace, sign in below. The Hub MCP tools on this Space stay read-only.
489
  value="{}",
490
  interactive=True,
491
  )
492
- file_name = gr.Textbox(label="file name (.pdf is added if missing)", value="document.pdf")
493
  render_btn = gr.Button("Render from this workspace", variant="primary")
494
  render_out = gr.Markdown()
495
  workspace_outputs = [
 
39
  design_choices,
40
  design_parameters,
41
  empty_params_template,
 
42
  filename_from_choice_label,
43
+ sanitize_filename,
44
  list_designs,
45
  parse_design_choice,
46
  render_document,
 
224
  gr.update(choices=[], value=None),
225
  "Sign in, then pick one of your designs. The fields below become the form.",
226
  "{}",
227
+ "document",
228
  "",
229
  )
230
 
 
284
  gr.update(choices=[], value=None),
285
  "This workspace has no designs yet. Copy a public slug from the gallery above (once).",
286
  "{}",
287
+ "document",
288
  "",
289
  )
290
  selected = choices[0][1]
 
352
  choice: str, visitor_key: str | None, request: gr.Request
353
  ) -> tuple[str, str, str]:
354
  _, _, label = (choice or "").partition("::")
355
+ suggested = filename_from_choice_label(label) if label else "document"
356
  try:
357
  guide, template = _schema_for_choice(_bound(request, visitor_key), choice)
358
  except OAuthError as err:
 
392
  design_id,
393
  version,
394
  params,
395
+ sanitize_filename(file_name),
396
  )
397
  except (OAuthError, ValueError, json.JSONDecodeError) as err:
398
  return str(err)
 
489
  value="{}",
490
  interactive=True,
491
  )
492
+ file_name = gr.Textbox(label="file name", value="document")
493
  render_btn = gr.Button("Render from this workspace", variant="primary")
494
  render_out = gr.Markdown()
495
  workspace_outputs = [
workspace.py CHANGED
@@ -126,7 +126,7 @@ def render_document(
126
  design_id: str,
127
  version: int,
128
  params: dict[str, Any],
129
- file_name: str = "document.pdf",
130
  client: httpx.Client | None = None,
131
  ) -> dict[str, Any]:
132
  if "/" in design_id or ".." in design_id or not design_id.strip():
@@ -141,7 +141,7 @@ def render_document(
141
  "designId": design_id.strip(),
142
  "version": version,
143
  "content": {
144
- "fileName": ensure_pdf_filename(file_name),
145
  "params": sanitize_params_for_render(params),
146
  },
147
  },
@@ -222,16 +222,16 @@ _VERSION_SUFFIX = re.compile(r"\s+\(v\d+\)\s*$")
222
  _UNSAFE_FILENAME = re.compile(r'[/\\:*?"<>|\x00-\x1f]+')
223
 
224
 
225
- def filename_from_choice_label(label: str) -> str:
226
- return ensure_pdf_filename(_VERSION_SUFFIX.sub("", label or "").strip())
227
-
228
-
229
- def ensure_pdf_filename(name: str, fallback: str = "document") -> str:
230
  base = _UNSAFE_FILENAME.sub("", (name or "").strip()) or fallback
231
  if base.lower().endswith(".pdf"):
232
  base = base[:-4].rstrip()
233
- base = base or fallback
234
- return f"{base}.pdf"
 
 
 
235
 
236
 
237
  def sanitize_params_for_render(params: dict[str, Any]) -> dict[str, Any]:
 
126
  design_id: str,
127
  version: int,
128
  params: dict[str, Any],
129
+ file_name: str = "document",
130
  client: httpx.Client | None = None,
131
  ) -> dict[str, Any]:
132
  if "/" in design_id or ".." in design_id or not design_id.strip():
 
141
  "designId": design_id.strip(),
142
  "version": version,
143
  "content": {
144
+ "fileName": sanitize_filename(file_name),
145
  "params": sanitize_params_for_render(params),
146
  },
147
  },
 
222
  _UNSAFE_FILENAME = re.compile(r'[/\\:*?"<>|\x00-\x1f]+')
223
 
224
 
225
+ def sanitize_filename(name: str, fallback: str = "document") -> str:
226
+ """Basename only. content-service adds .pdf itself — do not send it."""
 
 
 
227
  base = _UNSAFE_FILENAME.sub("", (name or "").strip()) or fallback
228
  if base.lower().endswith(".pdf"):
229
  base = base[:-4].rstrip()
230
+ return base or fallback
231
+
232
+
233
+ def filename_from_choice_label(label: str) -> str:
234
+ return sanitize_filename(_VERSION_SUFFIX.sub("", label or "").strip())
235
 
236
 
237
  def sanitize_params_for_render(params: dict[str, Any]) -> dict[str, Any]: