Server ready to get images
This commit is contained in:
parent
624329b3a1
commit
7ccc951107
|
@ -0,0 +1,3 @@
|
|||
EVENT_IMAGE_BUCKET_PUBLIC_URL_BASE="https://storage.googleapis.com/qpa-event-images"
|
||||
EVENT_IMAGE_TMP_LOCAL_PATH="/Users/amit/workspace/sandbox/event-images-tmp"
|
||||
EVENT_IMAGE_GCS_BUCKET_NAME="qpa-event-images"
|
|
@ -3,3 +3,4 @@ node_modules
|
|||
.idea
|
||||
lib/
|
||||
dist
|
||||
.env
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
"cookie": "^0.4.0",
|
||||
"cors": "^2.8.5",
|
||||
"date-fns": "^2.7.0",
|
||||
"dotenv": "^8.2.0",
|
||||
"express": "^4.17.1",
|
||||
"graphql": "^14.4.2",
|
||||
"graphql-import": "^0.7.1",
|
||||
|
|
|
@ -7,8 +7,8 @@ import { FileUpload } from "graphql-upload"
|
|||
import { Metadata } from "@google-cloud/common"
|
||||
|
||||
export interface ImageBucketServiceOptions {
|
||||
GCS_BUCKET_NAME: string
|
||||
BUCKET_PUBLIC_URL_BASE: string
|
||||
gcsBucketName: string
|
||||
buckerPublicURLBase: string
|
||||
tmpLocalPath: string
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ export default class ImageBucketService {
|
|||
|
||||
constructor(options: ImageBucketServiceOptions) {
|
||||
this.options = options
|
||||
this.gcsBucket = new Storage().bucket(this.options.GCS_BUCKET_NAME)
|
||||
this.gcsBucket = new Storage().bucket(this.options.gcsBucketName)
|
||||
|
||||
// quick fail in case of bad credentials
|
||||
this.gcsBucket.getFiles()
|
||||
|
@ -86,6 +86,6 @@ export default class ImageBucketService {
|
|||
})
|
||||
|
||||
this.deleteLocally(localTempPath) // don't care about result
|
||||
return `${this.options.BUCKET_PUBLIC_URL_BASE}/${bucketFile.name}`
|
||||
return `${this.options.buckerPublicURLBase}/${bucketFile.name}`
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ const canChangeEvent = async (event: Event, user: User) => {
|
|||
export const EventImageResolvers = (
|
||||
imageBucketService: ImageBucketService
|
||||
) => ({
|
||||
Query: {},
|
||||
Mutation: {
|
||||
setEventCoverImage: async (
|
||||
_,
|
||||
|
|
|
@ -3,3 +3,8 @@ export const mailgun = {
|
|||
apiKey: process.env.MAILGUN_KEY,
|
||||
domain: process.env.EMAIL_DOMAIN,
|
||||
}
|
||||
export const eventImage = {
|
||||
imageBucketPublicURLBase: process.env.EVENT_IMAGE_BUCKET_PUBLIC_URL_BASE,
|
||||
imageTempLocalPath: process.env.EVENT_IMAGE_TMP_LOCAL_PATH,
|
||||
imageCGSBucketName: process.env.EVENT_IMAGE_GCS_BUCKET_NAME
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ import {Session} from "./Auth/Session.entity"
|
|||
import {Context} from "./@types/graphql-utils"
|
||||
import SessionManager from "./Auth/SessionManager"
|
||||
import { tagResolvers } from "./Calendar/tagsResolvers";
|
||||
import ImageBucketService from "./Image/ImageBucketService";
|
||||
import { EventImageResolvers } from "./Image/eventImageResolvers";
|
||||
|
||||
interface Dependencies {
|
||||
typeormConnection: Connection
|
||||
|
@ -17,6 +19,7 @@ interface Dependencies {
|
|||
domain?: string
|
||||
customContext?: Context
|
||||
sessionManager: SessionManager
|
||||
imageBucketService: ImageBucketService
|
||||
}
|
||||
|
||||
const resolvers = {
|
||||
|
@ -32,6 +35,7 @@ export const createServer = async (dependencies: Dependencies) => {
|
|||
sessionManager: dependencies.sessionManager
|
||||
})
|
||||
|
||||
const eventImageResolvers = EventImageResolvers(dependencies.imageBucketService)
|
||||
const typeDefs = importSchema(__dirname + '/schema.graphql')
|
||||
|
||||
const { Query: EventQueryResolvers, Mutation: EventResolversMutation,...eventResolvers} = EventsResolvers
|
||||
|
@ -47,14 +51,16 @@ export const createServer = async (dependencies: Dependencies) => {
|
|||
...EventQueryResolvers,
|
||||
...authResolvers.Query,
|
||||
...UserQueryResolvers,
|
||||
...tagResolvers.Query
|
||||
...tagResolvers.Query,
|
||||
...eventImageResolvers.Query
|
||||
},
|
||||
Mutation: {
|
||||
...resolvers.Mutation,
|
||||
...EventResolversMutation,
|
||||
...authResolvers.Mutation,
|
||||
...UserMutationResolvers,
|
||||
...tagResolvers.Mutation
|
||||
...tagResolvers.Mutation,
|
||||
...eventImageResolvers.Mutation
|
||||
},
|
||||
UserSession: {
|
||||
...authResolvers.UserSession
|
||||
|
|
11
src/index.ts
11
src/index.ts
|
@ -1,3 +1,5 @@
|
|||
require('dotenv').config()
|
||||
|
||||
import { createServer } from "./graphql"
|
||||
import typeormConfig from './ormconfig'
|
||||
import {createConnection} from "typeorm"
|
||||
|
@ -7,6 +9,7 @@ import express from 'express'
|
|||
import authHttpHandlers from "./Auth/authHttpHandlers"
|
||||
import SessionManager from "./Auth/SessionManager"
|
||||
import morgan from 'morgan'
|
||||
import ImageBucketService from "./Image/ImageBucketService";
|
||||
|
||||
const start = async () => {
|
||||
const sessionManager = new SessionManager({
|
||||
|
@ -15,6 +18,11 @@ const start = async () => {
|
|||
emailSenderDomain: config.mailgun.domain
|
||||
})
|
||||
|
||||
const imageBucketService = new ImageBucketService({
|
||||
buckerPublicURLBase: config.eventImage.imageBucketPublicURLBase,
|
||||
tmpLocalPath: config.eventImage.imageTempLocalPath,
|
||||
gcsBucketName: config.eventImage.imageCGSBucketName,
|
||||
})
|
||||
console.log(`Starting with db: ${typeormConfig.database} and config:\n ${JSON.stringify(typeormConfig,null,'\t')}`)
|
||||
const connection = await createConnection(typeormConfig)
|
||||
console.log('Will look for migrations and run them')
|
||||
|
@ -24,7 +32,8 @@ const start = async () => {
|
|||
typeormConnection: connection,
|
||||
sendEmail,
|
||||
domain: config.domain,
|
||||
sessionManager
|
||||
sessionManager,
|
||||
imageBucketService
|
||||
})
|
||||
|
||||
const authHandlers = authHttpHandlers(sessionManager)
|
||||
|
|
|
@ -1909,6 +1909,11 @@ dotenv@^6.2.0:
|
|||
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-6.2.0.tgz#941c0410535d942c8becf28d3f357dbd9d476064"
|
||||
integrity sha512-HygQCKUBSFl8wKQZBSemMywRWcEDNidvNbjGVyZu3nbZ8qq9ubiPoGLMdRDpfSrpkkm9BXYFkpKxxFX38o/76w==
|
||||
|
||||
dotenv@^8.2.0:
|
||||
version "8.2.0"
|
||||
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a"
|
||||
integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==
|
||||
|
||||
duplexer3@^0.1.4:
|
||||
version "0.1.4"
|
||||
resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2"
|
||||
|
|
Loading…
Reference in New Issue