|
|
|
|
@ -1,5 +1,5 @@ |
|
|
|
|
import { Team, Room } from '@rocket.chat/core-services'; |
|
|
|
|
import type { IRoom, ISubscription, IUser, RoomType, IUpload } from '@rocket.chat/core-typings'; |
|
|
|
|
import type { IRoom, ISubscription, IUser, RoomType } from '@rocket.chat/core-typings'; |
|
|
|
|
import { Integrations, Messages, Rooms, Subscriptions, Uploads, Users } from '@rocket.chat/models'; |
|
|
|
|
import { |
|
|
|
|
isChannelsAddAllProps, |
|
|
|
|
@ -18,7 +18,6 @@ import { |
|
|
|
|
isChannelsConvertToTeamProps, |
|
|
|
|
isChannelsSetReadOnlyProps, |
|
|
|
|
isChannelsDeleteProps, |
|
|
|
|
isRoomsImagesProps, |
|
|
|
|
} from '@rocket.chat/rest-typings'; |
|
|
|
|
import { Meteor } from 'meteor/meteor'; |
|
|
|
|
|
|
|
|
|
@ -800,55 +799,6 @@ API.v1.addRoute( |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
API.v1.addRoute( |
|
|
|
|
'channels.images', |
|
|
|
|
{ |
|
|
|
|
authRequired: true, |
|
|
|
|
validateParams: isRoomsImagesProps, |
|
|
|
|
deprecation: { |
|
|
|
|
version: '7.0.0', |
|
|
|
|
alternatives: ['rooms.images'], |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
async get() { |
|
|
|
|
const room = await Rooms.findOneById<Pick<IRoom, '_id' | 't' | 'teamId' | 'prid'>>(this.queryParams.roomId, { |
|
|
|
|
projection: { t: 1, teamId: 1, prid: 1 }, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (!room || !(await canAccessRoomAsync(room, { _id: this.userId }))) { |
|
|
|
|
return API.v1.unauthorized(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let initialImage: IUpload | null = null; |
|
|
|
|
if (this.queryParams.startingFromId) { |
|
|
|
|
initialImage = await Uploads.findOneById(this.queryParams.startingFromId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const { offset, count } = await getPaginationItems(this.queryParams); |
|
|
|
|
|
|
|
|
|
const { cursor, totalCount } = Uploads.findImagesByRoomId(room._id, initialImage?.uploadedAt, { |
|
|
|
|
skip: offset, |
|
|
|
|
limit: count, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const [files, total] = await Promise.all([cursor.toArray(), totalCount]); |
|
|
|
|
|
|
|
|
|
// If the initial image was not returned in the query, insert it as the first element of the list
|
|
|
|
|
if (initialImage && !files.find(({ _id }) => _id === (initialImage as IUpload)._id)) { |
|
|
|
|
files.splice(0, 0, initialImage); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return API.v1.success({ |
|
|
|
|
files, |
|
|
|
|
count, |
|
|
|
|
offset, |
|
|
|
|
total, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
API.v1.addRoute( |
|
|
|
|
'channels.getIntegrations', |
|
|
|
|
{ |
|
|
|
|
|