feed: truncate file name if too long

This commit is contained in:
knoflook 2022-02-03 15:57:01 +01:00
parent e32743ecd5
commit a4f22b95b7
Signed by untrusted user: knoflook
GPG Key ID: D6A1D0E8FC4FEF1C
1 changed files with 8 additions and 0 deletions

View File

@ -1,6 +1,7 @@
import os
import shutil
import time
from hashlib import md5
from ast import literal_eval as make_tuple
from pathlib import Path
from urllib.parse import urlparse
@ -238,6 +239,13 @@ def main():
entry["feed_name"] = feed_name
post_name = slugify(entry.title)
# pixelfed returns the whole post text as the post name. max
# filename length is 255 on many systems. here we're shortening
# the name and adding a hash to it to avoid a conflict in a
# situation where 2 posts start with exactly the same text.
if len(post_name) > 150:
post_hash = md5(bytes(post_name, "utf-8"))
post_name = post_name[:150] + "-" + post_hash.hexdigest()
post_dir = os.path.join(output_dir, feed_name, post_name)
if post_name not in existing_posts: