uEdition-Editor 2.0.0b21__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- uedition_editor-2.0.0b21/.gitignore +5 -0
- uedition_editor-2.0.0b21/.pre-commit-config.yaml +7 -0
- uedition_editor-2.0.0b21/Containerfile +16 -0
- uedition_editor-2.0.0b21/LICENSE.txt +9 -0
- uedition_editor-2.0.0b21/PKG-INFO +76 -0
- uedition_editor-2.0.0b21/README.md +39 -0
- uedition_editor-2.0.0b21/pyproject.toml +189 -0
- uedition_editor-2.0.0b21/uedition_editor/__about__.py +6 -0
- uedition_editor-2.0.0b21/uedition_editor/__init__.py +69 -0
- uedition_editor-2.0.0b21/uedition_editor/__main__.py +9 -0
- uedition_editor-2.0.0b21/uedition_editor/api/__init__.py +72 -0
- uedition_editor-2.0.0b21/uedition_editor/api/auth.py +208 -0
- uedition_editor-2.0.0b21/uedition_editor/api/branches.py +175 -0
- uedition_editor-2.0.0b21/uedition_editor/api/configs.py +86 -0
- uedition_editor-2.0.0b21/uedition_editor/api/files.py +861 -0
- uedition_editor-2.0.0b21/uedition_editor/api/tests.py +39 -0
- uedition_editor-2.0.0b21/uedition_editor/api/util.py +130 -0
- uedition_editor-2.0.0b21/uedition_editor/cli/__init__.py +38 -0
- uedition_editor-2.0.0b21/uedition_editor/cron.py +73 -0
- uedition_editor-2.0.0b21/uedition_editor/frontend/dist/assets/CodeMirrorEditor-BQ_2Br3R.js +30 -0
- uedition_editor-2.0.0b21/uedition_editor/frontend/dist/assets/CodeMirrorEditor-DUGUrxLC.css +1 -0
- uedition_editor-2.0.0b21/uedition_editor/frontend/dist/assets/FolderEditor-BoZKd6vE.js +1 -0
- uedition_editor-2.0.0b21/uedition_editor/frontend/dist/assets/ImageEditor-ByHNG8tf.js +1 -0
- uedition_editor-2.0.0b21/uedition_editor/frontend/dist/assets/PdfEditor-B2D-YWAt.js +1 -0
- uedition_editor-2.0.0b21/uedition_editor/frontend/dist/assets/TeiEditor-HM_a848_.js +103 -0
- uedition_editor-2.0.0b21/uedition_editor/frontend/dist/assets/index-B32uewzl.css +1 -0
- uedition_editor-2.0.0b21/uedition_editor/frontend/dist/assets/index-B5VZ1r-_.js +13 -0
- uedition_editor-2.0.0b21/uedition_editor/frontend/dist/assets/index-Vcq4gwWv.js +1 -0
- uedition_editor-2.0.0b21/uedition_editor/frontend/dist/index.html +17 -0
- uedition_editor-2.0.0b21/uedition_editor/frontend/dist/ueditor.svg +1 -0
- uedition_editor-2.0.0b21/uedition_editor/settings.py +516 -0
- uedition_editor-2.0.0b21/uedition_editor/state.py +7 -0
- uedition_editor-2.0.0b21/update_version.py +25 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
FROM python:3.13-bookworm
|
|
2
|
+
|
|
3
|
+
RUN useradd -u 1000 -g 100 -d /etc/ueditor -m ueditor
|
|
4
|
+
|
|
5
|
+
RUN apt-get update && \
|
|
6
|
+
apt-get dist-upgrade -y && \
|
|
7
|
+
apt-get install -y tini
|
|
8
|
+
|
|
9
|
+
COPY dist/*.whl /tmp/uedition-editor-source/
|
|
10
|
+
|
|
11
|
+
RUN pip install /tmp/uedition-editor-source/*.whl
|
|
12
|
+
|
|
13
|
+
USER ueditor
|
|
14
|
+
|
|
15
|
+
ENTRYPOINT ["/usr/bin/tini", "--"]
|
|
16
|
+
CMD [ "uvicorn", "--port", "8000", "--host", "0.0.0.0", "uedition_editor:app" ]
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present Mark Hall <mark.hall@work.room3b.eu>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: uEdition-Editor
|
|
3
|
+
Version: 2.0.0b21
|
|
4
|
+
Project-URL: Documentation, https://github.com/uEdition/uEditor#readme
|
|
5
|
+
Project-URL: Issues, https://github.com/uEdition/uEditor/issues
|
|
6
|
+
Project-URL: Source, https://github.com/uEdition/uEditor
|
|
7
|
+
Author-email: Mark Hall <mark.hall@work.room3b.eu>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE.txt
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Programming Language :: Python
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
16
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Requires-Dist: aiocron<3,>=2.1
|
|
19
|
+
Requires-Dist: fastapi<1
|
|
20
|
+
Requires-Dist: httptools<1
|
|
21
|
+
Requires-Dist: httpx<1,>=0.28.1
|
|
22
|
+
Requires-Dist: lxml<7,>=5
|
|
23
|
+
Requires-Dist: pydantic-settings<3,>=2
|
|
24
|
+
Requires-Dist: pydantic[email]<3,>=2
|
|
25
|
+
Requires-Dist: pygit2<2,>=1.17.0
|
|
26
|
+
Requires-Dist: pyjwt[crypto]<3,>=2.10.1
|
|
27
|
+
Requires-Dist: python-multipart<1,>=0.0.9
|
|
28
|
+
Requires-Dist: python-slugify<9,>=8.0.4
|
|
29
|
+
Requires-Dist: pyyaml-include<3,>=2
|
|
30
|
+
Requires-Dist: pyyaml<7,>=6
|
|
31
|
+
Requires-Dist: typer<1,>=0.15.1
|
|
32
|
+
Requires-Dist: uedition<2.1,>=2.0.0b5
|
|
33
|
+
Requires-Dist: uvicorn<1
|
|
34
|
+
Requires-Dist: uvloop<1
|
|
35
|
+
Requires-Dist: websockets<17,>=15
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# μEditor
|
|
39
|
+
|
|
40
|
+
[](https://pypi.org/project/uedition-editor)
|
|
41
|
+
[](https://pypi.org/project/uedition-editor)
|
|
42
|
+
[](https://github.com/uEdition/uEditor/actions/workflows/tests.yml)
|
|
43
|
+
[](https://github.com/uEdition/uEditor/actions/workflows/tests.yml)
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
**Table of Contents**
|
|
48
|
+
|
|
49
|
+
- [Installation](#installation)
|
|
50
|
+
- [Documentation](#documentation)
|
|
51
|
+
- [License](#license)
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
|
|
55
|
+
The simplest way to install the μEditor is using [pipx](https://github.com/pypa/pipx). Install pipx for your
|
|
56
|
+
operating system and then run the following command to install the μEditor:
|
|
57
|
+
|
|
58
|
+
```console
|
|
59
|
+
pipx install "uedition-editor>=2.0.0b2,<3"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Then run the following command to start the μEditor:
|
|
63
|
+
|
|
64
|
+
```console
|
|
65
|
+
UEDITOR__BASE_DIR=path/to/where/your/files/are ueditor server
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The μEditor is then available at http://localhost:8000.
|
|
69
|
+
|
|
70
|
+
## Documentation
|
|
71
|
+
|
|
72
|
+
Documentation to come soon.
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
`ueditor` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# μEditor
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/uedition-editor)
|
|
4
|
+
[](https://pypi.org/project/uedition-editor)
|
|
5
|
+
[](https://github.com/uEdition/uEditor/actions/workflows/tests.yml)
|
|
6
|
+
[](https://github.com/uEdition/uEditor/actions/workflows/tests.yml)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
**Table of Contents**
|
|
11
|
+
|
|
12
|
+
- [Installation](#installation)
|
|
13
|
+
- [Documentation](#documentation)
|
|
14
|
+
- [License](#license)
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
The simplest way to install the μEditor is using [pipx](https://github.com/pypa/pipx). Install pipx for your
|
|
19
|
+
operating system and then run the following command to install the μEditor:
|
|
20
|
+
|
|
21
|
+
```console
|
|
22
|
+
pipx install "uedition-editor>=2.0.0b2,<3"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Then run the following command to start the μEditor:
|
|
26
|
+
|
|
27
|
+
```console
|
|
28
|
+
UEDITOR__BASE_DIR=path/to/where/your/files/are ueditor server
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The μEditor is then available at http://localhost:8000.
|
|
32
|
+
|
|
33
|
+
## Documentation
|
|
34
|
+
|
|
35
|
+
Documentation to come soon.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
`ueditor` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling", "hatch-build-scripts"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "uEdition-Editor"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = ''
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
keywords = []
|
|
13
|
+
authors = [{ name = "Mark Hall", email = "mark.hall@work.room3b.eu" }]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Programming Language :: Python",
|
|
17
|
+
"Programming Language :: Python :: 3.11",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"Programming Language :: Python :: 3.13",
|
|
20
|
+
"Programming Language :: Python :: Implementation :: CPython",
|
|
21
|
+
"Programming Language :: Python :: Implementation :: PyPy",
|
|
22
|
+
]
|
|
23
|
+
dependencies = [
|
|
24
|
+
"aiocron>=2.1,<3",
|
|
25
|
+
"fastapi<1",
|
|
26
|
+
"httptools<1",
|
|
27
|
+
"httpx>=0.28.1,<1",
|
|
28
|
+
"lxml>=5,<7",
|
|
29
|
+
"pydantic[email]>=2,<3",
|
|
30
|
+
"pydantic_settings>=2,<3",
|
|
31
|
+
"pygit2>=1.17.0,<2",
|
|
32
|
+
"python-multipart>=0.0.9,<1",
|
|
33
|
+
"python-slugify>=8.0.4,<9",
|
|
34
|
+
"pyjwt[crypto]>=2.10.1,<3",
|
|
35
|
+
"PyYaml>=6,<7",
|
|
36
|
+
"pyyaml_include>=2,<3",
|
|
37
|
+
"uEdition>=2.0.0b5,<2.1",
|
|
38
|
+
"typer>=0.15.1,<1",
|
|
39
|
+
"uvicorn<1",
|
|
40
|
+
"uvloop<1",
|
|
41
|
+
"websockets>=15,<17",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[project.urls]
|
|
45
|
+
Documentation = "https://github.com/uEdition/uEditor#readme"
|
|
46
|
+
Issues = "https://github.com/uEdition/uEditor/issues"
|
|
47
|
+
Source = "https://github.com/uEdition/uEditor"
|
|
48
|
+
|
|
49
|
+
[project.scripts]
|
|
50
|
+
ueditor = "uedition_editor.cli:app"
|
|
51
|
+
|
|
52
|
+
[tool.hatch.version]
|
|
53
|
+
path = "uedition_editor/__about__.py"
|
|
54
|
+
|
|
55
|
+
[tool.hatch.build.targets.sdist]
|
|
56
|
+
artifacts = ["uedition_editor/frontend/dist/**/*"]
|
|
57
|
+
exclude = [
|
|
58
|
+
".github",
|
|
59
|
+
"dev",
|
|
60
|
+
"docs",
|
|
61
|
+
"tests",
|
|
62
|
+
".pre-config-config.yaml",
|
|
63
|
+
".readthedocs.yml",
|
|
64
|
+
"uedition_editor/frontend",
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
[tool.hatch.build.targets.wheel]
|
|
68
|
+
artifacts = ["uedition_editor/frontend/dist/**/*"]
|
|
69
|
+
exclude = [
|
|
70
|
+
".github",
|
|
71
|
+
"dev",
|
|
72
|
+
"docs",
|
|
73
|
+
"tests",
|
|
74
|
+
".pre-config-config.yaml",
|
|
75
|
+
".readthedocs.yml",
|
|
76
|
+
"uedition_editor/frontend",
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
[[tool.hatch.build.hooks.build-scripts.scripts]]
|
|
80
|
+
artifacts = []
|
|
81
|
+
commands = ["npm ci", "npm run build"]
|
|
82
|
+
work_dir = "uedition_editor/frontend"
|
|
83
|
+
out_dir = "tmp"
|
|
84
|
+
|
|
85
|
+
[tool.hatch.envs.default]
|
|
86
|
+
extra-dependencies = ["coverage[toml]>=6.5", "httpx", "pytest", "ruff==0.9.5"]
|
|
87
|
+
|
|
88
|
+
[tool.hatch.envs.default.scripts]
|
|
89
|
+
server = "uvicorn --reload --port 8000 uedition_editor:app {args}"
|
|
90
|
+
frontend-server = "cd uedition_editor/frontend && npm install && vite"
|
|
91
|
+
build-frontend = "cd uedition_editor/frontend && npm install && vite build"
|
|
92
|
+
|
|
93
|
+
# Test commands
|
|
94
|
+
e2e-tests = "cd tests/e2e_tests && UEDITOR__BASE_PATH=./tmp_fixtures UEDITOR__TEST=true UEDITOR__AUTH__PROVIDER=no-auth UEDITOR__AUTH__EMAIL= UEDITOR__AUTH__NAME= npx playwright test"
|
|
95
|
+
test = "UEDITOR__BASE_PATH=./tmp_fixtures UEDITOR__TEST=true UEDITOR__AUTH__PROVIDER=no-auth UEDITOR__AUTH__EMAIL= UEDITOR__AUTH__NAME= pytest {args:tests}"
|
|
96
|
+
test-cov = "UEDITOR__BASE_PATH=./tmp_fixtures UEDITOR__TEST=true UEDITOR__AUTH__PROVIDER=no-auth UEDITOR__AUTH__EMAIL= UEDITOR__AUTH__NAME= coverage run -m pytest {args:tests}"
|
|
97
|
+
cov-report = ["- coverage combine", "coverage report"]
|
|
98
|
+
cov = ["test-cov", "cov-report"]
|
|
99
|
+
|
|
100
|
+
# Style commands
|
|
101
|
+
style = [
|
|
102
|
+
"ruff check --fix --exit-non-zero-on-fix {args:.}",
|
|
103
|
+
"ruff format --check {args:.}",
|
|
104
|
+
]
|
|
105
|
+
|
|
106
|
+
# Release commands
|
|
107
|
+
update-version = "hatch run python update_version.py"
|
|
108
|
+
|
|
109
|
+
[tool.ruff]
|
|
110
|
+
target-version = "py37"
|
|
111
|
+
line-length = 120
|
|
112
|
+
|
|
113
|
+
[tool.ruff.lint]
|
|
114
|
+
select = [
|
|
115
|
+
"A",
|
|
116
|
+
"ARG",
|
|
117
|
+
"B",
|
|
118
|
+
"C",
|
|
119
|
+
"D",
|
|
120
|
+
"DTZ",
|
|
121
|
+
"E",
|
|
122
|
+
"EM",
|
|
123
|
+
"F",
|
|
124
|
+
"FBT",
|
|
125
|
+
"I",
|
|
126
|
+
"ICN",
|
|
127
|
+
"ISC",
|
|
128
|
+
"N",
|
|
129
|
+
"PLC",
|
|
130
|
+
"PLE",
|
|
131
|
+
"PLR",
|
|
132
|
+
"PLW",
|
|
133
|
+
"Q",
|
|
134
|
+
"RUF",
|
|
135
|
+
"S",
|
|
136
|
+
"T",
|
|
137
|
+
"TID",
|
|
138
|
+
"UP",
|
|
139
|
+
"W",
|
|
140
|
+
"YTT",
|
|
141
|
+
]
|
|
142
|
+
ignore = [
|
|
143
|
+
# Allow non-abstract empty methods in abstract base classes
|
|
144
|
+
"B027",
|
|
145
|
+
# Allow boolean positional values in function calls, like `dict.get(... True)`
|
|
146
|
+
"FBT003",
|
|
147
|
+
# Ignore checks for possible passwords
|
|
148
|
+
"S105",
|
|
149
|
+
"S106",
|
|
150
|
+
"S107",
|
|
151
|
+
# Ignore complexity
|
|
152
|
+
"C901",
|
|
153
|
+
"PLR0911",
|
|
154
|
+
"PLR0912",
|
|
155
|
+
"PLR0913",
|
|
156
|
+
"PLR0915",
|
|
157
|
+
# Pydocstyle settings
|
|
158
|
+
"D203",
|
|
159
|
+
"D212",
|
|
160
|
+
]
|
|
161
|
+
unfixable = [
|
|
162
|
+
# Don't touch unused imports
|
|
163
|
+
"F401",
|
|
164
|
+
]
|
|
165
|
+
|
|
166
|
+
[tool.ruff.lint.isort]
|
|
167
|
+
known-first-party = ["uedition_editor"]
|
|
168
|
+
|
|
169
|
+
[tool.ruff.lint.flake8-tidy-imports]
|
|
170
|
+
ban-relative-imports = "all"
|
|
171
|
+
|
|
172
|
+
[tool.ruff.lint.per-file-ignores]
|
|
173
|
+
# Tests can use magic values, assertions, and relative imports
|
|
174
|
+
"tests/**/*" = ["PLR2004", "S101", "TID252"]
|
|
175
|
+
|
|
176
|
+
[tool.coverage.run]
|
|
177
|
+
source_pkgs = ["uedition_editor"]
|
|
178
|
+
branch = true
|
|
179
|
+
parallel = true
|
|
180
|
+
omit = ["uedition_editor/__about__.py"]
|
|
181
|
+
|
|
182
|
+
[tool.coverage.paths]
|
|
183
|
+
uedition_editor = ["uedition_editor", "*/uedition_editor/uedition_editor"]
|
|
184
|
+
tests = ["tests", "*/uedition_editor/tests"]
|
|
185
|
+
|
|
186
|
+
[tool.coverage.report]
|
|
187
|
+
exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"]
|
|
188
|
+
skip_covered = true
|
|
189
|
+
show_missing = true
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2024-present Mark Hall <mark.hall@work.room3b.eu>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""The main uEditor server."""
|
|
5
|
+
|
|
6
|
+
import logging
|
|
7
|
+
from contextlib import asynccontextmanager
|
|
8
|
+
from copy import deepcopy
|
|
9
|
+
|
|
10
|
+
from fastapi import FastAPI
|
|
11
|
+
from fastapi.exceptions import HTTPException
|
|
12
|
+
from fastapi.responses import RedirectResponse, Response
|
|
13
|
+
from fastapi.staticfiles import StaticFiles
|
|
14
|
+
from httpx import AsyncClient
|
|
15
|
+
from uvicorn.config import LOGGING_CONFIG
|
|
16
|
+
|
|
17
|
+
from uedition_editor import cron
|
|
18
|
+
from uedition_editor.api import router as api_router
|
|
19
|
+
from uedition_editor.settings import init_settings
|
|
20
|
+
|
|
21
|
+
logger = logging.getLogger(__name__)
|
|
22
|
+
# Configure logging
|
|
23
|
+
conf = deepcopy(LOGGING_CONFIG)
|
|
24
|
+
conf["loggers"]["uedition_editor"] = {
|
|
25
|
+
"level": logging.INFO,
|
|
26
|
+
"qualname": "uedition_editor",
|
|
27
|
+
"handlers": ["default"],
|
|
28
|
+
}
|
|
29
|
+
conf["formatters"]["default"]["fmt"] = "%(levelprefix)s %(name)-40s %(message)s"
|
|
30
|
+
conf["root"] = {"level": logging.INFO}
|
|
31
|
+
if init_settings.test: # pragma: no cover
|
|
32
|
+
conf["loggers"]["uedition_editor"]["level"] = logging.DEBUG
|
|
33
|
+
logging.config.dictConfig(conf)
|
|
34
|
+
logger.debug("Logging configuration set up")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@asynccontextmanager
|
|
38
|
+
async def lifespan(app: FastAPI): # noqa:ARG001
|
|
39
|
+
"""Startup/shutdown handler."""
|
|
40
|
+
await cron.track_branches.func()
|
|
41
|
+
yield
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
app = FastAPI(lifespan=lifespan)
|
|
45
|
+
app.include_router(api_router)
|
|
46
|
+
|
|
47
|
+
if init_settings.dev:
|
|
48
|
+
|
|
49
|
+
@app.get("/app/{path:path}")
|
|
50
|
+
async def ui_dev(path: str):
|
|
51
|
+
"""Proxy the development frontend server."""
|
|
52
|
+
async with AsyncClient() as client:
|
|
53
|
+
response = await client.get(f"http://localhost:5173/app/{path}")
|
|
54
|
+
if response.status_code == 200: # noqa:PLR2004
|
|
55
|
+
return Response(content=response.content, media_type=response.headers["Content-Type"])
|
|
56
|
+
else:
|
|
57
|
+
raise HTTPException(response.status_code)
|
|
58
|
+
|
|
59
|
+
else:
|
|
60
|
+
app.mount("/app", StaticFiles(packages=[("uedition_editor", "frontend/dist")], html=True))
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@app.get("/", response_class=RedirectResponse)
|
|
64
|
+
def redirect_to_app(timestamp: int | None = None):
|
|
65
|
+
"""Redirect to the application UI."""
|
|
66
|
+
if timestamp is not None:
|
|
67
|
+
return f"/app/?timestamp={timestamp}"
|
|
68
|
+
else:
|
|
69
|
+
return "/app/"
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2024-present Mark Hall <mark.hall@work.room3b.eu>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""The uEditor server API."""
|
|
5
|
+
|
|
6
|
+
from typing import Literal
|
|
7
|
+
|
|
8
|
+
from fastapi import APIRouter
|
|
9
|
+
from pydantic import BaseModel
|
|
10
|
+
from pygit2 import GitError, Repository
|
|
11
|
+
from pygit2.enums import RepositoryOpenFlag
|
|
12
|
+
|
|
13
|
+
from uedition_editor.__about__ import __version__
|
|
14
|
+
from uedition_editor.api.auth import router as auth_router
|
|
15
|
+
from uedition_editor.api.branches import router as branches_router
|
|
16
|
+
from uedition_editor.settings import init_settings
|
|
17
|
+
|
|
18
|
+
router = APIRouter(prefix="/api")
|
|
19
|
+
router.include_router(auth_router)
|
|
20
|
+
router.include_router(branches_router)
|
|
21
|
+
if init_settings.test: # pragma: no cover
|
|
22
|
+
from uedition_editor.api.tests import router as tests_router
|
|
23
|
+
|
|
24
|
+
router.include_router(tests_router)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class APIStatusAuth(BaseModel):
|
|
28
|
+
"""Pydantic model for validating the auth settings."""
|
|
29
|
+
|
|
30
|
+
provider: Literal["no-auth"] | Literal["email"] | Literal["email-password"] | Literal["github"]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class APIStatusGit(BaseModel):
|
|
34
|
+
"""Pydantic model for validating the git API status."""
|
|
35
|
+
|
|
36
|
+
enabled: bool
|
|
37
|
+
default_branch: str | None = None
|
|
38
|
+
protect_default_branch: bool | None = None
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class APIStatus(BaseModel):
|
|
42
|
+
"""Pydantic model for validating the API status."""
|
|
43
|
+
|
|
44
|
+
ready: bool
|
|
45
|
+
"""Indicate whether the API is ready."""
|
|
46
|
+
git: APIStatusGit
|
|
47
|
+
"""Indicate the Git status."""
|
|
48
|
+
auth: APIStatusAuth
|
|
49
|
+
"""Indicate the authentication system status."""
|
|
50
|
+
version: str
|
|
51
|
+
"""The backend API version."""
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@router.get("", response_model=APIStatus)
|
|
55
|
+
def api() -> dict:
|
|
56
|
+
"""Return the status of the API."""
|
|
57
|
+
api_status = {
|
|
58
|
+
"ready": True,
|
|
59
|
+
"git": {
|
|
60
|
+
"enabled": False,
|
|
61
|
+
},
|
|
62
|
+
"auth": {"provider": init_settings.auth.provider},
|
|
63
|
+
"version": __version__,
|
|
64
|
+
}
|
|
65
|
+
try:
|
|
66
|
+
Repository(init_settings.base_path, flags=RepositoryOpenFlag.NO_SEARCH)
|
|
67
|
+
api_status["git"]["enabled"] = True
|
|
68
|
+
api_status["git"]["default_branch"] = init_settings.git.default_branch
|
|
69
|
+
api_status["git"]["protect_default_branch"] = init_settings.git.protect_default_branch
|
|
70
|
+
except GitError:
|
|
71
|
+
pass
|
|
72
|
+
return api_status
|