flams/endpoints.rs
1#![allow(rustdoc::private_intra_doc_links)]
2#![allow(unused_imports)]
3/*!
4 *
5 * # Public API Endpoints
6 *
7 * ## Encoding
8 *
9 * **POST** requests have their arguments `application/x-www-form-urlencoded`-encoded, unless otherwise
10 * specified.
11 *
12 * **GET** requests have their arguments url-encoded. Endpoints that take a
13 * (particular kind of) [URI] have those represented via the following encoding:
14 * - Either `uri=<STRING>` ( a full [URI]), or
15 * - `a=<STRING>&rp=<STRING>` (an [ArchiveId] and a relative path to a source file in the archive including file extension)
16 * can be used for [DocumentURI]s, or
17 * - the [URI] components with relevant argument names; e.g. for a [DocumentURI]:
18 * `?a=<STRING>[&p=<STRING>]&l=<LANGUAGE>&d=<NAME>`.
19 *
20 * ## Endpoints
21 *
22 * | Path | GET/POST | Arguments | Description / Return Value |
23 * | ------------ | --- | --------- | ----------- |
24 * | [`/api/index`](backend::index()) | POST | (None) | |
25 * | [`/api/settings`](server_fns::settings) | POST | (None) | [Settings](SettingsSpec) (requires admin login) |
26 * | [`/api/reload`](server_fns::reload) | POST | (None) | (requires admin login) |
27 * | [`/api/login`](login) | POST | `username=<STRING>`, `password=<STRING>` | log in |
28 * | [`/api/login_state`](login_state) | POST | (None) | [LoginState] |
29 * | [`/api/search`](search::search_query) | POST | `query=<STRING>&opts=`[`QueryFilter`](flams_ontology::search::QueryFilter)`&num_results=<INT>` | `Vec<(<FLOAT>,`[`SearchResult`](flams_ontology::search::SearchResult)`)>` |
30 * | [`/api/search_symbols`](search::search_symbols) | POST | `query=<STRING>&num_results=<INT>` | `Vec<(`[`SymbolURI`]`Vec<(<FLOAT>,`[`SearchResult`](flams_ontology::search::SearchResult)`)>)>` |
31 * | [`/content/grade`](content::grade()) | POST | TODO |
32 * | [`/content/grade_enc`](content::grade_enc()) | POST | TODO |
33 * | `/gitlab_login` | POST | | |
34 * | **Backend** | | | |
35 * | [`/api/backend/group_entries`](backend::group_entries) | POST | (optional) `in=<STRING>` | `(Vec<`[ArchiveGroupData](crate::router::backend::ArchiveGroupData)`>,Vec<`[ArchiveData](crate::router::backend::ArchiveData)`>)` - the archives and archive groups in the provided archive group (if given) or on the top-level (if None) |
36 * | [`/api/backend/archive_entries`](backend::archive_entries) | POST | `archive=<STRING>`, (optional) `path=<STRING>` | `(Vec<`[DirectoryData](crate::router::backend::DirectoryData)`>,Vec<`[FileData](crate::router::backend::FileData)`>)` - the source directories and files in the provided archive, or (if given) the relative path within the provided archive |
37 * | [`/api/backend/build_status`](backend::build_status) | POST | `archive=<STRING>`, (optional) `path=<STRING>` | [FileStates](crate::router::backend::FileStates) - the build status of the provided archive, or (if given) the relative path within the provided archive (requires admin login) |
38 * | [`/api/backend/query`](query_api) | `query=<STRING>` | POST | `STRING` - SPARQL query endpoint; returns SPARQL JSON |
39 * | [`/api/backend/archive_dependencies`](backend::archive_dependencies) | POST | `archives=Vec<STRING>` | `Vec<`[`ArchiveId`]`>` |
40 * | [`/api/backend/source_file`](backend::source_file) | POST | [URI] | `STRING` - Returns the git URL of the source file for the given URL |
41 * | **Build Queue** | | |
42 * | [`/api/buildqueue/enqueue`](buildqueue::enqueue) | POST | `archive=<STRING>`, `target=<`[FormatOrTarget](crate::router::backend::FormatOrTarget)`>`, (optional) `path=STRING`, (optional) `stale_only=<BOOL>` (default:true) | `usize` - enqueue a new build job. Returns number of jobs queued (requires admin login)|
43 * | [`/api/buildqueue/get_queues`](buildqueue::get_queues) | POST | | `Vec<(NonZeroU32,String)>` - return the list of all (waiting or running) build queues as (id,name) pairs (requires admin login)|
44 * | [`/api/buildqueue/run`](buildqueue::run) | POST | `id=<NonZeroU32>` | runs the build queue with the given id (requires admin login)|
45 * | [`/api/buildqueue/requeue`](buildqueue::requeue) | POST | `id=<NonZeroU32>` | requeues failed tasks in the queue with the given id (requires admin login)|
46 * | [`/api/buildqueue/log`](buildqueue::get_log) | POST | `archive=<STRING>`, `rel_path=<STRING>`, `target=<STRING>` | returns the log of the stated build job (requires admin login)|
47 * | [`/api/buildqueue/migrate`](buildqueue::migrate) | POST | `id=<NonZeroU32>` | |
48 * | [`/api/buildqueue/delete`](buildqueue::delete) | POST | `id=<NonZeroU32>` | |
49 * | **Git** | | |
50 * | [`/api/gitlab/get_archives`](git::get_archives) | POST | | - returns the list of GitLab projects |
51 * | [`/api/gitlab/get_branches`](git::get_branches) | POST | `id=<u64>` | `Vec<`[`Branch`](flams_git::Branch)`>` - returns the list of branches for the given GitLab project |
52 * | [`/api/gitlab/get_new_commits`](git::get_new_commit) | POST | `queue=<u64>&id=ArchiveId` | `Vec<`(String,`[`Commit`](flams_git::Commit)`)`>` |
53 * | | **Web Sockets** | | |
54 * | [`/ws/log`](crate::router::logging::LogSocket) | | | |
55 * | [`/ws/queue`](crate::router::buildqueue::QueueSocket) | | | |
56 * | **Content** | | | |
57 * | [`/img`](img_handler) | GET | `kpse=<STRING>` or `file=<STRING>` (LSP only) or `a=<ArchiveID>&rp=<STRING>` | Images |
58 * | [`/content/document`](content::document) | GET | [DocumentURI] | `(`[DocumentURI],`Vec<`[CSS]`>,String)` Returns a pair of CSS rules and the full body of the HTML for the given document (with the `<body>` node replaced by a `<div>`, but preserving all attributes/classes) |
59 * | [`/content/fragment`](content::fragment) | GET | [URI]`[&context=`[URI]`]` | `(`[URI]`,Vec<`[CSS]`>,String)` Returns a pair of CSS rules and the HTML fragment representing the given element; i.e. the inner HTML of a document (for inputrefs), the HTML of a semantic paragraph, etc. |
60 * | [`/content/title`](content::title) | GET | [URI] | `(Vec<`[CSS]`>,String)` Returns a pair of CSS rules and the HTML title of the given element |
61 * | [`/content/omdoc`](content::omdoc) | GET | [URI] | [`AnySpec`] Returns the structural representation of the OMDoc content at the given URI |
62 * | [`/content/toc`](content::toc()) | GET | [DocumentURI] | `(Vec<`[CSS]`>,Vec<`[TOCElem]`>)` Returns a pair of CSS rules and the table of contents of the given document, including section titles |
63 * | [`/content/los`](content::los()) | GET | [SymbolURI] | `(Vec<(`[DocumentElementURI]`,`[LOKind]`)>` Returns a list of all Learning Objects for the given symbol |
64 * | [`/content/notations`](content::notations()) | GET | [SymbolURI] | `(Vec<(`[DocumentElementURI]`,`[Notation]`)>` Returns a list of all Notations for the given symbol or variable |
65 * | [`/content/solution`](content::solution()) | GET | [DocumentElementURI] | [`Solutions`](flams_ontology::narration::problems::Solutions) |
66 * | [`/content/quiz`](content::get_quiz()) | GET | [DocumentURI] | [`Quiz`](flams_ontology::narration::problems::Quiz) |
67 * | [`/content/slides`](content::slides_view()) | GET | [DocumentURI] or [DocumentElementURI] | `(Vec<CSS>,Vec<SlideElement>)` |
68 * | [`/content/legacy/uris`](content::uris()) | GET | | |
69*/
70
71use crate::server::files::img_handler;
72
73use flams_ontology::{
74 narration::{notations::Notation, LOKind},
75 uris::*,
76};
77use flams_router_dashboard::{
78 server_fns::{
79 self, backend, buildqueue, content, git,search,
80 login::{login, login_state},
81 },
82 LoginState,
83 query::query_api
84};
85use flams_utils::{settings::SettingsSpec, CSS};
86use ftml_viewer_components::components::{omdoc::OMDoc, TOCElem};