* @brief Open MDF4 file */
| 121 | * @brief Open MDF4 file |
| 122 | */ |
| 123 | API::CommandResponse API::Handlers::MDF4PlayerHandler::open(const QString& id, |
| 124 | const QJsonObject& params) |
| 125 | { |
| 126 | if (!params.contains(QStringLiteral("filePath"))) { |
| 127 | return CommandResponse::makeError( |
| 128 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: filePath")); |
| 129 | } |
| 130 | |
| 131 | const QString file_path = params.value(QStringLiteral("filePath")).toString(); |
| 132 | if (file_path.isEmpty()) { |
| 133 | return CommandResponse::makeError( |
| 134 | id, ErrorCode::InvalidParam, QStringLiteral("filePath cannot be empty")); |
| 135 | } |
| 136 | |
| 137 | if (!API::isPathAllowed(file_path)) { |
| 138 | return CommandResponse::makeError( |
| 139 | id, ErrorCode::InvalidParam, QStringLiteral("filePath is not allowed")); |
| 140 | } |
| 141 | |
| 142 | MDF4::Player::instance().openFile(file_path); |
| 143 | |
| 144 | QJsonObject result; |
| 145 | result[QStringLiteral("filePath")] = file_path; |
| 146 | result[QStringLiteral("isOpen")] = MDF4::Player::instance().isOpen(); |
| 147 | return CommandResponse::makeSuccess(id, result); |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * @brief Close MDF4 file |