HermesAgent commited on
Commit
e583820
·
1 Parent(s): f8002a8

fix: rename R2 files with slugified prompt

Browse files
Files changed (1) hide show
  1. r2_uploader.py +9 -1
r2_uploader.py CHANGED
@@ -154,6 +154,13 @@ def _client(cfg: dict):
154
  )
155
 
156
 
 
 
 
 
 
 
 
157
  def _now_stamp() -> str:
158
  return datetime.datetime.now(datetime.timezone.utc).strftime("%Y%m%d%H%M%S")
159
 
@@ -256,7 +263,8 @@ def upload_asset(
256
  data = fh.read()
257
 
258
  safe_uid = uid or "anonymous"
259
- filekey = f"{namespace}/{safe_uid}/{_now_stamp()}-{uuid.uuid4().hex[:8]}{ext}"
 
260
 
261
  s3 = _client(cfg)
262
  _ensure_bucket(s3, bucket)
 
154
  )
155
 
156
 
157
+ def _slugify(text):
158
+ import re
159
+ text = str(text).lower()
160
+ text = re.sub(r'[^\w\s-]', '', text)
161
+ text = re.sub(r'[\s_-]+', '-', text)
162
+ return text[:50]
163
+
164
  def _now_stamp() -> str:
165
  return datetime.datetime.now(datetime.timezone.utc).strftime("%Y%m%d%H%M%S")
166
 
 
263
  data = fh.read()
264
 
265
  safe_uid = uid or "anonymous"
266
+ slug = _slugify(prompt)
267
+ filekey = f"{namespace}/{safe_uid}/{slug}-{_now_stamp()}-{uuid.uuid4().hex[:8]}{ext}"
268
 
269
  s3 = _client(cfg)
270
  _ensure_bucket(s3, bucket)