diff --git a/modules/archive/lib.py b/modules/archive/lib.py index ed8bb429..74644e3d 100644 --- a/modules/archive/lib.py +++ b/modules/archive/lib.py @@ -70,6 +70,9 @@ def get_domain_directory(url: str) -> pathlib.Path: return directory +MAXIMUM_ARCHIVE_FILE_CHARACTER_LENGTH = 200 + + def get_new_archive_files(url: str, title: Optional[str]) -> ArchiveFiles: """Create a list of archive files using a shared name schema. Raise an error if any of them exist.""" directory = get_domain_directory(url) @@ -77,7 +80,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] + title = title[:MAXIMUM_ARCHIVE_FILE_CHARACTER_LENGTH] prefix = f'{dt}_{title}' singlefile_path = directory / f'{prefix}.html' readability_path = directory / f'{prefix}.readability.html' diff --git a/modules/archive/test/test_lib.py b/modules/archive/test/test_lib.py index 55d6b200..de608139 100644 --- a/modules/archive/test/test_lib.py +++ b/modules/archive/test/test_lib.py @@ -298,6 +298,18 @@ async def test_get_title_from_html(test_session, fake_now): assert archive.title is None +@skip_circleci +def test_get_new_archive_files_length(fake_now): + """Archive titles are truncated to fit file system length limit. (255-character limit for most file systems)""" + fake_now(datetime(2001, 1, 1)) + archive_files = get_new_archive_files('https://example.com', 'a' * 500) + assert len(str(archive_files.singlefile.name)) == 225 + assert len(str(archive_files.readability.name)) == 237 + assert len(str(archive_files.readability_txt.name)) == 236 + assert len(str(archive_files.readability_json.name)) == 237 + assert len(str(archive_files.screenshot.name)) == 224 + + @skip_circleci def test_get_new_archive_files(fake_now): """Archive files have a specific format so they are sorted by datetime, and are near each other."""