Update for covers download via opds + inserts permissions if needed (only available with a link)
This commit is contained in:
parent
df9124f78b
commit
fb6a37eec3
|
@ -34,7 +34,18 @@ class GdriveId(Base):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return str(self.path)
|
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():
|
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'"):
|
for sql in session.execute("select sql from sqlite_master where type='table'"):
|
||||||
if 'CREATE TABLE gdrive_ids' in sql[0]:
|
if 'CREATE TABLE gdrive_ids' in sql[0]:
|
||||||
currUniqueConstraint='UNIQUE (gdrive_id)'
|
currUniqueConstraint='UNIQUE (gdrive_id)'
|
||||||
|
|
25
cps/web.py
25
cps/web.py
|
@ -1413,13 +1413,26 @@ def advanced_search():
|
||||||
return render_title_template('search_form.html', tags=tags, languages=languages, series=series, title=_(u"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>")
|
@app.route("/cover/<path:cover_path>")
|
||||||
@login_required_if_no_ano
|
@login_required_if_no_ano
|
||||||
def get_cover(cover_path):
|
def get_cover(cover_path):
|
||||||
if config.config_use_google_drive:
|
if config.config_use_google_drive:
|
||||||
df=gdriveutils.getFileFromEbooksFolder(Gdrive.Instance().drive, cover_path, 'cover.jpg')
|
return redirect(get_cover_via_gdrive(cover_path))
|
||||||
download_url = df.metadata.get('webContentLink')
|
|
||||||
return redirect(download_url)
|
|
||||||
else:
|
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, cover_path), "cover.jpg")
|
||||||
|
|
||||||
|
@ -1432,11 +1445,9 @@ def get_cover(cover_path):
|
||||||
def feed_get_cover(book_id):
|
def feed_get_cover(book_id):
|
||||||
book = db.session.query(db.Books).filter(db.Books.id == book_id).first()
|
book = db.session.query(db.Books).filter(db.Books.id == book_id).first()
|
||||||
if config.config_use_google_drive:
|
if config.config_use_google_drive:
|
||||||
df=gdriveutils.getFileFromEbooksFolder(Gdrive.Instance().drive, cover_path, 'cover.jpg')
|
return redirect(get_cover_via_gdrive(book.path))
|
||||||
download_url = df.metadata.get('webContentLink')
|
|
||||||
return redirect(download_url)
|
|
||||||
else:
|
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):
|
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()
|
readBooks=ub.session.query(ub.ReadBook).filter(ub.ReadBook.user_id == int(current_user.id)).filter(ub.ReadBook.is_read == True).all()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user