Spaces:
Sleeping
Sleeping
CocoonAI
commited on
Commit
·
04342ca
1
Parent(s):
8beeaaf
Update app.py
Browse files
app.py
CHANGED
|
@@ -202,4 +202,26 @@ async def add_resource(
|
|
| 202 |
try:
|
| 203 |
safe_title = title.replace(" ", "_").lower()
|
| 204 |
file_path = f"Resources_and_Skills/resources/{safe_title}.md"
|
| 205 |
-
content = f"#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
try:
|
| 203 |
safe_title = title.replace(" ", "_").lower()
|
| 204 |
file_path = f"Resources_and_Skills/resources/{safe_title}.md"
|
| 205 |
+
content = f"""# 📎 {title}
|
| 206 |
+
- Type: {resource_type}
|
| 207 |
+
- Link: {link}
|
| 208 |
+
"""
|
| 209 |
+
|
| 210 |
+
vault_path = get_user_vault_path(user_id)
|
| 211 |
+
full_path = os.path.join(vault_path, file_path)
|
| 212 |
+
os.makedirs(os.path.dirname(full_path), exist_ok=True)
|
| 213 |
+
|
| 214 |
+
# Write to file
|
| 215 |
+
with open(full_path, "w", encoding="utf-8") as f:
|
| 216 |
+
f.write(content.strip())
|
| 217 |
+
|
| 218 |
+
# Sync with Supabase
|
| 219 |
+
supabase_client.table("vault_files").upsert({
|
| 220 |
+
"user_id": user_id,
|
| 221 |
+
"path": file_path,
|
| 222 |
+
"content": content.strip()
|
| 223 |
+
}).execute()
|
| 224 |
+
|
| 225 |
+
return {"status": "Resource saved.", "file": file_path}
|
| 226 |
+
except Exception as e:
|
| 227 |
+
return JSONResponse(status_code=500, content={"error": str(e)})
|