|
@@ -35,14 +35,20 @@ def upload_test(iurl):
|
|
|
@upload_app.route('/backstage/upload/<path:iurl>', methods=['POST'])
|
|
|
def upload_post(iurl):
|
|
|
|
|
|
- #取得md路徑
|
|
|
+ # 取得md路徑
|
|
|
mdPath = ""
|
|
|
new_response = requests.get(PORTAL_SERVER + 'contents?url=' + iurl)
|
|
|
#my_dict = json.loads(new_response.content.decode('utf-8'))[0].items()
|
|
|
- for key, value in json.loads(new_response.content.decode('utf-8'))[0].items():
|
|
|
- if key == 'path':
|
|
|
- mdPath = value.replace('\\', '/')
|
|
|
- mdPath = mdPath[0:mdPath.rfind('/')+1]
|
|
|
+ obj = json.loads(new_response.content.decode('utf-8'))
|
|
|
+
|
|
|
+ if len(obj) > 0:
|
|
|
+ for key, value in obj[0].items():
|
|
|
+ if key == 'path':
|
|
|
+ mdPath = value.replace('\\', '/')
|
|
|
+ #print(mdPath)
|
|
|
+ mdPath = mdPath[0:mdPath.rfind('/')+1]
|
|
|
+ #print(mdPath)
|
|
|
+ print(mdPath)
|
|
|
isProduct = False
|
|
|
if mdPath.find("設計家具") >= 0 or mdPath.find("模組系統櫃") >= 0:
|
|
|
isProduct = True
|
|
@@ -91,7 +97,7 @@ def upload_post(iurl):
|
|
|
else:
|
|
|
sitepath = UPLOAD_PATH_MAP[0][0] + "../" + itype + "/" + filepath + "/img/"
|
|
|
|
|
|
- wfname = str(uuid.uuid4()) + ".webp"
|
|
|
+ wfname = str(uuid.uuid4()).replace('-','') + ".webp"
|
|
|
owfname = wfname.replace('webp', oimgtype)
|
|
|
#fullpath = UPLOAD_PATH_MAP[0][0] + filepath[filepath.rfind("/")+1:] + "\\img\\" + fname
|
|
|
#print(UPLOAD_PATH_MAP[0][1] + filepath[filepath.rfind("/")+1:] + "/img/" + fname)
|
|
@@ -121,13 +127,15 @@ def upload_post(iurl):
|
|
|
# aa = {"success": 1, "file": {"url": UPLOAD_PATH_MAP[0][1] + filepath[filepath.rfind(
|
|
|
# "/")+1:] + "/img/" + fname, "width": image_object.width, "height": image_object.height}}
|
|
|
return aa
|
|
|
- else:
|
|
|
+ elif isProduct:
|
|
|
wpath = os.getcwd() + "/backstage/upload/" + filepath+"/img/"
|
|
|
wfname = str(uuid.uuid4()) + ".webp"
|
|
|
image_object = Image.open(file)
|
|
|
#image_object.save(mdPath+wfname, oimgtypeName)
|
|
|
if image_object.size[0] > 1000:
|
|
|
image_object.thumbnail(size=((1600, 1600)))
|
|
|
+ if not os.path.exists(wpath):
|
|
|
+ os.makedirs(wpath)
|
|
|
image_object.save(wpath+wfname, 'webp')
|
|
|
image_object.save(mdPath+wfname, 'webp')
|
|
|
owfname = wfname.replace('webp', oimgtype)
|