Spaces:
Sleeping
Sleeping
CocoonAI
commited on
Commit
·
ffe3f33
1
Parent(s):
a8d2456
Update
Browse files- app.py +11 -3
- profile_writer.py +2 -2
app.py
CHANGED
|
@@ -111,7 +111,15 @@ async def save_profile(req: ProfileRequest):
|
|
| 111 |
with open(os.path.join(path, "user_profile.json"), "w", encoding="utf-8") as f:
|
| 112 |
json.dump(req.profile_data, f, indent=2)
|
| 113 |
|
| 114 |
-
write_profile_to_obsidian(req.user_id, req.profile_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
return {"status": "Profile saved & Obsidian updated."}
|
| 116 |
except Exception as e:
|
| 117 |
return JSONResponse(status_code=500, content={"error": str(e)})
|
|
@@ -202,7 +210,7 @@ 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"""#
|
| 206 |
- Type: {resource_type}
|
| 207 |
- Link: {link}
|
| 208 |
"""
|
|
@@ -224,4 +232,4 @@ async def add_resource(
|
|
| 224 |
|
| 225 |
return {"status": "Resource saved.", "file": file_path}
|
| 226 |
except Exception as e:
|
| 227 |
-
return JSONResponse(status_code=500, content={"error": str(e)})
|
|
|
|
| 111 |
with open(os.path.join(path, "user_profile.json"), "w", encoding="utf-8") as f:
|
| 112 |
json.dump(req.profile_data, f, indent=2)
|
| 113 |
|
| 114 |
+
vault_path, files_written = write_profile_to_obsidian(req.user_id, req.profile_data)
|
| 115 |
+
|
| 116 |
+
for rel_path, content in files_written:
|
| 117 |
+
supabase_client.table("vault_files").upsert({
|
| 118 |
+
"user_id": req.user_id,
|
| 119 |
+
"path": rel_path,
|
| 120 |
+
"content": content
|
| 121 |
+
}).execute()
|
| 122 |
+
|
| 123 |
return {"status": "Profile saved & Obsidian updated."}
|
| 124 |
except Exception as e:
|
| 125 |
return JSONResponse(status_code=500, content={"error": str(e)})
|
|
|
|
| 210 |
try:
|
| 211 |
safe_title = title.replace(" ", "_").lower()
|
| 212 |
file_path = f"Resources_and_Skills/resources/{safe_title}.md"
|
| 213 |
+
content = f"""# 💎 {title}
|
| 214 |
- Type: {resource_type}
|
| 215 |
- Link: {link}
|
| 216 |
"""
|
|
|
|
| 232 |
|
| 233 |
return {"status": "Resource saved.", "file": file_path}
|
| 234 |
except Exception as e:
|
| 235 |
+
return JSONResponse(status_code=500, content={"error": str(e)})
|
profile_writer.py
CHANGED
|
@@ -6,12 +6,12 @@ SUPABASE_URL = os.getenv("SUPABASE_URL")
|
|
| 6 |
SUPABASE_KEY = os.getenv("SUPABASE_KEY")
|
| 7 |
supabase_client = create_client(SUPABASE_URL, SUPABASE_KEY)
|
| 8 |
|
| 9 |
-
def write_file(
|
| 10 |
full_path = os.path.join(user_path, relative_path)
|
| 11 |
os.makedirs(os.path.dirname(full_path), exist_ok=True)
|
| 12 |
-
|
| 13 |
with open(full_path, "w", encoding="utf-8") as f:
|
| 14 |
f.write(content.strip() + "\n")
|
|
|
|
| 15 |
|
| 16 |
# Stocker aussi dans Supabase (table "vault_files")
|
| 17 |
supabase_client.table("vault_files").upsert({
|
|
|
|
| 6 |
SUPABASE_KEY = os.getenv("SUPABASE_KEY")
|
| 7 |
supabase_client = create_client(SUPABASE_URL, SUPABASE_KEY)
|
| 8 |
|
| 9 |
+
def write_file(user_path, relative_path, content):
|
| 10 |
full_path = os.path.join(user_path, relative_path)
|
| 11 |
os.makedirs(os.path.dirname(full_path), exist_ok=True)
|
|
|
|
| 12 |
with open(full_path, "w", encoding="utf-8") as f:
|
| 13 |
f.write(content.strip() + "\n")
|
| 14 |
+
return relative_path, content.strip()
|
| 15 |
|
| 16 |
# Stocker aussi dans Supabase (table "vault_files")
|
| 17 |
supabase_client.table("vault_files").upsert({
|