* @brief Open CSV file */
| 164 | * @brief Open CSV file |
| 165 | */ |
| 166 | API::CommandResponse API::Handlers::CSVPlayerHandler::open(const QString& id, |
| 167 | const QJsonObject& params) |
| 168 | { |
| 169 | if (!params.contains(QStringLiteral("filePath"))) { |
| 170 | return CommandResponse::makeError( |
| 171 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: filePath")); |
| 172 | } |
| 173 | |
| 174 | const QString file_path = params.value(QStringLiteral("filePath")).toString(); |
| 175 | if (file_path.isEmpty()) { |
| 176 | return CommandResponse::makeError( |
| 177 | id, ErrorCode::InvalidParam, QStringLiteral("filePath cannot be empty")); |
| 178 | } |
| 179 | |
| 180 | if (!API::isPathAllowed(file_path)) { |
| 181 | return CommandResponse::makeError( |
| 182 | id, ErrorCode::InvalidParam, QStringLiteral("filePath is not allowed")); |
| 183 | } |
| 184 | |
| 185 | CSV::Player::instance().openFile(file_path); |
| 186 | |
| 187 | QJsonObject result; |
| 188 | result[QStringLiteral("filePath")] = file_path; |
| 189 | result[QStringLiteral("isOpen")] = CSV::Player::instance().isOpen(); |
| 190 | return CommandResponse::makeSuccess(id, result); |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * @brief Close CSV file |
no test coverage detected