유튜브 업로드 기능 완료 .
This commit is contained in:
1 parent
e1b860a15f
commit
fd9db31e52
12 files changed
+2257
-30
No files matched your search
+80
-6
@@ -22,6 +22,9 @@ import {
|
||||
SocialAccountsResponse,
|
||||
SocialAccountResponse,
|
||||
SocialDisconnectResponse,
|
||||
SocialUploadRequest,
|
||||
SocialUploadResponse,
|
||||
SocialUploadStatusResponse,
|
||||
} from '../types/api';
|
||||
|
||||
const API_URL = import.meta.env.VITE_API_URL || 'http://40.82.133.44';
|
||||
@@ -295,9 +298,9 @@ export async function getVideosList(page: number = 1, pageSize: number = 10): Pr
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// 비디오 삭제 API
|
||||
export async function deleteVideo(taskId: string): Promise<void> {
|
||||
const response = await authenticatedFetch(`${API_URL}/archive/videos/delete/${taskId}`, {
|
||||
// 비디오 삭제 API (개별 비디오 삭제)
|
||||
export async function deleteVideo(videoId: number): Promise<void> {
|
||||
const response = await authenticatedFetch(`${API_URL}/archive/videos/${videoId}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
|
||||
@@ -713,9 +716,9 @@ export async function getSocialAccountByPlatform(platform: 'youtube' | 'instagra
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// 소셜 계정 연결 해제
|
||||
export async function disconnectSocialAccount(platform: 'youtube' | 'instagram' | 'facebook'): Promise<SocialDisconnectResponse> {
|
||||
const response = await authenticatedFetch(`${API_URL}/social/oauth/${platform}/disconnect`, {
|
||||
// 소셜 계정 연결 해제 (계정 ID로)
|
||||
export async function disconnectSocialAccount(accountId: number): Promise<SocialDisconnectResponse> {
|
||||
const response = await authenticatedFetch(`${API_URL}/social/oauth/accounts/${accountId}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
|
||||
@@ -725,3 +728,74 @@ export async function disconnectSocialAccount(platform: 'youtube' | 'instagram'
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// Social Upload API (YouTube Video Upload)
|
||||
// ============================================
|
||||
|
||||
// YouTube 영상 업로드 시작
|
||||
export async function uploadToSocial(request: SocialUploadRequest): Promise<SocialUploadResponse> {
|
||||
const response = await authenticatedFetch(`${API_URL}/social/upload`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(request),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// 업로드 상태 조회
|
||||
export async function getUploadStatus(uploadId: string): Promise<SocialUploadStatusResponse> {
|
||||
const response = await authenticatedFetch(`${API_URL}/social/upload/${uploadId}/status`, {
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// 업로드 완료까지 폴링 (5분 타임아웃, 2초 간격)
|
||||
const UPLOAD_POLL_TIMEOUT = 5 * 60 * 1000; // 5분
|
||||
const UPLOAD_POLL_INTERVAL = 2000; // 2초
|
||||
|
||||
export async function waitForUploadComplete(
|
||||
uploadId: string,
|
||||
onStatusChange?: (status: string, progress?: number) => void
|
||||
): Promise<SocialUploadStatusResponse> {
|
||||
const startTime = Date.now();
|
||||
|
||||
const poll = async (): Promise<SocialUploadStatusResponse> => {
|
||||
// 5분 타임아웃 체크
|
||||
if (Date.now() - startTime > UPLOAD_POLL_TIMEOUT) {
|
||||
throw new Error('TIMEOUT');
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await getUploadStatus(uploadId);
|
||||
onStatusChange?.(response.status, response.upload_progress);
|
||||
|
||||
if (response.status === 'completed') {
|
||||
return response;
|
||||
} else if (response.status === 'failed') {
|
||||
throw new Error(response.error_message || '업로드에 실패했습니다.');
|
||||
}
|
||||
|
||||
// pending, uploading은 대기 후 재시도
|
||||
await new Promise(resolve => setTimeout(resolve, UPLOAD_POLL_INTERVAL));
|
||||
return poll();
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
return poll();
|
||||
}
|
||||
Reference in new issue
Block a user