diff options
-rw-r--r-- | blenderkit/categories.py | 8 | ||||
-rw-r--r-- | blenderkit/download.py | 18 | ||||
-rw-r--r-- | blenderkit/ratings.py | 3 | ||||
-rw-r--r-- | blenderkit/search.py | 17 | ||||
-rw-r--r-- | blenderkit/ui.py | 4 | ||||
-rw-r--r-- | blenderkit/ui_panels.py | 2 | ||||
-rw-r--r-- | blenderkit/upload.py | 9 | ||||
-rw-r--r-- | blenderkit/upload_bg.py | 23 | ||||
-rw-r--r-- | blenderkit/utils.py | 9 |
9 files changed, 50 insertions, 43 deletions
diff --git a/blenderkit/categories.py b/blenderkit/categories.py index e7fd72bd..f6cde8dd 100644 --- a/blenderkit/categories.py +++ b/blenderkit/categories.py @@ -1,7 +1,7 @@ import requests import json import os -from blenderkit import paths +from blenderkit import paths,utils import shutil import threading @@ -62,10 +62,8 @@ def fetch_categories(API_key): url = paths.get_bkit_url() + 'categories/' - headers = { - "accept": "application/json", - "Authorization": "Bearer %s" % API_key - } + headers = utils.get_headers(api_key) + tempdir = paths.get_temp_dir() categories_filepath = os.path.join(tempdir, 'categories.json') diff --git a/blenderkit/download.py b/blenderkit/download.py index 3f340981..65dc631b 100644 --- a/blenderkit/download.py +++ b/blenderkit/download.py @@ -29,6 +29,7 @@ if "bpy" in locals(): imp.reload(paths) imp.reload(append_link) + imp.reload(utils) else: from blenderkit import paths, append_link, utils @@ -171,7 +172,7 @@ def report_usages(): user_preferences = bpy.context.preferences.addons['blenderkit'].preferences api_key = user_preferences.api_key sid = get_scene_id() - headers = {"accept": "application/json", "Authorization": "Bearer %s" % api_key} + headers = utils.get_headers(api_key) url = paths.get_bkit_url() + paths.BLENDERKIT_REPORT_URL assets = {} @@ -526,8 +527,7 @@ def main_thread(asset_data, tcom, scene_id, api_key): with open(file_name, "wb") as f: print("Downloading %s" % file_name) - headers = {"accept": "application/json", - "Authorization": "Bearer %s" % api_key} + headers = utils.get_headers(api_key) response = requests.get(asset_data['url'], stream=True) total_length = response.headers.get('Content-Length') @@ -560,10 +560,7 @@ def download(asset_data, **kwargs): user_preferences = bpy.context.preferences.addons['blenderkit'].preferences api_key = user_preferences.api_key scene_id = get_scene_id() - if api_key == '': - props = utils.get_search_props() - props.report = 'Register online to use the free library.' - return + tcom = ThreadCom() tcom.passargs = kwargs @@ -680,10 +677,9 @@ def fprint(text): def get_download_url(asset_data, scene_id, api_key, tcom=None): ''''retrieves the download url. The server checks if user can download the item.''' mt = time.time() - headers = { - "accept": "application/json", - "Authorization": "Bearer %s" % api_key, - } + + headers = utils.get_headers(api_key) + data = { 'scene_uuid': scene_id } diff --git a/blenderkit/ratings.py b/blenderkit/ratings.py index 7601a98f..122e89cb 100644 --- a/blenderkit/ratings.py +++ b/blenderkit/ratings.py @@ -83,7 +83,8 @@ def uplaod_review_thread(url, reviews, headers): def upload_rating(asset): user_preferences = bpy.context.preferences.addons['blenderkit'].preferences api_key = user_preferences.api_key - headers = {"accept": "application/json", "Authorization": "Bearer %s" % api_key} + headers = utils.get_headers(api_key) + asset_data = asset['asset_data'] diff --git a/blenderkit/search.py b/blenderkit/search.py index 0c674dcf..40d30146 100644 --- a/blenderkit/search.py +++ b/blenderkit/search.py @@ -21,8 +21,12 @@ if "bpy" in locals(): imp.reload(paths) imp.reload(utils) + imp.reload(categories) + imp.reload(ui) + imp.reload(version_checker) else: from blenderkit import paths, utils, categories, ui, version_checker + import blenderkit from bpy.app.handlers import persistent @@ -513,17 +517,8 @@ class Searcher(threading.Thread): tempdir = paths.get_temp_dir('%s_search' % query['asset_type']) json_filepath = os.path.join(tempdir, '%s_searchresult.json' % query['asset_type']) - if query['token'] != '': - headers = { - "accept": "application/json", - "Authorization": "Bearer %s" % query['token'], - # "Content-Type": "application/json", - } - else: - headers = { - "accept": "application/json", - # "Content-Type": "application/json", - } + headers = utils.get_headers(query['token']) + rdata = {} rdata['results'] = [] diff --git a/blenderkit/ui.py b/blenderkit/ui.py index 7f974d99..66a3ffc6 100644 --- a/blenderkit/ui.py +++ b/blenderkit/ui.py @@ -567,7 +567,7 @@ def draw_callback_2d_search(self, context): # object type icons - just a test..., adds clutter/ not so userfull: # icons = ('type_finished.png', 'type_template.png', 'type_particle_system.png') - if not result.get('can_download', True) == True or user_preferences.api_key == '': + if (result.get('can_download', True)) == 0: img = utils.get_thumbnail('locked.png') ui_bgl.draw_image(x + 2, y + 2, 24, 24, img, 1) @@ -577,7 +577,7 @@ def draw_callback_2d_search(self, context): ui_bgl.draw_image(x + ui_props.thumb_size - 26, y + 2, 24, 24, img, 1) if user_preferences.api_key == '': - report = 'Please register on BlenderKit website to use the free content.' + report = 'Register on BlenderKit website to upload your own assets.' ui_bgl.draw_text(report, ui_props.bar_x + ui_props.margin, ui_props.bar_y - 25 - ui_props.margin - ui_props.bar_height, 15) elif len(search_results) == 0: diff --git a/blenderkit/ui_panels.py b/blenderkit/ui_panels.py index 4aa4e25a..98281747 100644 --- a/blenderkit/ui_panels.py +++ b/blenderkit/ui_panels.py @@ -524,7 +524,7 @@ class VIEW3D_PT_blenderkit_unified(Panel): w = context.region.width - if len(user_preferences.api_key) < 35 and user_preferences.counter >10: + if len(user_preferences.api_key) < 35 and user_preferences.asset_counter >25: op = layout.operator("wm.url_open", text="Register online", icon='QUESTION') op.url = paths.BLENDERKIT_SIGNUP_URL diff --git a/blenderkit/upload.py b/blenderkit/upload.py index c1611525..be00430c 100644 --- a/blenderkit/upload.py +++ b/blenderkit/upload.py @@ -24,6 +24,7 @@ if "bpy" in locals(): imp.reload(utils) imp.reload(bg_blender) imp.reload(autothumb) + imp.reload(version_checker) else: from blenderkit import asset_inspector, paths, utils, bg_blender, autothumb, version_checker @@ -465,7 +466,9 @@ def mark_for_validation(self, context, asset_type): } url = paths.get_bkit_url() + 'assets/' - headers = {"accept": "application/json", "Authorization": "Bearer %s" % user_preferences.api_key} + + headers = utils.get_headers(user_preferences.api_key) + url += props.id + '/' try: @@ -557,7 +560,9 @@ def start_upload(self, context, asset_type, as_new, metadata_only): # first upload metadata to server, so it can be saved inside the current file url = paths.get_bkit_url() + 'assets/' - headers = {"accept": "application/json", "Authorization": "Bearer %s" % upload_data['token']} + + headers = utils.get_headers(upload_data['token']) + # upload_data['license'] = 'ovejajojo' json_metadata = upload_data # json.dumps(upload_data, ensure_ascii=False).encode('utf8') global reports diff --git a/blenderkit/upload_bg.py b/blenderkit/upload_bg.py index 681193ec..1678b194 100644 --- a/blenderkit/upload_bg.py +++ b/blenderkit/upload_bg.py @@ -22,7 +22,7 @@ import logging import bpy import addon_utils -from blenderkit import paths, append_link, bg_blender +from blenderkit import paths, append_link, bg_blender, utils BLENDERKIT_EXPORT_DATA = sys.argv[-1] @@ -65,7 +65,8 @@ class upload_in_chunks(object): def upload_files(filepath, upload_data, files): - headers = {"accept": "application/json", "Authorization": "Bearer %s" % upload_data['token']} + headers = utils.get_headers(upload_data['token']) + version_id = upload_data['id'] for f in files: bg_blender.progress('uploading %s' % f['type']) @@ -79,13 +80,13 @@ def upload_files(filepath, upload_data, files): upload = requests.post(upload_create_url, json=upload_info, headers=headers, verify=True) upload = upload.json() - upheaders = { - "accept": "application/json", - "Authorization": "Bearer %s" % upload_data['token'], - "Content-Type": "multipart/form-data", - "Content-Disposition": 'form-data; name="file"; filename=%s' % f['file_path'] - - } + # upheaders = { + # "accept": "application/json", + # "Authorization": "Bearer %s" % upload_data['token'], + # "Content-Type": "multipart/form-data", + # "Content-Disposition": 'form-data; name="file"; filename=%s' % f['file_path'] + # + # } chunk_size = 1024 * 256 # file gets uploaded here: @@ -185,7 +186,9 @@ if __name__ == "__main__": } url = paths.get_bkit_url() + 'assets/' - headers = {"accept": "application/json", "Authorization": "Bearer %s" % upload_data['token']} + + headers = utils.get_headers(upload_data['token']) + url += upload_data["id"] + '/' r = requests.patch(url, json=confirm_data, headers=headers, verify=True) # files = files, diff --git a/blenderkit/utils.py b/blenderkit/utils.py index 20e47db9..336b4ab1 100644 --- a/blenderkit/utils.py +++ b/blenderkit/utils.py @@ -372,6 +372,15 @@ def requests_post_thread(url, json, headers): r = requests.post(url, json=json, verify=True, headers=headers) +def get_headers(api_key): + headers = { + "accept": "application/json", + } + if api_key != '': + headers["Authorization"] = "Bearer %s" % api_key + return headers + + # map uv cubic and switch of auto tex space and set it to 1,1,1 def automap(target_object=None, target_slot=None, tex_size=1, bg_exception=False): from blenderkit import bg_blender as bg |