Philasil commited on
Commit
870ea08
·
verified ·
1 Parent(s): 13e8bb3

Support model repos and bare paths in addition to buckets/ prefix

Browse files
Files changed (1) hide show
  1. app.py +22 -6
app.py CHANGED
@@ -115,8 +115,17 @@ def sign(
115
  _check_admin(t, authorization)
116
  _check_bucket(bucket)
117
  path = path.lstrip("/")
118
- full = f"buckets/{bucket}/{path}"
119
- if not fs.exists(full):
 
 
 
 
 
 
 
 
 
120
  raise HTTPException(404, f"file not found: {bucket}/{path}")
121
  exp = int(time.time()) + ttl
122
  sig = _sign(bucket, path, exp)
@@ -146,10 +155,17 @@ def download(
146
  if not hmac.compare_digest(expected, sig):
147
  raise HTTPException(403, "bad signature")
148
 
149
- full = f"buckets/{b}/{f}"
150
- try:
151
- info = fs.info(full)
152
- except FileNotFoundError:
 
 
 
 
 
 
 
153
  raise HTTPException(404, "file not found")
154
  size = info.get("size")
155
 
 
115
  _check_admin(t, authorization)
116
  _check_bucket(bucket)
117
  path = path.lstrip("/")
118
+ # Try model repo first (no prefix), then datasets/, then buckets/
119
+ candidates = [f"{bucket}/{path}", f"datasets/{bucket}/{path}", f"buckets/{bucket}/{path}"]
120
+ full = None
121
+ for c in candidates:
122
+ try:
123
+ if fs.exists(c):
124
+ full = c
125
+ break
126
+ except Exception:
127
+ continue
128
+ if full is None:
129
  raise HTTPException(404, f"file not found: {bucket}/{path}")
130
  exp = int(time.time()) + ttl
131
  sig = _sign(bucket, path, exp)
 
155
  if not hmac.compare_digest(expected, sig):
156
  raise HTTPException(403, "bad signature")
157
 
158
+ candidates = [f"{b}/{f}", f"datasets/{b}/{f}", f"buckets/{b}/{f}"]
159
+ full = None
160
+ info = None
161
+ for c in candidates:
162
+ try:
163
+ info = fs.info(c)
164
+ full = c
165
+ break
166
+ except Exception:
167
+ continue
168
+ if full is None:
169
  raise HTTPException(404, "file not found")
170
  size = info.get("size")
171