Преглед изворни кода

Dockerizing (3) #607 - Add Image Data Migration Code

hoparkgo9ma пре 7 година
родитељ
комит
924be29934
3 измењених фајлова са 11 додато и 9 уклоњено
  1. 1 1
      .gitignore
  2. 8 6
      app.py
  3. 2 2
      route/image_view.py

+ 1 - 1
.gitignore

@@ -6,7 +6,7 @@ __pycache__
 
 *.db
 *.db-journal
-image
+images
 robots.txt
 
 views/liberty

+ 8 - 6
app.py

@@ -157,8 +157,10 @@ if not curs.fetchall():
     curs.execute('delete from alist where name = "owner"')
     curs.execute('insert into alist (name, acl) values ("owner", "owner")')
 
-if not os.path.exists('data/image'):
-    os.makedirs('data/image')
+if os.path.exists('image'): # Data Migration Code
+    os.rename('image', 'data/images')
+if not os.path.exists('data/images'):
+    os.makedirs('data/images')
     
 if not os.path.exists('views'):
     os.makedirs('views')
@@ -3255,12 +3257,12 @@ def upload():
             else:
                 lice = '[[user:' + ip + ']]'
             
-        if os.path.exists(os.path.join('data/image', e_data)):
-            os.remove(os.path.join('data/image', e_data))
+        if os.path.exists(os.path.join('data/images', e_data)):
+            os.remove(os.path.join('data/images', e_data))
             
-            data.save(os.path.join('data/image', e_data))
+            data.save(os.path.join('data/images', e_data))
         else:
-            data.save(os.path.join('data/image', e_data))
+            data.save(os.path.join('data/images', e_data))
             
         curs.execute("select title from data where title = ?", ['file:' + name])
         if curs.fetchall(): 

+ 2 - 2
route/image_view.py

@@ -3,7 +3,7 @@ from .tool.func import *
 def image_view_2(conn, name):
     curs = conn.cursor()
     
-    if os.path.exists(os.path.join('data/image', name)):
-        return flask.send_from_directory('./data/image', name)
+    if os.path.exists(os.path.join('data/images', name)):
+        return flask.send_from_directory('./data/images', name)
     else:
         return redirect()