Compare commits
6 commits
637feaee55
...
07cdab8c2d
| Author | SHA1 | Date | |
|---|---|---|---|
| 07cdab8c2d | |||
| 74586d7164 | |||
| 3cd63695c4 | |||
| 4a956e2a65 | |||
| 3a1b3a5c3c | |||
| 709e067e14 |
6 changed files with 17 additions and 7 deletions
|
|
@ -168,6 +168,7 @@ def remove(data):
|
||||||
'''
|
'''
|
||||||
if 'ids' in data and data['ids']:
|
if 'ids' in data and data['ids']:
|
||||||
for i in models.Item.query.filter(models.Item.id.in_(data['ids'])):
|
for i in models.Item.query.filter(models.Item.id.in_(data['ids'])):
|
||||||
|
logger.info('remove item %s', i)
|
||||||
i.remove_file()
|
i.remove_file()
|
||||||
state.cache.clear('group:')
|
state.cache.clear('group:')
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -172,7 +172,8 @@ class UploadHandler(tornado.web.RequestHandler):
|
||||||
id = get_id(data=upload.body)
|
id = get_id(data=upload.body)
|
||||||
ids.append(id)
|
ids.append(id)
|
||||||
file = File.get(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_books = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books' + os.sep)
|
||||||
prefix_imported = os.path.join(prefix_books, '.import' + os.sep)
|
prefix_imported = os.path.join(prefix_books, '.import' + os.sep)
|
||||||
ox.makedirs(prefix_imported)
|
ox.makedirs(prefix_imported)
|
||||||
|
|
@ -190,7 +191,13 @@ class UploadHandler(tornado.web.RequestHandler):
|
||||||
file.move()
|
file.move()
|
||||||
else:
|
else:
|
||||||
user = state.user()
|
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:
|
if listname and ids:
|
||||||
l = List.get(settings.USER_ID, listname)
|
l = List.get(settings.USER_ID, listname)
|
||||||
if l:
|
if l:
|
||||||
|
|
|
||||||
|
|
@ -800,6 +800,7 @@ class File(db.Model):
|
||||||
if os.path.exists(path) and os.path.exists(current_path):
|
if os.path.exists(path) and os.path.exists(current_path):
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
return
|
return
|
||||||
|
logger.debug('mv "%s" "%s"', self.path, new_path)
|
||||||
self.path = new_path
|
self.path = new_path
|
||||||
self.save()
|
self.save()
|
||||||
for folder in set(os.path.dirname(p) for p in [current_path, path]):
|
for folder in set(os.path.dirname(p) for p in [current_path, path]):
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import os
|
||||||
import shutil
|
import shutil
|
||||||
import stat
|
import stat
|
||||||
import time
|
import time
|
||||||
|
import unicodedata
|
||||||
|
|
||||||
import ox
|
import ox
|
||||||
|
|
||||||
|
|
@ -31,6 +32,7 @@ def remove_missing(books=None):
|
||||||
prefix = get_prefix()
|
prefix = get_prefix()
|
||||||
if books is None:
|
if books is None:
|
||||||
books = collect_books(prefix)
|
books = collect_books(prefix)
|
||||||
|
books = [unicodedata.normalize('NFD', path) for path in books]
|
||||||
with db.session():
|
with db.session():
|
||||||
if os.path.exists(prefix):
|
if os.path.exists(prefix):
|
||||||
logger.debug('scan for removed files')
|
logger.debug('scan for removed files')
|
||||||
|
|
@ -40,6 +42,7 @@ def remove_missing(books=None):
|
||||||
if state.shutdown:
|
if state.shutdown:
|
||||||
return
|
return
|
||||||
path = f.fullpath()
|
path = f.fullpath()
|
||||||
|
path = unicodedata.normalize('NFD', path)
|
||||||
db_paths.append(path)
|
db_paths.append(path)
|
||||||
if f.item:
|
if f.item:
|
||||||
items[path] = f.sha1
|
items[path] = f.sha1
|
||||||
|
|
@ -172,7 +175,6 @@ def run_scan():
|
||||||
elif user not in file.item.users:
|
elif user not in file.item.users:
|
||||||
item = file.item
|
item = file.item
|
||||||
item.add_user(user)
|
item.add_user(user)
|
||||||
|
|
||||||
logger.debug('add %s to local user', id)
|
logger.debug('add %s to local user', id)
|
||||||
add_record('additem', item.id, file.info)
|
add_record('additem', item.id, file.info)
|
||||||
add_record('edititem', item.id, item.meta)
|
add_record('edititem', item.id, item.meta)
|
||||||
|
|
@ -194,11 +196,10 @@ def run_scan():
|
||||||
library_items = set([str(i) for i in user.library.items])
|
library_items = set([str(i) for i in user.library.items])
|
||||||
gone = library_items - ids
|
gone = library_items - ids
|
||||||
if gone:
|
if gone:
|
||||||
logger.debug('cleaning up %s deleted records', len(gone))
|
|
||||||
for id in gone:
|
for id in gone:
|
||||||
i = Item.get(id)
|
i = Item.get(id)
|
||||||
path = i.get_path()
|
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)
|
logger.debug('cleaning orphaned record %s %s', i, path)
|
||||||
i.remove_file()
|
i.remove_file()
|
||||||
missing = ids - library_items
|
missing = ids - library_items
|
||||||
|
|
|
||||||
|
|
@ -288,7 +288,7 @@ class Peer(object):
|
||||||
l.remove_items(lremove, commit=False)
|
l.remove_items(lremove, commit=False)
|
||||||
if ladd or lremove:
|
if ladd or lremove:
|
||||||
logger.debug('update list %s', l.name)
|
logger.debug('update list %s', l.name)
|
||||||
else:
|
elif self.info['lists'][l.name]:
|
||||||
l.add_items(self.info['lists'][l.name], commit=False)
|
l.add_items(self.info['lists'][l.name], commit=False)
|
||||||
update_items = list(set(update_items) - set(self.info['lists'][l.name]))
|
update_items = list(set(update_items) - set(self.info['lists'][l.name]))
|
||||||
logger.debug('update list %s', l.name)
|
logger.debug('update list %s', l.name)
|
||||||
|
|
|
||||||
|
|
@ -1028,7 +1028,7 @@ oml.updateDebugMenu = function() {
|
||||||
oml.user.ui.showDebugMenu ? menu.show() : menu.hide();
|
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) {
|
oml.upload = function(fileslist, callback) {
|
||||||
var files = [], ids = [];
|
var files = [], ids = [];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue