Merge pull request #32 from DarkflameUniverse/local-ldd-db

Local ldd db
This commit is contained in:
Aaron Kimbrell 2022-05-11 21:34:17 -05:00 committed by GitHub
commit 3668ca8792
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 20 deletions

View File

@ -16,6 +16,7 @@ from functools import partial
from sqlalchemy import func from sqlalchemy import func
import time import time
@click.command("init_db") @click.command("init_db")
@click.argument('drop_tables', nargs=1) @click.argument('drop_tables', nargs=1)
@with_appcontext @with_appcontext

View File

@ -3,7 +3,9 @@ from flask import (
send_file, send_file,
g, g,
redirect, redirect,
url_for url_for,
make_response,
abort
) )
from flask_user import login_required from flask_user import login_required
from app.models import CharacterInfo from app.models import CharacterInfo
@ -12,6 +14,7 @@ import os
from wand import image from wand import image
from wand.exceptions import BlobError as BE from wand.exceptions import BlobError as BE
import pathlib import pathlib
import json
import sqlite3 import sqlite3
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
@ -123,6 +126,43 @@ def get_icon_iconid(id):
return send_file(pathlib.Path(cache).resolve()) return send_file(pathlib.Path(cache).resolve())
@luclient_blueprint.route('/ldddb/')
@login_required
def brick_list():
brick_list = []
if len(brick_list) == 0:
suffixes = [".g", ".g1", ".g2", ".g3", ".xml"]
res = pathlib.Path('app/luclient/res/')
# Load g files
for path in res.rglob("*.*"):
if str(path.suffix) in suffixes:
brick_list.append(
{
"type": "file",
"name": str(path.as_posix()).replace("app/luclient/res/", "")
}
)
response = make_response(json.dumps(brick_list))
response.headers.set('Content-Type', 'application/json')
return response
@luclient_blueprint.route('/ldddb/', defaults={'req_path': ''})
@luclient_blueprint.route('/ldddb/<path:req_path>')
def dir_listing(req_path):
# Joining the base and the requested path
rel_path = pathlib.Path(str(pathlib.Path(f'app/luclient/res/{req_path}').resolve()))
# Return 404 if path doesn't exist
if not rel_path.exists():
return abort(404)
# Check if path is a file and serve
if rel_path.is_file():
return send_file(rel_path)
else:
return abort(404)
@luclient_blueprint.route('/unknown') @luclient_blueprint.route('/unknown')
@login_required @login_required
def unknown(): def unknown():

View File

@ -99,7 +99,7 @@ def reject(id):
form = RejectPropertyForm() form = RejectPropertyForm()
if form.validate_on_submit(): if form.validate_on_submit():
char_name = CharacterInfo.query.filter(CharacterInfo.id==property_data.owner_id).first().name char_name = CharacterInfo.query.filter(CharacterInfo.id == property_data.owner_id).first().name
zone_name = query_cdclient( zone_name = query_cdclient(
'select DisplayDescription from ZoneTable where zoneID = ?', 'select DisplayDescription from ZoneTable where zoneID = ?',
[property_data.zone_id], [property_data.zone_id],
@ -197,11 +197,11 @@ def get(status="all"):
if status == "approved": if status == "approved":
query = db.session.query().select_from(Property).join( query = db.session.query().select_from(Property).join(
CharacterInfo, CharacterInfo.id == Property.owner_id CharacterInfo, CharacterInfo.id == Property.owner_id
).join(Account).filter(Property.mod_approved == True).filter(Property.privacy_option == 2) ).join(Account).filter(Property.mod_approved == True).filter(Property.privacy_option == 2) # noqa
elif status == "unapproved": elif status == "unapproved":
query = db.session.query().select_from(Property).join( query = db.session.query().select_from(Property).join(
CharacterInfo, CharacterInfo.id == Property.owner_id CharacterInfo, CharacterInfo.id == Property.owner_id
).join(Account).filter(Property.mod_approved == False).filter(Property.privacy_option == 2).filter(Property.rejection_reason == "") ).join(Account).filter(Property.mod_approved == False).filter(Property.privacy_option == 2).filter(Property.rejection_reason == "") # noqa
else: else:
query = db.session.query().select_from(Property).join(CharacterInfo, CharacterInfo.id == Property.owner_id).join(Account) query = db.session.query().select_from(Property).join(CharacterInfo, CharacterInfo.id == Property.owner_id).join(Account)

View File

@ -469,14 +469,14 @@
this.Parts = [] this.Parts = []
this.studsFields2D = [] this.studsFields2D = []
let lod = {{ lod }} let lod = {{ lod }}
let GeometryLocation = `lod${lod}/${designID}.g` let GeometryLocation = `brickprimitives/lod${lod}/${designID}.g`
let PrimitiveLocation = `${designID}.xml` let PrimitiveLocation = `Primitives/${designID}.xml`
let GeometryCount = 0 let GeometryCount = 0
while (GeometryLocation in database.filelist) { while (GeometryLocation in database.filelist) {
this.Parts[GeometryCount] = new GeometryReader(database.filelist[GeometryLocation].read()) this.Parts[GeometryCount] = new GeometryReader(database.filelist[GeometryLocation].read())
GeometryCount = GeometryCount + 1 GeometryCount = GeometryCount + 1
GeometryLocation = `lod${lod}/${designID}.g${GeometryCount}` GeometryLocation = `brickprimitives/lod${lod}/${designID}.g${GeometryCount}`
} }
let primitive = new Primitive(database.filelist[PrimitiveLocation].read()) let primitive = new Primitive(database.filelist[PrimitiveLocation].read())
this.Partname = primitive.Designname this.Partname = primitive.Designname
@ -549,7 +549,7 @@
LoadDBURL(dbURLlocation){ LoadDBURL(dbURLlocation){
this.database = new DBURLReader(dbURLlocation) this.database = new DBURLReader(dbURLlocation)
if(this.database.initok && this.database.fileexist('Materials.xml') && this.database.fileexist('localizedStrings.loc')){ if(this.database.initok && this.database.fileexist('Materials.xml')){
this.allMaterials = new Materials(this.database.filelist['Materials.xml'].read()) this.allMaterials = new Materials(this.database.filelist['Materials.xml'].read())
} }
} }
@ -881,7 +881,6 @@
class Materials { class Materials {
//done
constructor(data) { constructor(data) {
this.Materials = {} this.Materials = {}
let parser = new DOMParser(); let parser = new DOMParser();
@ -928,13 +927,11 @@
function FindDBURL(){ function FindDBURL(){
let dburl = 'https://json.aronwk.com/LDD-DB/' let dburl = '/luclient/ldddb/'
let xhr = new XMLHttpRequest(); let xhr = new XMLHttpRequest();
xhr.open('GET', dburl, false); // `false` makes the request synchronous xhr.open('GET', dburl, false); // `false` makes the request synchronous
// request state change event // request state change event
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
// request completed? // request completed?
if (xhr.readyState !== 4) {//return; if (xhr.readyState !== 4) {//return;
dburl = false; dburl = false;
@ -950,7 +947,6 @@
console.log('HTTP error in FindDBURL:', xhr.status, xhr.statusText); console.log('HTTP error in FindDBURL:', xhr.status, xhr.statusText);
} }
}; };
// start request // start request
xhr.send(); xhr.send();
return dburl return dburl
@ -1041,13 +1037,7 @@
self.parse(dburl + obj.name + '/', obj.name) self.parse(dburl + obj.name + '/', obj.name)
} }
else if (obj.type == 'file'){ else if (obj.type == 'file'){
self.filelist[obj.name] = new DBURLFile(dburl + obj.name, obj.name)
if (folder.includes("lod")){
self.filelist[`${folder}/${obj.name}`] = new DBURLFile(dburl + obj.name, obj.name)
} else {
self.filelist[obj.name] = new DBURLFile(dburl + obj.name, obj.name)
}
} }
else { else {
console.log('Strange object parsed: ' + obj.type) console.log('Strange object parsed: ' + obj.type)