SeaWolf-AI commited on
Commit
6216937
ยท
verified ยท
1 Parent(s): 95ef3f4

fix restore path filter; dedicated participant key header

Browse files
Files changed (3) hide show
  1. app/ledger.py +11 -5
  2. app/main.py +11 -4
  3. app/static/index.html +1 -1
app/ledger.py CHANGED
@@ -67,21 +67,26 @@ def restore():
67
  a.repo_info(MIRROR, repo_type="dataset")
68
  except Exception:
69
  a.create_repo(MIRROR, repo_type="dataset", private=True, exist_ok=True)
70
- d = snapshot_download(MIRROR, repo_type="dataset",
71
- token=a.token, local_dir=None)
 
 
 
 
72
  import shutil, glob
73
  os.makedirs(os.path.join(ROOT, "positions"), exist_ok=True)
74
  n = 0
75
  for src in glob.glob(os.path.join(d, "**", "*"), recursive=True):
76
- if not os.path.isfile(src) or os.sep + ".cache" in src:
77
  continue
78
  rel = os.path.relpath(src, d)
79
- if rel.startswith(".git"):
80
  continue
81
  dst = os.path.join(ROOT, rel)
82
  os.makedirs(os.path.dirname(dst), exist_ok=True)
83
  shutil.copyfile(src, dst)
84
  n += 1
 
85
  _MIR["ok"] = True
86
  _MIR["n"] = n
87
  return "๋ณต์› %d๊ฐœ" % n
@@ -98,7 +103,8 @@ def flush(force=False):
98
  a = _api()
99
  a.upload_folder(repo_id=MIRROR, repo_type="dataset", folder_path=ROOT,
100
  commit_message="ledger sync",
101
- ignore_patterns=["*.tmp", ".cache/*"])
 
102
  _MIR["dirty"] = False
103
  _MIR["at"] = time.time()
104
  return True
 
67
  a.repo_info(MIRROR, repo_type="dataset")
68
  except Exception:
69
  a.create_repo(MIRROR, repo_type="dataset", private=True, exist_ok=True)
70
+ # ๐Ÿ”ด ๊ธฐ๋ณธ ์บ์‹œ๋กœ ๋ฐ›์œผ๋ฉด ๊ฒฝ๋กœ์— .cache ๊ฐ€ ๋“ค์–ด๊ฐ„๋‹ค. ๊ทธ๊ฑธ ๊ฑธ๋Ÿฌ๋‚ด๋Š”
71
+ # ํ•„ํ„ฐ๋ฅผ ๋‘๋ฉด **๋ฐ›์€ ํŒŒ์ผ์ด ์ „๋ถ€ ๊ฑธ๋Ÿฌ์ง„๋‹ค** โ€” ์‹ค์ œ๋กœ ๊ทธ๋ ‡๊ฒŒ ๋˜์–ด
72
+ # "๋ณต์› 0๊ฐœ"๊ฐ€ ๋‚˜์™”๋‹ค. ๋ชฉ์ ์ง€๋ฅผ ์šฐ๋ฆฌ๊ฐ€ ์ •ํ•ด ๊ทธ ํ•จ์ •์„ ์—†์•ค๋‹ค.
73
+ tmp = os.path.join(ROOT, ".restore")
74
+ d = snapshot_download(MIRROR, repo_type="dataset", token=a.token,
75
+ local_dir=tmp)
76
  import shutil, glob
77
  os.makedirs(os.path.join(ROOT, "positions"), exist_ok=True)
78
  n = 0
79
  for src in glob.glob(os.path.join(d, "**", "*"), recursive=True):
80
+ if not os.path.isfile(src):
81
  continue
82
  rel = os.path.relpath(src, d)
83
+ if rel.startswith(".git") or rel.startswith(".huggingface"):
84
  continue
85
  dst = os.path.join(ROOT, rel)
86
  os.makedirs(os.path.dirname(dst), exist_ok=True)
87
  shutil.copyfile(src, dst)
88
  n += 1
89
+ shutil.rmtree(tmp, ignore_errors=True)
90
  _MIR["ok"] = True
91
  _MIR["n"] = n
92
  return "๋ณต์› %d๊ฐœ" % n
 
103
  a = _api()
104
  a.upload_folder(repo_id=MIRROR, repo_type="dataset", folder_path=ROOT,
105
  commit_message="ledger sync",
106
+ ignore_patterns=["*.tmp", ".cache/*", ".restore/*",
107
+ ".huggingface/*"])
108
  _MIR["dirty"] = False
109
  _MIR["at"] = time.time()
110
  return True
app/main.py CHANGED
@@ -194,9 +194,14 @@ async def api_register(req: Request):
194
 
195
 
196
  @app.post("/api/submit")
197
- async def api_submit(req: Request, authorization: str = Header(None)):
 
198
  b = await req.json()
199
- key = (authorization or "").replace("Bearer ", "").strip() or b.get("key", "")
 
 
 
 
200
  try:
201
  u = me_from(key)
202
  except PermissionError as e:
@@ -280,9 +285,11 @@ def _call(name, args, key=None):
280
 
281
 
282
  @app.post("/mcp")
283
- async def mcp_endpoint(req: Request, authorization: str = Header(None)):
 
284
  body = await req.json()
285
- key = (authorization or "").replace("Bearer ", "").strip()
 
286
  resp = MCP.handle(body, lambda n, a: _call(n, a, key))
287
  if resp is None:
288
  return JSONResponse({}, 202)
 
194
 
195
 
196
  @app.post("/api/submit")
197
+ async def api_submit(req: Request, authorization: str = Header(None),
198
+ x_finchal_key: str = Header(None)):
199
  b = await req.json()
200
+ # Authorization ์€ ์•ž๋‹จ ํ”„๋ก์‹œ๊ฐ€ ์ž๊ธฐ ์ธ์ฆ์— ์“ฐ๊ธฐ๋„ ํ•œ๋‹ค. ๊ทธ๋•Œ ์ฐธ๊ฐ€ํ‚ค๊ฐ€
201
+ # ์•ฑ๊นŒ์ง€ ์˜ค์ง€ ์•Š๋Š”๋‹ค. ์ „์šฉ ํ—ค๋”๋ฅผ ํ•จ๊ป˜ ๋ฐ›์•„ ๊ทธ ์ถฉ๋Œ์„ ํ”ผํ•œ๋‹ค.
202
+ key = ((x_finchal_key or "").strip()
203
+ or (authorization or "").replace("Bearer ", "").strip()
204
+ or b.get("key", ""))
205
  try:
206
  u = me_from(key)
207
  except PermissionError as e:
 
285
 
286
 
287
  @app.post("/mcp")
288
+ async def mcp_endpoint(req: Request, authorization: str = Header(None),
289
+ x_finchal_key: str = Header(None)):
290
  body = await req.json()
291
+ key = ((x_finchal_key or "").strip()
292
+ or (authorization or "").replace("Bearer ", "").strip())
293
  resp = MCP.handle(body, lambda n, a: _call(n, a, key))
294
  if resp is None:
295
  return JSONResponse({}, 202)
app/static/index.html CHANGED
@@ -413,7 +413,7 @@ async function submit(){
413
  const pos = +document.getElementById('pos').value / 100;
414
  const r = await (await fetch('/api/submit', {method:'POST',
415
  headers:{'Content-Type':'application/json',
416
- 'Authorization':'Bearer ' + reg.key},
417
  body:JSON.stringify({asset:ASSET, position:pos, source:'web'})})).json();
418
  if(!r.ok) throw new Error(r.error || '์‹คํŒจ');
419
  msg.innerHTML = `<div class="key"><b>์ ‘์ˆ˜๋์Šต๋‹ˆ๋‹ค.</b>
 
413
  const pos = +document.getElementById('pos').value / 100;
414
  const r = await (await fetch('/api/submit', {method:'POST',
415
  headers:{'Content-Type':'application/json',
416
+ 'X-Finchal-Key': reg.key}, /* ์•ž๋‹จ ํ”„๋ก์‹œ์™€ ์•ˆ ๋ถ€๋”ชํžˆ๋Š” ์ „์šฉ ํ—ค๋” */
417
  body:JSON.stringify({asset:ASSET, position:pos, source:'web'})})).json();
418
  if(!r.ok) throw new Error(r.error || '์‹คํŒจ');
419
  msg.innerHTML = `<div class="key"><b>์ ‘์ˆ˜๋์Šต๋‹ˆ๋‹ค.</b>