Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/meteor/server/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type { IVideoConfService } from './types/IVideoConfService';
import type { ISAUMonitorService } from './types/ISAUMonitorService';
import type { IDeviceManagementService } from './types/IDeviceManagementService';
import { FibersContextStore } from './lib/ContextStore';
import type { IUploadService } from './types/IUploadService';

// TODO think in a way to not have to pass the service name to proxify here as well
export const Authorization = proxifyWithWait<IAuthorization>('authorization');
Expand All @@ -40,7 +41,7 @@ export const LDAP = proxifyWithWait<ILDAPService>('ldap');
export const SAUMonitor = proxifyWithWait<ISAUMonitorService>('sau-monitor');
export const DeviceManagement = proxifyWithWait<IDeviceManagementService>('device-management');
export const VideoConf = proxifyWithWait<IVideoConfService>('video-conference');

export const Upload = proxifyWithWait<IUploadService>('upload');
// Calls without wait. Means that the service is optional and the result may be an error
// of service/method not available
export const EnterpriseSettings = proxify<IEnterpriseSettings>('ee-settings');
Expand Down
27 changes: 27 additions & 0 deletions apps/meteor/server/sdk/types/IUploadService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { IUploadDetails } from '@rocket.chat/apps-engine/definition/uploads/IUploadDetails';
import type { IMessage, IUpload } from '@rocket.chat/core-typings';

export interface IUploadFileParams {
userId: string;
buffer: Buffer;
details: Partial<IUploadDetails>;
}
export interface ISendFileMessageParams {
roomId: string;
userId: string;
file: IUpload;
message?: IMessage;
}

export interface ISendFileLivechatMessageParams {
roomId: string;
visitorToken: string;
file: IUpload;
message?: IMessage;
}

export interface IUploadService {
uploadFile(params: IUploadFileParams): Promise<IUpload>;
sendFileMessage(params: ISendFileMessageParams): Promise<IMessage | undefined>;
sendFileLivechatMessage(params: ISendFileLivechatMessageParams): Promise<IMessage | undefined>;
}
2 changes: 2 additions & 0 deletions apps/meteor/server/services/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { isRunningMs } from '../lib/isRunningMs';
import { PushService } from './push/service';
import { DeviceManagementService } from './device-management/service';
import { FederationService } from './federation/service';
import { UploadService } from './upload/service';

const { db } = MongoInternals.defaultRemoteCollectionDriver().mongo;

Expand All @@ -43,6 +44,7 @@ api.registerService(new PushService());
api.registerService(new DeviceManagementService());
api.registerService(new VideoConfService());
api.registerService(new FederationService());
api.registerService(new UploadService());

// if the process is running in micro services mode we don't need to register services that will run separately
if (!isRunningMs()) {
Expand Down
36 changes: 36 additions & 0 deletions apps/meteor/server/services/upload/service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { IMessage, IUpload } from '@rocket.chat/core-typings';
import { Meteor } from 'meteor/meteor';

import { ServiceClassInternal } from '../../sdk/types/ServiceClass';
import type {
ISendFileLivechatMessageParams,
ISendFileMessageParams,
IUploadFileParams,
IUploadService,
} from '../../sdk/types/IUploadService';
import { FileUpload } from '../../../app/file-upload/server';

export class UploadService extends ServiceClassInternal implements IUploadService {
protected name = 'upload';

async uploadFile({ buffer, details, userId }: IUploadFileParams): Promise<IUpload> {
let uploadedFile: IUpload = {} as IUpload;
Meteor.runAsUser(userId, () => {
const fileStore = FileUpload.getStore('Uploads');
uploadedFile = fileStore.insertSync(details, buffer);
});
return uploadedFile;
Comment thread
KevLehman marked this conversation as resolved.
Outdated
}

async sendFileMessage({ roomId, file, userId, message }: ISendFileMessageParams): Promise<IMessage | undefined> {
let msg;
Meteor.runAsUser(userId, () => {
msg = Meteor.call('sendFileMessage', roomId, null, file, message);
});
return msg;
Comment thread
KevLehman marked this conversation as resolved.
Outdated
}

async sendFileLivechatMessage({ roomId, visitorToken, file, message }: ISendFileLivechatMessageParams): Promise<IMessage> {
return Meteor.call('sendFileLivechatMessage', roomId, visitorToken, file, message);
}
Comment thread
KevLehman marked this conversation as resolved.
}