Extension support for storage adapters #14742
Replies: 4 comments 3 replies
-
|
@bpy That's a great start!
Should we also define all possible exceptions? I see the the current drive package already has some, this list will probably grow/shrink depending on what available methods the Storage class has to have.
Sorry if this is a stupid question, but is it really necessary to store files/folders information in the database? Having two sources of truth for where the files/folders are located will lead to sync problems.
That's a great idea. That way we could use picture-only hosting providers (for example) and leave other file kinds to other storage adapters. |
Beta Was this translation helpful? Give feedback.
-
Would you list them and propose some ?
For me it's two different concepts. Therefore, not enforcing a structure sync between the Directus folders and the storage structure would make things really easy for the Directus Core. I think that on the build-in version, Directus should continue to ship simple storage adapters like export class LocalWithFolderStorageAdapter extends StorageAdapter{
private localStorageAdapter: StorageAdapter;
constructor(storageManager: StorageManager) {
this.localStorageAdapter : storageManager.disk('local');
}
put(_location: string, _content: Buffer | NodeJS.ReadableStream | string, _type?: string): Promise<Response> {
// Do something with the _location for deciding the folder
[...]
// Create the folder on the local storage
[...]
this.localStorageAdapter.put(_location, _content, _type);
}
}Still sticking to my idea that passing the
I would propose the same as above: injection of the StorageManager. This way, the Storage Adapter can use another StorageAdapter before deciding to send an exception. But that's totally opened. That would look like this export class ImageOnlyStorageAdapter extends StorageAdapter{
private fallbackStorageAdapter: StorageAdapter;
private myStorageClient: any;
constructor(storageManager: StorageManager) {
this.fallbackStorageAdapter : storageManager.disk('local');
// create the "myStorageClient"
[...]
}
put(_location: string, _content: Buffer | NodeJS.ReadableStream | string, _type?: string): Promise<Response> {
if (this.isTypeSupported(_type)) {
const myStorageRelativeInfo = this.myStorageClient.upload(_content); //i.e.
// Do Something with the returned info
return Promise.resolve()
} else {
return this.localStorageAdapter.put(_location, _content, _type);
}
}Here you can also see an example where having the |
Beta Was this translation helpful? Give feedback.
-
|
@emrahnazif You came to mind as you were having some serious production issues in the large number of files combined with the storage adapters. Mind leaving your thoughts on the points above? I'm mostly curious to hear about your suggestions around folder structures and how to handle those cross storage adapters ❤️ |
Beta Was this translation helpful? Give feedback.
-
|
Note to self: A lot of work has already been done to make the storage adapters properly modular (under |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Note: I am quite new to the Directus world, so I might not have the big picture. Here under is my contribution to start the discussions, and maybe end up to a design that could lead to an implementation. Please excuse me, and correct me, if some information are wrong.
Purpose
Question about extension support for storage adapters has been coming and going without reaching a critical mass. This discussion aims to gather the question to be answered, a tour of the existing features and how to build this without leveraging the risk of breaking changes in the future.
Main topics
The following topic need to be addressed before thinking about implementation
Some other ideas
What does a storage adapter class look like?
Comments from @rijkvanzanten
Here under, the current methods of the
Storageabstract class and their usage.TL;DR; The used methods are
Folder support
Comments from @rijkvanzanten
Currently, the information of the folder is only stored in the Database. Files are seen as flat for the Storage Adapter.
My opinion: the Directus Folder information (the three from the root) could be also passed to the Storage Adapter methods. This way it would be the responsibility of the Storage Manager to manage what to do with it.
Custom file naming
Comments from @rijkvanzanten
My opinion: the storage should be seen as a "black box". The responsibility could be deferred to the Storage Adapter itself by passing the Directus File entity to the Storage Adapter methods. This way, it's the Storage Adapter responsibility to manage the naming, maybe depending on a Storage Adapter configuration. This would also require the Storage Adapter to be able to store some specific information in the Directus File entity for further use. See below for this topic.
File duplication handling
Comments from @rijkvanzanten
My opinion: this responsibility could also be transferred to the Storage Adapter, and activated/deactivated through a configuration of the Storage Adapter. If the Storage Adapter is able to store it's own information in the Directus File entity, I think that everything is possible. The Directus File entity would remain independent of the file as managed by the Storage Adapter. See below for this topic
Two way sync
Comments from @rijkvanzanten
My opinion: this is a little bit trickier, but again should be the responsibility of the Storage Adapter to handle this. That would require that the Storage adapter expose some methods to get triggered of a change on the external storage, but also have the ability to update the Directus File entity's directory. There is also here some thoughts about performances when big changes happen on the external storage.
Storage specific information on the Directus File entity
My opinion: by allowing the Storage Adapter to store specific information, many responsibilities can be transferred to the Storage Adapter. This also allows a great openness. I see something like a json object in a column. An attention on performance should be made if the database does not support json queries.
Storage adapter per mime type
My opinion: it's an idea that comes through my last development with Rokka. Rokka does not support all mime types. That could be something developed inside of the
FileService, but also simply transferred to the Storage Adapter itself, if it's given the ability to get references to other Storage Adapters. All the logic would remain in the Storage Adapter.Beta Was this translation helpful? Give feedback.
All reactions