feat(lists): adds redirector data format
This commit is contained in:
parent
c16a80dc16
commit
60255afe3f
8 changed files with 117 additions and 4 deletions
|
@ -13,6 +13,7 @@ from app.extensions import db
|
|||
from app.lists.bc2 import mirror_sites
|
||||
from app.lists.bridgelines import bridgelines
|
||||
from app.lists.mirror_mapping import mirror_mapping
|
||||
from app.lists.redirector import redirector_data
|
||||
from app.models.base import MirrorList, Pool
|
||||
from app.portal.util import response_404, view_lifecycle
|
||||
|
||||
|
@ -63,6 +64,8 @@ def list_preview(format_: str, pool_id: int) -> ResponseReturnValue:
|
|||
return Response(json.dumps(mirror_sites(pool)), content_type="application/json")
|
||||
if format_ == "bridgelines":
|
||||
return Response(json.dumps(bridgelines(pool)), content_type="application/json")
|
||||
if format_ == "rdr":
|
||||
return Response(json.dumps(redirector_data(pool)), content_type="application/json")
|
||||
return response_404(message="Format not found")
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import secrets
|
||||
from datetime import datetime
|
||||
|
||||
from flask import render_template, url_for, flash, redirect, Response, Blueprint
|
||||
|
@ -22,6 +23,8 @@ class NewPoolForm(FlaskForm): # type: ignore[misc]
|
|||
|
||||
class EditPoolForm(FlaskForm): # type: ignore[misc]
|
||||
description = StringField("Description", validators=[DataRequired()])
|
||||
api_key = StringField("API Key", description=("Any change to this field (e.g. clearing it) will result in the "
|
||||
"API key being regenerated."))
|
||||
submit = SubmitField('Save Changes', render_kw={"class": "btn btn-success"})
|
||||
|
||||
|
||||
|
@ -48,6 +51,7 @@ def pool_new() -> ResponseReturnValue:
|
|||
pool = Pool()
|
||||
pool.pool_name = form.group_name.data
|
||||
pool.description = form.description.data
|
||||
pool.api_key = secrets.token_urlsafe(nbytes=32)
|
||||
pool.created = datetime.utcnow()
|
||||
pool.updated = datetime.utcnow()
|
||||
try:
|
||||
|
@ -70,9 +74,13 @@ def pool_edit(pool_id: int) -> ResponseReturnValue:
|
|||
header="404 Pool Not Found",
|
||||
message="The requested pool could not be found."),
|
||||
status=404)
|
||||
form = EditPoolForm(description=pool.description)
|
||||
form = EditPoolForm(description=pool.description,
|
||||
api_key=pool.api_key)
|
||||
if form.validate_on_submit():
|
||||
pool.description = form.description.data
|
||||
if form.api_key.data != pool.api_key:
|
||||
pool.api_key = secrets.token_urlsafe(nbytes=32)
|
||||
form.api_key.data = pool.api_key
|
||||
pool.updated = datetime.utcnow()
|
||||
try:
|
||||
db.session.commit()
|
||||
|
|
|
@ -367,7 +367,9 @@
|
|||
<tr>
|
||||
<td>{{ pool.pool_name }}</td>
|
||||
<td>{{ pool.description }}</td>
|
||||
<td><a href="{{ url_for("portal.pool.pool_edit", pool_id=pool.id) }}" class="btn btn-primary btn-sm">View/Edit</a></td>
|
||||
<td><a href="{{ url_for("portal.pool.pool_edit", pool_id=pool.id) }}" class="btn btn-primary btn-sm">View/Edit</a>
|
||||
<a href="javascript:navigator.clipboard.writeText('{{ pool.api_key }}');"
|
||||
class="btn btn-sm btn-outline-dark">Copy API key</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue