Merge remote-tracking branch 'cover_images/thumbnails' into cover_thumbnail
# Conflicts: # cps/admin.py # cps/config_sql.py # cps/helper.py # cps/tasks/upload.py # cps/updater.py # cps/web.py
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import atexit
|
||||
import os
|
||||
import sys
|
||||
import datetime
|
||||
@@ -510,6 +511,28 @@ class RemoteAuthToken(Base):
|
||||
return '<Token %r>' % self.id
|
||||
|
||||
|
||||
def filename(context):
|
||||
file_format = context.get_current_parameters()['format']
|
||||
if file_format == 'jpeg':
|
||||
return context.get_current_parameters()['uuid'] + '.jpg'
|
||||
else:
|
||||
return context.get_current_parameters()['uuid'] + '.' + file_format
|
||||
|
||||
|
||||
class Thumbnail(Base):
|
||||
__tablename__ = 'thumbnail'
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
entity_id = Column(Integer)
|
||||
uuid = Column(String, default=lambda: str(uuid.uuid4()), unique=True)
|
||||
format = Column(String, default='jpeg')
|
||||
type = Column(SmallInteger, default=constants.THUMBNAIL_TYPE_COVER)
|
||||
resolution = Column(SmallInteger, default=constants.COVER_THUMBNAIL_SMALL)
|
||||
filename = Column(String, default=filename)
|
||||
generated_at = Column(DateTime, default=lambda: datetime.datetime.utcnow())
|
||||
expiration = Column(DateTime, nullable=True)
|
||||
|
||||
|
||||
# Add missing tables during migration of database
|
||||
def add_missing_tables(engine, _session):
|
||||
if not engine.dialect.has_table(engine.connect(), "book_read_link"):
|
||||
@@ -524,6 +547,8 @@ def add_missing_tables(engine, _session):
|
||||
KoboStatistics.__table__.create(bind=engine)
|
||||
if not engine.dialect.has_table(engine.connect(), "archived_book"):
|
||||
ArchivedBook.__table__.create(bind=engine)
|
||||
if not engine.dialect.has_table(engine.connect(), "thumbnail"):
|
||||
Thumbnail.__table__.create(bind=engine)
|
||||
if not engine.dialect.has_table(engine.connect(), "registration"):
|
||||
Registration.__table__.create(bind=engine)
|
||||
with engine.connect() as conn:
|
||||
@@ -829,6 +854,16 @@ def init_db(app_db_path):
|
||||
sys.exit(3)
|
||||
|
||||
|
||||
def get_new_session_instance():
|
||||
new_engine = create_engine(u'sqlite:///{0}'.format(cli.settingspath), echo=False)
|
||||
new_session = scoped_session(sessionmaker())
|
||||
new_session.configure(bind=new_engine)
|
||||
|
||||
atexit.register(lambda: new_session.remove() if new_session else True)
|
||||
|
||||
return new_session
|
||||
|
||||
|
||||
def dispose():
|
||||
global session
|
||||
|
||||
|
||||
Reference in New Issue
Block a user