✨ oo-connector: OO forgotten files batch processor, and testing, but WIP (#525)
This commit is contained in:
@@ -5,17 +5,10 @@ import {
|
||||
IApiServiceApplicationTokenResponse,
|
||||
} from '@/interfaces/api.interface';
|
||||
import axios, { Axios, AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||
import {
|
||||
CREDENTIALS_ENDPOINT,
|
||||
CREDENTIALS_ID,
|
||||
CREDENTIALS_SECRET,
|
||||
twakeDriveTokenRefrehPeriodMS,
|
||||
onlyOfficeForgottenFilesCheckPeriodMS,
|
||||
} from '@config';
|
||||
import { CREDENTIALS_ENDPOINT, CREDENTIALS_ID, CREDENTIALS_SECRET, twakeDriveTokenRefrehPeriodMS } from '@config';
|
||||
import logger from '../lib/logger';
|
||||
import * as Utils from '@/utils';
|
||||
import { PolledThingieValue } from '@/lib/polled-thingie-value';
|
||||
import onlyofficeService from './onlyoffice.service';
|
||||
|
||||
/**
|
||||
* Client for the Twake Drive backend API on behalf of the plugin (or provided token in parameters).
|
||||
@@ -23,15 +16,9 @@ import onlyofficeService from './onlyoffice.service';
|
||||
*/
|
||||
class ApiService implements IApiService {
|
||||
private readonly tokenPoller: PolledThingieValue<Axios>;
|
||||
private readonly forgottenFilesPoller: PolledThingieValue<number>;
|
||||
|
||||
constructor() {
|
||||
this.tokenPoller = new PolledThingieValue('Refresh Twake Drive token', async () => await this.refreshToken(), twakeDriveTokenRefrehPeriodMS);
|
||||
this.forgottenFilesPoller = new PolledThingieValue(
|
||||
'Process forgotten files in OO',
|
||||
async () => await this.processForgottenFiles(),
|
||||
onlyOfficeForgottenFilesCheckPeriodMS,
|
||||
);
|
||||
}
|
||||
|
||||
public async hasToken() {
|
||||
@@ -42,14 +29,6 @@ class ApiService implements IApiService {
|
||||
return this.tokenPoller.requireLatestValueWithTry('No Twake Drive app token.');
|
||||
}
|
||||
|
||||
private async processForgottenFiles() {
|
||||
if (!this.tokenPoller.hasValue()) return -1;
|
||||
return await onlyofficeService.processForgotten(async (/* key, url */) => {
|
||||
//TODO: when endpoint decided, call here. See if accept HTTP 202 for ex. to avoid deleting.
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
public get = async <T>(params: IApiServiceRequestParams<T>): Promise<T> => {
|
||||
const { url, token, responseType, headers } = params;
|
||||
|
||||
@@ -95,6 +74,7 @@ class ApiService implements IApiService {
|
||||
|
||||
const axiosWithToken = await this.requireAxios();
|
||||
|
||||
logger.info(`POST to Twake Drive ${url} - payload: ${payload}`);
|
||||
try {
|
||||
return await axiosWithToken.post(url, payload, {
|
||||
headers: {
|
||||
@@ -103,7 +83,7 @@ class ApiService implements IApiService {
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Failed to post to Twake drive: ', error.stack);
|
||||
logger.error('Failed to post to Twake Drive: ', { error });
|
||||
this.refreshToken();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user