📝 OO connector technical documentation (#547)
This commit is contained in:
committed by
ericlinagora
parent
5e1ac7b010
commit
6534f23cc2
@@ -23,7 +23,17 @@ interface RequestEditorQuery {
|
|||||||
file_id: string;
|
file_id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* These routes are called by Twake Drive frontend. The user's browser opens ( +) `${config.plugin.edition_url}/` (`index`).
|
||||||
|
* The user is redirected from there to open directly the OnlyOffice edition server's web UI, with appropriate preview or not
|
||||||
|
* and rights checks.
|
||||||
|
*/
|
||||||
class IndexController {
|
class IndexController {
|
||||||
|
/**
|
||||||
|
* Opened by the user's browser, proxied through the Twake Drive backend. Checks access to the
|
||||||
|
* file with the backend, then redirects the user to the `editor` method but directly on this
|
||||||
|
* connector, not proxied by Twake Drive's backend anymore.
|
||||||
|
*/
|
||||||
public index = async (req: Request<{}, {}, {}, RequestQuery>, res: Response, next: NextFunction): Promise<void> => {
|
public index = async (req: Request<{}, {}, {}, RequestQuery>, res: Response, next: NextFunction): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { file_id, drive_file_id, company_id, preview, token } = req.query;
|
const { file_id, drive_file_id, company_id, preview, token } = req.query;
|
||||||
@@ -89,6 +99,9 @@ class IndexController {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders this connector's view to initialise the Docs API client side component.
|
||||||
|
*/
|
||||||
public editor = async (req: Request<{}, {}, {}, RequestEditorQuery>, res: Response, next: NextFunction): Promise<void> => {
|
public editor = async (req: Request<{}, {}, {}, RequestEditorQuery>, res: Response, next: NextFunction): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { office_token } = req.query;
|
const { office_token } = req.query;
|
||||||
|
|||||||
@@ -21,7 +21,16 @@ interface SaveRequestBody {
|
|||||||
users: string[];
|
users: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** These expose a OnlyOffice document storage service methods, called by the OnlyOffice document editing service
|
||||||
|
* to load and save files
|
||||||
|
*/
|
||||||
class OnlyOfficeController {
|
class OnlyOfficeController {
|
||||||
|
/**
|
||||||
|
* Get a file from Twake Drive backend, and proxy it back the previewer/editor (via the document editing service).
|
||||||
|
*
|
||||||
|
* Parameters are standard Express middleware.
|
||||||
|
* @see https://api.onlyoffice.com/editors/open
|
||||||
|
*/
|
||||||
public read = async (req: Request<{}, {}, {}, RequestQuery>, res: Response, next: NextFunction): Promise<void> => {
|
public read = async (req: Request<{}, {}, {}, RequestQuery>, res: Response, next: NextFunction): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { token } = req.query;
|
const { token } = req.query;
|
||||||
@@ -55,6 +64,13 @@ class OnlyOfficeController {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Receive a file from OnlyOffice document editing service and save it into Twake Drive backend
|
||||||
|
*
|
||||||
|
* Parameters are standard Express middleware.
|
||||||
|
* @see https://api.onlyoffice.com/editors/save
|
||||||
|
* @see https://api.onlyoffice.com/editors/callback
|
||||||
|
*/
|
||||||
public save = async (req: Request<{}, {}, SaveRequestBody, RequestQuery>, res: Response, next: NextFunction): Promise<void> => {
|
public save = async (req: Request<{}, {}, SaveRequestBody, RequestQuery>, res: Response, next: NextFunction): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { url, key } = req.body;
|
const { url, key } = req.body;
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import {
|
|||||||
import axios, { Axios, AxiosRequestConfig, AxiosResponse } from 'axios';
|
import axios, { Axios, AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||||
import { CREDENTIALS_ENDPOINT, CREDENTIALS_ID, CREDENTIALS_SECRET, ONLY_OFFICE_SERVER } from '@config';
|
import { CREDENTIALS_ENDPOINT, CREDENTIALS_ID, CREDENTIALS_SECRET, ONLY_OFFICE_SERVER } from '@config';
|
||||||
import loggerService from './logger.service';
|
import loggerService from './logger.service';
|
||||||
|
|
||||||
|
/** Client for the Twake Drive backend API on behalf of the plugin (or provided token in parameters) */
|
||||||
class ApiService implements IApiService {
|
class ApiService implements IApiService {
|
||||||
private axios: Axios;
|
private axios: Axios;
|
||||||
private initialized: Promise<string>;
|
private initialized: Promise<string>;
|
||||||
@@ -20,7 +22,7 @@ class ApiService implements IApiService {
|
|||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
this.initialized = this.refreshToken();
|
this.initialized = this.refreshToken();
|
||||||
loggerService.info('Refreshing token 🪙');
|
loggerService.info('Refreshing token 🪙');
|
||||||
}, 1000 * 60); //Every 10 minutes
|
}, 1000 * 60); //TODO: should be Every 10 minutes
|
||||||
}
|
}
|
||||||
|
|
||||||
public get = async <T>(params: IApiServiceRequestParams<T>): Promise<T> => {
|
public get = async <T>(params: IApiServiceRequestParams<T>): Promise<T> => {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { DriveFileType, IDriveService } from '@/interfaces/drive.interface';
|
|||||||
import apiService from './api.service';
|
import apiService from './api.service';
|
||||||
import loggerService from './logger.service';
|
import loggerService from './logger.service';
|
||||||
|
|
||||||
|
/** Client for the Twake Drive backend API dealing with `DriveItem`s */
|
||||||
class DriveService implements IDriveService {
|
class DriveService implements IDriveService {
|
||||||
public get = async (params: { company_id: string; drive_file_id: string; user_token?: string }): Promise<DriveFileType> => {
|
public get = async (params: { company_id: string; drive_file_id: string; user_token?: string }): Promise<DriveFileType> => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user