Comments (8)
FileStorageDriver
interface proposal (taken from current PHP implementation).
Some things may change due to async nature of node. I am also considering support for file streams as a parameter to setContents
.
declare interface IFileStorageDriver {
supportsTouching: boolean;
supportsDirectories: boolean;
supportsFileSizeRetrieval: boolean;
supportsAbsolutePathRetrieval: boolean;
/**
* Reads the contents of the file
*/
getContents(key: string): Promise<string | boolean>;
/**
* Writes the given File
*/
setContents(key: string, contents: string, append: boolean): Promise<number | boolean>;
/**
* Checks whether the file exists
*/
keyExists(key: string): Promise<boolean>;
/**
* Returns an array of all keys (files and directories)
*
* For storage that doesn't support directories, both parameters are irrelevant.
*
* @param key (Optional) Key of a directory to get keys from. If not set - keys will be read from the storage root.
* @param recursive (Optional) Read all items recursively. Pass integer value to specify recursion depth.
*
* @return array
*/
getKeys(key: string, recursive: number | boolean): Promise<Array<string>>;
/**
* Returns the last modified time
*/
getTimeModified(key: string): Promise<number | boolean>;
/**
* Deletes the file
*/
deleteKey(key: string): Promise<boolean>;
/**
* Renames a file
*/
renameKey(sourceKey: string, targetKey: string) : Promise<boolean>;
/**
* Returns most recent file key that was used by a storage
*/
getRecentKey(): string | null;
/**
* Returns public file URL
*/
getURL(key: string): string;
/**
* Does this storage create a date folder structure?
*/
createDateFolderStructure(): boolean;
}
from webiny-js.
Looks good @Pavel910.
Just wondering, is word 'Key' necessary in methods like renameKey
, deleteKey
?
from webiny-js.
@Adrian1358 delete
is a keyword, I'm afraid we will run into troubles if we use it as a method name. And if it is present in deleteKey
then it is better to keep it consistent.
from webiny-js.
Good point @Pavel910
from webiny-js.
Here is the second revision, cleaned up and improved comparing to the PHP version:
- almost everything is converted to async functions returning Promises
Directory
class is removed entirely, not really needed for our current plans- added set/get meta methods - it will be up to the driver to implement these methods if possible
- renamed to
delete
andrename
@Adrian1358 after reading about compatibility - should be fine
declare interface IFileData {
data: string | Buffer | ReadableStream,
meta?: Object
}
declare interface IFileStorageDriver {
/**
* Reads the contents of the file
*/
getFile(key: string, options?: { encoding: string }): Promise<IFileData | boolean>;
/**
* Writes the given File
*/
setFile(key: string, file: IFileData): Promise<boolean>;
/**
* Get meta data
*/
getMeta(key: string): Promise<Object>;
/**
* Set meta data
*/
setMeta(key: string, meta: Object): Promise<boolean>;
/**
* Checks whether the file exists
*/
exists(key: string): Promise<boolean>;
/**
* Returns an array of all keys (files and directories)
*
* For storage that doesn't support directories, both parameters are irrelevant.
*
* @param key (Optional) Key of a directory to get keys from. If not set - keys will be read from the storage root.
* @param filter (Optional) Glob pattern to filter returned files
*
* @return array
*/
getKeys(key?: string, filter?: string | null): Promise<Array<string>>;
/**
* Returns the last modified time
*/
getTimeModified(key: string): Promise<number | boolean>;
/**
* Deletes the file
*/
delete(key: string): Promise<boolean>;
/**
* Renames a file
*/
rename(sourceKey: string, targetKey: string): Promise<boolean>;
/**
* Returns public file URL
*/
getURL(key: string): string;
/**
* Does this storage create a date prefix?
*/
createDatePrefix(): boolean;
/**
* Get file size (if supported)
*/
getSize(key: string): Promise<number | null>;
/**
* Get absolute file path (if supported)
*/
getAbsolutePath(key: string): Promise<string | null>;
}
declare interface IFile {
/**
* Constructor
*/
constructor(key: string, storage: IFileStorageDriver): IFile;
/**
* Get file storage
*/
getStorage(): IFileStorageDriver;
/**
* Get file key
*/
getKey(): string;
/**
* Get public file URL
*/
getUrl(): string;
/**
* Get file contents
*/
getContents(options?: { encoding: string }): Promise<string | Buffer | ReadableStream>;
/**
* Get file meta
*/
getMeta(): Promise<Object>;
/**
* Get time modified
*/
getTimeModified(): Promise<number>;
/**
* Set file contents (writes contents to storage)
*/
setContents(data: IFileData): Promise<boolean>;
/**
* Set file meta
*/
setMeta(meta: Object): Promise<boolean>;
/**
* Rename a file
*/
rename(newKey: string): Promise<boolean>;
/**
* Delete a file
*/
delete(): Promise<boolean>;
/**
* Get absolute file path.
* If storage driver does not support absolute paths (cloud storage), returns file key
*
* @return string
*/
getAbsolutePath(): Promise<string | null>;
/**
* Get file size in bytes
*
* @return int|null Number of bytes or null
*/
getSize(): Promise<number | null>;
}
from webiny-js.
Why do we duplicate some methods, like getMeta
between IFileStorageDriver
and IFile
? Shouldn't the storage just return an IFile
instance and then those methods are available via that instance only.
from webiny-js.
Never mind ... I got my answer :) The interfaces look good! 👍
from webiny-js.
Awesome!
from webiny-js.
Related Issues (20)
- 💾 Caching mechanism to improve performance
- 🆙 Node Update to v18 HOT 1
- 🧩 Enable the usage of Reference Fields inside Dynamic Zones
- 📝 Ability to save a Draft in the HCMS entries
- There should be a lexical state to html converter for backend HOT 3
- 👁️ Watch Command Output Enhancement
- 📚 Advanced Content Organization Customizations Capabilities
- Getting a field from ref type as titleFieldId
- You are not authorized to access this tenant
- ✅ Bulk Metadata update for Custom Fields in FM HOT 1
- 📅 Custom DateTime and Identity Input HOT 2
- 📅 Custom DateTime and Identity Input
- ⚒️ HCMS Revision vs Entry Dates and Identity Fields Update
- Downloading files of about 5Mb results in an "internal server error" HOT 3
- 5.39.0 - Using `AWS_PROFILE` in Env Vars No Longer Works HOT 4
- Dynamic Plugin Loading
- Export of Published Site
- Create project failing due to `yarn add @webiny/cwp-template-aws@latest` HOT 3
- Unlink Template not functional
- UI Breakpoints doesn't update when I add a new breakpoint in the Theme Object
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webiny-js.