Chore: Migrate REST API - getFiles to Typescript (#3873)

This commit is contained in:
Alex Junior 2022-03-10 12:29:33 -03:00 committed by GitHub
parent b5f8f6f305
commit d73da2942b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 20 deletions

View File

@ -1,3 +1,5 @@
import { IUser } from './IUser';
export interface IAttachment { export interface IAttachment {
ts: string | Date; ts: string | Date;
title: string; title: string;
@ -23,3 +25,30 @@ export interface IAttachment {
color?: string; color?: string;
thumb_url?: string; thumb_url?: string;
} }
export interface IServerAttachment {
_id: string;
name: string;
size: number;
type: string;
rid: string;
userId: string;
AmazonS3: { path: string };
store: string;
identify: {
format: string;
size: {
width: number;
height: number;
};
};
complete: boolean;
etag: string;
path: string;
progress: boolean;
token: string;
uploadedAt: string | Date;
uploading: boolean;
url: string;
user: Pick<IUser, '_id' | 'username' | 'name'>;
}

View File

@ -1,18 +1,15 @@
import { ITeam } from '../../ITeam'; import { ITeam } from '../../ITeam';
import type { IMessage, IMessageFromServer } from '../../IMessage'; import type { IMessageFromServer } from '../../IMessage';
import type { IServerRoom } from '../../IRoom'; import type { IServerRoom } from '../../IRoom';
import type { IUser } from '../../IUser'; import type { IUser } from '../../IUser';
import { IServerAttachment } from '../../IAttachment';
export type ChannelsEndpoints = { export type ChannelsEndpoints = {
'channels.files': { 'channels.files': {
GET: (params: { GET: (params: { roomId: IServerRoom['_id']; offset: number; sort: string | { uploadedAt: number } }) => {
roomId: IServerRoom['_id']; files: IServerAttachment[];
offset: number;
count: number; count: number;
sort: string | { uploadedAt: number }; offset: number;
query: string;
}) => {
files: IMessage[];
total: number; total: number;
}; };
}; };

View File

@ -1,12 +1,15 @@
import { ITeam } from '../../ITeam'; import { ITeam } from '../../ITeam';
import type { IMessage, IMessageFromServer } from '../../IMessage'; import type { IMessageFromServer } from '../../IMessage';
import type { IServerRoom } from '../../IRoom'; import type { IServerRoom } from '../../IRoom';
import type { IUser } from '../../IUser'; import type { IUser } from '../../IUser';
import { IServerAttachment } from '../../IAttachment';
export type GroupsEndpoints = { export type GroupsEndpoints = {
'groups.files': { 'groups.files': {
GET: (params: { roomId: IServerRoom['_id']; count: number; sort: string | { uploadedAt: number }; query: string }) => { GET: (params: { roomId: IServerRoom['_id']; offset: number; sort: string | { uploadedAt: number } }) => {
files: IMessage[]; files: IServerAttachment[];
count: number;
offset: number;
total: number; total: number;
}; };
}; };

View File

@ -1,6 +1,7 @@
import type { IMessage, IMessageFromServer } from '../../IMessage'; import type { IMessageFromServer } from '../../IMessage';
import type { IServerRoom, RoomID, RoomType } from '../../IRoom'; import type { IServerRoom, RoomID, RoomType } from '../../IRoom';
import type { IUser } from '../../IUser'; import type { IUser } from '../../IUser';
import { IServerAttachment } from '../../IAttachment';
export type ImEndpoints = { export type ImEndpoints = {
'im.create': { 'im.create': {
@ -25,8 +26,10 @@ export type ImEndpoints = {
}; };
}; };
'im.files': { 'im.files': {
GET: (params: { roomId: IServerRoom['_id']; count: number; sort: string | { uploadedAt: number }; query: string }) => { GET: (params: { roomId: IServerRoom['_id']; offset: number; sort: string | { uploadedAt: number } }) => {
files: IMessage[]; files: IServerAttachment[];
count: number;
offset: number;
total: number; total: number;
}; };
}; };

View File

@ -590,15 +590,15 @@ export const getUsernameSuggestion = () =>
// RC 0.65.0 // RC 0.65.0
sdk.get('users.getUsernameSuggestion'); sdk.get('users.getUsernameSuggestion');
export const getFiles = (roomId: string, type: RoomTypes, offset: number): any => export const getFiles = (roomId: string, type: SubscriptionType, offset: number) => {
const t = type as SubscriptionType.DIRECT | SubscriptionType.CHANNEL | SubscriptionType.GROUP;
// RC 0.59.0 // RC 0.59.0
// TODO: missing definitions from server return sdk.get(`${roomTypeToApiType(t)}.files`, {
// @ts-ignore
sdk.get(`${roomTypeToApiType(type)}.files`, {
roomId, roomId,
offset, offset,
sort: { uploadedAt: -1 } sort: { uploadedAt: -1 }
}); });
};
export const getMessages = ( export const getMessages = (
roomId: string, roomId: string,

View File

@ -196,9 +196,10 @@ class MessagesView extends React.Component<IMessagesViewProps, any> {
name: I18n.t('Files'), name: I18n.t('Files'),
fetchFunc: async () => { fetchFunc: async () => {
const { messages } = this.state; const { messages } = this.state;
// @ts-ignore
const result = await RocketChat.getFiles(this.rid, this.t, messages.length); const result = await RocketChat.getFiles(this.rid, this.t, messages.length);
return { ...result, messages: result.files }; if (result.success) {
return { ...result, messages: result.files };
}
}, },
noDataMsg: I18n.t('No_files'), noDataMsg: I18n.t('No_files'),
testID: 'room-files-view', testID: 'room-files-view',