♻️ OOConnector: refactor a bit of string manipulation
This commit is contained in:
committed by
ericlinagora
parent
6534f23cc2
commit
ca267df7ac
@@ -7,6 +7,7 @@ import {
|
||||
import axios, { Axios, AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||
import { CREDENTIALS_ENDPOINT, CREDENTIALS_ID, CREDENTIALS_SECRET, ONLY_OFFICE_SERVER } from '@config';
|
||||
import loggerService from './logger.service';
|
||||
import * as Utils from '@/utils';
|
||||
|
||||
/** Client for the Twake Drive backend API on behalf of the plugin (or provided token in parameters) */
|
||||
class ApiService implements IApiService {
|
||||
@@ -73,7 +74,7 @@ class ApiService implements IApiService {
|
||||
private refreshToken = async (): Promise<string> => {
|
||||
try {
|
||||
const response = await axios.post<IApiServiceApplicationTokenRequestParams, { data: IApiServiceApplicationTokenResponse }>(
|
||||
`${CREDENTIALS_ENDPOINT.replace(/\/$/, '')}/api/console/v1/login`,
|
||||
Utils.joinURL([CREDENTIALS_ENDPOINT, '/api/console/v1/login']),
|
||||
{
|
||||
id: CREDENTIALS_ID,
|
||||
secret: CREDENTIALS_SECRET,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { EditConfigInitResult, IEditorService, ModeParametersType } from '@/interfaces/editor.interface';
|
||||
import { UserType } from '@/interfaces/user.interface';
|
||||
import { ONLY_OFFICE_SERVER } from '@config';
|
||||
import * as Utils from '@/utils';
|
||||
|
||||
class EditorService implements IEditorService {
|
||||
public init = async (
|
||||
@@ -12,12 +13,14 @@ class EditorService implements IEditorService {
|
||||
file_id: string,
|
||||
): Promise<EditConfigInitResult> => {
|
||||
const { color, mode: fileMode } = this.getFileMode(file_name);
|
||||
let [, extension] = Utils.splitFilename(file_name);
|
||||
|
||||
extension = extension.toLocaleLowerCase();
|
||||
return {
|
||||
color,
|
||||
file_id,
|
||||
file_version_id,
|
||||
file_type: file_name.split('.').pop(),
|
||||
file_type: extension,
|
||||
filename: file_name,
|
||||
language: user.preferences.locale || 'en',
|
||||
mode: fileMode,
|
||||
@@ -32,7 +35,8 @@ class EditorService implements IEditorService {
|
||||
};
|
||||
|
||||
private getFileMode = (filename: string): ModeParametersType => {
|
||||
const extension = filename.split('.').pop();
|
||||
let [, extension] = Utils.splitFilename(filename);
|
||||
extension = extension.toLocaleLowerCase();
|
||||
|
||||
if (
|
||||
[
|
||||
|
||||
@@ -3,8 +3,10 @@ import apiService from './api.service';
|
||||
import loggerService from './logger.service';
|
||||
import { Stream } from 'stream';
|
||||
import FormData from 'form-data';
|
||||
import * as Utils from '@/utils';
|
||||
|
||||
class FileService implements IFileService {
|
||||
|
||||
public get = async (params: FileRequestParams): Promise<FileType> => {
|
||||
try {
|
||||
const { company_id, file_id } = params;
|
||||
@@ -55,7 +57,7 @@ class FileService implements IFileService {
|
||||
|
||||
const form = new FormData();
|
||||
|
||||
const nameSplit = (originalFile.metadata.name || '').split('.');
|
||||
const nameSplit = Utils.splitFilename(originalFile.metadata.name || '');
|
||||
const filename =
|
||||
nameSplit[0].replace(/-[0-9]{8}-[0-9]{4}$/, '') +
|
||||
(!create_new ? '.' : `-${new Date().toISOString().split('.')[0].split(':').slice(0, 2).join('').replace(/-/gm, '').split('T').join('-')}.`) +
|
||||
|
||||
Reference in New Issue
Block a user