| 285 | } |
| 286 | |
| 287 | void Conductor::QueryFile(std::shared_ptr<RtcChannel> datachannel, const protocol::Packet &pkt) { |
| 288 | if (!pkt.has_query_file_request()) { |
| 289 | ERROR_PRINT("Invalid metadata request"); |
| 290 | return; |
| 291 | } |
| 292 | |
| 293 | if (args.record_path.empty()) { |
| 294 | ERROR_PRINT("Recording path is not set, unable to query files."); |
| 295 | return; |
| 296 | } |
| 297 | |
| 298 | auto req = pkt.query_file_request(); |
| 299 | auto type = req.type(); |
| 300 | const std::string ¶meter = req.parameter(); |
| 301 | |
| 302 | if (type == protocol::QueryFileType::LATEST_FILE || parameter.empty()) { |
| 303 | auto path = Utils::FindSecondNewestFile(args.record_path, ".mp4"); |
| 304 | DEBUG_PRINT("LATEST: %s", path.c_str()); |
| 305 | SendFileResponse(datachannel, path); |
| 306 | } else if (type == protocol::QueryFileType::BEFORE_FILE) { |
| 307 | auto paths = Utils::FindOlderFiles(parameter, 8); |
| 308 | for (auto &path : paths) { |
| 309 | DEBUG_PRINT("OLDER: %s", path.c_str()); |
| 310 | SendFileResponse(datachannel, path); |
| 311 | } |
| 312 | } else if (type == protocol::QueryFileType::BEFORE_TIME) { |
| 313 | auto path = Utils::FindFilesFromDatetime(args.record_path, parameter); |
| 314 | DEBUG_PRINT("TIME_MATCH: %s", path.c_str()); |
| 315 | SendFileResponse(datachannel, path); |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | void Conductor::SendFileResponse(std::shared_ptr<RtcChannel> datachannel, const std::string &path) { |
| 320 | if (path.empty()) |