From 4bdcf35d0caf129a8beb76531bdb37d9f6bb527b Mon Sep 17 00:00:00 2001 From: Altay Aydemir Date: Sun, 16 Jan 2022 15:12:08 +0300 Subject: [PATCH] add file conversion response types --- src/resources/Files/File.ts | 8 +++++--- src/resources/Files/types.ts | 13 +++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/resources/Files/File.ts b/src/resources/Files/File.ts index 14f91fa..db57c7d 100644 --- a/src/resources/Files/File.ts +++ b/src/resources/Files/File.ts @@ -1,6 +1,6 @@ import URI from 'urijs' import { PutioAPIClient } from '../../client' -import { IGetStartFromResponse } from './types' +import { IFileConversionStatusResponse, IGetStartFromResponse } from './types' export default class File { private client: PutioAPIClient @@ -78,11 +78,13 @@ export default class File { } public ConvertToMp4(fileId: number) { - return this.client.post(`/files/${fileId}/mp4`) + return this.client.post<{ count: number }>(`/files/${fileId}/mp4`) } public ConvertStatus(fileId: number) { - return this.client.get(`/files/${fileId}/mp4`) + return this.client.get( + `/files/${fileId}/mp4`, + ) } public DeleteMp4(fileId: number) { diff --git a/src/resources/Files/types.ts b/src/resources/Files/types.ts index be4a313..ba38124 100644 --- a/src/resources/Files/types.ts +++ b/src/resources/Files/types.ts @@ -48,3 +48,16 @@ export interface IFileDeleteResponse { skipped: number cursor: string } + +export type FileConversionStatus = + | { status: 'NOT_AVAILABLE' } + | { status: 'IN_QUEUE' } + | { status: 'CONVERTING'; percent_done: number } + | { status: 'COMPLETED'; size: IFile['size'] } + | { status: 'ERROR' } + +export interface IFileConversionStatusResponse { + mp4: FileConversionStatus & { + id: IFile['id'] + } +}