Add forum_url to API, change to forum.luanti.org

This commit is contained in:
rubenwardy 2024-11-03 14:20:14 +00:00
parent dd2e73b40f
commit a54104aa82
20 changed files with 31 additions and 27 deletions

@ -77,7 +77,7 @@ def claim_forums():
# Get signature # Get signature
try: try:
profile = get_profile("https://forum.minetest.net", username) profile = get_profile("https://forum.luanti.org", username)
sig = profile.signature if profile else None sig = profile.signature if profile else None
except IOError as e: except IOError as e:
if hasattr(e, 'message'): if hasattr(e, 'message'):

@ -78,6 +78,9 @@ curl -X DELETE https://content.luanti.org/api/delete-token/ \
* GET `/api/packages/` (List) * GET `/api/packages/` (List)
* See [Package Queries](#package-queries) * See [Package Queries](#package-queries)
* GET `/api/packages/<username>/<name>/` (Read) * GET `/api/packages/<username>/<name>/` (Read)
* Redirects a JSON object with the keys documented by the PUT endpoint, below.
* Plus:
* `forum_url`: String or null.
* PUT `/api/packages/<author>/<name>/` (Update) * PUT `/api/packages/<author>/<name>/` (Update)
* Requires authentication. * Requires authentication.
* JSON object with any of these keys (all are optional, null to delete Nullables): * JSON object with any of these keys (all are optional, null to delete Nullables):

@ -158,7 +158,7 @@ class ForumTopic(db.Model):
@property @property
def url(self): def url(self):
return "https://forum.minetest.net/viewtopic.php?t=" + str(self.topic_id) return "https://forum.luanti.org/viewtopic.php?t=" + str(self.topic_id)
def get_repo_url(self): def get_repo_url(self):
if self.link is None: if self.link is None:

@ -457,7 +457,7 @@ class Package(db.Model):
if self.forums is None: if self.forums is None:
return None return None
return "https://forum.minetest.net/viewtopic.php?t=" + str(self.forums) return "https://forum.luanti.org/viewtopic.php?t=" + str(self.forums)
enable_game_support_detection = db.Column(db.Boolean, nullable=False, default=True) enable_game_support_detection = db.Column(db.Boolean, nullable=False, default=True)
@ -679,6 +679,7 @@ class Package(db.Model):
"website": self.website, "website": self.website,
"issue_tracker": self.issueTracker, "issue_tracker": self.issueTracker,
"forums": self.forums, "forums": self.forums,
"forum_url": self.forums_url,
"video_url": self.video_url, "video_url": self.video_url,
"video_thumbnail_url": self.get_video_thumbnail_url(True), "video_thumbnail_url": self.get_video_thumbnail_url(True),
"donate_url": self.donate_url_actual, "donate_url": self.donate_url_actual,

@ -26,7 +26,7 @@ window.addEventListener("load", () => {
try { try {
const pasteData = e.clipboardData.getData('text'); const pasteData = e.clipboardData.getData('text');
const url = new URL(pasteData); const url = new URL(pasteData);
if (url.hostname === "forum.minetest.net") { if (url.hostname === "forum.luanti.org") {
forumsField.value = url.searchParams.get("t"); forumsField.value = url.searchParams.get("t");
e.preventDefault(); e.preventDefault();
} }
@ -37,7 +37,7 @@ window.addEventListener("load", () => {
const openForums = document.getElementById("forums-button"); const openForums = document.getElementById("forums-button");
openForums.addEventListener("click", () => { openForums.addEventListener("click", () => {
window.open("https://forum.minetest.net/viewtopic.php?t=" + forumsField.value, "_blank"); window.open("https://forum.luanti.org/viewtopic.php?t=" + forumsField.value, "_blank");
}); });
function setupHints(id, hints) { function setupHints(id, hints) {

@ -57,7 +57,7 @@ def _get_or_create_user(forums_username: str, cache: Optional[dict] = None) -> O
def check_forum_account(forums_username, force_replace_pic=False): def check_forum_account(forums_username, force_replace_pic=False):
print("### Checking " + forums_username, file=sys.stderr) print("### Checking " + forums_username, file=sys.stderr)
try: try:
profile = get_profile("https://forum.minetest.net", forums_username) profile = get_profile("https://forum.luanti.org", forums_username)
except OSError as e: except OSError as e:
print(e, file=sys.stderr) print(e, file=sys.stderr)
return return
@ -88,13 +88,13 @@ def check_forum_account(forums_username, force_replace_pic=False):
db.session.commit() db.session.commit()
if pic: if pic:
pic = urljoin("https://forum.minetest.net/", pic) pic = urljoin("https://forum.luanti.org/", pic)
print(f"####### Picture: {pic}", file=sys.stderr) print(f"####### Picture: {pic}", file=sys.stderr)
print(f"####### User pp {user.profile_pic}", file=sys.stderr) print(f"####### User pp {user.profile_pic}", file=sys.stderr)
pic_needs_replacing = user.profile_pic is None or user.profile_pic == "" or \ pic_needs_replacing = user.profile_pic is None or user.profile_pic == "" or \
user.profile_pic.startswith("https://forum.minetest.net") or force_replace_pic user.profile_pic.startswith("https://forum.luanti.org") or force_replace_pic
if pic_needs_replacing and pic.startswith("https://forum.minetest.net"): if pic_needs_replacing and pic.startswith("https://forum.luanti.org"):
print(f"####### Queueing", file=sys.stderr) print(f"####### Queueing", file=sys.stderr)
set_profile_picture_from_url.delay(user.username, pic) set_profile_picture_from_url.delay(user.username, pic)

@ -45,7 +45,7 @@ def update_package_scores():
def desc_contains(desc: str, search_str: str): def desc_contains(desc: str, search_str: str):
if search_str.startswith("https://forum.minetest.net/viewtopic.php?%t="): if search_str.startswith("https://forum.luanti.org/viewtopic.php?%t="):
reg = re.compile(search_str.replace(".", "\\.").replace("/", "\\/").replace("?", "\\?").replace("%", ".*")) reg = re.compile(search_str.replace(".", "\\.").replace("/", "\\/").replace("?", "\\?").replace("%", ".*"))
return reg.search(desc) return reg.search(desc)
else: else:
@ -58,7 +58,7 @@ def notify_about_git_forum_links():
.filter(Package.repo.is_not(None), Package.state == PackageState.APPROVED).all()] .filter(Package.repo.is_not(None), Package.state == PackageState.APPROVED).all()]
for pair in db.session.query(Package, Package.forums) \ for pair in db.session.query(Package, Package.forums) \
.filter(Package.forums.is_not(None), Package.state == PackageState.APPROVED).all(): .filter(Package.forums.is_not(None), Package.state == PackageState.APPROVED).all():
package_links.append((pair[0], f"https://forum.minetest.net/viewtopic.php?%t={pair[1]}")) package_links.append((pair[0], f"https://forum.luanti.org/viewtopic.php?%t={pair[1]}"))
clauses = [and_(Package.id != pair[0].id, Package.desc.ilike(f"%{pair[1]}%")) for pair in package_links] clauses = [and_(Package.id != pair[0].id, Package.desc.ilike(f"%{pair[1]}%")) for pair in package_links]
packages = Package.query.filter(Package.desc != "", Package.desc.is_not(None), Package.state == PackageState.APPROVED, or_(*clauses)).all() packages = Package.query.filter(Package.desc != "", Package.desc.is_not(None), Package.state == PackageState.APPROVED, or_(*clauses)).all()

@ -14,7 +14,7 @@
[{{ topic.type.text }}] [{{ topic.type.text }}]
</td> </td>
<td> <td>
<a href="https://forum.minetest.net/viewtopic.php?t={{ topic.topic_id}}">{{ topic.title }}</a> <a href="https://forum.luanti.org/viewtopic.php?t={{ topic.topic_id}}">{{ topic.title }}</a>
{% if topic.wip %}[{{ _("WIP") }}]{% endif %} {% if topic.wip %}[{{ _("WIP") }}]{% endif %}
</td> </td>
{% if show_author %} {% if show_author %}
@ -42,7 +42,7 @@
{% macro render_topics(topics, current_user) -%} {% macro render_topics(topics, current_user) -%}
<div class="list-group"> <div class="list-group">
{% for topic in topics %} {% for topic in topics %}
<a class="list-group-item list-group-item-action" href="https://forum.minetest.net/viewtopic.php?t={{ topic.topic_id}}"> <a class="list-group-item list-group-item-action" href="https://forum.luanti.org/viewtopic.php?t={{ topic.topic_id}}">
<span class="float-end text-muted"> <span class="float-end text-muted">
{{ topic.created_at | date }} {{ topic.created_at | date }}
</span> </span>

@ -23,7 +23,7 @@
{% for t in similar_topics %} {% for t in similar_topics %}
<li> <li>
[{{ t.type.text }}] [{{ t.type.text }}]
<a href="https://forum.minetest.net/viewtopic.php?t={{ t.topic_id }}"> <a href="https://forum.luanti.org/viewtopic.php?t={{ t.topic_id }}">
{{ _("%(title)s by %(display_name)s", title=t.title, display_name=t.author.display_name) }} {{ _("%(title)s by %(display_name)s", title=t.title, display_name=t.author.display_name) }}
</a> </a>
{% if t.wip %}[{{ _("WIP") }}]{% endif %} {% if t.wip %}[{{ _("WIP") }}]{% endif %}

@ -137,7 +137,7 @@
{{ render_field(form.issueTracker, class_="pkg_meta", hint=_("Where should users report issues?")) }} {{ render_field(form.issueTracker, class_="pkg_meta", hint=_("Where should users report issues?")) }}
{{ render_field_prefix_button(form.forums, class_="pkg_meta", {{ render_field_prefix_button(form.forums, class_="pkg_meta",
pattern="[0-9]+", pattern="[0-9]+",
prefix="forum.minetest.net/viewtopic.php?t=", prefix="forum.luanti.org/viewtopic.php?t=",
placeholder=_("Paste a forum topic URL"), placeholder=_("Paste a forum topic URL"),
has_view=True) }} has_view=True) }}
{{ render_field(form.video_url, class_="pkg_meta", hint=_("YouTube videos will be shown in an embed.")) }} {{ render_field(form.video_url, class_="pkg_meta", hint=_("YouTube videos will be shown in an embed.")) }}

@ -34,7 +34,7 @@
{% for t in similar_topics %} {% for t in similar_topics %}
<li> <li>
[{{ t.type.value }}] [{{ t.type.value }}]
<a href="https://forum.minetest.net/viewtopic.php?t={{ t.topic_id }}"> <a href="https://forum.luanti.org/viewtopic.php?t={{ t.topic_id }}">
{{ _("%(title)s by %(display_name)s", title=t.title, display_name=t.author.display_name) }} {{ _("%(title)s by %(display_name)s", title=t.title, display_name=t.author.display_name) }}
</a> </a>
{% if t.wip %}[{{ _("WIP") }}]{% endif %} {% if t.wip %}[{{ _("WIP") }}]{% endif %}

@ -5,7 +5,7 @@
{% endblock %} {% endblock %}
{% block ruben_link %} {% block ruben_link %}
<a href="https://forum.minetest.net/ucp.php?i=pm&mode=compose&u=2051">rubenwardy</a> <a href="https://forum.luanti.org/ucp.php?i=pm&mode=compose&u=2051">rubenwardy</a>
{% endblock %} {% endblock %}
{% block pane %} {% block pane %}
@ -36,7 +36,7 @@
<td>Forums</td> <td>Forums</td>
<td> <td>
{% if user.forums_username %} {% if user.forums_username %}
<a href="https://forum.minetest.net/memberlist.php?mode=viewprofile&un={{ user.forums_username }}"> <a href="https://forum.luanti.org/memberlist.php?mode=viewprofile&un={{ user.forums_username }}">
{{ user.forums_username }} {{ user.forums_username }}
</a> </a>
{% else %} {% else %}

@ -16,7 +16,7 @@
hint=_("Your email is needed to recover your account if you forget your password and to send (configurable) notifications. ") + hint=_("Your email is needed to recover your account if you forget your password and to send (configurable) notifications. ") +
_("Your email will never be shared with a third-party.")) }} _("Your email will never be shared with a third-party.")) }}
<p> <p>
{{ _("Note: protonmail is unsupported by ContentDB. <a href='https://forum.minetest.net/viewtopic.php?t=30709'>More info</a>.") }} {{ _("Note: protonmail is unsupported by ContentDB. <a href='https://forum.luanti.org/viewtopic.php?t=30709'>More info</a>.") }}
</p> </p>
{% endif %} {% endif %}

@ -20,7 +20,7 @@
<a class="btn btn-primary me-3" href="{{ url_for('users.register') }}"> <a class="btn btn-primary me-3" href="{{ url_for('users.register') }}">
{{ _("<b>No</b>, I don't have one") }} {{ _("<b>No</b>, I don't have one") }}
</a> </a>
<a class="btn btn-secondary" href="https://forum.minetest.net/ucp.php?mode=register"> <a class="btn btn-secondary" href="https://forum.luanti.org/ucp.php?mode=register">
{{ _("Create forum account") }} {{ _("Create forum account") }}
</a> </a>
</p> </p>

@ -41,7 +41,7 @@ Create Account from Forums User
<p> <p>
{{ _("You'll need to have the GitHub field in your forum profile filled out.") }} {{ _("You'll need to have the GitHub field in your forum profile filled out.") }}
{{ _("Log into the forum and <a href='https://forum.minetest.net/ucp.php?i=173'>do that here</a>.") }} {{ _("Log into the forum and <a href='https://forum.luanti.org/ucp.php?i=173'>do that here</a>.") }}
</p> </p>
<input class="btn btn-primary" type="submit" value="{{ _('Next: log in with GitHub') }}"> <input class="btn btn-primary" type="submit" value="{{ _('Next: log in with GitHub') }}">
@ -68,7 +68,7 @@ Create Account from Forums User
placeholder="{{ _('Forum username') }}" pattern="[a-zA-Z0-9._ -]+" title="{{ _('Only a-zA-Z0-9._ allowed') }}" required> placeholder="{{ _('Forum username') }}" pattern="[a-zA-Z0-9._ -]+" title="{{ _('Only a-zA-Z0-9._ allowed') }}" required>
<p> <p>
{{ _("Go to <a href='https://forum.minetest.net/ucp.php?i=profile&mode=signature'>User Control Panel &gt; Profile &gt; Edit signature</a>") }} {{ _("Go to <a href='https://forum.luanti.org/ucp.php?i=profile&mode=signature'>User Control Panel &gt; Profile &gt; Edit signature</a>") }}
</p> </p>
<p> <p>

@ -71,7 +71,7 @@
</span> </span>
{% if user.forums_username %} {% if user.forums_username %}
<a class="btn" href="https://forum.minetest.net/memberlist.php?mode=viewprofile&un={{ user.forums_username }}"> <a class="btn" href="https://forum.luanti.org/memberlist.php?mode=viewprofile&un={{ user.forums_username }}">
<i class="fas fa-comments"></i> <i class="fas fa-comments"></i>
<span class="count"> <span class="count">
{{ _("Forums") }} {{ _("Forums") }}

@ -11,7 +11,7 @@
<div class="row"> <div class="row">
<div class="col-md-2"> <div class="col-md-2">
{% if user.forums_username %} {% if user.forums_username %}
<a href="https://forum.minetest.net/ucp.php?i=profile&mode=avatar"> <a href="https://forum.luanti.org/ucp.php?i=profile&mode=avatar">
{% elif user.email %} {% elif user.email %}
<a href="https://en.gravatar.com/"> <a href="https://en.gravatar.com/">
{% endif %} {% endif %}

@ -24,7 +24,7 @@
hint=_("Your email is needed to recover your account if you forget your password and to send (configurable) notifications. ") + hint=_("Your email is needed to recover your account if you forget your password and to send (configurable) notifications. ") +
_("Your email will never be shared with a third-party.")) }} _("Your email will never be shared with a third-party.")) }}
<p> <p>
{{ _("Note: protonmail is unsupported by ContentDB. <a href='https://forum.minetest.net/viewtopic.php?t=30709'>More info</a>.") }} {{ _("Note: protonmail is unsupported by ContentDB. <a href='https://forum.luanti.org/viewtopic.php?t=30709'>More info</a>.") }}
</p> </p>
{{ render_field(form.password, hint=_("Must be at least 12 characters long.")) }} {{ render_field(form.password, hint=_("Must be at least 12 characters long.")) }}

@ -24,7 +24,7 @@
{{ _("Your email will never be shared with a third-party.") }} {{ _("Your email will never be shared with a third-party.") }}
</p> </p>
<p> <p>
{{ _("Note: protonmail is unsupported by ContentDB. <a href='https://forum.minetest.net/viewtopic.php?t=30709'>More info</a>.") }} {{ _("Note: protonmail is unsupported by ContentDB. <a href='https://forum.luanti.org/viewtopic.php?t=30709'>More info</a>.") }}
</p> </p>
{% if user.email_verifications.filter_by(is_password_reset=False).count() > 0 %} {% if user.email_verifications.filter_by(is_password_reset=False).count() > 0 %}

@ -124,7 +124,7 @@ def parse_forum_list_page(id, page, out, extra=None):
start = page*num_per_page+1 start = page*num_per_page+1
print(" - Fetching page {} (topics {}-{})".format(page, start, start+num_per_page), file=sys.stderr) print(" - Fetching page {} (topics {}-{})".format(page, start, start+num_per_page), file=sys.stderr)
url = "https://forum.minetest.net/viewforum.php?f=" + str(id) + "&start=" + str(start) url = "https://forum.luanti.org/viewforum.php?f=" + str(id) + "&start=" + str(start)
r = urllib.request.urlopen(url).read().decode("utf-8") r = urllib.request.urlopen(url).read().decode("utf-8")
soup = BeautifulSoup(r, "html.parser") soup = BeautifulSoup(r, "html.parser")