Spaces:
Running
Running
fix restore path filter; dedicated participant key header
Browse files- app/ledger.py +11 -5
- app/main.py +11 -4
- 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 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 = (
|
|
|
|
| 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 |
-
'
|
| 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>
|