Browse Source

210921 fix

yukyo0821 3 năm trước cách đây
mục cha
commit
d9874793eb

+ 1 - 1
backstage/blogs/routes.py

@@ -108,7 +108,7 @@ def blog_list():
     response = requests.get('{}contents?url=/blog'.format(PORTAL_SERVER))
     if response.status_code == 200:
         sortedData = sorted(response.json(), key=lambda x: x['date'], reverse=True)
-        print(sortedData)
+        #print(sortedData)
         return render_template('blogs.html',
                                title='設計專欄',
                                legend='設計專欄列表',

+ 12 - 10
backstage/static/js/yo.js

@@ -10,14 +10,16 @@ SwfType = {
 $(function () {
 
     $("#dialog-form").hide();
-    editor = new EditorJS({
-        readOnly: false,
-        holder: 'editorjs',
-    });
-    editor1 = new EditorJS({
-        readOnly: false,
-        holder: 'editorjs1',
-    });
+    if ($('#editorjs').length > 0)
+        editor = new EditorJS({
+            readOnly: false,
+            holder: 'editorjs',
+        });
+    if ($('#editorjs1').length > 0)
+        editor1 = new EditorJS({
+            readOnly: false,
+            holder: 'editorjs1',
+        });
 
 });
 
@@ -94,8 +96,7 @@ function writeMd() {
             mdContent += contentMatters.join("\n");
             var formData = new FormData();
             var imagefile = document.querySelector('#cfile');
-            if (imagefile != null)
-                formData.append("image", imagefile.files[0]);
+            formData.append("image", imagefile.files[0]);
             axios.post('/backstage/upload/title', formData, {
                 headers: {
                     'Content-Type': 'multipart/form-data'
@@ -118,6 +119,7 @@ function writeMd() {
                 alert('資料已更新'); // test
                 location.reload();
             });
+
         });
 }
 

+ 2 - 0
backstage/templates/blogs.html

@@ -1,5 +1,7 @@
 {% extends "tables/editor_table.html" %}
 {% block table_body %}
+<script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script>
+<script src="https://cdn.jsdelivr.net/npm/@editorjs/image@latest"></script><!-- Image -->
 <script type="text/javascript" src="/static/js/yo.js"></script>
 {% for idx in range(0, length) %}
 {% if blogs[idx].url != '/blogs' %}

+ 2 - 0
backstage/templates/collections.html

@@ -1,5 +1,7 @@
 {% extends "tables/editor_table.html" %}
 {% block table_body %}
+<script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script>
+<script src="https://cdn.jsdelivr.net/npm/@editorjs/image@latest"></script><!-- Image -->
 <script type="text/javascript" src="/static/js/yo.js"></script>
 {% for idx in range(0, length) %}
 {% if collections[idx].url != '/collection' %}

+ 1 - 0
backstage/templates/solid_wood_furniture.html

@@ -142,6 +142,7 @@
                     </tbody>
                 </table>
                 <div class="d-none">
+                    <input class="form-control" id="cfile" type="file" />
                     <input id="ctype" type="text" /><br />
                     <input id="curl" type="text" /><br />
                     <input id="cimage" type="text" /><br />

+ 15 - 7
backstage/upload/routes.py

@@ -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)