Files
logikonline 7e36d7d55c feat(api): add chunked upload support for large release attachments
Implement resumable chunked uploads to improve reliability for large file
uploads that may fail due to network issues or timeouts.

New API endpoints:
- POST /repos/{owner}/{repo}/releases/{id}/assets/upload-session
- PUT /repos/{owner}/{repo}/uploads/{session_id}/chunks/{chunk_number}
- GET /repos/{owner}/{repo}/uploads/{session_id}
- POST /repos/{owner}/{repo}/uploads/{session_id}/complete
- DELETE /repos/{owner}/{repo}/uploads/{session_id}

Features:
- Resumable uploads with session status tracking
- Out-of-order chunk uploads supported
- Configurable chunk size (default 10MB, max 100MB)
- Automatic cleanup of expired sessions (24h expiry, hourly cleanup)
- Progress tracking with bytes/chunks received counts

Files added:
- models/repo/upload_session.go - Session model and DB operations
- services/attachment/chunked.go - Chunk storage and assembly logic
- routers/api/v1/repo/upload.go - API endpoint handlers
- models/migrations/v1_26/v325.go - Database migration
2026-01-08 08:58:56 -05:00

36 lines
1.3 KiB
Go

// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package v1_26
import (
"code.gitea.io/gitea/modules/timeutil"
"xorm.io/xorm"
)
// AddUploadSessionTable adds the upload_session table for chunked uploads
func AddUploadSessionTable(x *xorm.Engine) error {
type UploadSession struct {
ID int64 `xorm:"pk autoincr"`
UUID string `xorm:"uuid UNIQUE NOT NULL"`
RepoID int64 `xorm:"INDEX NOT NULL"`
ReleaseID int64 `xorm:"INDEX"`
IssueID int64 `xorm:"INDEX"`
UploaderID int64 `xorm:"INDEX NOT NULL"`
FileName string `xorm:"NOT NULL"`
FileSize int64 `xorm:"DEFAULT -1"`
ChunkSize int64 `xorm:"NOT NULL"`
ChunksExpected int64 `xorm:"DEFAULT -1"`
ChunksReceived int64 `xorm:"DEFAULT 0"`
BytesReceived int64 `xorm:"DEFAULT 0"`
Status int `xorm:"DEFAULT 0"`
TempPath string `xorm:"NOT NULL"`
CreatedUnix timeutil.TimeStamp `xorm:"created"`
UpdatedUnix timeutil.TimeStamp `xorm:"updated"`
ExpiresUnix timeutil.TimeStamp `xorm:"INDEX"`
}
return x.Sync(new(UploadSession))
}