mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-10 15:07:35 +01:00
Add Krock's mod search to meta importer to find forum topic ID
This commit is contained in:
parent
db3d63d91a
commit
38ed03f49a
@ -24,13 +24,15 @@ $(function() {
|
|||||||
$(".pkg_repo").hide()
|
$(".pkg_repo").hide()
|
||||||
|
|
||||||
performTask("/tasks/getmeta/new/?url=" + encodeURI(repoURL)).then(function(result) {
|
performTask("/tasks/getmeta/new/?url=" + encodeURI(repoURL)).then(function(result) {
|
||||||
console.log(result)
|
|
||||||
$("#name").val(result.name || "")
|
$("#name").val(result.name || "")
|
||||||
$("#title").val(result.title || "")
|
$("#title").val(result.title || "")
|
||||||
$("#repo").val(result.repo || repoURL)
|
$("#repo").val(result.repo || repoURL)
|
||||||
$("#issueTracker").val(result.issueTracker || "")
|
$("#issueTracker").val(result.issueTracker || "")
|
||||||
$("#desc").val(result.description || "")
|
$("#desc").val(result.description || "")
|
||||||
$("#shortDesc").val(result.short_description || "")
|
$("#shortDesc").val(result.short_description || "")
|
||||||
|
if (result.forumId) {
|
||||||
|
$("#forums").val(result.forumId)
|
||||||
|
}
|
||||||
finish()
|
finish()
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
alert(e)
|
alert(e)
|
||||||
|
@ -52,6 +52,62 @@ class GithubURLMaker:
|
|||||||
return "https://github.com/" + self.user + "/" + self.repo + "/archive/" + commit + ".zip"
|
return "https://github.com/" + self.user + "/" + self.repo + "/archive/" + commit + ".zip"
|
||||||
|
|
||||||
|
|
||||||
|
krock_list_cache = None
|
||||||
|
krock_list_cache_by_name = None
|
||||||
|
def getKrockList():
|
||||||
|
global krock_list_cache
|
||||||
|
global krock_list_cache_by_name
|
||||||
|
|
||||||
|
if krock_list_cache is None:
|
||||||
|
contents = urllib.request.urlopen("http://krock-works.16mb.com/MTstuff/modList.php").read().decode("utf-8")
|
||||||
|
list = json.loads(contents)
|
||||||
|
|
||||||
|
def h(x):
|
||||||
|
if not ("title" in x and "author" in x and \
|
||||||
|
"topicId" in x and "link" in x and x["link"] != ""):
|
||||||
|
return False
|
||||||
|
|
||||||
|
import re
|
||||||
|
m = re.search("\[([A-Za-z0-9_]+)\]", x["title"])
|
||||||
|
if m is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
x["name"] = m.group(1)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def g(x):
|
||||||
|
return {
|
||||||
|
"title": x["title"],
|
||||||
|
"author": x["author"],
|
||||||
|
"name": x["name"],
|
||||||
|
"topicId": x["topicId"],
|
||||||
|
"link": x["link"],
|
||||||
|
}
|
||||||
|
|
||||||
|
krock_list_cache = [g(x) for x in list if h(x)]
|
||||||
|
krock_list_cache_by_name = {}
|
||||||
|
for x in krock_list_cache:
|
||||||
|
if not x["name"] in krock_list_cache_by_name:
|
||||||
|
krock_list_cache_by_name[x["name"]] = []
|
||||||
|
|
||||||
|
krock_list_cache_by_name[x["name"]].append(x)
|
||||||
|
|
||||||
|
return krock_list_cache, krock_list_cache_by_name
|
||||||
|
|
||||||
|
def findModInfo(author, name, link):
|
||||||
|
_, lookup = getKrockList()
|
||||||
|
|
||||||
|
if name in lookup:
|
||||||
|
if len(lookup[name]) == 1:
|
||||||
|
return lookup[name][0]
|
||||||
|
|
||||||
|
for x in lookup[name]:
|
||||||
|
if x["author"] == author:
|
||||||
|
return x
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def parseConf(string):
|
def parseConf(string):
|
||||||
retval = {}
|
retval = {}
|
||||||
for line in string.split("\n"):
|
for line in string.split("\n"):
|
||||||
@ -63,8 +119,9 @@ def parseConf(string):
|
|||||||
|
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
|
|
||||||
@celery.task()
|
@celery.task()
|
||||||
def getMeta(urlstr):
|
def getMeta(urlstr, author):
|
||||||
url = urlparse(urlstr)
|
url = urlparse(urlstr)
|
||||||
|
|
||||||
urlmaker = None
|
urlmaker = None
|
||||||
@ -108,6 +165,10 @@ def getMeta(urlstr):
|
|||||||
cutIdx = min(len(desc), 200 if idx < 5 else idx)
|
cutIdx = min(len(desc), 200 if idx < 5 else idx)
|
||||||
result["short_description"] = desc[:cutIdx]
|
result["short_description"] = desc[:cutIdx]
|
||||||
|
|
||||||
|
info = findModInfo(author, result["name"], result["repo"])
|
||||||
|
if info is not None:
|
||||||
|
result["forumId"] = info["topicId"]
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@celery.task()
|
@celery.task()
|
||||||
|
@ -13,7 +13,9 @@ from .utils import *
|
|||||||
@app.route("/tasks/getmeta/new/", methods=["POST"])
|
@app.route("/tasks/getmeta/new/", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def new_getmeta_page():
|
def new_getmeta_page():
|
||||||
aresult = getMeta.delay(request.args.get("url"))
|
author = request.args.get("author")
|
||||||
|
author = current_user.forums_username if author is None else author
|
||||||
|
aresult = getMeta.delay(request.args.get("url"), author)
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"poll_url": url_for("check_task", id=aresult.id),
|
"poll_url": url_for("check_task", id=aresult.id),
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user