fix: restore additional=["size","time"] to list_dir, update SPEC + tests
Root cause of DSM 408 was wrong path format (volume path vs share path), not the additional parameter. Confirmed via test_additional.py that json.dumps(["size","time"]) is the correct format; comma-separated string is silently ignored by DSM. - list_dir: restore 4-column table (Name, Type, Size, Modified) - list_dir: use additional=json.dumps(["size","time"]) (confirmed working) - SPEC.md: document share path requirement, additional format rules, note SYNO.FileStation.Stat unavailability, remove comma-sep gotcha - tests: restore size/mtime mock data and assertions - delete test_additional.py (throwaway diagnostic script) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -154,6 +154,7 @@ def register_filestation(
|
||||
"limit": limit,
|
||||
"sort_by": sort_by,
|
||||
"sort_direction": sort_direction,
|
||||
"additional": json.dumps(["size", "time"]),
|
||||
},
|
||||
)
|
||||
except SynologyError as e:
|
||||
@@ -165,22 +166,43 @@ def register_filestation(
|
||||
if not files:
|
||||
return f"Directory '{path}' is empty (or does not exist)."
|
||||
|
||||
# Build table — name + type only (no additional fields requested)
|
||||
# Build table
|
||||
rows = []
|
||||
for f in files:
|
||||
name = f.get("name", "")
|
||||
ftype = "dir" if f.get("isdir", False) else "file"
|
||||
rows.append((name, ftype))
|
||||
is_dir = f.get("isdir", False)
|
||||
ftype = "dir" if is_dir else "file"
|
||||
add = f.get("additional", {})
|
||||
size_str = "-" if is_dir else _fmt_size(add.get("size"))
|
||||
mtime_str = _fmt_time(add.get("time", {}).get("mtime"))
|
||||
rows.append((name, ftype, size_str, mtime_str))
|
||||
|
||||
w_name = max(len("Name"), *(len(r[0]) for r in rows))
|
||||
w_type = max(len("Type"), *(len(r[1]) for r in rows))
|
||||
w_size = max(len("Size"), *(len(r[2]) for r in rows))
|
||||
w_mtime = max(len("Modified"), *(len(r[3]) for r in rows))
|
||||
|
||||
sep = f"+{'-' * (w_name + 2)}+{'-' * (w_type + 2)}+"
|
||||
header = f"| {'Name':<{w_name}} | {'Type':<{w_type}} |"
|
||||
sep = (
|
||||
f"+{'-' * (w_name + 2)}"
|
||||
f"+{'-' * (w_type + 2)}"
|
||||
f"+{'-' * (w_size + 2)}"
|
||||
f"+{'-' * (w_mtime + 2)}+"
|
||||
)
|
||||
header = (
|
||||
f"| {'Name':<{w_name}} "
|
||||
f"| {'Type':<{w_type}} "
|
||||
f"| {'Size':<{w_size}} "
|
||||
f"| {'Modified':<{w_mtime}} |"
|
||||
)
|
||||
|
||||
lines = [f"Path: {path}", sep, header, sep]
|
||||
for name, ftype in rows:
|
||||
lines.append(f"| {name:<{w_name}} | {ftype:<{w_type}} |")
|
||||
for name, ftype, size_str, mtime_str in rows:
|
||||
lines.append(
|
||||
f"| {name:<{w_name}} "
|
||||
f"| {ftype:<{w_type}} "
|
||||
f"| {size_str:<{w_size}} "
|
||||
f"| {mtime_str:<{w_mtime}} |"
|
||||
)
|
||||
lines.append(sep)
|
||||
|
||||
end = offset + len(files)
|
||||
|
||||
Reference in New Issue
Block a user