-
Notifications
You must be signed in to change notification settings - Fork 22
/
file.ts
34 lines (28 loc) · 993 Bytes
/
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
//
// Copyright 2024 DXOS.org
//
import { type Plugin } from '../PluginHost';
// TODO(burdon): See Accept attribute (uses MIME types).
// E.g., 'image/*': ['.jpg', '.jpeg', '.png', '.gif'],
export const defaultFileTypes = {
images: ['png', 'jpg', 'jpeg', 'gif'],
media: ['mp3', 'mp4', 'mov', 'avi'],
text: ['pdf', 'txt', 'md'],
};
export type FileInfo = {
url?: string;
cid?: string; // TODO(burdon): Meta key? Or other common properties with other file management system? (e.g., WNFS).
};
export type FileUploader = (file: File) => Promise<FileInfo | undefined>;
/**
* Generic interface provided by file plugins (e.g., IPFS, WNFS).
*/
export type FileManagerProvides = {
file: {
upload?: FileUploader;
};
};
// TODO(burdon): Better match against interface? and Return provided service type. What if multiple?
export const parseFileManagerPlugin = (plugin: Plugin) => {
return (plugin.provides as any).file ? (plugin as Plugin<FileManagerProvides>) : undefined;
};