| 1116 | } |
| 1117 | |
| 1118 | void Backend::deleteGoogleDriveAppData(uint appId, const QString &token) |
| 1119 | { |
| 1120 | // Find app folder CloudRedirect/<accountId>/<appId> and delete recursively |
| 1121 | QString query = QString("name='CloudRedirect' and mimeType='application/vnd.google-apps.folder' and trashed=false"); |
| 1122 | QUrl url("https://www.googleapis.com/drive/v3/files"); |
| 1123 | QUrlQuery params; |
| 1124 | params.addQueryItem("q", query); |
| 1125 | params.addQueryItem("fields", "files(id)"); |
| 1126 | url.setQuery(params); |
| 1127 | |
| 1128 | QNetworkRequest req(url); |
| 1129 | req.setRawHeader("Authorization", ("Bearer " + token).toUtf8()); |
| 1130 | |
| 1131 | auto *reply = m_nam->get(req); |
| 1132 | connect(reply, &QNetworkReply::finished, this, [this, reply, token, appId]() { |
| 1133 | reply->deleteLater(); |
| 1134 | if (reply->error() != QNetworkReply::NoError) return; |
| 1135 | |
| 1136 | QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); |
| 1137 | QJsonArray files = doc.object().value("files").toArray(); |
| 1138 | if (files.isEmpty()) return; |
| 1139 | QString rootId = files[0].toObject().value("id").toString(); |
| 1140 | |
| 1141 | // Find account folder |
| 1142 | QString q2 = QString("name='%1' and '%2' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false") |
| 1143 | .arg(m_accountId, rootId); |
| 1144 | QUrl url2("https://www.googleapis.com/drive/v3/files"); |
| 1145 | QUrlQuery params2; |
| 1146 | params2.addQueryItem("q", q2); |
| 1147 | params2.addQueryItem("fields", "files(id)"); |
| 1148 | url2.setQuery(params2); |
| 1149 | QNetworkRequest req2(url2); |
| 1150 | req2.setRawHeader("Authorization", ("Bearer " + token).toUtf8()); |
| 1151 | |
| 1152 | auto *reply2 = m_nam->get(req2); |
| 1153 | connect(reply2, &QNetworkReply::finished, this, [this, reply2, token, appId]() { |
| 1154 | reply2->deleteLater(); |
| 1155 | if (reply2->error() != QNetworkReply::NoError) return; |
| 1156 | |
| 1157 | QJsonDocument doc2 = QJsonDocument::fromJson(reply2->readAll()); |
| 1158 | QJsonArray files2 = doc2.object().value("files").toArray(); |
| 1159 | if (files2.isEmpty()) return; |
| 1160 | QString accountId = files2[0].toObject().value("id").toString(); |
| 1161 | |
| 1162 | // Find app folder |
| 1163 | QString q3 = QString("name='%1' and '%2' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false") |
| 1164 | .arg(QString::number(appId), accountId); |
| 1165 | QUrl url3("https://www.googleapis.com/drive/v3/files"); |
| 1166 | QUrlQuery params3; |
| 1167 | params3.addQueryItem("q", q3); |
| 1168 | params3.addQueryItem("fields", "files(id)"); |
| 1169 | url3.setQuery(params3); |
| 1170 | QNetworkRequest req3(url3); |
| 1171 | req3.setRawHeader("Authorization", ("Bearer " + token).toUtf8()); |
| 1172 | |
| 1173 | auto *reply3 = m_nam->get(req3); |
| 1174 | connect(reply3, &QNetworkReply::finished, this, [this, reply3, token, appId]() { |
| 1175 | reply3->deleteLater(); |
nothing calls this directly
no outgoing calls
no test coverage detected