File Downloads API draft.

This commit is contained in:
levlam 2022-02-18 01:37:04 +03:00
parent 5ff92065bf
commit b20a98036f
4 changed files with 136 additions and 2 deletions

View File

@ -147,7 +147,7 @@ localFile path:string can_be_downloaded:Bool can_be_deleted:Bool is_downloading_
//@description Represents a remote file //@description Represents a remote file
//@id Remote file identifier; may be empty. Can be used by the current user across application restarts or even from other devices. Uniquely identifies a file, but a file can have a lot of different valid identifiers. //@id Remote file identifier; may be empty. Can be used by the current user across application restarts or even from other devices. Uniquely identifies a file, but a file can have a lot of different valid identifiers.
//-If the ID starts with "http://" or "https://", it represents the HTTP URL of the file. TDLib is currently unable to download files if only their URL is known. //-If the ID starts with "http://" or "https://", it represents the HTTP URL of the file. TDLib is currently unable to download files if only their URL is known.
//-If downloadFile is called on such a file or if it is sent to a secret chat, TDLib starts a file generation process by sending updateFileGenerationStart to the application with the HTTP URL in the original_path and "#url#" as the conversion string. Application must generate the file by downloading it to the specified location //-If downloadFile/addFileToDownloads is called on such a file or if it is sent to a secret chat, TDLib starts a file generation process by sending updateFileGenerationStart to the application with the HTTP URL in the original_path and "#url#" as the conversion string. Application must generate the file by downloading it to the specified location
//@unique_id Unique file identifier; may be empty if unknown. The unique file identifier which is the same for the same file even for different users and is persistent over time //@unique_id Unique file identifier; may be empty if unknown. The unique file identifier which is the same for the same file even for different users and is persistent over time
//@is_uploading_active True, if the file is currently being uploaded (or a remote copy is being generated by some other means) //@is_uploading_active True, if the file is currently being uploaded (or a remote copy is being generated by some other means)
//@is_uploading_completed True, if a remote copy is fully available //@is_uploading_completed True, if a remote copy is fully available
@ -872,6 +872,21 @@ messageCalendar total_count:int32 days:vector<messageCalendarDay> = MessageCalen
sponsoredMessage message_id:int53 sponsor_chat_id:int53 sponsor_chat_info:chatInviteLinkInfo link:InternalLinkType content:MessageContent = SponsoredMessage; sponsoredMessage message_id:int53 sponsor_chat_id:int53 sponsor_chat_info:chatInviteLinkInfo link:InternalLinkType content:MessageContent = SponsoredMessage;
//@description Describes a file added to file download list
//@file_id File identifier
//@message The message with the file
//@add_date Point in time (Unix timestamp) when the file was added to the download list
//@complete_date Point in time (Unix timestamp) when the file downloading was completed; 0 if the file downloading isn't completed
//@is_paused True, if downloading of the file is paused
fileDownload file_id:int32 message:message add_date:int32 complete_date:int32 is_paused:Bool = FileDownload;
//@description Contains a list of downloaded files found by a search
//@total_count Total count of files found
//@files List of downloaded files
//@next_offset The offset for the next request. If empty, there are no more results
foundFileDownloads total_count:int32 files:vector<fileDownload> next_offset:string = FoundFileDownloads;
//@class NotificationSettingsScope @description Describes the types of chats to which notification settings are relevant //@class NotificationSettingsScope @description Describes the types of chats to which notification settings are relevant
//@description Notification settings applied to all private and secret chats when the corresponding chat setting has a default value //@description Notification settings applied to all private and secret chats when the corresponding chat setting has a default value
@ -3927,6 +3942,15 @@ updateFileGenerationStart generation_id:int64 original_path:string destination_p
//@description File generation is no longer needed @generation_id Unique identifier for the generation process //@description File generation is no longer needed @generation_id Unique identifier for the generation process
updateFileGenerationStop generation_id:int64 = Update; updateFileGenerationStop generation_id:int64 = Update;
//@description The state of the file download list has changed
//@total_size Total size of files in the file download list, in bytes
//@total_count Total number of files in the file download list
//@downloaded_size Total downloaded size of files in the file download list, in bytes
updateFileDownloads total_size:int53 total_count:int32 downloaded_size:int53 = Update;
//@description A file was removed from the file download list @file_id File identifier
updateFileRemovedFromDownloads file_id:int32 = Update;
//@description New call was created or information about a call was updated @call New data about a call //@description New call was created or information about a call was updated @call New data about a call
updateCall call:call = Update; updateCall call:call = Update;
@ -5007,7 +5031,7 @@ setPinnedChats chat_list:ChatList chat_ids:vector<int53> = Ok;
//@description Downloads a file from the cloud. Download progress and completion of the download will be notified through updateFile updates //@description Downloads a file from the cloud. Download progress and completion of the download will be notified through updateFile updates
//@file_id Identifier of the file to download //@file_id Identifier of the file to download
//@priority Priority of the download (1-32). The higher the priority, the earlier the file will be downloaded. If the priorities of two files are equal, then the last one for which downloadFile was called will be downloaded first //@priority Priority of the download (1-32). The higher the priority, the earlier the file will be downloaded. If the priorities of two files are equal, then the last one for which downloadFile/addFileToDownloads was called will be downloaded first
//@offset The starting position from which the file needs to be downloaded //@offset The starting position from which the file needs to be downloaded
//@limit Number of bytes which need to be downloaded starting from the "offset" position before the download will automatically be canceled; use 0 to download without a limit //@limit Number of bytes which need to be downloaded starting from the "offset" position before the download will automatically be canceled; use 0 to download without a limit
//@synchronous If false, this request returns file state just after the download has been started. If true, this request returns file state only after //@synchronous If false, this request returns file state just after the download has been started. If true, this request returns file state only after
@ -5056,6 +5080,39 @@ readFilePart file_id:int32 offset:int32 count:int32 = FilePart;
//@description Deletes a file from the TDLib file cache @file_id Identifier of the file to delete //@description Deletes a file from the TDLib file cache @file_id Identifier of the file to delete
deleteFile file_id:int32 = Ok; deleteFile file_id:int32 = Ok;
//@description Adds a file from a message to the list of file downloads. Download progress and completion of the download will be notified through updateFile updates.
//-If message database is used, the list of file downloads is persistent across application restarts. The downloading is independent from download using downloadFile, i.e. it continues if downloadFile is canceled or is used to download a part of the file
//@file_id Identifier of the file to download
//@chat_id Chat identifier of the message with the file
//@message_id Message identifier
//@priority Priority of the download (1-32). The higher the priority, the earlier the file will be downloaded. If the priorities of two files are equal, then the last one for which downloadFile/addFileToDownloads was called will be downloaded first
addFileToDownloads file_id:int32 chat_id:int53 message_id:int53 priority:int32 = File;
//@description Changes pause state of a file in the file download list
//@file_id Identifier of the downloaded file
//@is_paused Pass true if the download is paused
toggleDownloadIsPaused file_id:int32 is_paused:Bool = Ok;
//@description Changes pause state of all files in the file download list @are_paused True, if the downloads are paused
toggleAllDownloadsArePaused are_paused:Bool = Ok;
//@description Removes a file from the file download list @file_id Identifier of the downloaded file @delete_from_cache Pass true if the file needs to be deleted from the TDLib file cache
removeFileFromDownloads file_id:int32 delete_from_cache:Bool = Ok;
//@description Removes all files from the file download list
//@only_active Pass true to remove only active downloads, including paused
//@only_completed Pass true to remove only completed downloads
//@delete_from_cache Pass true if the files need to be deleted from the TDLib file cache
removeAllFilesFromDownloads only_active:Bool only_completed:Bool delete_from_cache:Bool = Ok;
//@description Searches for files in the file download list or recently downloaded files from the list
//@query Query to search for; may be empty to return all downloaded files
//@only_active Pass true to search only for active downloads, including paused
//@only_completed Pass true to search only for completed downloads
//@offset Offset of the first entry to return as received from the previous request; use empty string to get the first chunk of results
//@limit The maximum number of files to be returned
searchFileDownloads query:string only_active:Bool only_completed:Bool offset:string limit:int32 = FoundFileDownloads;
//@description Returns information about a file with messages exported from another app @message_file_head Beginning of the message file; up to 100 first lines //@description Returns information about a file with messages exported from another app @message_file_head Beginning of the message file; up to 100 first lines
getMessageFileType message_file_head:string = MessageFileType; getMessageFileType message_file_head:string = MessageFileType;

View File

@ -6505,6 +6505,38 @@ void Td::on_request(uint64 id, const td_api::deleteFile &request) {
"td_api::deleteFile"); "td_api::deleteFile");
} }
void Td::on_request(uint64 id, const td_api::addFileToDownloads &request) {
CREATE_REQUEST_PROMISE();
promise.set_error(Status::Error(500, "Unsupported"));
}
void Td::on_request(uint64 id, const td_api::toggleDownloadIsPaused &request) {
CREATE_OK_REQUEST_PROMISE();
promise.set_error(Status::Error(500, "Unsupported"));
}
void Td::on_request(uint64 id, const td_api::toggleAllDownloadsArePaused &request) {
CREATE_OK_REQUEST_PROMISE();
promise.set_error(Status::Error(500, "Unsupported"));
}
void Td::on_request(uint64 id, const td_api::removeFileFromDownloads &request) {
CREATE_OK_REQUEST_PROMISE();
promise.set_error(Status::Error(500, "Unsupported"));
}
void Td::on_request(uint64 id, const td_api::removeAllFilesFromDownloads &request) {
CREATE_OK_REQUEST_PROMISE();
promise.set_error(Status::Error(500, "Unsupported"));
}
void Td::on_request(uint64 id, td_api::searchFileDownloads &request) {
CLEAN_INPUT_STRING(request.query_);
CLEAN_INPUT_STRING(request.offset_);
CREATE_REQUEST_PROMISE();
promise.set_error(Status::Error(500, "Unsupported"));
}
void Td::on_request(uint64 id, td_api::getMessageFileType &request) { void Td::on_request(uint64 id, td_api::getMessageFileType &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CLEAN_INPUT_STRING(request.message_file_head_); CLEAN_INPUT_STRING(request.message_file_head_);

View File

@ -925,6 +925,18 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::deleteFile &request); void on_request(uint64 id, const td_api::deleteFile &request);
void on_request(uint64 id, const td_api::addFileToDownloads &request);
void on_request(uint64 id, const td_api::toggleDownloadIsPaused &request);
void on_request(uint64 id, const td_api::toggleAllDownloadsArePaused &request);
void on_request(uint64 id, const td_api::removeFileFromDownloads &request);
void on_request(uint64 id, const td_api::removeAllFilesFromDownloads &request);
void on_request(uint64 id, td_api::searchFileDownloads &request);
void on_request(uint64 id, td_api::getMessageFileType &request); void on_request(uint64 id, td_api::getMessageFileType &request);
void on_request(uint64 id, const td_api::getMessageImportConfirmationText &request); void on_request(uint64 id, const td_api::getMessageImportConfirmationText &request);

View File

@ -2870,6 +2870,39 @@ class CliClient final : public Actor {
} else if (op == "delf" || op == "DeleteFile") { } else if (op == "delf" || op == "DeleteFile") {
const string &file_id = args; const string &file_id = args;
send_request(td_api::make_object<td_api::deleteFile>(as_file_id(file_id))); send_request(td_api::make_object<td_api::deleteFile>(as_file_id(file_id)));
} else if (op == "aftd") {
string file_id;
ChatId chat_id;
MessageId message_id;
int32 priority;
get_args(args, file_id, chat_id, message_id, priority);
send_request(
td_api::make_object<td_api::addFileToDownloads>(as_file_id(file_id), chat_id, message_id, max(priority, 1)));
} else if (op == "tdip") {
string file_id;
bool is_paused;
get_args(args, file_id, is_paused);
send_request(td_api::make_object<td_api::toggleDownloadIsPaused>(as_file_id(file_id), is_paused));
} else if (op == "tadap") {
bool are_paused;
get_args(args, are_paused);
send_request(td_api::make_object<td_api::toggleAllDownloadsArePaused>(are_paused));
} else if (op == "rffd") {
string file_id;
bool delete_from_cache;
get_args(args, file_id, delete_from_cache);
send_request(td_api::make_object<td_api::removeFileFromDownloads>(as_file_id(file_id), delete_from_cache));
} else if (op == "raffd" || op == "raffda" || op == "raffdc") {
bool delete_from_cache;
get_args(args, delete_from_cache);
send_request(td_api::make_object<td_api::removeAllFilesFromDownloads>(op.back() == 'a', op.back() == 'c',
delete_from_cache));
} else if (op == "sfd" || op == "sfda" || op == "sfdc") {
string offset;
SearchQuery query;
get_args(args, offset, query);
send_request(td_api::make_object<td_api::searchFileDownloads>(query.query, op.back() == 'a', op.back() == 'c',
offset, query.limit));
} else if (op == "dm" || op == "dmr") { } else if (op == "dm" || op == "dmr") {
ChatId chat_id; ChatId chat_id;
string message_ids; string message_ids;