djorm-storage-gcp
Advanced tools
Comparing version 0.1.18-alpha.1 to 0.1.19-alpha.0
43
index.js
@@ -1,21 +0,18 @@ | ||
const { Storage } = require('@google-cloud/storage') | ||
const { | ||
CharField, | ||
FileStorage, | ||
setSystemDefaultStorage | ||
} = require('djorm/fields') | ||
const { Storage: GcpStorage } = require('@google-cloud/storage') | ||
const { Storage: DjormStorage } = require('djorm/storage/Storage') | ||
class GcpFileStorage extends FileStorage { | ||
static projectId = new CharField() | ||
static clientEmail = new CharField() | ||
static privateKey = new CharField() | ||
static bucketName = new CharField() | ||
static basePath = new CharField() | ||
/** Google Cloud Platform Cloud Storage driver | ||
* @param basePath {string} Prepend this path to all files | ||
* @param bucketName {string} Bucket name | ||
* @param clientEmail {string} The username / e-mail of the service account | ||
* @param privateKey {string} The full private key | ||
* @param projectId {string} The GCP project ID | ||
*/ | ||
class GcpFileStorage extends DjormStorage { | ||
get storage () { | ||
return new Storage({ | ||
projectId: this.get('projectId'), | ||
return new GcpStorage({ | ||
projectId: this.getProp('projectId'), | ||
credentials: { | ||
client_email: this.get('clientEmail'), | ||
private_key: this.get('privateKey').replace(/\\n/g, '\n') | ||
client_email: this.getProp('clientEmail'), | ||
private_key: this.getProp('privateKey').replace(/\\n/g, '\n') | ||
} | ||
@@ -26,3 +23,3 @@ }) | ||
get bucket () { | ||
return this.storage.bucket(this.bucketName) | ||
return this.storage.bucket(this.getProp('bucketName')) | ||
} | ||
@@ -35,7 +32,7 @@ | ||
getReadStream (filePath) { | ||
return this.file(filePath).getReadStream() | ||
return this.file(filePath).createReadStream() | ||
} | ||
getWriteStream (filePath) { | ||
return this.file(filePath).getWriteStream() | ||
return this.file(filePath).createWriteStream() | ||
} | ||
@@ -62,6 +59,2 @@ | ||
function useAsDefault (props) { | ||
setSystemDefaultStorage(new GcpFileStorage(props)) | ||
} | ||
module.exports = { GcpFileStorage, useAsDefault } | ||
module.exports = { GcpFileStorage } |
{ | ||
"name": "djorm-storage-gcp", | ||
"version": "0.1.18-alpha.1", | ||
"version": "0.1.19-alpha.0", | ||
"description": "Google Cloud Storage support for Djorm", | ||
"author": "Pavel Žák <pavel@zak.global>", | ||
"homepage": "https://github.com/just-paja/djorm#readme", | ||
"homepage": "https://just-paja.github.io/djorm", | ||
"license": "ISC", | ||
@@ -24,5 +24,5 @@ "main": "index.js", | ||
"@google-cloud/storage": "^5.8.1", | ||
"djorm": "^0.1.18-alpha.1" | ||
"djorm": "^0.1.19-alpha.0" | ||
}, | ||
"gitHead": "f3a01cf12213650617ae9a2c554776d9cb6a38d5" | ||
"gitHead": "96cea85017466c1f3099c236f2e0a38623225629" | ||
} |
# `djorm-storage-gcp` | ||
> TODO: description | ||
> Google Cloud Platform storage driver for [Djorm](https://just-paja.github.io/djorm/) | ||
## Usage | ||
## Installation | ||
```shell | ||
npm install --save djorm-storage-gcp | ||
``` | ||
const djormStorageGcp = require('djorm-storage-gcp'); | ||
// TODO: DEMONSTRATE API | ||
## Configuration | ||
```javascript | ||
config({ | ||
storages: { | ||
default: { | ||
driver: 'djorm-storage-gcp.GcpFileStorage', | ||
basePath: '', | ||
bucketName: 'bucket-name', | ||
clientEmail: 'serviceaccount@gcp.com', | ||
privateKey: '### BEGIN PRIVATE KEY ...', | ||
projectId: 'gcp-project-id', | ||
} | ||
} | ||
}) | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2621
28
47
+ Addeddjorm@0.1.19-alpha.15(transitive)
+ Addeduuid@9.0.1(transitive)
- Removeddjorm@0.1.18-alpha.1(transitive)
Updateddjorm@^0.1.19-alpha.0