file-view.ts 1.1 KB

1234567891011121314151617181920212223242526272829
  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. return {
  5. _id: fileRef._id,
  6. name: fileRef.name,
  7. id: fileRef._id,
  8. type: 'file',
  9. selected: true,
  10. linkedFileData: fileRef.linkedFileData,
  11. created: fileRef.created ? new Date(fileRef.created) : new Date(),
  12. hash: fileRef.hash,
  13. }
  14. }
  15. // `FileViewHeader`, which is TypeScript, expects a BinaryFile, which has a
  16. // `created` property of type `Date`, while `TPRFileViewInfo`, written in JS,
  17. // into which `FileViewHeader` passes its BinaryFile, expects a file object with
  18. // `created` property of type `string`, which is a mismatch. `TPRFileViewInfo`
  19. // is the only one making runtime complaints and it seems that other uses of
  20. // `FileViewHeader` pass in a string for `created`, so that's what this function
  21. // does too.
  22. export function fileViewFile(fileRef: FileRef) {
  23. return {
  24. ...convertFileRefToBinaryFile(fileRef),
  25. created: fileRef.created,
  26. }
  27. }