Uploads/README.md
2026-04-23 15:46:26 +07:00

208 lines
2.8 KiB
Markdown

# Typora Uploads
This repository is used to store images uploaded from Typora and serve them via raw URLs.
---
## 📌 Overview
When you paste an image into Typora:
1. The image is copied into this repository
2. It is committed and pushed to remote (Gitea)
3. A raw URL is generated
4. Typora replaces the local image with that URL
---
## 🚀 Setup (First Time Only)
### Clone repository
```bash
git clone https://git.tltdb.com/Typora/Uploads.git ~/typora-uploads
cd ~/typora-uploads
```
> ⚠️ Do NOT run `git init`. Always use `git clone`.
---
### Setup authentication
Create `.netrc`:
```bash
nano ~/.netrc
```
```text
machine git.tltdb.com
login tltdb
password YOUR_TOKEN_HERE
```
```bash
chmod 600 ~/.netrc
```
---
### Setup upload script
Create script:
```bash
mkdir -p ~/bin
nano ~/bin/typora-gitea-upload.sh
```
Paste your upload script, then:
```bash
chmod +x ~/bin/typora-gitea-upload.sh
```
---
### Configure Typora
**Preferences → Image**
* When Insert Local Images → `Upload Image`
* Image Uploader → `Custom Command`
Command:
```bash
/Users/YOUR_USERNAME/bin/typora-gitea-upload.sh
```
---
## 🖥️ Using on Multiple Computers
On any new machine:
```bash
git clone https://git.tltdb.com/Typora/Uploads.git ~/typora-uploads
cd ~/typora-uploads
```
Then repeat:
* authentication setup (`~/.netrc`)
* upload script setup
* Typora configuration
---
## 🔁 Daily Workflow
Before using Typora:
```bash
cd ~/typora-uploads
git pull origin main
```
After uploading images:
```bash
git push origin main
```
---
## ⚠️ Conflict Prevention
If using multiple devices:
* Always run `git pull` before uploading
* Avoid working offline too long
If conflict occurs:
```bash
git pull --rebase origin main
```
---
## 🧠 Recommended Improvement (Optional)
Add auto-sync to your script:
```bash
git pull --rebase origin main >/dev/null 2>&1 || true
```
---
## 📂 Repository Structure
```text
Uploads/
├── README.md
└── uploads/
└── YYYY/
└── MM/
├── image-1.png
└── image-2.jpg
```
---
## 🌐 Image URL Format
```text
https://git.tltdb.com/Typora/Uploads/raw/branch/main/uploads/YYYY/MM/filename.png
```
---
## 🔒 Notes
* Use **public repo** if images must be accessible everywhere
* Do NOT embed token in Git remote URL
* Prefer `.netrc` for authentication
---
## 🧯 Troubleshooting
### Remote rejected (non-fast-forward)
```bash
git pull --rebase origin main
git push
```
---
### Authentication failed
* Check `~/.netrc`
* Verify token permissions
---
### Script not working in Typora
* Check script path
* Ensure executable (`chmod +x`)
* Test manually:
```bash
~/bin/typora-gitea-upload.sh "/path/to/image.png"
```
---
## ✅ Key Rule
```bash
git clone # correct
git init # wrong (for this project)
```