cycls 0.0.2.103__py3-none-any.whl → 0.0.2.105__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,8 +17,8 @@
17
17
  rel="stylesheet"
18
18
  href="https://esm.sh/katex@0.16.8/dist/katex.min.css"
19
19
  />
20
- <script type="module" crossorigin src="/assets/index-qcHL6SRo.js"></script>
21
- <link rel="stylesheet" crossorigin href="/assets/index-CjN0qc53.css">
20
+ <script type="module" crossorigin src="/assets/index-DMDqC1yz.js"></script>
21
+ <link rel="stylesheet" crossorigin href="/assets/index-q-dOswxc.css">
22
22
  </head>
23
23
  <body style="overflow-x: hidden">
24
24
  <div id="root"></div>
cycls/web.py CHANGED
@@ -1,4 +1,5 @@
1
- import json, inspect
1
+ import json, inspect, secrets
2
+ from urllib.parse import quote
2
3
  from pathlib import Path
3
4
  from pydantic import BaseModel
4
5
  from typing import Optional, Any
@@ -114,11 +115,13 @@ def web(func, config):
114
115
  raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=f"Invalid token: {e}", headers={"WWW-Authenticate": "Bearer"})
115
116
  except Exception as e:
116
117
  raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=f"Auth error: {e}", headers={"WWW-Authenticate": "Bearer"})
117
-
118
+
119
+ auth = Depends(validate) if config.auth else None
120
+
118
121
  @app.post("/")
119
122
  @app.post("/chat/cycls")
120
123
  @app.post("/chat/completions")
121
- async def back(request: Request, jwt: Optional[dict] = Depends(validate) if config.auth else None):
124
+ async def back(request: Request, jwt: Optional[dict] = auth):
122
125
  data = await request.json()
123
126
  messages = data.get("messages")
124
127
  user_data = jwt.get("user") if jwt else None
@@ -137,22 +140,22 @@ def web(func, config):
137
140
  async def get_config():
138
141
  return config
139
142
 
140
- @app.post("/files")
141
- async def upload_file(file: UploadFile = File(...), jwt: dict = Depends(validate)):
142
- user_id = jwt["user"]["id"]
143
- user_dir = Path(f"/workspace/{user_id}/files")
144
- user_dir.mkdir(parents=True, exist_ok=True)
143
+ @app.post("/attachments")
144
+ async def upload_attachment(request: Request, file: UploadFile = File(...), jwt: Optional[dict] = auth):
145
+ token = secrets.token_urlsafe(32)
146
+ token_dir = Path(f"/workspace/attachments/{token}")
147
+ token_dir.mkdir(parents=True, exist_ok=True)
145
148
 
146
- file_path = user_dir / file.filename
149
+ file_path = token_dir / file.filename
147
150
  with open(file_path, "wb") as f:
148
151
  f.write(await file.read())
149
152
 
150
- return {"url": f"/files/{file.filename}"}
153
+ base_url = str(request.base_url).rstrip("/")
154
+ return {"url": f"{base_url}/attachments/{token}/{quote(file.filename)}"}
151
155
 
152
- @app.get("/files/{filename}")
153
- async def get_file(filename: str, jwt: dict = Depends(validate)):
154
- user_id = jwt["user"]["id"]
155
- file_path = Path(f"/workspace/{user_id}/files") / filename
156
+ @app.get("/attachments/{token}/{filename}")
157
+ async def get_attachment(token: str, filename: str):
158
+ file_path = Path(f"/workspace/attachments/{token}") / filename
156
159
 
157
160
  if not file_path.exists():
158
161
  raise HTTPException(status_code=404, detail="File not found")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cycls
3
- Version: 0.0.2.103
3
+ Version: 0.0.2.105
4
4
  Summary: Distribute Intelligence
5
5
  Author-email: "Mohammed J. AlRujayi" <mj@cycls.com>
6
6
  Requires-Python: >=3.10
@@ -0,0 +1,20 @@
1
+ cycls/__init__.py,sha256=XnLv709ktYzCVON0PwwFZFe6_m54pXfXZH9-niTxYxU,121
2
+ cycls/app.py,sha256=k5TS4mvbmQQsjGW9mAGexzOloPA5ASS30ZDCy_A1m8Y,3285
3
+ cycls/auth.py,sha256=xkndHZyCfnlertMMEKerCJjf23N3fVcTRVTTSXTTuzg,247
4
+ cycls/cli.py,sha256=cVbIkTDnVofohvByyYUrXF_RYDQZVQECJqo7cPBPJfs,4781
5
+ cycls/function.py,sha256=JiJZ1xDoGIsfDe4_o6DvCb5tIbZ5VGbDEP1ttsCpcm4,16347
6
+ cycls/web.py,sha256=hP-_VDoVZKdPx45AF8ipBci0JAc4-YO7E5-66e9UCAA,6590
7
+ cycls/themes/default/index.html,sha256=0abrYRyBokKNWLIz0RryvBomYnOPi_ItfrpHN6EKC7o,1082
8
+ cycls/themes/default/assets/FileSaver.min-D3FSkpuq.js,sha256=vV1HznTqRgC3DxT6jQj3MCh4VLnXOj0riK3e8r5WZUM,3009
9
+ cycls/themes/default/assets/html2canvas.esm-CBrSDip1.js,sha256=tPOt2Amm1Z9GJg6P1WyrJA8xU975dzhrIwqDnoywsoE,202301
10
+ cycls/themes/default/assets/index-DMDqC1yz.js,sha256=0_54cKL-8oGVwNL-kz71DZvKldqDX4CtIR-5Crve2DM,1761736
11
+ cycls/themes/default/assets/index-q-dOswxc.css,sha256=LaxMkQEBU6wUVRdSXtMIvdJiUpHm5TxKKQCEZQL5C9s,8493
12
+ cycls/themes/default/assets/index-vX_oGdsN.js,sha256=CiDDAGv9nDWUNtKfhHFtXBg_DcwG4iGN8gkPZKfm0AA,395723
13
+ cycls/themes/default/assets/index.es-C6RWrIg8.js,sha256=tL4ythD5tPrYImzM78n_AbANrkzPC0v-ePMh7gab7-E,159345
14
+ cycls/themes/default/assets/jspdf.es.min-Cx6CH6ND.js,sha256=9qdYqWk0a0GxVdj0GdXJQmDW2G3YS1dDM44sLKIb_rY,388078
15
+ cycls/themes/default/assets/purify.es-B9ZVCkUG.js,sha256=j5lP7czBWW-_UT-iJC8cboa3pTAxBhTf5bOyjWN99G4,22636
16
+ cycls/themes/dev/index.html,sha256=QJBHkdNuMMiwQU7o8dN8__8YQeQB45D37D-NCXIWB2Q,11585
17
+ cycls-0.0.2.105.dist-info/METADATA,sha256=uuaDGE2arLAo6fpISrKqsp7wat739ogjnfR5RpzPFYQ,8871
18
+ cycls-0.0.2.105.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
19
+ cycls-0.0.2.105.dist-info/entry_points.txt,sha256=CktT5eNvW_Qxomf7L_Ez_GdUbL6qAfx_Utm6_HtUJwE,41
20
+ cycls-0.0.2.105.dist-info/RECORD,,
@@ -1 +0,0 @@
1
- import{c as p,g as _}from"./index-qcHL6SRo.js";function x(u,m){for(var l=0;l<m.length;l++){const r=m[l];if(typeof r!="string"&&!Array.isArray(r)){for(const s in r)if(s!=="default"&&!(s in u)){const c=Object.getOwnPropertyDescriptor(r,s);c&&Object.defineProperty(u,s,c.get?c:{enumerable:!0,get:()=>r[s]})}}}return Object.freeze(Object.defineProperty(u,Symbol.toStringTag,{value:"Module"}))}var v={exports:{}},F=v.exports,E;function O(){return E||(E=1,(function(u,m){(function(l,r){r()})(F,function(){function l(e,t){return typeof t>"u"?t={autoBom:!1}:typeof t!="object"&&(console.warn("Deprecated: Expected third argument to be a object"),t={autoBom:!t}),t.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)?new Blob(["\uFEFF",e],{type:e.type}):e}function r(e,t,i){var n=new XMLHttpRequest;n.open("GET",e),n.responseType="blob",n.onload=function(){d(n.response,t,i)},n.onerror=function(){console.error("could not download file")},n.send()}function s(e){var t=new XMLHttpRequest;t.open("HEAD",e,!1);try{t.send()}catch{}return 200<=t.status&&299>=t.status}function c(e){try{e.dispatchEvent(new MouseEvent("click"))}catch{var t=document.createEvent("MouseEvents");t.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),e.dispatchEvent(t)}}var a=typeof window=="object"&&window.window===window?window:typeof self=="object"&&self.self===self?self:typeof p=="object"&&p.global===p?p:void 0,b=a.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),d=a.saveAs||(typeof window!="object"||window!==a?function(){}:"download"in HTMLAnchorElement.prototype&&!b?function(e,t,i){var n=a.URL||a.webkitURL,o=document.createElement("a");t=t||e.name||"download",o.download=t,o.rel="noopener",typeof e=="string"?(o.href=e,o.origin===location.origin?c(o):s(o.href)?r(e,t,i):c(o,o.target="_blank")):(o.href=n.createObjectURL(e),setTimeout(function(){n.revokeObjectURL(o.href)},4e4),setTimeout(function(){c(o)},0))}:"msSaveOrOpenBlob"in navigator?function(e,t,i){if(t=t||e.name||"download",typeof e!="string")navigator.msSaveOrOpenBlob(l(e,i),t);else if(s(e))r(e,t,i);else{var n=document.createElement("a");n.href=e,n.target="_blank",setTimeout(function(){c(n)})}}:function(e,t,i,n){if(n=n||open("","_blank"),n&&(n.document.title=n.document.body.innerText="downloading..."),typeof e=="string")return r(e,t,i);var o=e.type==="application/octet-stream",S=/constructor/i.test(a.HTMLElement)||a.safari,h=/CriOS\/[\d]+/.test(navigator.userAgent);if((h||o&&S||b)&&typeof FileReader<"u"){var w=new FileReader;w.onloadend=function(){var f=w.result;f=h?f:f.replace(/^data:[^;]*;/,"data:attachment/file;"),n?n.location.href=f:location=f,n=null},w.readAsDataURL(e)}else{var j=a.URL||a.webkitURL,y=j.createObjectURL(e);n?n.location=y:location.href=y,n=null,setTimeout(function(){j.revokeObjectURL(y)},4e4)}});a.saveAs=d.saveAs=d,u.exports=d})})(v)),v.exports}var g=O();const R=_(g),L=x({__proto__:null,default:R},[g]);export{L as F};