-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathStorageAdapter.ts
More file actions
99 lines (87 loc) · 5.04 KB
/
Copy pathStorageAdapter.ts
File metadata and controls
99 lines (87 loc) · 5.04 KB
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
/**
* Each storage adapter should support two ways of storing files:
* - publically (public URL) - the file can be accessed by anyone by HTTP GET / HEAD request with plain URL
* - privately (presigned URL) - the file can be accessed by anyone by HTTP GET / HEAD request only with presigned URLs, limited by expiration time
*
*/
export interface StorageAdapter {
/**
* This method should return the presigned URL for the given key capable of upload (adapter user will call PUT multipart form data to this URL within expiresIn seconds after link generation).
* By default file which will be uploaded on PUT should be marked for deletion. So if during 24h it is not marked for not deletion, it adapter should delete it forever.
* The PUT method should fail if the file already exists.
*
* Adapter user will always pass next parameters to the method:
* @param key - The key of the file to be uploaded e.g. "uploads/file.txt"
* @param expiresIn - The expiration time in seconds for the presigned URL
* @param contentType - The content type of the file to be uploaded, e.g. "image/png"
*
* @returns A promise that resolves to an object containing the upload URL and any extra parameters which should be sent with PUT multipart form data
*/
getUploadSignedUrl(key: string, contentType: string, expiresIn?: number): Promise<{
uploadUrl: string;
uploadExtraParams?: Record<string, string>;
}>;
/**
* This method should return the URL for the given key capable of download (200 GET request with response body or 200 HEAD request without response body).
* If adapter configured to store objects publically, this method should return the public URL of the file.
* If adapter configured to no allow public storing of images, this method should return the presigned URL for the file.
*
* @param key - The key of the file to be downloaded e.g. "uploads/file.txt"
* @param expiresIn - The expiration time in seconds for the presigned URL
*/
getDownloadUrl(key: string, expiresIn?: number): Promise<string>;
/**
* This method should mark the file for deletion.
* If file is marked for delation and exists more then 24h (since creation date) it should be deleted.
* This method should work even if the file does not exist yet (e.g. only presigned URL was generated).
* @param key - The key of the file to be uploaded e.g. "uploads/file.txt"
*/
markKeyForDeletation(key: string): Promise<void>; //TODO delete after one year
markKeyForDeletion(key: string): Promise<void>;
/**
* This method should mark the file to not be deleted.
* This method should be used to cancel the deletion of the file if it was marked for deletion.
* @param key - The key of the file to be uploaded e.g. "uploads/file.txt"
*/
markKeyForNotDeletation(key: string): Promise<void>; //TODO delete after one year
markKeyForNotDeletion(key: string): Promise<void>;
/**
* This method can start needed schedullers, cron jobs, etc. to clean up the storage.
* @param adapterUserUniqueRepresentation - The unique representation of the plugin instance which
* wil use this adapter. Might be handy if you need to distinguish between different instances of the same adapter.
*/
setupLifecycle(adapterUserUniqueRepresentation: string): Promise<void>;
/**
* If adapter is configured to publically, this method should return true.
*/
objectCanBeAccesedPublicly(): Promise<boolean>;
/**
* This method should return the key as a data URL (base64 encoded string).
* @param key - The key of the file to be converted to a data URL
* @returns A promise that resolves to a string containing the data URL
*/
getKeyAsDataURL(key: string): Promise<string>;
/**
* Determines whether the given URL points to a resource managed by this storage adapter.
* * This method is important for plugins (such as MarkdownPlugin) to distinguish between
* "own" resources (stored in your S3 bucket or local storage) and external links * (such as images from Unsplash or Google).
* * The implementation logic typically includes:
* 1. Checking whether the hostname of the URL matches the configured bucket domain or custom CDN.
* 2. Checking whether the URL path contains the adapter's specific download prefix.
* * @param url - The full URL string to check (can be a public URL or a pre-signed URL).
* @returns A promise that returns true if the URL belongs to this adapter, false otherwise.
*/
isInternalUrl (url: string): Promise<boolean>;
/**
* Creates an object writer for the specified key and content type.
* For example, this can be used to write large files in chunks or streams (AWS S3 Multipart Upload).
* @param key - The key of the file to be written e.g. "uploads/file.txt"
* @param contentType - The MIME type of the file to be written e.g. "image/png"
*/
createWriteStream(key: string, contentType: string, bufferSizeMb?: number): Promise<ObjectWriter>;
}
interface ObjectWriter {
write(data: string | Buffer | Uint8Array): Promise<void>;
close(): Promise<void>;
abort(): Promise<void>;
}