# Raw Content, Media, and Archives

These endpoints return file content directly (not base64-encoded) and provide access to archives and comparison diffs.

## Get Raw File Content

```
GET /repos/{owner}/{repo}/raw/{filepath}
```

Returns the raw file content directly with the appropriate content type. Supports `ref` query parameter.

```bash
# Get raw file content
curl -s -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/repos/{owner}/{repo}/raw/README.md"

# Get raw content from a specific branch
curl -s -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/repos/{owner}/{repo}/raw/src/main.go?ref={branch}"

# Save raw content to a local file
curl -s -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/repos/{owner}/{repo}/raw/config.yaml" -o config.yaml
```

## Get Media File

```
GET /repos/{owner}/{repo}/media/{filepath}
```

Returns the file content with the appropriate media type. Useful for images and binary files rendered in the web UI.

```bash
# Get a media file (e.g., an image)
curl -s -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/repos/{owner}/{repo}/media/docs/logo.png" -o logo.png

# Get media from a specific ref
curl -s -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/repos/{owner}/{repo}/media/assets/banner.svg?ref={tag}"
```

## Get EditorConfig Rules

```
GET /repos/{owner}/{repo}/editorconfig/{filepath}
```

Returns the .editorconfig rules that apply to the specified file path.

```bash
# Get editorconfig rules for a file
curl -s -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/repos/{owner}/{repo}/editorconfig/src/main.go"

# Example response:
# {
#   "charset": "utf-8",
#   "indent_style": "tab",
#   "indent_size": "4",
#   "end_of_line": "lf",
#   "insert_final_newline": "true",
#   "trim_trailing_whitespace": "true"
# }
```

## Download Archive

```
GET /repos/{owner}/{repo}/archive/{archive}
```

Download a repository archive. The `archive` parameter specifies the format via file extension.

Supported formats:
- `.tar.gz` / `.tgz` - Gzipped tar archive
- `.zip` - ZIP archive

```bash
# Download as tar.gz (default branch)
curl -s -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/repos/{owner}/{repo}/archive/main.tar.gz" -o repo.tar.gz

# Download as zip
curl -s -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/repos/{owner}/{repo}/archive/{branch}.zip" -o repo.zip

# Download a specific tag
curl -s -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/repos/{owner}/{repo}/archive/{tag}.tar.gz" -o release.tar.gz

# Download a specific branch
curl -s -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/repos/{owner}/{repo}/archive/{branch}.zip" -o branch.zip
```

## Compare Two Refs

```
GET /repos/{owner}/{repo}/compare/{basehead}
```

Compare two branches, tags, or commits. The `basehead` format is `base...head` (three dots).

```bash
# Compare two branches
curl -s -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/repos/{owner}/{repo}/compare/{base}...{head}"

# Compare a branch against a tag
curl -s -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/repos/{owner}/{repo}/compare/v1.0.0...main"

# Compare two commits
curl -s -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/repos/{owner}/{repo}/compare/{sha1}...{sha2}"

# Get just the diff stats
curl -s -H "Authorization: token ${FORGEJO_PAT}" \
  "${FORGEJO_URL}/api/v1/repos/{owner}/{repo}/compare/{base}...{head}" | jq '{total_commits: .total_commits, files: [.files[] | {filename, additions, deletions, status}]}'
```

### Compare Response

The response includes:
- `total_commits` - Number of commits between the refs
- `commits` - Array of commit objects
- `files` - Array of changed files with diff information (filename, additions, deletions, status)

## Important Notes

- Raw and media endpoints return content directly — no JSON wrapping or base64 encoding
- Use the `ref` query parameter to access files from specific branches, tags, or commits
- Archive downloads can be large — consider using `-o` to save to a file
- The compare endpoint is useful for building PR-like diffs between any two refs
- For binary files, prefer `raw` or `media` endpoints over the contents API
