|
|
@@ -1,6 +1,7 @@
|
|
|
-import { createReadStream, ReadStream } from 'fs';
|
|
|
+import type { ReadStream } from 'fs';
|
|
|
+import { createReadStream } from 'fs';
|
|
|
import { basename } from 'path';
|
|
|
-import { Readable } from 'stream';
|
|
|
+import type { Readable } from 'stream';
|
|
|
|
|
|
// eslint-disable-next-line no-restricted-imports
|
|
|
import rawAxios, { type AxiosRequestConfig } from 'axios';
|
|
|
@@ -201,10 +202,10 @@ interface Receiver {
|
|
|
updateFileUploadConfigs(fileUploadConfigs: FileUploadConfigs): Promise<void>
|
|
|
/**
|
|
|
* Upload attachment file
|
|
|
- * @param {Readable} content Pushed attachment data from source GROWI
|
|
|
+ * @param {ReadStream} content Pushed attachment data from source GROWI
|
|
|
* @param {any} attachmentMap Map-ped Attachment instance
|
|
|
*/
|
|
|
- receiveAttachment(content: Readable, attachmentMap: any): Promise<void>
|
|
|
+ receiveAttachment(content: ReadStream, attachmentMap: any): Promise<void>
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -325,7 +326,7 @@ export class G2GTransferPusherService implements Pusher {
|
|
|
public async transferAttachments(tk: TransferKey): Promise<void> {
|
|
|
const BATCH_SIZE = 100;
|
|
|
const { fileUploadService, socketIoService } = this.crowi;
|
|
|
- const socket = socketIoService.getAdminSocket();
|
|
|
+ const socket = socketIoService?.getAdminSocket();
|
|
|
const filesFromSrcGROWI = await this.listFilesInStorage(tk);
|
|
|
|
|
|
/**
|
|
|
@@ -390,7 +391,7 @@ export class G2GTransferPusherService implements Pusher {
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.warn(`Error occured when getting Attachment(ID=${attachment.id}), skipping: `, err);
|
|
|
- socket.emit('admin:g2gError', {
|
|
|
+ socket?.emit('admin:g2gError', {
|
|
|
message: `Error occured when uploading Attachment(ID=${attachment.id})`,
|
|
|
key: `Error occured when uploading Attachment(ID=${attachment.id})`,
|
|
|
// TODO: emit error with params
|
|
|
@@ -404,7 +405,7 @@ export class G2GTransferPusherService implements Pusher {
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(`Error occured when uploading attachment(ID=${attachment.id})`, err);
|
|
|
- socket.emit('admin:g2gError', {
|
|
|
+ socket?.emit('admin:g2gError', {
|
|
|
message: `Error occured when uploading Attachment(ID=${attachment.id})`,
|
|
|
key: `Error occured when uploading Attachment(ID=${attachment.id})`,
|
|
|
// TODO: emit error with params
|
|
|
@@ -417,9 +418,9 @@ export class G2GTransferPusherService implements Pusher {
|
|
|
|
|
|
// eslint-disable-next-line max-len
|
|
|
public async startTransfer(tk: TransferKey, user: any, collections: string[], optionsMap: any, destGROWIInfo: IDataGROWIInfo): Promise<void> {
|
|
|
- const socket = this.crowi.socketIoService.getAdminSocket();
|
|
|
+ const socket = this.crowi.socketIoService?.getAdminSocket();
|
|
|
|
|
|
- socket.emit('admin:g2gProgress', {
|
|
|
+ socket?.emit('admin:g2gProgress', {
|
|
|
mongo: G2G_PROGRESS_STATUS.IN_PROGRESS,
|
|
|
attachments: G2G_PROGRESS_STATUS.PENDING,
|
|
|
});
|
|
|
@@ -439,11 +440,11 @@ export class G2GTransferPusherService implements Pusher {
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
- socket.emit('admin:g2gProgress', {
|
|
|
+ socket?.emit('admin:g2gProgress', {
|
|
|
mongo: G2G_PROGRESS_STATUS.ERROR,
|
|
|
attachments: G2G_PROGRESS_STATUS.PENDING,
|
|
|
});
|
|
|
- socket.emit('admin:g2gError', { message: 'Failed to generate GROWI archive file', key: 'admin:g2g:error_generate_growi_archive' });
|
|
|
+ socket?.emit('admin:g2gError', { message: 'Failed to generate GROWI archive file', key: 'admin:g2g:error_generate_growi_archive' });
|
|
|
throw err;
|
|
|
}
|
|
|
|
|
|
@@ -462,15 +463,15 @@ export class G2GTransferPusherService implements Pusher {
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
- socket.emit('admin:g2gProgress', {
|
|
|
+ socket?.emit('admin:g2gProgress', {
|
|
|
mongo: G2G_PROGRESS_STATUS.ERROR,
|
|
|
attachments: G2G_PROGRESS_STATUS.PENDING,
|
|
|
});
|
|
|
- socket.emit('admin:g2gError', { message: 'Failed to send GROWI archive file to the destination GROWI', key: 'admin:g2g:error_send_growi_archive' });
|
|
|
+ socket?.emit('admin:g2gError', { message: 'Failed to send GROWI archive file to the destination GROWI', key: 'admin:g2g:error_send_growi_archive' });
|
|
|
throw err;
|
|
|
}
|
|
|
|
|
|
- socket.emit('admin:g2gProgress', {
|
|
|
+ socket?.emit('admin:g2gProgress', {
|
|
|
mongo: G2G_PROGRESS_STATUS.COMPLETED,
|
|
|
attachments: G2G_PROGRESS_STATUS.IN_PROGRESS,
|
|
|
});
|
|
|
@@ -480,15 +481,15 @@ export class G2GTransferPusherService implements Pusher {
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
- socket.emit('admin:g2gProgress', {
|
|
|
+ socket?.emit('admin:g2gProgress', {
|
|
|
mongo: G2G_PROGRESS_STATUS.COMPLETED,
|
|
|
attachments: G2G_PROGRESS_STATUS.ERROR,
|
|
|
});
|
|
|
- socket.emit('admin:g2gError', { message: 'Failed to transfer attachments', key: 'admin:g2g:error_upload_attachment' });
|
|
|
+ socket?.emit('admin:g2gError', { message: 'Failed to transfer attachments', key: 'admin:g2g:error_upload_attachment' });
|
|
|
throw err;
|
|
|
}
|
|
|
|
|
|
- socket.emit('admin:g2gProgress', {
|
|
|
+ socket?.emit('admin:g2gProgress', {
|
|
|
mongo: G2G_PROGRESS_STATUS.COMPLETED,
|
|
|
attachments: G2G_PROGRESS_STATUS.COMPLETED,
|
|
|
});
|
|
|
@@ -516,9 +517,9 @@ export class G2GTransferPusherService implements Pusher {
|
|
|
*/
|
|
|
export class G2GTransferReceiverService implements Receiver {
|
|
|
|
|
|
- crowi: any;
|
|
|
+ crowi: Crowi;
|
|
|
|
|
|
- constructor(crowi: any) {
|
|
|
+ constructor(crowi: Crowi) {
|
|
|
this.crowi = crowi;
|
|
|
}
|
|
|
|
|
|
@@ -539,7 +540,7 @@ export class G2GTransferReceiverService implements Receiver {
|
|
|
}
|
|
|
|
|
|
public async answerGROWIInfo(): Promise<IDataGROWIInfo> {
|
|
|
- const { version, configManager, fileUploadService } = this.crowi;
|
|
|
+ const { version, fileUploadService } = this.crowi;
|
|
|
const userUpperLimit = configManager.getConfig('crowi', 'security:userUpperLimit');
|
|
|
const fileUploadDisabled = configManager.getConfig('crowi', 'app:fileUploadDisabled');
|
|
|
const fileUploadTotalLimit = fileUploadService.getFileUploadTotalLimit();
|
|
|
@@ -636,7 +637,7 @@ export class G2GTransferReceiverService implements Receiver {
|
|
|
importSettingsMap: { [key: string]: ImportSettings; },
|
|
|
sourceGROWIUploadConfigs: FileUploadConfigs,
|
|
|
): Promise<void> {
|
|
|
- const { configManager, importService, appService } = this.crowi;
|
|
|
+ const { importService, appService } = this.crowi;
|
|
|
/** whether to keep current file upload configs */
|
|
|
const shouldKeepUploadConfigs = configManager.getConfig('crowi', 'app:fileUploadType') !== 'none';
|
|
|
|
|
|
@@ -664,7 +665,6 @@ export class G2GTransferReceiverService implements Receiver {
|
|
|
}
|
|
|
|
|
|
public async getFileUploadConfigs(): Promise<FileUploadConfigs> {
|
|
|
- const { configManager } = this.crowi;
|
|
|
const fileUploadConfigs = Object.fromEntries(UPLOAD_CONFIG_KEYS.map((key) => {
|
|
|
return [key, configManager.getConfigFromDB('crowi', key)];
|
|
|
})) as FileUploadConfigs;
|
|
|
@@ -673,7 +673,7 @@ export class G2GTransferReceiverService implements Receiver {
|
|
|
}
|
|
|
|
|
|
public async updateFileUploadConfigs(fileUploadConfigs: FileUploadConfigs): Promise<void> {
|
|
|
- const { appService, configManager } = this.crowi;
|
|
|
+ const { appService } = this.crowi;
|
|
|
|
|
|
await configManager.removeConfigsInTheSameNamespace('crowi', Object.keys(fileUploadConfigs));
|
|
|
await configManager.updateConfigsInTheSameNamespace('crowi', fileUploadConfigs);
|
|
|
@@ -681,7 +681,7 @@ export class G2GTransferReceiverService implements Receiver {
|
|
|
await appService.setupAfterInstall();
|
|
|
}
|
|
|
|
|
|
- public async receiveAttachment(content: Readable, attachmentMap): Promise<void> {
|
|
|
+ public async receiveAttachment(content: ReadStream, attachmentMap): Promise<void> {
|
|
|
const { fileUploadService } = this.crowi;
|
|
|
return fileUploadService.uploadAttachment(content, attachmentMap);
|
|
|
}
|