-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfile.ts
126 lines (106 loc) · 2.1 KB
/
file.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import type { NoteInternalId } from './note.js';
import type { Buffer } from 'buffer';
import type User from './user.js';
/**
* File types for storing in object storage
*/
export enum FileType {
/**
* Type for testing uploads
*/
Test = 0,
/**
* File is a part of note
*/
NoteAttachment = 1,
/**
* Tool cover
*/
EditorToolCover = 2
}
/**
* Additional data about uploaded file, ex. user id, who uploaded it
*/
export interface FileMetadata {
/**
* User who uploaded file
*/
userId: User['id'];
}
/**
* File location for testing uploads, there is no defined location
*/
export type TestFileLocation = Record<never, never>;
/**
* File location, when it is a part of note
*/
export type NoteAttachmentFileLocation = {
noteId: NoteInternalId;
};
/**
* Editor tool cover location
*/
export type EditorToolCoverFileLocation = {
isEditorToolCover: boolean;
};
/**
* Possible file location
*/
export type FileLocation = TestFileLocation | NoteAttachmentFileLocation | EditorToolCoverFileLocation;
/**
* File location type, wich depends on file type
*/
export interface FileLocationByType {
[FileType.Test]: TestFileLocation;
[FileType.NoteAttachment]: NoteAttachmentFileLocation;
[FileType.EditorToolCover]: EditorToolCoverFileLocation;
}
/**
* Interface representing a file entity
*/
export default interface UploadedFile {
/**
* File identifier
*/
id: number;
/**
* File unique hash which stores in some object storage
*/
key: string;
/**
* File name
*/
name: string;
/**
* File mimetype (e.g. `image/png`)
*/
mimetype: string;
/**
* File type, using to store in object storage
*/
type: FileType;
/**
* File size in bytes
*/
size: number;
/**
* File creation date
*/
createdAt: Date;
/**
* Object, which stores information about file location
*/
location: FileLocation;
/**
* File metadata
*/
metadata: FileMetadata;
}
/**
* File creation attributes
*/
export type FileCreationAttributes = Omit<UploadedFile, 'id' | 'createdAt'>;
/**
* File data
*/
export type FileData = Buffer;