Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions packages/gcs-store/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ npm install @tus/gcs-store
const {Server} = require('@tus/server')
const {GCSStore} = require('@tus/gcs-store')

const {Storage} = require('@google-cloud/storage');

const storage = new Storage({keyFilename: 'key.json'})

const server = new Server({
path: '/files',
datastore: new GCSStore({
projectId: 'id',
keyFilename: path.resolve('./some-path', 'keyfile.json'),
bucket: 'tus-node-server-ci',
bucket: storage.bucket('tus-node-server-ci'),
}),
})
// ...
Expand All @@ -46,19 +48,11 @@ This package exports `GCSStore`. There is no default export.

### `new GCSStore(options)`

Creates a new Google Cloud Storage store with options.

#### `options.projectId`

The GCS project ID (`string`).

#### `options.keyFilename`

Path to the keyfile with credentials (`string`).
Creates a new Google Cloud Storage store by passing a GCS bucket instance.

#### `options.bucket`

The bucket name.
The bucket instance

## Extensions

Expand Down
20 changes: 5 additions & 15 deletions packages/gcs-store/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import {Storage, Bucket} from '@google-cloud/storage'
import {Bucket} from '@google-cloud/storage'
import stream from 'node:stream'
import http from 'node:http'
import debug from 'debug'

import {ERRORS, TUS_RESUMABLE} from '@tus/server'
import {Upload, DataStore} from '@tus/server'

type Options = {
bucket: string
projectId: string
keyFilename: string
}

const log = debug('tus-node-server:stores:gcsstore')

type Options = {bucket: Bucket}

export class GCSStore extends DataStore {
bucket: Bucket
bucket_name: string
gcs: Storage

constructor(options: Options) {
super()
Expand All @@ -26,13 +20,9 @@ export class GCSStore extends DataStore {
throw new Error('GCSDataStore must have a bucket')
}

this.bucket = options.bucket

this.extensions = ['creation', 'creation-with-upload', 'creation-defer-length']
this.bucket_name = options.bucket
this.gcs = new Storage({
projectId: options.projectId,
keyFilename: options.keyFilename,
})
this.bucket = this.gcs.bucket(this.bucket_name)
}

create(file: Upload): Promise<Upload> {
Expand Down
5 changes: 3 additions & 2 deletions packages/gcs-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
"test": "mocha test.ts --timeout 30000 --exit --extension ts --require ts-node/register"
},
"dependencies": {
"@google-cloud/storage": "^6.9.3",
"debug": "^4.3.3"
},
"devDependencies": {
"@google-cloud/storage": "^6.9.3",
"@tus/server": "workspace:^",
"@types/debug": "^4.1.7",
"@types/mocha": "^10.0.1",
Expand All @@ -35,7 +35,8 @@
"should": "^13.2.3",
"typescript": "latest"
},
"peerdependencies": {
"peerDependencies": {
"@google-cloud/storage": "*",
"@tus/server": "workspace:^"
},
"engines": {
Expand Down
9 changes: 7 additions & 2 deletions packages/gcs-store/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {GCSStore} from './'

import * as shared from '../../test/stores.test'

import {Storage} from '@google-cloud/storage'

const fixturesPath = path.resolve('../', '../', 'test', 'fixtures')
const storePath = path.resolve('../', '../', 'test', 'output')

Expand All @@ -16,10 +18,13 @@ describe('GCSStore', () => {
})

beforeEach(function () {
this.datastore = new GCSStore({
const storage = new Storage({
projectId: 'tus-node-server',
keyFilename: path.resolve('../', '../', 'keyfile.json'),
bucket: 'tus-node-server-ci',
})

this.datastore = new GCSStore({
bucket: storage.bucket('tus-node-server-ci'),
})
})

Expand Down
9 changes: 6 additions & 3 deletions test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,15 @@ describe('EndToEnd', () => {
const files_created: string[] = []

before(() => {
const storage = new Storage({
projectId: PROJECT_ID,
keyFilename: KEYFILE,
})

server = new Server({
path: STORE_PATH,
datastore: new GCSStore({
projectId: PROJECT_ID,
keyFilename: KEYFILE,
bucket: BUCKET,
bucket: storage.bucket(BUCKET),
}),
})
listener = server.listen()
Expand Down
3 changes: 3 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ __metadata:
mocha: ^10.1.0
should: ^13.2.3
typescript: latest
peerDependencies:
"@google-cloud/storage": "*"
"@tus/server": "workspace:^"
languageName: unknown
linkType: soft

Expand Down