lobe-chat

Форк
0
/
upload.ts 
91 строка · 2.0 Кб
1
import { z } from 'zod';
2

3
import { FileParsingTask } from '@/types/asyncTask';
4

5
export interface FileUploadState {
6
  progress: number;
7
  /**
8
   * rest time in s
9
   */
10
  restTime: number;
11
  /**
12
   * upload speed in Byte/s
13
   */
14
  speed: number;
15
}
16

17
export type FileUploadStatus = 'pending' | 'uploading' | 'processing' | 'success' | 'error';
18

19
export type FileProcessStatus = 'pending' | 'chunking' | 'embedding' | 'success' | 'error';
20

21
export const UPLOAD_STATUS_SET = new Set(['uploading', 'pending', 'processing']);
22

23
// the file that is upload at chat page
24
export interface UploadFileItem {
25
  /**
26
   * base64 data, it will use in other data
27
   */
28
  base64Url?: string;
29
  file: File;
30
  /**
31
   * the file url after upload,it will be s3 url
32
   * if enable the S3 storage, or the data is same as base64Url
33
   */
34
  fileUrl?: string;
35
  id: string;
36
  /**
37
   * blob url for local preview
38
   * it will use in the file preview before send the message
39
   */
40
  previewUrl?: string;
41
  status: FileUploadStatus;
42
  tasks?: FileParsingTask;
43
  uploadState?: FileUploadState;
44
}
45

46
export const FileMetadataSchema = z.object({
47
  date: z.string(),
48
  dirname: z.string(),
49
  filename: z.string(),
50
  path: z.string(),
51
});
52

53
export type FileMetadata = z.infer<typeof FileMetadataSchema>;
54

55
export const UploadFileSchema = z.object({
56
  data: z.instanceof(ArrayBuffer).optional(),
57
  /**
58
   * file type
59
   * @example 'image/png'
60
   */
61
  fileType: z.string(),
62
  // TODO: Need be required
63
  hash: z.string().optional(),
64

65
  knowledgeBaseId: z.string().optional(),
66

67
  metadata: z.any().optional(),
68

69
  /**
70
   * file name
71
   * @example 'test.png'
72
   */
73
  name: z.string(),
74

75
  /**
76
   * the mode database save the file
77
   * local mean save the raw file into data
78
   * url mean upload the file to a cdn and then save the url
79
   */
80
  saveMode: z.enum(['local', 'url']),
81
  /**
82
   * file size
83
   */
84
  size: z.number(),
85
  /**
86
   * file url if saveMode is url
87
   */
88
  url: z.string().optional(),
89
});
90

91
export type UploadFileParams = z.infer<typeof UploadFileSchema>;
92

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.