mirror of
https://github.com/turt2live/matrix-dimension.git
synced 2024-10-01 01:05:53 -04:00
599fb80112
The frontend is still broken and doesn't use these endpoints at all. A migration tool still needs to be written to pull in existing widget configurations.
54 lines
2.0 KiB
TypeScript
54 lines
2.0 KiB
TypeScript
import { GET, Path, QueryParam } from "typescript-rest";
|
|
import * as Promise from "bluebird";
|
|
import { ScalarService } from "../scalar/ScalarService";
|
|
import { DimensionStore } from "../../db/DimensionStore";
|
|
import { DimensionAdminService } from "./DimensionAdminService";
|
|
import { Widget } from "../../integrations/Widget";
|
|
import { MemoryCache } from "../../MemoryCache";
|
|
|
|
interface IntegrationsResponse {
|
|
widgets: Widget[],
|
|
}
|
|
|
|
@Path("/api/v1/dimension/integrations")
|
|
export class DimensionIntegrationsService {
|
|
|
|
private static integrationCache = new MemoryCache();
|
|
|
|
public static clearIntegrationCache() {
|
|
DimensionIntegrationsService.integrationCache.clear();
|
|
}
|
|
|
|
@GET
|
|
@Path("enabled")
|
|
public getEnabledIntegrations(@QueryParam("scalar_token") scalarToken: string): Promise<IntegrationsResponse> {
|
|
return ScalarService.getTokenOwner(scalarToken).then(_userId => {
|
|
return this.getIntegrations(true);
|
|
}, ScalarService.invalidTokenErrorHandler);
|
|
}
|
|
|
|
@GET
|
|
@Path("all")
|
|
public getAllIntegrations(@QueryParam("scalar_token") scalarToken: string): Promise<IntegrationsResponse> {
|
|
return DimensionAdminService.validateAndGetAdminTokenOwner(scalarToken).then(_userId => {
|
|
return this.getIntegrations(null);
|
|
});
|
|
}
|
|
|
|
private getIntegrations(isEnabledCheck?: boolean): Promise<IntegrationsResponse> {
|
|
const cachedResponse = DimensionIntegrationsService.integrationCache.get("integrations_" + isEnabledCheck);
|
|
if (cachedResponse) {
|
|
return cachedResponse;
|
|
}
|
|
const response = <IntegrationsResponse>{
|
|
widgets: [],
|
|
};
|
|
return Promise.resolve()
|
|
.then(() => DimensionStore.getWidgets(isEnabledCheck))
|
|
.then(widgets => response.widgets = widgets)
|
|
|
|
// Cache and return response
|
|
.then(() => DimensionIntegrationsService.integrationCache.put("integrations_" + isEnabledCheck, response))
|
|
.then(() => response);
|
|
}
|
|
} |