1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-12-25 09:30:31 +00:00

Update for covers download via opds + inserts permissions if needed (only available with a link)

This commit is contained in:
Jack Darlington 2017-03-02 23:55:32 +00:00
parent df9124f78b
commit fb6a37eec3
2 changed files with 29 additions and 7 deletions

View File

@ -34,7 +34,18 @@ class GdriveId(Base):
def __repr__(self):
return str(self.path)
class PermissionAdded(Base):
__tablename__='permissions_added'
id = Column(Integer, primary_key=True)
gdrive_id = Column(Integer, unique=True)
def __repr__(self):
return str(self.gdrive_id)
def migrate():
if not engine.dialect.has_table(engine.connect(), "permissions_added"):
PermissionAdded.__table__.create(bind = engine)
for sql in session.execute("select sql from sqlite_master where type='table'"):
if 'CREATE TABLE gdrive_ids' in sql[0]:
currUniqueConstraint='UNIQUE (gdrive_id)'

View File

@ -1413,13 +1413,26 @@ def advanced_search():
return render_title_template('search_form.html', tags=tags, languages=languages, series=series, title=_(u"search"))
def get_cover_via_gdrive(cover_path):
df=gdriveutils.getFileFromEbooksFolder(Gdrive.Instance().drive, cover_path, 'cover.jpg')
if not gdriveutils.session.query(gdriveutils.PermissionAdded).filter(gdriveutils.PermissionAdded.gdrive_id == df['id']).first():
permissions=df.GetPermissions()
df.InsertPermission({
'type': 'anyone',
'value': 'anyone',
'role': 'reader',
'withLink' : True})
permissionAdded=gdriveutils.PermissionAdded()
permissionAdded.gdrive_id=df['id']
gdriveutils.session.add(permissionAdded)
gdriveutils.session.commit()
return df.metadata.get('webContentLink')
@app.route("/cover/<path:cover_path>")
@login_required_if_no_ano
def get_cover(cover_path):
if config.config_use_google_drive:
df=gdriveutils.getFileFromEbooksFolder(Gdrive.Instance().drive, cover_path, 'cover.jpg')
download_url = df.metadata.get('webContentLink')
return redirect(download_url)
return redirect(get_cover_via_gdrive(cover_path))
else:
return send_from_directory(os.path.join(config.config_calibre_dir, cover_path), "cover.jpg")
@ -1432,11 +1445,9 @@ def get_cover(cover_path):
def feed_get_cover(book_id):
book = db.session.query(db.Books).filter(db.Books.id == book_id).first()
if config.config_use_google_drive:
df=gdriveutils.getFileFromEbooksFolder(Gdrive.Instance().drive, cover_path, 'cover.jpg')
download_url = df.metadata.get('webContentLink')
return redirect(download_url)
return redirect(get_cover_via_gdrive(book.path))
else:
return send_from_directory(os.path.join(config.config_calibre_dir, cover_path), "cover.jpg")
return send_from_directory(os.path.join(config.config_calibre_dir, book.path), "cover.jpg")
def render_read_books(page, are_read, as_xml=False):
readBooks=ub.session.query(ub.ReadBook).filter(ub.ReadBook.user_id == int(current_user.id)).filter(ub.ReadBook.is_read == True).all()