Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/update dependencies #326

Merged
merged 8 commits into from
Oct 15, 2024
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
567 changes: 270 additions & 297 deletions .pnp.cjs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions packages/nestjs-signed-url/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
"postpack": "rm -rf dist"
},
"devDependencies": {
"@google-cloud/storage": "5.7.2",
"@google-cloud/storage": "7.13.0",
"@jest/globals": "29.7.0",
"@nestjs/common": "10.4.1",
"@nestjs/core": "10.4.1",
"@nestjs/testing": "10.4.1",
"@types/node": "22.5.5",
"@nestjs/common": "10.4.4",
"@nestjs/core": "10.4.4",
"@nestjs/testing": "10.4.4",
"@types/node": "22.7.5",
"reflect-metadata": "0.2.2",
"rxjs": "7.8.1",
"typescript": "5.4.2"
Expand Down
20 changes: 10 additions & 10 deletions packages/nestjs-signed-url/src/services/signed-url.service.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import type { SignUrlOptions } from '../storage/index.js'
import type { SignedUrl } from '../storage/index.js'
import type { SignUrlOptions } from '../storage/index.js'
import type { SignedUrl } from '../storage/index.js'
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
import type { AbstractStorage } from '../storage/index.js'

import { Inject } from '@nestjs/common'
import { Injectable } from '@nestjs/common'
import { Inject } from '@nestjs/common'
import { Injectable } from '@nestjs/common'

import { STORAGE } from '../storage/index.js'
import { STORAGE } from '../storage/index.js'

@Injectable()
export class SignedUrlService {
@Inject(STORAGE)
storage: any
storage: AbstractStorage

async generateWriteUrl(
bucket: string,
filename: string,
options: SignUrlOptions
): Promise<SignedUrl> {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
return this.storage.generateWriteUrl(bucket, filename, options) as Promise<SignedUrl>
return this.storage.generateWriteUrl(bucket, filename, options)
}

async generateReadUrl(bucket: string, filename: string): Promise<SignedUrl> {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
return this.storage.generateReadUrl(bucket, filename) as Promise<SignedUrl>
return this.storage.generateReadUrl(bucket, filename)
}
}
2 changes: 1 addition & 1 deletion packages/nestjs-signed-url/src/storage/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const STORAGE = `SIGNED_URL_UPLOAD_STORAGE_PROVIDER`
export const STORAGE = Symbol('SIGNED_URL_UPLOAD_STORAGE_PROVIDER')
23 changes: 10 additions & 13 deletions packages/nestjs-signed-url/src/storage/gcs.storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,47 @@ import type { OnModuleInit } from '@nestjs/common'
import type { SignUrlOptions } from './storage.interfaces.js'
import type { SignedUrl } from './storage.interfaces.js'

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

import { AbstractStorage } from './abstract.storage.js'

@Injectable()
export class GcsStorage extends AbstractStorage implements OnModuleInit {
storage: any
storage: Storage

bucket: string

onModuleInit(): void {
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
const { Storage } = require('@google-cloud/storage')

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
this.storage = new Storage()
}

async generateWriteUrl(
bucket: string,
bucketName: string,
filename: string,
options: SignUrlOptions
): Promise<SignedUrl> {
const params = {
version: 'v4',
action: 'write',
version: 'v4' as const,
action: 'write' as const,
expires: Date.now() + 15 * 60 * 1000,
contentType: options.type,
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const [url] = await this.storage.bucket(bucket).file(filename).getSignedUrl(params)
const bucket = this.storage.bucket(bucketName)
const file = bucket.file(filename)
const [url] = await file.getSignedUrl(params)

return { url, fields: [] }
}

async generateReadUrl(bucket: string, filename: string): Promise<SignedUrl> {
const params = {
version: 'v4',
action: 'read',
version: 'v4' as const,
action: 'read' as const,
expires: Date.now() + 15 * 60 * 1000,
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const [url] = await this.storage.bucket(bucket).file(filename).getSignedUrl(params)

return { url, fields: [] }
Expand Down
Loading