mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 23:16:17 -05:00
Handling when Singlefile extension uploads may be not be the usual text/html.
Some checks failed
CodeQL / Analyze (push) Has been cancelled
Some checks failed
CodeQL / Analyze (push) Has been cancelled
This commit is contained in:
parent
76b9ead174
commit
d7691fba71
6 changed files with 27 additions and 6 deletions
|
|
@ -101,6 +101,10 @@ function handleEvents(events) {
|
|||
() => window.open(url, '_self'));
|
||||
}
|
||||
|
||||
if (event === 'upload_archive_failed') {
|
||||
eventToast('Archive Upload Failed!', message, 'error', 5000);
|
||||
}
|
||||
|
||||
if (subject) {
|
||||
newestEvents[subject] = dt;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,8 +112,8 @@ def model_archive(file_group: FileGroup, session: Session = None) -> Archive:
|
|||
session.flush([file_group])
|
||||
file_group_id = file_group.id
|
||||
|
||||
# All Archives have an HTML Singlefile.
|
||||
html_paths = file_group.my_paths('text/html')
|
||||
# All Archives have an HTML Singlefile. Singlefile may be text HTML, or bytes HTML.
|
||||
html_paths = file_group.my_html_paths()
|
||||
if not html_paths:
|
||||
logger.error('Query returned a group without an HTML file!')
|
||||
raise InvalidArchive('FileGroup does not contain any html files')
|
||||
|
|
|
|||
|
|
@ -107,9 +107,15 @@ async def singlefile_upload_switch_handler(url=None):
|
|||
q_size = q.qsize()
|
||||
logger.info(f'singlefile_upload_switch_handler queue size: {q_size}')
|
||||
|
||||
archive = await lib.singlefile_to_archive(singlefile)
|
||||
logger.info(f'Created Archive from upload ({q_size}): {archive}')
|
||||
try:
|
||||
archive = await lib.singlefile_to_archive(singlefile)
|
||||
except Exception as e:
|
||||
logger.error(f'singlefile_upload_switch_handler failed', exc_info=e)
|
||||
Events.send_upload_archive_failed(f'Failed to convert singlefile to archive: {e}')
|
||||
raise
|
||||
|
||||
name = archive.file_group.title or archive.file_group.url
|
||||
logger.info(f'Created Archive from upload ({q_size}): {archive}')
|
||||
Events.send_archive_uploaded(f'Created Archive from upload: {name}', url=archive.location)
|
||||
url = archive.file_group.url
|
||||
if url and (download := Download.get_by_url(url)):
|
||||
|
|
|
|||
|
|
@ -141,8 +141,7 @@ class Archive(Base, ModelHelper):
|
|||
@property
|
||||
def singlefile_file(self) -> Optional[dict]:
|
||||
from modules.archive.lib import is_singlefile_file
|
||||
files = self.file_group.my_files('text/html')
|
||||
for file in files:
|
||||
for file in self.file_group.my_html_files():
|
||||
if is_singlefile_file(file['path']):
|
||||
return file
|
||||
|
||||
|
|
|
|||
|
|
@ -96,6 +96,10 @@ class Events:
|
|||
def send_archive_uploaded(cls, message: str = None, url: str = None):
|
||||
send_event('upload_archive', message, subject='upload', url=url)
|
||||
|
||||
@classmethod
|
||||
def send_upload_archive_failed(cls, message: str = None):
|
||||
send_event('upload_archive_failed', message, subject='upload')
|
||||
|
||||
|
||||
def log_event(event: str, message: str = None, action: str = None, subject: str = None):
|
||||
log = f'{event=}'
|
||||
|
|
|
|||
|
|
@ -275,6 +275,14 @@ class FileGroup(ModelHelper, Base):
|
|||
def my_mobi_files(self) -> List[dict]:
|
||||
return self.my_files('application/x-mobipocket-ebook')
|
||||
|
||||
def my_html_files(self) -> List[dict]:
|
||||
html_files = self.my_files('text/html', 'application/octet-stream')
|
||||
html_files = [i for i in html_files if i['path'].name.endswith('.html')]
|
||||
return html_files
|
||||
|
||||
def my_html_paths(self) -> List[pathlib.Path]:
|
||||
return [i['path'] for i in self.my_html_files()]
|
||||
|
||||
def delete(self, add_to_skip_list: bool = True):
|
||||
"""Delete this FileGroup record, and all of its files.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue