mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Limiting maximum title length in Archive files.
This commit is contained in:
parent
7b1c07f076
commit
01bfe4de97
2 changed files with 7 additions and 3 deletions
|
|
@ -78,6 +78,7 @@ def get_new_archive_files(url: str, title: Optional[str]) -> ArchiveFiles:
|
|||
dt = archive_strftime(now())
|
||||
|
||||
title = escape_file_name(title or 'NA')
|
||||
title = title[:50]
|
||||
prefix = f'{dt}_{title}'
|
||||
singlefile_path = directory / f'{prefix}.html'
|
||||
readability_path = directory / f'{prefix}.readability.html'
|
||||
|
|
@ -407,6 +408,8 @@ def migrate_archive_files():
|
|||
with archive_files.readability_json.open() as fh:
|
||||
title = escape_file_name(json.load(fh).get('title') or 'NA')
|
||||
|
||||
title = title[:50]
|
||||
|
||||
dt = archive_strftime(dt)
|
||||
prefix = f'{dt}_{title}'
|
||||
singlefile_path = domain_directory / f'{prefix}.html'
|
||||
|
|
|
|||
|
|
@ -490,7 +490,7 @@ def test_migrate_archive_files(test_session, archive_directory, archive_factory)
|
|||
# Archive6
|
||||
(example_org_directory / '2000-01-01 00:00:00.000000.html').touch()
|
||||
path = example_org_directory / '2000-01-01 00:00:00.000000.readability.json'
|
||||
path.write_text(json.dumps({'title': 'invalid#*: title'}))
|
||||
path.write_text(json.dumps({'title': 'A' * 500})) # Really long file name.
|
||||
|
||||
# Migration forms a plan, then performs it.
|
||||
plan = lib.migrate_archive_files()
|
||||
|
|
@ -510,9 +510,10 @@ def test_migrate_archive_files(test_session, archive_directory, archive_factory)
|
|||
(pathlib.Path('example.com/2021-10-05 16:20:10.346823.readability.json'),
|
||||
pathlib.Path('example.com/2021-10-05-16-20-10_my title.readability.json')),
|
||||
(pathlib.Path('example.org/2000-01-01 00:00:00.000000.html'),
|
||||
pathlib.Path('example.org/2000-01-01-00-00-00_invalid# title.html')),
|
||||
pathlib.Path('example.org/2000-01-01-00-00-00_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.html')),
|
||||
(pathlib.Path('example.org/2000-01-01 00:00:00.000000.readability.json'),
|
||||
pathlib.Path('example.org/2000-01-01-00-00-00_invalid# title.readability.json')),
|
||||
pathlib.Path(
|
||||
'example.org/2000-01-01-00-00-00_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.readability.json')),
|
||||
]
|
||||
# New Archive files still exist.
|
||||
assert all(i.is_file() for i in archive1.my_paths())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue