From a8d0a7395dd7f3c3874c4ae0573cc7f867c7f2b4 Mon Sep 17 00:00:00 2001 From: James McKinney <26463+jpmckinney@users.noreply.github.com> Date: Mon, 15 Jul 2024 11:54:32 -0400 Subject: [PATCH] feat: Add "Last modified" column to the directory listings of log files and item feeds, closes #509 --- docs/news.rst | 1 + scrapyd/website.py | 118 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 116 insertions(+), 3 deletions(-) diff --git a/docs/news.rst b/docs/news.rst index 5a6424d4..6879c863 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -11,6 +11,7 @@ Unreleased Added ~~~~~ +- Add "Last modified" column to the directory listings of log files and item feeds. - Add environment variables to override common options. See :doc:`config`. - Add documentation on how to add webservices (endpoints). See :ref:`config-services`. diff --git a/scrapyd/website.py b/scrapyd/website.py index cfcc557a..7a60120e 100644 --- a/scrapyd/website.py +++ b/scrapyd/website.py @@ -1,9 +1,11 @@ import socket from datetime import datetime, timedelta -from urllib.parse import urlparse +from html import escape +from urllib.parse import quote, urlparse from scrapy.utils.misc import load_object from twisted.application.service import IServiceCollection +from twisted.python import filepath from twisted.web import resource, static from scrapyd.interfaces import IEggStorage, IPoller, ISpiderScheduler @@ -15,6 +17,116 @@ def get_base_path(self, txrequest): return txrequest.getHeader(self.prefix_header) or '' +# Use local DirectoryLister class. +class File(static.File): + def directoryListing(self): + path = self.path + names = self.listNames() + return DirectoryLister( + path, names, self.contentTypes, self.contentEncodings, self.defaultType + ) + + +# Add "Last modified" column. +class DirectoryLister(static.DirectoryLister): + template = """ +
+Filename | +Size | +Last modified | +Content type | +Content encoding | +
---|