Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	
		CocoonAI
		
	commited on
		
		
					Commit 
							
							·
						
						979ac42
	
1
								Parent(s):
							
							ffe3f33
								
Update profile_writer.py
Browse files- profile_writer.py +8 -6
    	
        profile_writer.py
    CHANGED
    
    | @@ -1,23 +1,25 @@ | |
| 1 | 
             
            import os
         | 
|  | |
| 2 | 
             
            from supabase import create_client
         | 
| 3 | 
            -
            import json
         | 
| 4 |  | 
|  | |
| 5 | 
             
            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(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 | 
| 14 | 
            -
                return relative_path, content.strip()
         | 
| 15 |  | 
| 16 | 
            -
                #  | 
| 17 | 
             
                supabase_client.table("vault_files").upsert({
         | 
| 18 | 
             
                    "user_id": user_id,
         | 
| 19 | 
             
                    "path": relative_path,
         | 
| 20 | 
            -
                    "content": content | 
| 21 | 
             
                }).execute()
         | 
| 22 |  | 
| 23 | 
             
            def write_profile_to_obsidian(user_id: str, data: dict, base_path=None):
         | 
|  | |
| 1 | 
             
            import os
         | 
| 2 | 
            +
            import tempfile
         | 
| 3 | 
             
            from supabase import create_client
         | 
|  | |
| 4 |  | 
| 5 | 
            +
            # === Supabase Init ===
         | 
| 6 | 
             
            SUPABASE_URL = os.getenv("SUPABASE_URL")
         | 
| 7 | 
             
            SUPABASE_KEY = os.getenv("SUPABASE_KEY")
         | 
| 8 | 
             
            supabase_client = create_client(SUPABASE_URL, SUPABASE_KEY)
         | 
| 9 |  | 
| 10 | 
            +
            def write_file(user_id, user_path, relative_path, content):
         | 
| 11 | 
            +
                # Write locally
         | 
| 12 | 
             
                full_path = os.path.join(user_path, relative_path)
         | 
| 13 | 
             
                os.makedirs(os.path.dirname(full_path), exist_ok=True)
         | 
| 14 | 
            +
                content = content.strip() + "\n"
         | 
| 15 | 
             
                with open(full_path, "w", encoding="utf-8") as f:
         | 
| 16 | 
            +
                    f.write(content)
         | 
|  | |
| 17 |  | 
| 18 | 
            +
                # Write to Supabase
         | 
| 19 | 
             
                supabase_client.table("vault_files").upsert({
         | 
| 20 | 
             
                    "user_id": user_id,
         | 
| 21 | 
             
                    "path": relative_path,
         | 
| 22 | 
            +
                    "content": content
         | 
| 23 | 
             
                }).execute()
         | 
| 24 |  | 
| 25 | 
             
            def write_profile_to_obsidian(user_id: str, data: dict, base_path=None):
         |