refactor: split git provider adapters
This commit is contained in:
@@ -12,7 +12,7 @@ Built for La Fabrik Durable's internal use, but open-sourced for anyone looking
|
||||
- [**Next.js 16.2.5** (App Router)](https://nextjs.org/docs/app/getting-started/installation) + [React 19](https://react.dev/learn/creating-a-react-app) + [TypeScript](https://www.typescriptlang.org/docs/)
|
||||
- [**Three.js**](https://threejs.org/docs/#manual/en/introduction/Creating-a-scene) ([React Three Fiber](https://r3f.docs.pmnd.rs/getting-started/introduction) + [Drei](https://drei.docs.pmnd.rs/getting-started/introduction)) for 3D preview
|
||||
- [**Tailwind CSS**](https://v3.tailwindcss.com/docs/installation) for styling
|
||||
- [**Octokit**](https://github.com/octokit/rest.js/#readme) for pushing via a GitHub-compatible API (GitHub or Gitea)
|
||||
- [**Octokit**](https://github.com/octokit/rest.js/#readme) + provider adapters for GitHub and Gitea uploads
|
||||
- [**Nextcloud WebDAV**](https://docs.nextcloud.com/server/latest/developer_manual/client_apis/WebDAV/index.html) for Drive archiving with automatic versioning
|
||||
- [**Sharp**](https://sharp.pixelplumbing.com/install/) for server-side texture compression
|
||||
- [**npm lockfile + Coolify** (Docker)](https://coolify.io/docs/applications/build-packs/dockerfile) for hosting
|
||||
@@ -206,7 +206,15 @@ lib/
|
||||
├── diff-files.ts # File diff classification (new/changed/unchanged/deleted)
|
||||
├── sanitize.ts # Filename sanitization
|
||||
├── auth.ts # Upload secret validation (timing-safe)
|
||||
├── github.ts # Octokit helpers for GitHub-compatible remotes
|
||||
├── git/ # Git provider layer selected by env
|
||||
│ ├── config.ts # GIT_PROVIDER/GIT_REPO_URL/GIT_TOKEN parsing
|
||||
│ ├── content.ts # Shared remote folder/file content helpers
|
||||
│ ├── http.ts # Shared Git API request helpers
|
||||
│ ├── index.ts # Public getRemoteFolder/pushAllToGit facade
|
||||
│ ├── lfs.ts # Shared Git LFS upload helpers
|
||||
│ └── providers/
|
||||
│ ├── gitea.ts # Gitea Contents API implementation
|
||||
│ └── github.ts # GitHub Git Data API implementation
|
||||
├── nextcloud.ts # Nextcloud WebDAV client (native fetch, cached config)
|
||||
├── upload-staging.ts # Temporary server-side staging and prepared asset reuse
|
||||
├── upload-lock.ts # Lightweight in-memory per-folder upload lock
|
||||
@@ -237,6 +245,7 @@ Copy `.env.example` to `.env.local` and fill in the values:
|
||||
|
||||
```env
|
||||
UPLOAD_SECRET_KEY=your-secret-key-here
|
||||
GIT_PROVIDER=gitea
|
||||
GIT_USERNAME=your-gitea-username
|
||||
GIT_TOKEN=your-git-provider-token
|
||||
GIT_BRANCH=main
|
||||
@@ -251,6 +260,7 @@ NEXTCLOUD_BASE_PATH=Models
|
||||
| Variable | Description | Required |
|
||||
|----------|-------------|----------|
|
||||
| `UPLOAD_SECRET_KEY` | Secret key for upload authentication | Yes |
|
||||
| `GIT_PROVIDER` | Git provider adapter to use: `github` or `gitea`. If omitted, it is inferred from `GIT_REPO_URL` (`github.com` → GitHub, anything else → Gitea). | No |
|
||||
| `GIT_USERNAME` | Git username for Git LFS Basic auth on Gitea. Required for Gitea when LFS files are uploaded. | Gitea LFS |
|
||||
| `GIT_TOKEN` | Git provider token with repository read/write access. `GITHUB_TOKEN` is still accepted for backward compatibility. | Yes |
|
||||
| `GIT_BRANCH` | Target branch (default: main) | No |
|
||||
@@ -262,6 +272,34 @@ NEXTCLOUD_BASE_PATH=Models
|
||||
|
||||
> GitHub tokens need `Contents: Read and write`. Gitea tokens need repository read/write access.
|
||||
|
||||
### Git provider selection
|
||||
|
||||
The upload routes call a small provider layer in `lib/git/`:
|
||||
|
||||
- `lib/git/config.ts` reads `GIT_PROVIDER`, `GIT_REPO_URL`, `GIT_TOKEN`, `GIT_USERNAME`, and `GIT_BRANCH`
|
||||
- `lib/git/providers/github.ts` handles GitHub commits with the Git Data API
|
||||
- `lib/git/providers/gitea.ts` handles Gitea commits with the Contents API
|
||||
- `lib/git/lfs.ts` handles Git LFS upload/auth for both providers
|
||||
|
||||
For GitHub:
|
||||
|
||||
```env
|
||||
GIT_PROVIDER=github
|
||||
GIT_TOKEN=ghp_xxx
|
||||
GIT_REPO_URL=https://github.com/org/repo.git
|
||||
GIT_BRANCH=main
|
||||
```
|
||||
|
||||
For Gitea:
|
||||
|
||||
```env
|
||||
GIT_PROVIDER=gitea
|
||||
GIT_USERNAME=your-gitea-username
|
||||
GIT_TOKEN=token_xxx
|
||||
GIT_REPO_URL=https://git.fabrik.mathieu-chavanel.fr/math-pixel/La-Fabrik
|
||||
GIT_BRANCH=main
|
||||
```
|
||||
|
||||
> To create a Nextcloud public share token: Nextcloud > Files > select folder > Share > Create public share > set permissions (write access required) > copy the share link and extract the token
|
||||
|
||||
### Production (Coolify / Docker)
|
||||
@@ -280,6 +318,7 @@ After a security patch:
|
||||
docker build -t upload-gltf .
|
||||
docker run -p 3000:3000 \
|
||||
-e UPLOAD_SECRET_KEY=your-key \
|
||||
-e GIT_PROVIDER=gitea \
|
||||
-e GIT_USERNAME=your-gitea-username \
|
||||
-e GIT_TOKEN=token_xxx \
|
||||
-e GIT_REPO_URL=https://git.fabrik.mathieu-chavanel.fr/math-pixel/La-Fabrik \
|
||||
|
||||
Reference in New Issue
Block a user