jan/web/utils/file.ts
NamH d7070d8c4a
fix: some bugs for import model (#2181)
* fix: some bugs for import model

Signed-off-by: James <james@jan.ai>

Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>
2024-02-27 23:59:37 +07:00

30 lines
584 B
TypeScript

import { baseName } from '@janhq/core'
export type FilePathWithSize = {
path: string
name: string
size: number
}
export interface FileWithPath extends File {
path?: string
}
export const getFileInfoFromFile = async (
files: FileWithPath[]
): Promise<FilePathWithSize[]> => {
const result: FilePathWithSize[] = []
for (const file of files) {
if (file.path && file.path.length > 0) {
const fileName = await baseName(file.path)
result.push({
path: file.path,
name: fileName,
size: file.size,
})
}
}
return result
}