Compare commits

...

5 commits

Author SHA1 Message Date
j
f8d226a3de fix icons.db creation during startup 2019-01-30 22:22:16 +05:30
j
3969f6dfa7 add inbox height 2019-01-30 18:16:01 +05:30
j
0234b8dffb don't block db while serving images 2019-01-30 18:09:04 +05:30
j
f24e095987 for update 2019-01-30 18:00:38 +05:30
j
ee52791a56 create Metadata folder 2019-01-30 16:35:44 +05:30
5 changed files with 53 additions and 48 deletions

View file

@ -134,7 +134,7 @@ def command_postupdate(*args):
print('usage: -o oldversion -n newversion')
sys.exit(1)
if old <= '20140521-65-e14c686' and new > '20140521-65-e14c686':
if not os.path.exists(settings.db_path):
if not os.path.exists(settings.db_path) and sys.platform != 'win32':
r('./ctl', 'setup')
import setup
setup.upgrade_db(old, new)

View file

@ -30,7 +30,10 @@ class Icons(dict):
def is_available(self):
folder = os.path.dirname(self._db)
if os.path.exists(folder):
base = os.path.dirname(os.path.dirname(folder))
if os.path.exists(base):
if not os.path.exists(folder):
ox.makedirs(folder)
if not os.path.exists(self._db):
self.create()
return os.path.exists(self._db)
@ -137,7 +140,7 @@ def get_icons_db_path():
import settings
import shutil
library = os.path.expanduser(settings.preferences['libraryPath'])
library = os.path.normpath(os.path.expanduser(settings.preferences['libraryPath']))
metadata = os.path.join(library, 'Metadata')
icons_db_path = os.path.join(metadata, 'icons.db')
if os.path.exists(os.path.dirname(library)):

View file

@ -34,7 +34,7 @@ def api_requestPeering(user_id, username, message):
return False
def api_acceptPeering(user_id, username, message):
user = User.get(user_id)
user = User.get(user_id, for_update=True)
if user:
logger.debug('incoming acceptPeering event: pending: %s', user.pending)
if user.pending == 'sent':
@ -50,7 +50,7 @@ def api_acceptPeering(user_id, username, message):
return False
def api_rejectPeering(user_id, message):
user = User.get(user_id)
user = User.get(user_id, for_update=True)
if user:
user.info['message'] = message
user.update_peering(False)
@ -59,7 +59,7 @@ def api_rejectPeering(user_id, message):
return False
def api_removePeering(user_id, message):
user = User.get(user_id)
user = User.get(user_id, for_update=True)
if user:
user.info['message'] = message
user.update_peering(False)
@ -68,7 +68,7 @@ def api_removePeering(user_id, message):
return False
def api_cancelPeering(user_id, message):
user = User.get(user_id)
user = User.get(user_id, for_update=True)
if user:
user.info['message'] = message
user.update_peering(False)

View file

@ -121,55 +121,56 @@ class Handler(http.server.SimpleHTTPRequestHandler):
else:
id = None
if id and len(id) == 32 and id.isalnum():
path = None
data = None
with db.session():
if preview:
from item.icons import get_icon_sync
try:
data = get_icon_sync(id, 'preview', 512)
content = get_icon_sync(id, 'preview', 512)
except:
data = None
if data:
content = None
if content:
self.send_response(200, 'ok')
self.send_header('Content-type', 'image/jpg')
mimetype = 'image/jpg'
else:
self.send_response(404, 'Not Found')
self.send_header('Content-type', 'text/plain')
data = b'404 - Not Found'
content_length = len(data)
self.send_header('Content-Length', str(content_length))
self.end_headers()
self.write_with_limit(data, content_length)
return
file = item.models.File.get(id)
if not file:
self.send_response(404, 'Not Found')
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(b'404 - Not Found')
return
path = file.fullpath()
mimetype = {
'epub': 'application/epub+zip',
'pdf': 'application/pdf',
'txt': 'text/plain',
}.get(path.split('.')[-1], None)
self.send_response(200, 'OK')
self.send_header('Content-Type', mimetype)
self.send_header('X-Node-Protocol', settings.NODE_PROTOCOL)
if mimetype == 'text/plain':
with open(path, 'rb') as f:
content = f.read()
content = self.gzip_data(content)
content_length = len(content)
content = b'404 - Not Found'
mimetype = 'text/plain'
else:
content = None
content_length = os.path.getsize(path)
self.send_header('Content-Length', str(content_length))
self.end_headers()
if content:
self.write_with_limit(content, content_length)
else:
self.write_file_with_limit(path, content_length)
file = item.models.File.get(id)
if file:
path = file.fullpath()
mimetype = {
'epub': 'application/epub+zip',
'pdf': 'application/pdf',
'txt': 'text/plain',
}.get(path.split('.')[-1], None)
self.send_response(200, 'OK')
else:
self.send_response(404, 'Not Found')
content = b'404 - Not Found'
mimetype = 'text/plain'
self.send_header('Content-Type', mimetype)
self.send_header('X-Node-Protocol', settings.NODE_PROTOCOL)
if mimetype == 'text/plain' and path:
with open(path, 'rb') as f:
content = f.read()
content = self.gzip_data(content)
content_length = len(content)
elif path:
content = None
content_length = os.path.getsize(path)
elif content:
content_length = len(content)
else:
content_length = 0
self.send_header('Content-Length', str(content_length))
self.end_headers()
if content:
self.write_with_limit(content, content_length)
elif path:
self.write_file_with_limit(path, content_length)
elif len(parts) == 2 and parts[1] == 'log':
self._changelog()
else:

View file

@ -340,8 +340,9 @@ oml.ui.folders = function() {
var items = lists.filter(function(list) {
return list.user == '' && list.type != 'library' && list.name != 'Inbox';
});
// Library + Inbox + lists
oml.$ui.folder[0].$content
.css({height: 16 + items.length * 16 + 'px'});
.css({height: 16 + 16 + items.length * 16 + 'px'});
oml.$ui.folderList[0].options({
items: Ox.clone(items, true)
})