1
This commit is contained in:
parent
6753c1f16c
commit
d2c78b75d3
@ -115,8 +115,8 @@ TOS_ENDPOINT=tos-cn-beijing.volces.com
|
||||
|
||||
## 文件存储路径
|
||||
|
||||
- **图片**: `images/image-{timestamp}-{random}.png`
|
||||
- **视频**: `videos/video-{timestamp}-{random}.mp4`
|
||||
- **图片**: `jimeng_free/images/{taskId}/image-{timestamp}-{random}.png`
|
||||
- **视频**: `jimeng_free/videos/{taskId}/video-{timestamp}-{random}.mp4`
|
||||
|
||||
## 错误处理
|
||||
|
||||
|
||||
@ -77,7 +77,7 @@ export class ImagesTaskCache {
|
||||
* @param imageUrls 图片URL数组
|
||||
* @returns TOS URL数组
|
||||
*/
|
||||
private async uploadImagesToTOS(imageUrls: string[]): Promise<string[]> {
|
||||
private async uploadImagesToTOS(imageUrls: string[], task_id: string): Promise<string[]> {
|
||||
const tosUrls: string[] = [];
|
||||
|
||||
for (const imageUrl of imageUrls) {
|
||||
@ -85,7 +85,7 @@ export class ImagesTaskCache {
|
||||
// 从URL获取文件名
|
||||
const fileName = `image-${Date.now()}-${Math.random().toString(36).substr(2, 9)}.png`;
|
||||
// 上传到TOS
|
||||
const tosUrl = await TOSService.uploadFromUrl(imageUrl, `jimeng_free/images/${fileName}`);
|
||||
const tosUrl = await TOSService.uploadFromUrl(imageUrl, `jimeng_free/images/${task_id}/${fileName}`);
|
||||
tosUrls.push(tosUrl);
|
||||
logger.info(`图片上传到TOS成功: ${imageUrl} -> ${tosUrl}`);
|
||||
} catch (error) {
|
||||
@ -115,7 +115,7 @@ export class ImagesTaskCache {
|
||||
// 任务成功完成时,自动上传到TOS
|
||||
cacheLog(`开始上传图片到TOS: ${taskId}`);
|
||||
const imageUrls = url.split(',');
|
||||
const tosUrls = await this.uploadImagesToTOS(imageUrls);
|
||||
const tosUrls = await this.uploadImagesToTOS(imageUrls, taskId);
|
||||
finalUrl = tosUrls.join(',');
|
||||
this.tosProcessedTasks.add(taskId);
|
||||
cacheLog(`Task ${taskId} TOS上传完成,存储TOS地址: ${finalUrl}`);
|
||||
|
||||
@ -77,7 +77,7 @@ export class VideoTaskCache {
|
||||
* @param videoUrls 视频URL数组
|
||||
* @returns TOS URL数组
|
||||
*/
|
||||
private async uploadVideosToTOS(videoUrls: string[]): Promise<string[]> {
|
||||
private async uploadVideosToTOS(videoUrls: string[], task_id: string): Promise<string[]> {
|
||||
const tosUrls: string[] = [];
|
||||
|
||||
for (const videoUrl of videoUrls) {
|
||||
@ -85,7 +85,7 @@ export class VideoTaskCache {
|
||||
// 从URL获取文件名
|
||||
const fileName = `video-${Date.now()}-${Math.random().toString(36).substr(2, 9)}.mp4`;
|
||||
// 上传到TOS
|
||||
const tosUrl = await TOSService.uploadFromUrl(videoUrl, `jimeng_free/videos/${fileName}`);
|
||||
const tosUrl = await TOSService.uploadFromUrl(videoUrl, `jimeng_free/videos/${task_id}/${fileName}`);
|
||||
tosUrls.push(tosUrl);
|
||||
logger.info(`视频上传到TOS成功: ${videoUrl} -> ${tosUrl}`);
|
||||
} catch (error) {
|
||||
@ -115,7 +115,7 @@ export class VideoTaskCache {
|
||||
// 任务成功完成时,自动上传到TOS
|
||||
cacheLog(`开始上传视频到TOS: ${taskId}`);
|
||||
const videoUrls = url.split(',');
|
||||
const tosUrls = await this.uploadVideosToTOS(videoUrls);
|
||||
const tosUrls = await this.uploadVideosToTOS(videoUrls, taskId);
|
||||
finalUrl = tosUrls.join(',');
|
||||
this.tosProcessedTasks.add(taskId);
|
||||
cacheLog(`Task ${taskId} TOS上传完成,存储TOS地址: ${finalUrl}`);
|
||||
|
||||
@ -340,7 +340,7 @@ export class TaskPollingService {
|
||||
taskLog(`Task ${task.task_id} generated ${originalUrls.length} files`);
|
||||
|
||||
// 上传到TOS
|
||||
const tosUrls = await this.uploadToTOS(originalUrls, task.task_type);
|
||||
const tosUrls = await this.uploadToTOS(originalUrls, task.task_type, task.task_id);
|
||||
|
||||
// 创建结果记录
|
||||
const expireTime = currentTime + parseInt(process.env.RESULT_EXPIRE_TIME || '86400');
|
||||
@ -746,7 +746,7 @@ export class TaskPollingService {
|
||||
/**
|
||||
* 上传文件到TOS
|
||||
*/
|
||||
private async uploadToTOS(urls: string[], taskType: 'image' | 'video'): Promise<string[]> {
|
||||
private async uploadToTOS(urls: string[], taskType: 'image' | 'video', task_id: string): Promise<string[]> {
|
||||
const tosUrls: string[] = [];
|
||||
|
||||
for (const url of urls) {
|
||||
@ -756,7 +756,7 @@ export class TaskPollingService {
|
||||
: `video-${Date.now()}-${Math.random().toString(36).substr(2, 9)}.mp4`;
|
||||
|
||||
const folder = taskType === 'image' ? 'images' : 'videos';
|
||||
const tosUrl = await TOSService.uploadFromUrl(url, `jimeng_free/${folder}/${fileName}`);
|
||||
const tosUrl = await TOSService.uploadFromUrl(url, `jimeng_free/${folder}/${task_id}/${fileName}`);
|
||||
tosUrls.push(tosUrl);
|
||||
|
||||
taskLog(`${taskType} uploaded to TOS: ${url} -> ${tosUrl}`);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user