Dwayne Harris 5 years ago
parent
commit
776073650c
  1. 5
      src/lib/utils.ts
  2. 10
      src/plugins/api/uploads.ts
  3. 14
      src/plugins/api/users.ts

5
src/lib/utils.ts

@ -8,9 +8,10 @@ export function trimContent(content?: string, length: number = 128): string {
return content.slice(0, length).trim()
}
export const createPostId = () => 'p' + v1().replace(/-/g, '')
export const createId = () => v1().replace(/-/g, '')
export const createPostId = () => 'p' + createId()
export const createInvitationCode = () => generateString(8)
export const createInstallationId = () => 'i' + v1().replace(/-/g, '')
export const createInstallationId = () => 'i' + createId()
export function wait(ms: number = 5000): Promise<void> {
return new Promise(resolve => {

10
src/plugins/api/uploads.ts

@ -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(),
}
})
}

14
src/plugins/api/users.ts

@ -83,6 +83,8 @@ function updateRoute(server: FastifyInstance<Server, IncomingMessage, ServerResp
about?: string
requiresApproval?: boolean
privacy?: UserPrivacyType
imageUrl?: string
coverImageUrl?: string
}
const options: RouteShorthandOptions = {
@ -100,6 +102,8 @@ function updateRoute(server: FastifyInstance<Server, IncomingMessage, ServerResp
type: 'string',
enum: ['public', 'group', 'subscribers', 'private'],
},
imageUrl: { type: 'string' },
coverImageUrl: { type: 'string' },
},
},
response: {
@ -136,6 +140,16 @@ function updateRoute(server: FastifyInstance<Server, IncomingMessage, ServerResp
viewer.privacy = request.body.privacy
}
if (request.body.imageUrl) {
const imageUrl = request.body.imageUrl.trim()
if (imageUrl !== '') viewer.imageUrl = imageUrl
}
if (request.body.coverImageUrl) {
const coverImageUrl = request.body.coverImageUrl.trim()
if (coverImageUrl !== '') viewer.coverImageUrl = coverImageUrl
}
await viewerItem.replace<User>(viewer)
return viewer
})

Loading…
Cancel
Save