40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { Context, Inject, Provide } from '@midwayjs/core';
|
|
import { InjectEntityModel } from '@midwayjs/typeorm';
|
|
import { Repository } from 'typeorm';
|
|
import { Chapter } from '../entity/chapter.entity';
|
|
import { VodService } from './vod.service';
|
|
|
|
@Provide()
|
|
export class ChapterService {
|
|
@Inject()
|
|
ctx: Context;
|
|
|
|
@Inject()
|
|
vodService: VodService;
|
|
|
|
@InjectEntityModel(Chapter)
|
|
chapterModel: Repository<Chapter>;
|
|
|
|
async create(chapterList: Chapter[]) {
|
|
for (const chapter of chapterList) {
|
|
const { chapter_file_id: fileID } = chapter;
|
|
if (fileID) {
|
|
const { data } = await this.vodService.selectMediaByFileId(fileID);
|
|
chapter.media_cover_url = data.MediaInfoSet[0].BasicInfo.CoverUrl;
|
|
chapter.media_time = '' + data.MediaInfoSet[0].MetaData.Duration;
|
|
chapter.media_url =
|
|
data.MediaInfoSet[0].AdaptiveDynamicStreamingInfo.AdaptiveDynamicStreamingSet[0].Url;
|
|
}
|
|
await this.chapterModel.save(chapter);
|
|
}
|
|
}
|
|
|
|
async select(course_id: string) {
|
|
const result = await this.chapterModel.find({
|
|
where: { chapter_course_id: course_id },
|
|
order: { order: 'asc' },
|
|
});
|
|
return result;
|
|
}
|
|
}
|