Skip to content

Commit

Permalink
fix: unit test + sanitize uploaded filename
Browse files Browse the repository at this point in the history
  • Loading branch information
marrouchi committed Oct 18, 2024
1 parent c5a55cb commit 0054e02
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
22 changes: 22 additions & 0 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"patch-package": "^8.0.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"sanitize-filename": "^1.6.3",
"slug": "^8.2.2",
"ts-migrate-mongoose": "^3.8.4",
"uuid": "^9.0.1"
Expand Down
2 changes: 0 additions & 2 deletions api/src/channel/lib/Handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import { ChannelSetting } from '../types';

import EventWrapper from './EventWrapper';

import EventWrapper from './EventWrapper';

@Injectable()
export default abstract class ChannelHandler<N extends string = string> {
private readonly name: N;
Expand Down
3 changes: 0 additions & 3 deletions api/src/chat/services/block.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ import { FileType } from '../schemas/types/attachment';
import { Context } from '../schemas/types/context';
import { PayloadType, StdOutgoingListMessage } from '../schemas/types/message';
import { SubscriberContext } from '../schemas/types/subscriberContext';
import { CategoryRepository } from './../repositories/category.repository';
import { BlockService } from './block.service';
import { CategoryService } from './category.service';

import { CategoryRepository } from './../repositories/category.repository';
import { BlockService } from './block.service';
Expand Down
7 changes: 4 additions & 3 deletions api/src/extensions/channels/offline/base-web-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Injectable } from '@nestjs/common';
import { EventEmitter2, OnEvent } from '@nestjs/event-emitter';
import { Request, Response } from 'express';
import multer, { diskStorage } from 'multer';
import sanitize from 'sanitize-filename';
import { Socket } from 'socket.io';
import { v4 as uuidv4 } from 'uuid';

Expand Down Expand Up @@ -684,9 +685,9 @@ export default class BaseWebChannelHandler<

// Store file as attachment
const dirPath = path.join(config.parameters.uploadDir);
const filename = `${req.session.offline.profile.id}_${+new Date()}_${
upload.name
}`;
const filename = sanitize(
`${req.session.offline.profile.id}_${+new Date()}_${upload.name}`,
);
if ('isSocket' in req && req.isSocket) {
// @TODO : test this
try {
Expand Down

0 comments on commit 0054e02

Please sign in to comment.