|
5 | 5 | //! `Cargo.toml` file. |
6 | 6 |
|
7 | 7 | use crate::app::AppState; |
8 | | -use crate::controllers::helpers::pagination::PaginationOptions; |
9 | 8 | use crate::controllers::krate::CratePath; |
10 | | -use crate::controllers::version::CrateVersionPath; |
11 | 9 | use crate::models::{ |
12 | | - Category, Crate, CrateCategory, CrateKeyword, CrateName, Keyword, RecentCrateDownloads, User, |
13 | | - Version, VersionOwnerAction, |
| 10 | + Category, Crate, CrateCategory, CrateKeyword, Keyword, RecentCrateDownloads, User, Version, |
| 11 | + VersionOwnerAction, |
14 | 12 | }; |
15 | 13 | use crate::schema::*; |
16 | 14 | use crate::util::errors::{bad_request, crate_not_found, AppResult, BoxedAppError}; |
17 | | -use crate::util::{redirect, RequestUtils}; |
18 | | -use crate::views::{ |
19 | | - EncodableCategory, EncodableCrate, EncodableDependency, EncodableKeyword, EncodableVersion, |
20 | | -}; |
21 | | -use axum::response::{IntoResponse, Response}; |
| 15 | +use crate::util::RequestUtils; |
| 16 | +use crate::views::{EncodableCategory, EncodableCrate, EncodableKeyword, EncodableVersion}; |
22 | 17 | use axum_extra::json; |
23 | 18 | use axum_extra::response::ErasedJson; |
24 | 19 | use diesel::prelude::*; |
@@ -244,80 +239,3 @@ impl FromStr for ShowIncludeMode { |
244 | 239 | Ok(mode) |
245 | 240 | } |
246 | 241 | } |
247 | | - |
248 | | -/// Get the readme of a crate version. |
249 | | -#[utoipa::path( |
250 | | - get, |
251 | | - path = "/api/v1/crates/{name}/{version}/readme", |
252 | | - params(CrateVersionPath), |
253 | | - tag = "versions", |
254 | | - responses((status = 200, description = "Successful Response")), |
255 | | -)] |
256 | | -pub async fn get_version_readme(app: AppState, path: CrateVersionPath, req: Parts) -> Response { |
257 | | - let redirect_url = app.storage.readme_location(&path.name, &path.version); |
258 | | - if req.wants_json() { |
259 | | - json!({ "url": redirect_url }).into_response() |
260 | | - } else { |
261 | | - redirect(redirect_url) |
262 | | - } |
263 | | -} |
264 | | - |
265 | | -/// List reverse dependencies of a crate. |
266 | | -#[utoipa::path( |
267 | | - get, |
268 | | - path = "/api/v1/crates/{name}/reverse_dependencies", |
269 | | - params(CratePath), |
270 | | - tag = "crates", |
271 | | - responses((status = 200, description = "Successful Response")), |
272 | | -)] |
273 | | -pub async fn list_reverse_dependencies( |
274 | | - app: AppState, |
275 | | - path: CratePath, |
276 | | - req: Parts, |
277 | | -) -> AppResult<ErasedJson> { |
278 | | - let mut conn = app.db_read().await?; |
279 | | - |
280 | | - let pagination_options = PaginationOptions::builder().gather(&req)?; |
281 | | - |
282 | | - let krate = path.load_crate(&mut conn).await?; |
283 | | - |
284 | | - let (rev_deps, total) = krate |
285 | | - .reverse_dependencies(&mut conn, pagination_options) |
286 | | - .await?; |
287 | | - |
288 | | - let rev_deps: Vec<_> = rev_deps |
289 | | - .into_iter() |
290 | | - .map(|dep| EncodableDependency::from_reverse_dep(dep, &krate.name)) |
291 | | - .collect(); |
292 | | - |
293 | | - let version_ids: Vec<i32> = rev_deps.iter().map(|dep| dep.version_id).collect(); |
294 | | - |
295 | | - let versions_and_publishers: Vec<(Version, CrateName, Option<User>)> = versions::table |
296 | | - .filter(versions::id.eq_any(version_ids)) |
297 | | - .inner_join(crates::table) |
298 | | - .left_outer_join(users::table) |
299 | | - .select(<(Version, CrateName, Option<User>)>::as_select()) |
300 | | - .load(&mut conn) |
301 | | - .await?; |
302 | | - |
303 | | - let versions = versions_and_publishers |
304 | | - .iter() |
305 | | - .map(|(v, ..)| v) |
306 | | - .collect::<Vec<_>>(); |
307 | | - |
308 | | - let actions = VersionOwnerAction::for_versions(&mut conn, &versions).await?; |
309 | | - |
310 | | - let versions = versions_and_publishers |
311 | | - .into_iter() |
312 | | - .zip(actions) |
313 | | - .map(|((version, krate_name, published_by), actions)| { |
314 | | - EncodableVersion::from(version, &krate_name.name, published_by, actions) |
315 | | - }) |
316 | | - .collect::<Vec<_>>(); |
317 | | - |
318 | | - Ok(json!({ |
319 | | - "dependencies": rev_deps, |
320 | | - "versions": versions, |
321 | | - "meta": { "total": total }, |
322 | | - })) |
323 | | -} |
0 commit comments