From 709e067e14f4679db5eaa69aa8f57b2e9cd08bb3 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 13 Jan 2019 18:34:38 +0530 Subject: [PATCH 1/6] support txt drag and drop --- static/js/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/js/utils.js b/static/js/utils.js index fc7186f..388c453 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -1028,7 +1028,7 @@ oml.updateDebugMenu = function() { oml.user.ui.showDebugMenu ? menu.show() : menu.hide(); }; -oml.supportedExtensions = ['pdf', 'epub', 'kepub', 'cbr', 'cbz']; +oml.supportedExtensions = ['pdf', 'epub', 'kepub', 'cbr', 'cbz', 'txt']; oml.upload = function(fileslist, callback) { var files = [], ids = []; From 3a1b3a5c3c253f852ff43fe08771c96113848914 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 13 Jan 2019 18:35:01 +0530 Subject: [PATCH 2/6] more cleanup fallbacks --- oml/item/handlers.py | 11 +++++++++-- oml/item/scan.py | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/oml/item/handlers.py b/oml/item/handlers.py index aabeff2..36ca61a 100644 --- a/oml/item/handlers.py +++ b/oml/item/handlers.py @@ -172,7 +172,8 @@ class UploadHandler(tornado.web.RequestHandler): id = get_id(data=upload.body) ids.append(id) file = File.get(id) - if not file: + if not file or not os.path.exists(file.fullpath()): + logger.debug('add %s to library', id) prefix_books = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books' + os.sep) prefix_imported = os.path.join(prefix_books, '.import' + os.sep) ox.makedirs(prefix_imported) @@ -190,7 +191,13 @@ class UploadHandler(tornado.web.RequestHandler): file.move() else: user = state.user() - file.item.add_user(user) + item = file.item + if user not in item.users: + logger.debug('add %s to local user', id) + item.add_user(user) + add_record('additem', item.id, file.info) + add_record('edititem', item.id, item.meta) + item.update() if listname and ids: l = List.get(settings.USER_ID, listname) if l: diff --git a/oml/item/scan.py b/oml/item/scan.py index d9c4bb1..b6fa307 100644 --- a/oml/item/scan.py +++ b/oml/item/scan.py @@ -198,7 +198,7 @@ def run_scan(): for id in gone: i = Item.get(id) path = i.get_path() - if path and not os.path.exists(path): + if not path or not os.path.exists(path): logger.debug('cleaning orphaned record %s %s', i, path) i.remove_file() missing = ids - library_items From 4a956e2a6595694f151b0cbf987991c702bb9996 Mon Sep 17 00:00:00 2001 From: j Date: Mon, 14 Jan 2019 13:21:24 +0530 Subject: [PATCH 3/6] debugging --- oml/item/models.py | 1 + oml/item/scan.py | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/oml/item/models.py b/oml/item/models.py index 27e4191..9448260 100644 --- a/oml/item/models.py +++ b/oml/item/models.py @@ -800,6 +800,7 @@ class File(db.Model): if os.path.exists(path) and os.path.exists(current_path): os.unlink(path) return + logger.debug('mv "%s" "%s"', self.path, new_path) self.path = new_path self.save() for folder in set(os.path.dirname(p) for p in [current_path, path]): diff --git a/oml/item/scan.py b/oml/item/scan.py index b6fa307..d2f3fa6 100644 --- a/oml/item/scan.py +++ b/oml/item/scan.py @@ -172,7 +172,6 @@ def run_scan(): elif user not in file.item.users: item = file.item item.add_user(user) - logger.debug('add %s to local user', id) add_record('additem', item.id, file.info) add_record('edititem', item.id, item.meta) @@ -194,7 +193,6 @@ def run_scan(): library_items = set([str(i) for i in user.library.items]) gone = library_items - ids if gone: - logger.debug('cleaning up %s deleted records', len(gone)) for id in gone: i = Item.get(id) path = i.get_path() From 3cd63695c48445a5f21b551654594dedf6c90a44 Mon Sep 17 00:00:00 2001 From: j Date: Mon, 14 Jan 2019 13:49:09 +0530 Subject: [PATCH 4/6] only add items if there are items --- oml/library.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oml/library.py b/oml/library.py index d61398f..54902d1 100644 --- a/oml/library.py +++ b/oml/library.py @@ -288,7 +288,7 @@ class Peer(object): l.remove_items(lremove, commit=False) if ladd or lremove: logger.debug('update list %s', l.name) - else: + elif self.info['lists'][l.name]: l.add_items(self.info['lists'][l.name], commit=False) update_items = list(set(update_items) - set(self.info['lists'][l.name])) logger.debug('update list %s', l.name) From 74586d7164b42dbfc335c2c69f23f27ef614a3c6 Mon Sep 17 00:00:00 2001 From: j Date: Mon, 14 Jan 2019 17:10:40 +0530 Subject: [PATCH 5/6] compare NFD normalized paths --- oml/item/api.py | 1 + oml/item/scan.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/oml/item/api.py b/oml/item/api.py index 0fd7a6a..4493233 100644 --- a/oml/item/api.py +++ b/oml/item/api.py @@ -168,6 +168,7 @@ def remove(data): ''' if 'ids' in data and data['ids']: for i in models.Item.query.filter(models.Item.id.in_(data['ids'])): + logger.info('remove item %s', i) i.remove_file() state.cache.clear('group:') return { diff --git a/oml/item/scan.py b/oml/item/scan.py index d2f3fa6..8161203 100644 --- a/oml/item/scan.py +++ b/oml/item/scan.py @@ -7,6 +7,7 @@ import os import shutil import stat import time +import unicodedata import ox @@ -31,6 +32,7 @@ def remove_missing(books=None): prefix = get_prefix() if books is None: books = collect_books(prefix) + books = [unicodedata.normalize('NFD', path) for path in books] with db.session(): if os.path.exists(prefix): logger.debug('scan for removed files') @@ -40,6 +42,8 @@ def remove_missing(books=None): if state.shutdown: return path = f.fullpath() + path = unicode + path = unicodedata.normalize('NFD', path) db_paths.append(path) if f.item: items[path] = f.sha1 From 07cdab8c2d91a50aa10725ad77f9815cab3154f5 Mon Sep 17 00:00:00 2001 From: j Date: Mon, 14 Jan 2019 17:22:10 +0530 Subject: [PATCH 6/6] typo --- oml/item/scan.py | 1 - 1 file changed, 1 deletion(-) diff --git a/oml/item/scan.py b/oml/item/scan.py index 8161203..aa96bdc 100644 --- a/oml/item/scan.py +++ b/oml/item/scan.py @@ -42,7 +42,6 @@ def remove_missing(books=None): if state.shutdown: return path = f.fullpath() - path = unicode path = unicodedata.normalize('NFD', path) db_paths.append(path) if f.item: