|
|
@ -11,7 +11,7 @@ import { |
|
|
|
import { Server, IncomingMessage, ServerResponse } from 'http' |
|
|
|
import moment from 'moment' |
|
|
|
import { SharedKeyCredential, ContainerSASPermissions, generateBlobSASQueryParameters } from '@azure/storage-blob' |
|
|
|
|
|
|
|
import { createId } from '../../lib/utils' |
|
|
|
import { PluginOptions } from '../../types' |
|
|
|
|
|
|
|
function getSASRoute(server: FastifyInstance<Server, IncomingMessage, ServerResponse>) { |
|
|
@ -22,22 +22,24 @@ function getSASRoute(server: FastifyInstance<Server, IncomingMessage, ServerResp |
|
|
|
type: 'object', |
|
|
|
properties: { |
|
|
|
sas: { type: 'string' }, |
|
|
|
id: { type: 'string' }, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
server.post<DefaultQuery, DefaultParams, DefaultHeaders, DefaultBody>('/api/sas', options, async () => { |
|
|
|
server.get<DefaultQuery, DefaultParams, DefaultHeaders, DefaultBody>('/api/sas', options, async () => { |
|
|
|
const sharedKeyCredential = new SharedKeyCredential(process.env.BLOB_STORAGE_ACCOUNT!, process.env.BLOB_STORAGE_ACCOUNT_KEY!) |
|
|
|
|
|
|
|
return { |
|
|
|
sas: generateBlobSASQueryParameters({ |
|
|
|
containerName: process.env.BLOB_STORAGE_CONTAINER!, |
|
|
|
permissions: ContainerSASPermissions.parse('ar').toString(), |
|
|
|
permissions: ContainerSASPermissions.parse('arcw').toString(), |
|
|
|
startTime: new Date(), |
|
|
|
expiryTime: moment().add(5, 'm').toDate(), |
|
|
|
}, sharedKeyCredential).toString() |
|
|
|
}, sharedKeyCredential).toString(), |
|
|
|
id: createId(), |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|