Skip to content

Commit

Permalink
[WIP] fix path
Browse files Browse the repository at this point in the history
  • Loading branch information
fnwinter committed Sep 19, 2024
1 parent 2658bee commit 5e29384
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
45 changes: 28 additions & 17 deletions cnas/pages/gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from util.file_util import is_image_file
from util.config_path import get_gallery_path
from util.system_path import get_gallery_thumbnail_path

from genhtml.w3c.html import html
from genhtml.w3c.section import section
Expand All @@ -23,43 +24,53 @@ def __init__(self):
super().__init__()
self.pictures = []

self.gallery_path = get_gallery_path()
self.thumbnail_path = get_gallery_thumbnail_path()
self.current_path = self.get_session("current_path")
if not self.current_path:
self.current_path = self.gallery_path
if not os.path.abspath(self.gallery_path) in\
os.path.abspath(self.current_path):
self.current_path = self.gallery_path

self.get_path()
self.get_list()

def get_path(self):
_gallery_path = None
if self.json_data and self.json_data.get("path"):
_gallery_path = self.json_data.get("path")
else:
_gallery_path = get_gallery_path()
print(_gallery_path)

if _gallery_path is None or not os.path.exists(_gallery_path):
return str(error("No gallery path"))
_rel_path = self.json_data.get("path")
_full = os.path.join(self.current_path, _rel_path)
self.set_session("current_path", os.path.abspath(_full))
print(_full)
print(_rel_path)

def get_list(self):
# folder
for _folder in os.listdir(self.current_path):
_path = os.path.join(self.current_path, _folder)
if os.path.isdir(_path):
_div.append(
self.pictures.append(
photo_builder(
src="static/images/folder.png",
path=_folder))

# images
for _file in os.listdir(self.current_path):
_path = os.path.join(self.current_path, _file)
_rel_path = ""
_thumb_nail_path = ""
if not is_image_file(_file):
continue
if not os.path.exists(_path):
continue
if os.path.exist(_thumb_nail_path):
_div.append(

_rel_path = os.path.relpath(self.current_path, self.gallery_path)
_rel_full = os.path.join(_rel_path, _file)
_thumb_nail_path = os.path.join(self.thumbnail_path, _rel_path)

if os.path.exists(_thumb_nail_path):
self.pictures.append(
photo_builder(
src="gallery_thumbnail/" + _rel_path,
src="gallery_thumbnail/" + _rel_full,
path=_file))
else:
_div.append(
self.pictures.append(
photo_builder(src="static/images/no_cache.png"))


Expand Down
6 changes: 3 additions & 3 deletions cnas/pages/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ def __init__(self):
if request.is_json:
self.json_data = request.get_json()

def set_session(key, value):
def set_session(self, key, value):
session[key] = value

def get_session(key):
def get_session(self, key):
return session.get(key)

def clear_session(key):
def clear_session(self, key):
session.pop(key, None)
4 changes: 2 additions & 2 deletions cnas/route/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ def index_page() -> str:
def gallery_page() -> str:
return str(gallery())

@app.route('/gallery_file/<filename>')
@app.route('/gallery_file/<path:filename>')
def gallery_file(filename):
directory = CONFIG.get('gallery_path')
return send_from_directory(directory, filename)

@app.route('/gallery_thumbnail/<filename>')
@app.route('/gallery_thumbnail/<path:filename>')
def gallery_thumbnail(filename):
directory = get_gallery_thumbnail_path()
return send_from_directory(directory, filename)
Expand Down
2 changes: 1 addition & 1 deletion cnas/static/javascripts/cnas_gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ $(document).ready(function(){
contentType: 'application/json',
data: JSON.stringify(data),
success: function(response) {
console.log(response)
document.body.innerHTML = response
window.location.reload();
},
error: function(xhr, status, error) {
console.log(error)
Expand Down

0 comments on commit 5e29384

Please sign in to comment.