Chore: Migrate REST API - getFiles to Typescript (#3873)
This commit is contained in:
parent
b5f8f6f305
commit
d73da2942b
|
@ -1,3 +1,5 @@
|
|||
import { IUser } from './IUser';
|
||||
|
||||
export interface IAttachment {
|
||||
ts: string | Date;
|
||||
title: string;
|
||||
|
@ -23,3 +25,30 @@ export interface IAttachment {
|
|||
color?: 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'>;
|
||||
}
|
||||
|
|
|
@ -1,18 +1,15 @@
|
|||
import { ITeam } from '../../ITeam';
|
||||
import type { IMessage, IMessageFromServer } from '../../IMessage';
|
||||
import type { IMessageFromServer } from '../../IMessage';
|
||||
import type { IServerRoom } from '../../IRoom';
|
||||
import type { IUser } from '../../IUser';
|
||||
import { IServerAttachment } from '../../IAttachment';
|
||||
|
||||
export type ChannelsEndpoints = {
|
||||
'channels.files': {
|
||||
GET: (params: {
|
||||
roomId: IServerRoom['_id'];
|
||||
offset: number;
|
||||
GET: (params: { roomId: IServerRoom['_id']; offset: number; sort: string | { uploadedAt: number } }) => {
|
||||
files: IServerAttachment[];
|
||||
count: number;
|
||||
sort: string | { uploadedAt: number };
|
||||
query: string;
|
||||
}) => {
|
||||
files: IMessage[];
|
||||
offset: number;
|
||||
total: number;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
import { ITeam } from '../../ITeam';
|
||||
import type { IMessage, IMessageFromServer } from '../../IMessage';
|
||||
import type { IMessageFromServer } from '../../IMessage';
|
||||
import type { IServerRoom } from '../../IRoom';
|
||||
import type { IUser } from '../../IUser';
|
||||
import { IServerAttachment } from '../../IAttachment';
|
||||
|
||||
export type GroupsEndpoints = {
|
||||
'groups.files': {
|
||||
GET: (params: { roomId: IServerRoom['_id']; count: number; sort: string | { uploadedAt: number }; query: string }) => {
|
||||
files: IMessage[];
|
||||
GET: (params: { roomId: IServerRoom['_id']; offset: number; sort: string | { uploadedAt: number } }) => {
|
||||
files: IServerAttachment[];
|
||||
count: number;
|
||||
offset: number;
|
||||
total: number;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import type { IMessage, IMessageFromServer } from '../../IMessage';
|
||||
import type { IMessageFromServer } from '../../IMessage';
|
||||
import type { IServerRoom, RoomID, RoomType } from '../../IRoom';
|
||||
import type { IUser } from '../../IUser';
|
||||
import { IServerAttachment } from '../../IAttachment';
|
||||
|
||||
export type ImEndpoints = {
|
||||
'im.create': {
|
||||
|
@ -25,8 +26,10 @@ export type ImEndpoints = {
|
|||
};
|
||||
};
|
||||
'im.files': {
|
||||
GET: (params: { roomId: IServerRoom['_id']; count: number; sort: string | { uploadedAt: number }; query: string }) => {
|
||||
files: IMessage[];
|
||||
GET: (params: { roomId: IServerRoom['_id']; offset: number; sort: string | { uploadedAt: number } }) => {
|
||||
files: IServerAttachment[];
|
||||
count: number;
|
||||
offset: number;
|
||||
total: number;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -590,15 +590,15 @@ export const getUsernameSuggestion = () =>
|
|||
// RC 0.65.0
|
||||
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
|
||||
// TODO: missing definitions from server
|
||||
// @ts-ignore
|
||||
sdk.get(`${roomTypeToApiType(type)}.files`, {
|
||||
return sdk.get(`${roomTypeToApiType(t)}.files`, {
|
||||
roomId,
|
||||
offset,
|
||||
sort: { uploadedAt: -1 }
|
||||
});
|
||||
};
|
||||
|
||||
export const getMessages = (
|
||||
roomId: string,
|
||||
|
|
|
@ -196,9 +196,10 @@ class MessagesView extends React.Component<IMessagesViewProps, any> {
|
|||
name: I18n.t('Files'),
|
||||
fetchFunc: async () => {
|
||||
const { messages } = this.state;
|
||||
// @ts-ignore
|
||||
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'),
|
||||
testID: 'room-files-view',
|
||||
|
|
Loading…
Reference in New Issue