Dwayne Harris 5 years ago
parent
commit
eb3f16d9bc
  1. 101
      src/plugins/api/apps.ts
  2. 14
      src/plugins/api/groups.ts
  3. 2
      src/plugins/api/index.ts
  4. 2
      src/schemas.ts

101
src/plugins/api/apps.ts

@ -119,7 +119,7 @@ function appsRoute(server: FastifyInstance<Server, IncomingMessage, ServerRespon
a.iconImageUrl, a.iconImageUrl,
a.about, a.about,
a.websiteUrl, a.websiteUrl,
a.companyName
a.companyName,
a.rating, a.rating,
a.users, a.users,
a.created a.created
@ -500,7 +500,7 @@ function getRoute(server: FastifyInstance<Server, IncomingMessage, ServerRespons
} }
if (request.viewer && request.viewer.id === app.userId) { if (request.viewer && request.viewer.id === app.userId) {
attributes = [...attributes, 'publicKey', 'privateKey', 'revisions']
attributes = [...attributes, 'publicKey', 'privateKey', 'revisions', 'composerUrl', 'rendererUrl']
} }
return { return {
@ -687,6 +687,101 @@ function installationsRoute(server: FastifyInstance<Server, IncomingMessage, Ser
}) })
} }
function activateRoute(server: FastifyInstance<Server, IncomingMessage, ServerResponse>) {
interface Headers {
adminkey: string
}
interface Params {
id: string
}
const options: RouteShorthandOptions = {
schema: {
headers: {
type: 'object',
required: ['adminkey'],
properties: {
'adminkey': { type: 'string' },
},
},
params: {
type: 'object',
properties: {
id: { type: 'string' },
},
},
response: {
400: errorSchema,
}
},
}
server.post<DefaultQuery, Params, Headers, DefaultBody>('/api/app/:id/activate', options, async (request, reply) => {
if (!server.database) return serverError(reply)
if (request.headers.adminkey !== process.env.ADMIN_KEY) return serverError(reply)
const container = containerFor(server.database.client, 'Apps')
const item = container.item(request.params.id, APP_PARTITION_KEY)
const { resource: app } = await item.read<App>()
await item.replace<App>({
...app,
active: true,
})
reply.code(204)
})
}
function setPreinstallRoute(server: FastifyInstance<Server, IncomingMessage, ServerResponse>) {
interface Headers {
adminkey: string
}
interface Params {
id: string
}
const options: RouteShorthandOptions = {
schema: {
headers: {
type: 'object',
required: ['adminkey'],
properties: {
adminkey: { type: 'string' },
},
},
params: {
type: 'object',
properties: {
id: { type: 'string' },
},
},
response: {
400: errorSchema,
}
},
}
server.post<DefaultQuery, Params, Headers, DefaultBody>('/api/app/:id/preinstall', options, async (request, reply) => {
if (!server.database) return serverError(reply)
if (request.headers.adminkey !== process.env.ADMIN_KEY) return serverError(reply)
const container = containerFor(server.database.client, 'Apps')
const item = container.item(request.params.id, APP_PARTITION_KEY)
const { resource: app } = await item.read<App>()
await item.replace<App>({
...app,
preinstall: true,
active: true,
})
reply.code(204)
})
}
const plugin: Plugin<Server, IncomingMessage, ServerResponse, PluginOptions> = async server => { const plugin: Plugin<Server, IncomingMessage, ServerResponse, PluginOptions> = async server => {
availabilityRoute(server) availabilityRoute(server)
appsRoute(server) appsRoute(server)
@ -697,6 +792,8 @@ const plugin: Plugin<Server, IncomingMessage, ServerResponse, PluginOptions> = a
installRoute(server) installRoute(server)
uninstallRoute(server) uninstallRoute(server)
installationsRoute(server) installationsRoute(server)
activateRoute(server)
setPreinstallRoute(server)
} }
export default plugin export default plugin

14
src/plugins/api/groups.ts

@ -462,12 +462,23 @@ function unblockRoute(server: FastifyInstance<Server, IncomingMessage, ServerRes
} }
function activateRoute(server: FastifyInstance<Server, IncomingMessage, ServerResponse>) { function activateRoute(server: FastifyInstance<Server, IncomingMessage, ServerResponse>) {
interface Headers {
adminkey: string
}
interface Params { interface Params {
id: string id: string
} }
const options: RouteShorthandOptions = { const options: RouteShorthandOptions = {
schema: { schema: {
headers: {
type: 'object',
required: ['adminkey'],
properties: {
adminkey: { type: 'string' },
},
},
params: { params: {
type: 'object', type: 'object',
properties: { properties: {
@ -477,8 +488,9 @@ function activateRoute(server: FastifyInstance<Server, IncomingMessage, ServerRe
}, },
} }
server.post<DefaultQuery, Params, DefaultHeaders, DefaultBody>('/api/group/:id/activate', options, async (request, reply) => {
server.post<DefaultQuery, Params, Headers, DefaultBody>('/api/group/:id/activate', options, async (request, reply) => {
if (!server.database) return serverError(reply) if (!server.database) return serverError(reply)
if (request.headers.adminkey !== process.env.ADMIN_KEY) return serverError(reply)
const container = containerFor(server.database.client, 'Groups') const container = containerFor(server.database.client, 'Groups')
const groupItem = container.item(request.params.id, request.params.id) const groupItem = container.item(request.params.id, request.params.id)

2
src/plugins/api/index.ts

@ -62,6 +62,8 @@ const plugin: Plugin<Server, IncomingMessage, ServerResponse, PluginOptions> = a
}) })
server.setErrorHandler(function(error, request, reply) { server.setErrorHandler(function(error, request, reply) {
request.log.error(error)
const response: HttpError = { const response: HttpError = {
message: error.message, message: error.message,
} }

2
src/schemas.ts

@ -67,6 +67,8 @@ export const appSchema: JSONSchema = {
publicKey: { type: 'string' }, publicKey: { type: 'string' },
privateKey: { type: 'string' }, privateKey: { type: 'string' },
composerUrl: { type: 'string' },
rendererUrl: { type: 'string' },
revisions: { revisions: {
type: 'array', type: 'array',
items: { items: {

Loading…
Cancel
Save