feat: launcher.exe와 game.zip 별도 업로드/서빙 분리
All checks were successful
Server CI/CD / deploy (push) Successful in 36s
All checks were successful
Server CI/CD / deploy (push) Successful in 36s
- POST /api/download/upload/game - 게임 zip 업로드 - POST /api/download/upload/launcher - launcher.exe 업로드 - GET /api/download/launcher - launcher.exe 서빙 - Info 모델에 LauncherURL, LauncherSize 필드 추가 - Content-Disposition 헤더로 올바른 파일명 설정 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -31,6 +31,49 @@ func (s *Service) GameFilePath() string {
|
||||
return filepath.Join(s.gameDir, "game.zip")
|
||||
}
|
||||
|
||||
func (s *Service) LauncherFilePath() string {
|
||||
return filepath.Join(s.gameDir, "launcher.exe")
|
||||
}
|
||||
|
||||
func (s *Service) UploadLauncher(body io.Reader, baseURL string) (*Info, error) {
|
||||
if err := os.MkdirAll(s.gameDir, 0755); err != nil {
|
||||
return nil, fmt.Errorf("디렉토리 생성 실패: %w", err)
|
||||
}
|
||||
|
||||
finalPath := s.LauncherFilePath()
|
||||
tmpPath := finalPath + ".tmp"
|
||||
|
||||
f, err := os.Create(tmpPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("파일 생성 실패: %w", err)
|
||||
}
|
||||
|
||||
n, err := io.Copy(f, body)
|
||||
f.Close()
|
||||
if err != nil {
|
||||
os.Remove(tmpPath)
|
||||
return nil, fmt.Errorf("파일 저장 실패: %w", err)
|
||||
}
|
||||
|
||||
if err := os.Rename(tmpPath, finalPath); err != nil {
|
||||
os.Remove(tmpPath)
|
||||
return nil, fmt.Errorf("파일 이동 실패: %w", err)
|
||||
}
|
||||
|
||||
launcherSize := ""
|
||||
if n > 0 {
|
||||
launcherSize = fmt.Sprintf("%.1f MB", float64(n)/1024/1024)
|
||||
}
|
||||
|
||||
info, err := s.repo.GetLatest()
|
||||
if err != nil {
|
||||
info = &Info{}
|
||||
}
|
||||
info.LauncherURL = baseURL + "/api/download/launcher"
|
||||
info.LauncherSize = launcherSize
|
||||
return info, s.repo.Save(info)
|
||||
}
|
||||
|
||||
// Upload streams the body directly to disk, then extracts metadata from the zip.
|
||||
func (s *Service) Upload(filename string, body io.Reader, baseURL string) (*Info, error) {
|
||||
if err := os.MkdirAll(s.gameDir, 0755); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user