Files
my-vault/.claude/commands/download-attachment.md
T

132 lines
3.0 KiB
Markdown
Raw Normal View History

# download-attachment
2025-09-17 16:06:52 -04:00
Download files from URLs to attachments folder and organize them with
descriptive names.
## Usage
2025-09-17 16:06:52 -04:00
```
/download-attachment <url1> [url2] [url3...]
```
## Examples
2025-09-17 16:06:52 -04:00
```
/download-attachment https://example.com/document.pdf
/download-attachment https://site.com/image.png https://site.com/report.pdf
```
## Implementation
2025-09-17 16:06:52 -04:00
You are tasked with downloading files from URLs and organizing them in the
Obsidian vault attachments folder.
### Step 1: Parse and Validate URLs
2025-09-17 16:06:52 -04:00
Extract the URL(s) from the user's input. Handle multiple URLs if provided.
2025-09-17 16:06:52 -04:00
- **Validate URL scheme**: Only allow http:// or https:// URLs
- **Reject invalid URLs**: file://, ftp://, or malformed URLs
- **Example validation**:
2025-09-17 16:06:52 -04:00
```bash
if [[ ! "$url" =~ ^https?:// ]]; then
echo "Error: Only HTTP/HTTPS URLs are allowed"
exit 1
fi
```
### Step 2: Download Files
2025-09-17 16:06:52 -04:00
For each URL:
2025-09-17 16:06:52 -04:00
```bash
# Sanitize filename to prevent path traversal
# Remove ../ and other dangerous characters
filename=$(basename "$url" | sed 's/[^a-zA-Z0-9._-]/_/g')
# Use wget or curl to download with timeout
wget --timeout=30 -O "05_Attachments/$filename" "$url"
# or
curl --max-time 30 -L "$url" -o "05_Attachments/$filename"
```
### Step 3: Verify Downloads
2025-09-17 16:06:52 -04:00
Check that files were downloaded successfully:
2025-09-17 16:06:52 -04:00
```bash
ls -la "05_Attachments/"
```
### Step 4: Organize Files
2025-09-17 16:06:52 -04:00
After downloading, run the organize-attachments command to rename files with
descriptive names:
For PDFs:
2025-09-17 16:06:52 -04:00
- Extract text with `pdftotext`
- Analyze content for meaningful title
For Images:
2025-09-17 16:06:52 -04:00
- Use `mcp__gemini-vision__analyze_image` or
`mcp__gemini-vision__analyze_multiple`
- Generate descriptive filename based on content
### Step 5: Move to Organized
2025-09-17 16:06:52 -04:00
Move renamed files to `05_Attachments/Organized/` with descriptive names
### Step 6: Update Index
2025-09-17 16:06:52 -04:00
Add entries to `05_Attachments/00_Index.md`
### Step 7: Commit Changes
2025-09-17 16:06:52 -04:00
```bash
git add -A
git commit -m "Download and organize attachments from URLs"
git push
```
## Important Notes
2025-09-17 16:06:52 -04:00
1. **File Naming**:
- Initial download: Use URL filename or generate from URL
- After analysis: Rename with descriptive title
2. **Supported Types**:
- Images: .png, .jpg, .jpeg, .gif, .webp
- Documents: .pdf, .doc, .docx
- Text: .txt, .md
- Data: .csv, .xlsx
3. **Error Handling**:
- Check if URL is accessible
- Verify file downloaded correctly
- Handle download failures gracefully
4. **Organization**:
- Downloaded files go to `05_Attachments/`
- After renaming, move to `05_Attachments/Organized/`
- Update links across vault if needed
## Workflow
1. Download file(s) from provided URL(s)
2. Identify file type and analyze content
3. Generate descriptive filename
4. Move to Organized folder
5. Update index and references
6. Commit and push changes
## Tips
- For multiple URLs, process them in batch for efficiency
- Use Gemini Vision for batch image analysis (up to 3 at once)
- Extract meaningful context from PDFs before renaming
- Preserve original file extensions
2025-09-17 16:06:52 -04:00
- Keep filenames concise but descriptive (max 60 chars)