chore: initial commit - CloudSearch v0.0.2
This commit is contained in:
37
packages/backend/src/video/video.service.ts
Executable file
37
packages/backend/src/video/video.service.ts
Executable file
@@ -0,0 +1,37 @@
|
||||
// Native fetch available in Node 20+
|
||||
import config from '../config';
|
||||
|
||||
export interface VideoInfo {
|
||||
title: string;
|
||||
coverUrl: string;
|
||||
videoUrl: string;
|
||||
author: string;
|
||||
platform: string;
|
||||
duration?: string;
|
||||
}
|
||||
|
||||
export async function parseVideo(url: string): Promise<VideoInfo> {
|
||||
const apiUrl = `${config.videoParserUrl}/parse`;
|
||||
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ url }),
|
||||
signal: AbortSignal.timeout(30000),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Video parser API error: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json() as any;
|
||||
|
||||
return {
|
||||
title: data.title || '',
|
||||
coverUrl: data.coverUrl || data.cover || '',
|
||||
videoUrl: data.videoUrl || data.url || data.video || '',
|
||||
author: data.author || data.nickname || '',
|
||||
platform: data.platform || '',
|
||||
duration: data.duration || '',
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user