diff --git a/apps/meteor/app/api/server/v1/channels.js b/apps/meteor/app/api/server/v1/channels.js index 2b02a1f86079027188eb211f19e625626c3155e1..6b5fb82a6e254baf69f0cadb3671ca3a11f076dd 100644 --- a/apps/meteor/app/api/server/v1/channels.js +++ b/apps/meteor/app/api/server/v1/channels.js @@ -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, diff --git a/apps/meteor/app/api/server/v1/groups.js b/apps/meteor/app/api/server/v1/groups.js index 6593effe5b7227228d3779cc2683d5a3786e0d5f..db2745df58722c27e9fe036b8cce435cf5cc2a4f 100644 --- a/apps/meteor/app/api/server/v1/groups.js +++ b/apps/meteor/app/api/server/v1/groups.js @@ -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, diff --git a/apps/meteor/app/api/server/v1/im.ts b/apps/meteor/app/api/server/v1/im.ts index eb66fefd672372f1e3addaadd1cc46d440bc9ea3..53683c0dbe8676eb9e438163b803e0b7433f47c5 100644 --- a/apps/meteor/app/api/server/v1/im.ts +++ b/apps/meteor/app/api/server/v1/im.ts @@ -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, @@ -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 = @@ -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, diff --git a/apps/meteor/app/file-upload/server/lib/FileUpload.js b/apps/meteor/app/file-upload/server/lib/FileUpload.js index d0ae8333fe646923c757e708ae5d6df94ac7a2f9..14c47463dd4e0b950d899d34d464cb5053723a7d 100644 --- a/apps/meteor/app/file-upload/server/lib/FileUpload.js +++ b/apps/meteor/app/file-upload/server/lib/FileUpload.js @@ -327,6 +327,8 @@ export const FileUpload = { name: `thumb-${file.name}`, size: buffer.length, type: file.type, + originalFileId: file._id, + typeGroup: 'thumb', rid, userId, }; diff --git a/apps/meteor/app/lib/server/methods/deleteMessage.ts b/apps/meteor/app/lib/server/methods/deleteMessage.ts index 8ae4ef8248d53c2ec4722425ae3e2b5d2493b3bb..8f96fd670ba6c8d9687b06f7112614e81a16d64a 100644 --- a/apps/meteor/app/lib/server/methods/deleteMessage.ts +++ b/apps/meteor/app/lib/server/methods/deleteMessage.ts @@ -28,6 +28,7 @@ Meteor.methods({ u: 1, rid: 1, file: 1, + files: 1, ts: 1, }, }); diff --git a/apps/meteor/server/models/raw/Uploads.ts b/apps/meteor/server/models/raw/Uploads.ts index 17a41042cbd24042c87c23ef1df884888ca640ce..fd3bcfc9db46b64f43122e404127e3e382be289f 100644 --- a/apps/meteor/server/models/raw/Uploads.ts +++ b/apps/meteor/server/models/raw/Uploads.ts @@ -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'; @@ -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, + ); + } } diff --git a/apps/meteor/tests/end-to-end/api/02-channels.js b/apps/meteor/tests/end-to-end/api/02-channels.js index 17c1aa713969aac7dcea39172f86c3661deb6495..975050750c640ba3d9400e3ce9d0bdc5bff0ac8d 100644 --- a/apps/meteor/tests/end-to-end/api/02-channels.js +++ b/apps/meteor/tests/end-to-end/api/02-channels.js @@ -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'; @@ -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); }); @@ -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) @@ -368,7 +370,7 @@ describe('[Channels]', function () { .get(api('channels.files')) .set(credentials) .query({ - roomId: 'GENERAL', + roomId: channel._id, count: 5, offset: 0, }) @@ -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) @@ -402,7 +404,7 @@ describe('[Channels]', function () { .get(api('channels.files')) .set(credentials) .query({ - roomName: 'general', + roomName: channel.name, count: 5, offset: 0, }) @@ -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]', () => { diff --git a/packages/model-typings/src/models/IUploadsModel.ts b/packages/model-typings/src/models/IUploadsModel.ts index 4da4d64e39c5a170ebe57521b36785682c28e64a..ab0971635d7a8dbe5527c5ae3643904069109466 100644 --- a/packages/model-typings/src/models/IUploadsModel.ts +++ b/packages/model-typings/src/models/IUploadsModel.ts @@ -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>; @@ -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>>>; }