mirror of
https://github.com/minetest/contentdb.git
synced 2024-11-10 01:23:48 +01:00
Add Minetest version checking to packages API
This commit is contained in:
parent
d77403c0be
commit
84b996c489
@ -614,8 +614,9 @@ class Tag(db.Model):
|
||||
|
||||
|
||||
class MinetestRelease(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(100), unique=True, nullable=False)
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(100), unique=True, nullable=False)
|
||||
protocol = db.Column(db.Integer, nullable=False, default=0)
|
||||
|
||||
def __init__(self, name=None):
|
||||
self.name = name
|
||||
@ -629,7 +630,7 @@ class PackageRelease(db.Model):
|
||||
|
||||
package_id = db.Column(db.Integer, db.ForeignKey("package.id"))
|
||||
title = db.Column(db.String(100), nullable=False)
|
||||
releaseDate = db.Column(db.DateTime, nullable=False)
|
||||
releaseDate = db.Column(db.DateTime, nullable=False)
|
||||
url = db.Column(db.String(200), nullable=False)
|
||||
approved = db.Column(db.Boolean, nullable=False, default=False)
|
||||
task_id = db.Column(db.String(37), nullable=True)
|
||||
|
@ -1,7 +1,8 @@
|
||||
from .models import db, PackageType, Package, ForumTopic, License
|
||||
from .models import db, PackageType, Package, ForumTopic, License, MinetestRelease, PackageRelease
|
||||
from .utils import isNo
|
||||
from sqlalchemy.sql.expression import func
|
||||
from flask import abort
|
||||
from sqlalchemy import or_
|
||||
|
||||
class QueryBuilder:
|
||||
title = None
|
||||
@ -27,6 +28,7 @@ class QueryBuilder:
|
||||
self.limit = 1 if self.lucky else None
|
||||
self.order_by = args.get("sort") or "score"
|
||||
self.order_dir = args.get("order") or "desc"
|
||||
self.protocol_version = args.get("protocol_version")
|
||||
|
||||
if self.search is not None and self.search.strip() == "":
|
||||
self.search = None
|
||||
@ -64,6 +66,18 @@ class QueryBuilder:
|
||||
query = query.filter(Package.license.has(License.is_foss == True))
|
||||
query = query.filter(Package.media_license.has(License.is_foss == True))
|
||||
|
||||
if self.protocol_version:
|
||||
self.protocol_version = int(self.protocol_version)
|
||||
version = MinetestRelease.query.filter(MinetestRelease.protocol>=self.protocol_version).first()
|
||||
if version is not None:
|
||||
version = version.id
|
||||
else:
|
||||
version = 10000000
|
||||
|
||||
query = query.join(Package.releases) \
|
||||
.filter(or_(PackageRelease.min_rel_id==None, PackageRelease.min_rel_id<=version)) \
|
||||
.filter(or_(PackageRelease.max_rel_id==None, PackageRelease.max_rel_id>=version))
|
||||
|
||||
if self.limit:
|
||||
query = query.limit(self.limit)
|
||||
|
||||
|
@ -61,3 +61,9 @@ def topic_set_discard():
|
||||
db.session.commit()
|
||||
|
||||
return jsonify(topic.getAsDictionary())
|
||||
|
||||
|
||||
@app.route("/api/minetest_versions/")
|
||||
def api_minetest_versions_page():
|
||||
return jsonify([{ "name": rel.name, "protocol_version": rel.protocol }\
|
||||
for rel in MinetestRelease.query.all() if rel.getActual() is not None])
|
||||
|
28
migrations/versions/97a9c461bc2d_.py
Normal file
28
migrations/versions/97a9c461bc2d_.py
Normal file
@ -0,0 +1,28 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 97a9c461bc2d
|
||||
Revises: 7def3e843d04
|
||||
Create Date: 2019-01-28 20:49:41.831991
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '97a9c461bc2d'
|
||||
down_revision = '7def3e843d04'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('minetest_release', sa.Column('protocol', sa.Integer(), nullable=False, server_default="0"))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('minetest_release', 'protocol')
|
||||
# ### end Alembic commands ###
|
Loading…
Reference in New Issue
Block a user