BlenderKit: better reporting for failed uploads
bugfix - only fetch server data when not in background(fetching api key during upload procedure is a very bad idea) updatea oauth script. Mention Petr Dlouhy as co-author Temporarily enable Api key field also with oauth on.
This commit is contained in:
parent
8009a267b8
commit
4fff91efba
|
@ -18,8 +18,8 @@
|
|||
|
||||
bl_info = {
|
||||
"name": "BlenderKit Asset Library",
|
||||
"author": "Vilem Duha",
|
||||
"version": (1, 0, 24),
|
||||
"author": "Vilem Duha, Petr Dlouhy",
|
||||
"version": (1, 0, 25),
|
||||
"blender": (2, 80, 0),
|
||||
"location": "View3D > Properties > BlenderKit",
|
||||
"description": "Online BlenderKit library (materials, models, brushes and more)",
|
||||
|
@ -1358,8 +1358,8 @@ class BlenderKitAddonPreferences(AddonPreferences):
|
|||
layout.operator("wm.blenderkit_logout", text="Logout",
|
||||
icon='URL')
|
||||
|
||||
if not self.enable_oauth:
|
||||
layout.prop(self, "api_key", text='Your API Key')
|
||||
#if not self.enable_oauth:
|
||||
layout.prop(self, "api_key", text='Your API Key')
|
||||
# layout.label(text='After you paste API Key, categories are downloaded, so blender will freeze for a few seconds.')
|
||||
layout.prop(self, "global_dir")
|
||||
layout.prop(self, "project_subdir")
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
if "bpy" in locals():
|
||||
from importlib import reload
|
||||
|
||||
ui = reload(ui)
|
||||
tasks_queue = reload(tasks_queue)
|
||||
utils = reload(utils)
|
||||
paths = reload(paths)
|
||||
search = reload(search)
|
||||
categories = reload(categories)
|
||||
oauth = reload(oauth)
|
||||
ui = reload(ui)
|
||||
else:
|
||||
from blenderkit import tasks_queue, utils, paths, search, categories, oauth, ui
|
||||
|
||||
|
@ -77,7 +77,8 @@ def write_tokens(auth_token, refresh_token):
|
|||
preferences.api_key = auth_token
|
||||
preferences.login_attempt = False
|
||||
props = utils.get_search_props()
|
||||
props.report = ''
|
||||
if props is not None:
|
||||
props.report = ''
|
||||
ui.add_report('BlenderKit Login success')
|
||||
search.get_profile()
|
||||
categories.fetch_categories_thread(auth_token)
|
||||
|
|
|
@ -55,6 +55,7 @@ class SimpleOAuthAuthenticator(object):
|
|||
|
||||
def get_new_token(self, register=True, redirect_url=None):
|
||||
class HTTPServerHandler(BaseHTTPRequestHandler):
|
||||
html_template = '<html>%(head)s<h1>%(message)s</h1></html>'
|
||||
def do_GET(self):
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'text/html')
|
||||
|
@ -69,9 +70,11 @@ class SimpleOAuthAuthenticator(object):
|
|||
)
|
||||
else:
|
||||
redirect_string = ""
|
||||
self.wfile.write(bytes('<html>%s<h1>You may now close this window.</h1></html>' % redirect_string, 'utf-8'))
|
||||
self.wfile.write(bytes(self.html_template % {'head': redirect_string, 'message': 'You may now close this window.'}, 'utf-8'))
|
||||
qs = parse_qs(urlparse(self.path).query)
|
||||
self.server.authorization_code = qs['code'][0]
|
||||
else:
|
||||
self.wfile.write(bytes(self.html_template % {'head': '', 'message': 'Authorization failed.'}, 'utf-8'))
|
||||
|
||||
for port in self.ports:
|
||||
try:
|
||||
|
|
|
@ -100,14 +100,15 @@ def scene_load(context):
|
|||
|
||||
def fetch_server_data():
|
||||
''' download categories and addon version'''
|
||||
user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
|
||||
url = paths.BLENDERKIT_ADDON_URL
|
||||
api_key = user_preferences.api_key
|
||||
# version_checker.check_version_thread(url, api_key, blenderkit)
|
||||
if user_preferences.enable_oauth:
|
||||
bkit_oauth.refresh_token_thread()
|
||||
get_profile()
|
||||
categories.fetch_categories_thread(api_key)
|
||||
if not bpy.app.background:
|
||||
user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
|
||||
url = paths.BLENDERKIT_ADDON_URL
|
||||
api_key = user_preferences.api_key
|
||||
# version_checker.check_version_thread(url, api_key, blenderkit)
|
||||
if user_preferences.enable_oauth:
|
||||
bkit_oauth.refresh_token_thread()
|
||||
get_profile()
|
||||
categories.fetch_categories_thread(api_key)
|
||||
|
||||
|
||||
@bpy.app.handlers.persistent
|
||||
|
@ -158,9 +159,13 @@ def timer_update(): # TODO might get moved to handle all blenderkit stuff.
|
|||
if ok:
|
||||
|
||||
for r in rdata['results']:
|
||||
|
||||
# TODO remove this fix when filesSize is fixed.
|
||||
# this is a temporary fix for too big numbers from the server.
|
||||
try:
|
||||
r['filesSize'] = int(r['filesSize'] / 1024)
|
||||
except:
|
||||
utils.p('asset with no files-size')
|
||||
if r['assetType'] == asset_type:
|
||||
# utils.pprint(r)
|
||||
if len(r['files']) > 0:
|
||||
furl = None
|
||||
tname = None
|
||||
|
@ -181,7 +186,6 @@ def timer_update(): # TODO might get moved to handle all blenderkit stuff.
|
|||
if durl and tname:
|
||||
|
||||
tooltip = generate_tooltip(r)
|
||||
# utils.pprint(print(r))
|
||||
asset_data = {'thumbnail': tname,
|
||||
'thumbnail_small': small_tname,
|
||||
# 'thumbnails':allthumbs,
|
||||
|
|
|
@ -28,10 +28,12 @@ if "bpy" in locals():
|
|||
version_checker = reload(version_checker)
|
||||
search = reload(search)
|
||||
ui_panels = reload(ui_panels)
|
||||
ui = reload(ui)
|
||||
overrides = reload(overrides)
|
||||
colors = reload(colors)
|
||||
else:
|
||||
from blenderkit import asset_inspector, paths, utils, bg_blender, autothumb, version_checker, search, ui_panels, \
|
||||
overrides
|
||||
from blenderkit import asset_inspector, paths, utils, bg_blender, autothumb, version_checker, search, ui_panels, ui, \
|
||||
overrides, colors
|
||||
|
||||
import tempfile, os, subprocess, json, re
|
||||
|
||||
|
@ -527,7 +529,7 @@ def check_storage_quota(props):
|
|||
|
||||
|
||||
def auto_fix(asset_type=''):
|
||||
#this applies various procedures to ensure coherency in the database.
|
||||
# this applies various procedures to ensure coherency in the database.
|
||||
asset = utils.get_active_asset()
|
||||
props = utils.get_upload_props()
|
||||
if asset_type == 'MATERIAL':
|
||||
|
@ -546,12 +548,11 @@ def start_upload(self, context, asset_type, as_new, metadata_only):
|
|||
location = get_upload_location(props)
|
||||
props.upload_state = 'preparing upload'
|
||||
|
||||
auto_fix(asset_type = asset_type)
|
||||
auto_fix(asset_type=asset_type)
|
||||
|
||||
# do this for fixing long tags in some upload cases
|
||||
props.tags = props.tags[:]
|
||||
|
||||
|
||||
props.name = props.name.strip()
|
||||
# TODO move this to separate function
|
||||
# check for missing metadata
|
||||
|
@ -646,15 +647,18 @@ def start_upload(self, context, asset_type, as_new, metadata_only):
|
|||
return {'FINISHED'}
|
||||
try:
|
||||
rj = r.json()
|
||||
utils.pprint(rj)
|
||||
if r.status_code != 200:
|
||||
if r.status_code == 401:
|
||||
ui.add_report(r.detail, 5, colors.RED)
|
||||
return {'CANCELLED'}
|
||||
if props.asset_base_id == '':
|
||||
props.asset_base_id = rj['assetBaseId']
|
||||
props.id = rj['id']
|
||||
|
||||
upload_data['assetBaseId'] = props.asset_base_id
|
||||
upload_data['id'] = props.id
|
||||
|
||||
bpy.ops.wm.save_mainfile()
|
||||
# fa
|
||||
props.uploading = True
|
||||
# save a copy of actual scene but don't interfere with the users models
|
||||
bpy.ops.wm.save_as_mainfile(filepath=source_filepath, compress=False, copy=True)
|
||||
|
@ -677,6 +681,7 @@ def start_upload(self, context, asset_type, as_new, metadata_only):
|
|||
except Exception as e:
|
||||
props.upload_state = str(e)
|
||||
props.uploading = False
|
||||
print(e)
|
||||
return {'CANCELLED'}
|
||||
|
||||
return {'FINISHED'}
|
||||
|
@ -751,7 +756,7 @@ class ModelUploadOperator(Operator):
|
|||
layout.label(text="For updates of thumbnail or model use reupload.")
|
||||
|
||||
if props.is_private == 'PUBLIC':
|
||||
ui_panels.label_multiline(layout, text='Since this version (1.0.24), '
|
||||
ui_panels.label_multiline(layout, text='Since version 1.0.24: '
|
||||
'PUBLIC ASSETS ARE VALIDATED AUTOMATICALLY '
|
||||
' after upload. '
|
||||
'Click Ok to proceed.')
|
||||
|
|
|
@ -78,6 +78,8 @@ def get_selected_models():
|
|||
|
||||
def get_search_props():
|
||||
scene = bpy.context.scene
|
||||
if scene is None:
|
||||
return;
|
||||
uiprops = scene.blenderkitUI
|
||||
props = None
|
||||
if uiprops.asset_type == 'MODEL':
|
||||
|
|
Loading…
Reference in New Issue