123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import axios from './instance'
- import { RECORD_FRAGMENT_LIST, DELETE_RECORD_FRAGMENT } from './constant'
- import type { Record } from './record'
- interface ServiceRecordFragment {
- videoId: number
- videoPath: string,
- voideName: string,
- videoCover: string,
- sort: number,
- }
- export type RecordFragment = {
- id: string,
- cover: string,
- sort: number,
- url: string
- }
- const toLocal = (serviceRecordFragment: ServiceRecordFragment) : RecordFragment => ({
- id: serviceRecordFragment.videoId.toString(),
- cover: serviceRecordFragment.videoCover,
- url: serviceRecordFragment.videoPath,
- sort: serviceRecordFragment.sort,
- })
- const toService = (recordFragment: RecordFragment, isUpdate = true): PartialProps<ServiceRecordFragment, 'videoId'> => ({
- videoId: isUpdate ? Number(recordFragment.id): undefined,
- videoCover: recordFragment.cover,
- videoPath: recordFragment.url,
- sort: recordFragment.sort,
- voideName: ''
- })
- export type RecordFragments = RecordFragment[]
- export const fetchRecordFragments = async (recordId: Record['id']) => {
- const data = await axios.get<ServiceRecordFragment[]>(RECORD_FRAGMENT_LIST, { params: { folderId: recordId } })
- return data.map(toLocal)
- }
- export const postDeleteRecordFragment = async (id: RecordFragment['id']) => {
- await axios.post(DELETE_RECORD_FRAGMENT, { videoId: Number(id) })
- }
|