| 1234567891011121314151617181920212223242526272829303132333435363738 |
- import { uploadFileApi, UPLOAD_BIZ_TYPE } from '@/api/minio';
- import type { ImageItem } from './types';
- export function stringToArray(str?: string): number[] | undefined {
- if (!str) return undefined;
- return JSON.parse('[' + str + ']');
- }
- export function unformatImage(file?: string) {
- if (!file) return undefined;
- const fileData: ImageItem[] = JSON.parse(file);
- return fileData;
- }
- const formatImage = async (data: ImageItem) => {
- if (!data.file) return data;
- const fileName = data.file.name;
- const fileSize = data.size;
- const res = await uploadFileApi({ bizType: UPLOAD_BIZ_TYPE.ATTACHMENT, fileName, file: data.file });
- const fileUrl = res.url;
- return {
- fileName,
- fileSize,
- fileUrl,
- };
- };
- export const formatImageList = async (data: ImageItem[] | undefined) => {
- if (!data || data.length === 0) return null;
- const res = await Promise.all(
- data.map(async (item) => {
- const res = await formatImage(item);
- return res;
- }),
- );
- return res;
- };
|