file-view.ts 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. import { FileRef } from '../../../../../types/file-ref'
  2. import { BinaryFile } from '@/features/file-view/types/binary-file'
  3. export function convertFileRefToBinaryFile(fileRef: FileRef): BinaryFile {
  4. const timestamp = fileRef.linkedFileData?.importedAt ?? fileRef.created
  5. return {
  6. _id: fileRef._id,
  7. name: fileRef.name,
  8. id: fileRef._id,
  9. type: 'file',
  10. selected: true,
  11. linkedFileData: fileRef.linkedFileData,
  12. created: timestamp ? new Date(timestamp) : new Date(),
  13. hash: fileRef.hash,
  14. }
  15. }
  16. // `FileViewHeader`, which is TypeScript, expects a BinaryFile, which has a
  17. // `created` property of type `Date`, while `TPRFileViewInfo`, written in JS,
  18. // into which `FileViewHeader` passes its BinaryFile, expects a file object with
  19. // `created` property of type `string`, which is a mismatch. `TPRFileViewInfo`
  20. // is the only one making runtime complaints and it seems that other uses of
  21. // `FileViewHeader` pass in a string for `created`, so that's what this function
  22. // does too.
  23. export function fileViewFile(fileRef: FileRef) {
  24. const converted = convertFileRefToBinaryFile(fileRef)
  25. return {
  26. ...converted,
  27. created: converted.created.toISOString(),
  28. }
  29. }