|
|
@ -119,7 +119,7 @@ function appsRoute(server: FastifyInstance<Server, IncomingMessage, ServerRespon |
|
|
|
a.iconImageUrl, |
|
|
|
a.about, |
|
|
|
a.websiteUrl, |
|
|
|
a.companyName |
|
|
|
a.companyName, |
|
|
|
a.rating, |
|
|
|
a.users, |
|
|
|
a.created |
|
|
@ -500,7 +500,7 @@ function getRoute(server: FastifyInstance<Server, IncomingMessage, ServerRespons |
|
|
|
} |
|
|
|
|
|
|
|
if (request.viewer && request.viewer.id === app.userId) { |
|
|
|
attributes = [...attributes, 'publicKey', 'privateKey', 'revisions'] |
|
|
|
attributes = [...attributes, 'publicKey', 'privateKey', 'revisions', 'composerUrl', 'rendererUrl'] |
|
|
|
} |
|
|
|
|
|
|
|
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 => { |
|
|
|
availabilityRoute(server) |
|
|
|
appsRoute(server) |
|
|
@ -697,6 +792,8 @@ const plugin: Plugin<Server, IncomingMessage, ServerResponse, PluginOptions> = a |
|
|
|
installRoute(server) |
|
|
|
uninstallRoute(server) |
|
|
|
installationsRoute(server) |
|
|
|
activateRoute(server) |
|
|
|
setPreinstallRoute(server) |
|
|
|
} |
|
|
|
|
|
|
|
export default plugin |