record-fragment.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import axios from './instance'
  2. import { RECORD_FRAGMENT_LIST, DELETE_RECORD_FRAGMENT } from './constant'
  3. import type { Record } from './record'
  4. interface ServiceRecordFragment {
  5. videoId: number
  6. videoPath: string,
  7. voideName: string,
  8. videoCover: string,
  9. sort: number,
  10. }
  11. export type RecordFragment = {
  12. id: string,
  13. cover: string,
  14. sort: number,
  15. url: string
  16. }
  17. const toLocal = (serviceRecordFragment: ServiceRecordFragment) : RecordFragment => ({
  18. id: serviceRecordFragment.videoId.toString(),
  19. cover: serviceRecordFragment.videoCover,
  20. url: serviceRecordFragment.videoPath,
  21. sort: serviceRecordFragment.sort,
  22. })
  23. const toService = (recordFragment: RecordFragment, isUpdate = true): PartialProps<ServiceRecordFragment, 'videoId'> => ({
  24. videoId: isUpdate ? Number(recordFragment.id): undefined,
  25. videoCover: recordFragment.cover,
  26. videoPath: recordFragment.url,
  27. sort: recordFragment.sort,
  28. voideName: ''
  29. })
  30. export type RecordFragments = RecordFragment[]
  31. export const fetchRecordFragments = async (recordId: Record['id']) => {
  32. const data = await axios.get<ServiceRecordFragment[]>(RECORD_FRAGMENT_LIST, { params: { folderId: recordId } })
  33. return data.map(toLocal)
  34. }
  35. export const postDeleteRecordFragment = async (id: RecordFragment['id']) => {
  36. await axios.post(DELETE_RECORD_FRAGMENT, { videoId: Number(id) })
  37. }