Skip to content

Commit

Permalink
[FIX] Showing thumbnails on files list (#23301)
Browse files Browse the repository at this point in the history
Co-authored-by: Carlos Rodrigues <51969060+carlosrodrigues94@users.noreply.github.com>
Co-authored-by: Diego Sampaio <8591547+sampaiodiego@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 12, 2022
1 parent 461a8e2 commit 3cf1c80
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 15 deletions.
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ API.v1.addRoute(

const ourQuery = Object.assign({}, query, { rid: findResult._id });

const { cursor, totalCount } = Uploads.findPaginated(ourQuery, {
const { cursor, totalCount } = Uploads.findPaginatedWithoutThumbs(ourQuery, {
sort: sort || { name: 1 },
skip: offset,
limit: count,
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ API.v1.addRoute(

const ourQuery = Object.assign({}, query, { rid: findResult.rid });

const { cursor, totalCount } = Uploads.findPaginated(ourQuery, {
const { cursor, totalCount } = Uploads.findPaginatedWithoutThumbs(ourQuery, {
sort: sort || { name: 1 },
skip: offset,
limit: count,
Expand Down
7 changes: 2 additions & 5 deletions apps/meteor/app/api/server/v1/im.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Docs: https://github.com/RocketChat/developer-docs/blob/master/reference/api/rest-api/endpoints/team-collaboration-endpoints/im-endpoints
*/
import type { IMessage, IRoom, ISubscription, IUpload } from '@rocket.chat/core-typings';
import type { IMessage, IRoom, ISubscription } from '@rocket.chat/core-typings';
import {
isDmDeleteProps,
isDmFileProps,
Expand All @@ -23,9 +23,6 @@ import { createDirectMessage } from '../../../../server/methods/createDirectMess
import { addUserToFileObj } from '../helpers/addUserToFileObj';
import { settings } from '../../../settings/server';

interface IImFilesObject extends IUpload {
userId: string;
}
// TODO: Refact or remove

type findDirectMessageRoomProps =
Expand Down Expand Up @@ -218,7 +215,7 @@ API.v1.addRoute(

const ourQuery = query ? { rid: room._id, ...query } : { rid: room._id };

const { cursor, totalCount } = Uploads.findPaginated<IImFilesObject>(ourQuery, {
const { cursor, totalCount } = Uploads.findPaginatedWithoutThumbs(ourQuery, {
sort: sort || { name: 1 },
skip: offset,
limit: count,
Expand Down
2 changes: 2 additions & 0 deletions apps/meteor/app/file-upload/server/lib/FileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ export const FileUpload = {
name: `thumb-${file.name}`,
size: buffer.length,
type: file.type,
originalFileId: file._id,
typeGroup: 'thumb',
rid,
userId,
};
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/app/lib/server/methods/deleteMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Meteor.methods({
u: 1,
rid: 1,
file: 1,
files: 1,
ts: 1,
},
});
Expand Down
14 changes: 12 additions & 2 deletions apps/meteor/server/models/raw/Uploads.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TODO: Lib imports should not exists inside the raw models
import type { IUpload, RocketChatRecordDeleted } from '@rocket.chat/core-typings';
import type { IUploadsModel } from '@rocket.chat/model-typings';
import type { Collection, FindCursor, Db, DeleteResult, IndexDescription, InsertOneResult, UpdateResult, WithId } from 'mongodb';
import type { FindPaginated, IUploadsModel } from '@rocket.chat/model-typings';
import type { Collection, FindCursor, Db, DeleteResult, IndexDescription, InsertOneResult, UpdateResult, WithId, Filter } from 'mongodb';
import { escapeRegExp } from '@rocket.chat/string-helpers';

import { BaseRaw } from './BaseRaw';
Expand Down Expand Up @@ -99,4 +99,14 @@ export class UploadsRaw extends BaseRaw<IUpload> implements IUploadsModel {
async deleteFile(fileId: string): Promise<DeleteResult> {
return this.deleteOne({ _id: fileId });
}

findPaginatedWithoutThumbs(query: Filter<IUpload> = {}, options?: any): FindPaginated<FindCursor<WithId<IUpload>>> {
return this.findPaginated(
{
...query,
typeGroup: { $ne: 'thumb' },
},
options,
);
}
}
41 changes: 37 additions & 4 deletions apps/meteor/tests/end-to-end/api/02-channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expect } from 'chai';
import { getCredentials, api, request, credentials, apiPublicChannelName, channel, reservedWords } from '../../data/api-data.js';
import { adminUsername, password } from '../../data/user.js';
import { createUser, login } from '../../data/users.helper';
import { imgURL } from '../../data/interactions.js';
import { updatePermission, updateSetting } from '../../data/permissions.helper';
import { createRoom } from '../../data/rooms.helper';
import { createVisitor } from '../../data/livechat/rooms';
Expand Down Expand Up @@ -43,6 +44,7 @@ describe('[Channels]', function () {
expect(res.body).to.have.nested.property('channel.t', 'c');
expect(res.body).to.have.nested.property('channel.msgs', 0);
channel._id = res.body.channel._id;
channel.name = res.body.channel.name;
})
.end(done);
});
Expand Down Expand Up @@ -352,7 +354,7 @@ describe('[Channels]', function () {
.get(api('channels.files'))
.set(credentials)
.query({
roomId: 'GENERAL',
roomId: channel._id,
})
.expect('Content-Type', 'application/json')
.expect(200)
Expand All @@ -368,7 +370,7 @@ describe('[Channels]', function () {
.get(api('channels.files'))
.set(credentials)
.query({
roomId: 'GENERAL',
roomId: channel._id,
count: 5,
offset: 0,
})
Expand All @@ -386,7 +388,7 @@ describe('[Channels]', function () {
.get(api('channels.files'))
.set(credentials)
.query({
roomName: 'general',
roomName: channel.name,
})
.expect('Content-Type', 'application/json')
.expect(200)
Expand All @@ -402,7 +404,7 @@ describe('[Channels]', function () {
.get(api('channels.files'))
.set(credentials)
.query({
roomName: 'general',
roomName: channel.name,
count: 5,
offset: 0,
})
Expand All @@ -414,6 +416,37 @@ describe('[Channels]', function () {
})
.end(done);
});

it('should not return thumbnails', async function () {
await request
.post(api(`rooms.upload/${channel._id}`))
.set(credentials)
.attach('file', imgURL)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
});

await request
.get(api('channels.files'))
.set(credentials)
.query({
roomId: channel._id,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('files').and.to.be.an('array').with.lengthOf(1);

const { files } = res.body;

files.forEach((file) => {
expect(file).to.not.have.property('originalFileId');
});
});
});
});

describe('[/channels.join]', () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/model-typings/src/models/IUploadsModel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { FindCursor, DeleteResult, InsertOneResult, UpdateResult, WithId } from 'mongodb';
import type { FindCursor, DeleteResult, InsertOneResult, UpdateResult, WithId, Filter } from 'mongodb';
import type { IUpload } from '@rocket.chat/core-typings';

import type { IBaseModel } from './IBaseModel';
import type { FindPaginated, IBaseModel } from './IBaseModel';

export interface IUploadsModel extends IBaseModel<IUpload> {
findNotHiddenFilesOfRoom(roomId: string, searchText: string, fileType: string, limit: number): FindCursor<IUpload>;
Expand All @@ -11,4 +11,6 @@ export interface IUploadsModel extends IBaseModel<IUpload> {
updateFileComplete(fileId: string, userId: string, file: object): Promise<UpdateResult | undefined>;

deleteFile(fileId: string): Promise<DeleteResult>;

findPaginatedWithoutThumbs(query: Filter<IUpload>, options?: any): FindPaginated<FindCursor<WithId<IUpload>>>;
}

0 comments on commit 3cf1c80

Please sign in to comment.