2023-12-15 04:19:42 -05:00
|
|
|
import { FileRef } from '../../../../../types/file-ref'
|
|
|
|
import { BinaryFile } from '@/features/file-view/types/binary-file'
|
|
|
|
|
|
|
|
export function convertFileRefToBinaryFile(fileRef: FileRef): BinaryFile {
|
2024-09-18 05:05:31 -04:00
|
|
|
const timestamp = fileRef.linkedFileData?.importedAt ?? fileRef.created
|
2023-12-15 04:19:42 -05:00
|
|
|
return {
|
|
|
|
_id: fileRef._id,
|
|
|
|
name: fileRef.name,
|
|
|
|
id: fileRef._id,
|
|
|
|
type: 'file',
|
|
|
|
selected: true,
|
|
|
|
linkedFileData: fileRef.linkedFileData,
|
2024-09-18 05:05:31 -04:00
|
|
|
created: timestamp ? new Date(timestamp) : new Date(),
|
2024-08-21 07:28:21 -04:00
|
|
|
hash: fileRef.hash,
|
2023-12-15 04:19:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// `FileViewHeader`, which is TypeScript, expects a BinaryFile, which has a
|
|
|
|
// `created` property of type `Date`, while `TPRFileViewInfo`, written in JS,
|
|
|
|
// into which `FileViewHeader` passes its BinaryFile, expects a file object with
|
|
|
|
// `created` property of type `string`, which is a mismatch. `TPRFileViewInfo`
|
|
|
|
// is the only one making runtime complaints and it seems that other uses of
|
|
|
|
// `FileViewHeader` pass in a string for `created`, so that's what this function
|
|
|
|
// does too.
|
|
|
|
export function fileViewFile(fileRef: FileRef) {
|
2024-09-18 05:05:31 -04:00
|
|
|
const converted = convertFileRefToBinaryFile(fileRef)
|
2023-12-15 04:19:42 -05:00
|
|
|
return {
|
2024-09-18 05:05:31 -04:00
|
|
|
...converted,
|
|
|
|
created: converted.created.toISOString(),
|
2023-12-15 04:19:42 -05:00
|
|
|
}
|
|
|
|
}
|