@@ -0,0 +1,3 @@
|
||||
import { Initializable, TdriveServiceProvider } from "../../core/platform/framework/api";
|
||||
|
||||
export interface GeneralServiceAPI extends TdriveServiceProvider, Initializable {}
|
||||
@@ -0,0 +1,30 @@
|
||||
import WebServerAPI from "../../core/platform/services/webserver/provider";
|
||||
import { Consumes, Prefix, TdriveService } from "../../core/platform/framework";
|
||||
import { GeneralServiceAPI } from "./api";
|
||||
import web from "./web/index";
|
||||
import { ServerConfiguration } from "./types";
|
||||
|
||||
@Prefix("/internal/services/general/v1")
|
||||
@Consumes(["webserver"])
|
||||
export default class GeneralService extends TdriveService<GeneralServiceAPI> {
|
||||
version = "1";
|
||||
name = "general";
|
||||
service: GeneralServiceAPI;
|
||||
|
||||
api(): GeneralServiceAPI {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
public async doInit(): Promise<this> {
|
||||
const fastify = this.context.getProvider<WebServerAPI>("webserver").getServer();
|
||||
|
||||
const configuration = this.configuration.get<ServerConfiguration["configuration"]>();
|
||||
|
||||
fastify.register((instance, _opts, next) => {
|
||||
web(instance, { prefix: this.prefix, configuration: configuration });
|
||||
next();
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { Languages } from "./types";
|
||||
|
||||
export const languages: Languages = {
|
||||
default: "en",
|
||||
availables: ["en", "fr", "es", "vn", "ru"],
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
export type Languages = {
|
||||
default: string;
|
||||
availables: string[];
|
||||
};
|
||||
|
||||
export type ServerConfiguration = {
|
||||
status: "ready";
|
||||
version: {
|
||||
current: string;
|
||||
minimal: {
|
||||
web: string;
|
||||
mobile: string;
|
||||
};
|
||||
};
|
||||
configuration: {
|
||||
help_url: string | null;
|
||||
pricing_plan_url: string | null;
|
||||
app_download_url: string | null;
|
||||
app_grid: { logo: string; name: string; url: string }[];
|
||||
mobile: {
|
||||
mobile_redirect: string;
|
||||
mobile_appstore: string;
|
||||
mobile_googleplay: string;
|
||||
};
|
||||
accounts: {
|
||||
type: "remote" | "internal";
|
||||
remote: null | {
|
||||
authority: string;
|
||||
client_id: string;
|
||||
account_management_url: string;
|
||||
company_management_url: string;
|
||||
company_subscription_url: string;
|
||||
collaborators_management_url: string;
|
||||
};
|
||||
internal: null | {
|
||||
disable_account_creation: boolean;
|
||||
disable_email_verification: boolean;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
import { FastifyInstance, FastifyRegisterOptions } from "fastify";
|
||||
import { ServerConfiguration } from "../types";
|
||||
import routes from "./routes";
|
||||
|
||||
export default (
|
||||
fastify: FastifyInstance,
|
||||
options: FastifyRegisterOptions<{
|
||||
prefix: string;
|
||||
configuration: ServerConfiguration["configuration"];
|
||||
}>,
|
||||
): void => {
|
||||
fastify.log.debug("Configuring /internal/services/general/v1 routes");
|
||||
fastify.register(routes, options);
|
||||
};
|
||||
@@ -0,0 +1,70 @@
|
||||
import { FastifyInstance, FastifyPluginCallback } from "fastify";
|
||||
import _ from "lodash";
|
||||
import { languages } from "../languages";
|
||||
import { Languages, ServerConfiguration } from "../types";
|
||||
import version from "../../../version";
|
||||
|
||||
const routes: FastifyPluginCallback<{ configuration: ServerConfiguration["configuration"] }> = (
|
||||
fastify: FastifyInstance,
|
||||
options,
|
||||
next,
|
||||
) => {
|
||||
fastify.route({
|
||||
method: "GET",
|
||||
url: "/server",
|
||||
handler: async (): Promise<ServerConfiguration> => {
|
||||
const accounts = options.configuration.accounts;
|
||||
return {
|
||||
status: "ready",
|
||||
version: version,
|
||||
configuration: {
|
||||
..._.pick(
|
||||
options.configuration,
|
||||
"help_url",
|
||||
"pricing_plan_url",
|
||||
"mobile",
|
||||
"app_download_url",
|
||||
"app_grid",
|
||||
),
|
||||
accounts: {
|
||||
type: accounts.type,
|
||||
remote: _.pick(
|
||||
accounts.remote,
|
||||
"authority",
|
||||
"client_id",
|
||||
"account_management_url",
|
||||
"company_subscription_url",
|
||||
"company_management_url",
|
||||
"collaborators_management_url",
|
||||
),
|
||||
internal: _.pick(
|
||||
accounts.internal,
|
||||
"disable_account_creation",
|
||||
"disable_email_verification",
|
||||
),
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
fastify.route({
|
||||
method: "GET",
|
||||
url: "/locales",
|
||||
handler: async (): Promise<Languages> => {
|
||||
return languages;
|
||||
},
|
||||
});
|
||||
|
||||
fastify.route({
|
||||
method: "GET",
|
||||
url: "/locales/:language",
|
||||
handler: async (): Promise<any> => {
|
||||
return {};
|
||||
},
|
||||
});
|
||||
|
||||
next();
|
||||
};
|
||||
|
||||
export default routes;
|
||||
Reference in New Issue
Block a user