From 2ed198f1a07b5d3aead2bbaf8a26456c85d08bec Mon Sep 17 00:00:00 2001 From: butubb <1422726308@qq.com> Date: Sun, 18 Oct 2026 14:12:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=B5=84=E4=BA=A7=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E7=B4=A0=E6=9D=90=E6=A0=B9=E7=9B=AE=E5=BD=95=E4=B8=8D=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E6=97=B6=E4=BB=8D=E5=88=97=E5=87=BA=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 生产只同步了账号库、没有搬素材时 data/accounts 不存在, list_accounts 提前 return [] 导致资产页一个账号都不显示。 根目录缺失按空目录处理,继续并入账号库;补回归用例。 --- core/account_folder.py | 6 ++++-- scripts/tests/test_account_folder.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/core/account_folder.py b/core/account_folder.py index 598832f..cb54300 100644 --- a/core/account_folder.py +++ b/core/account_folder.py @@ -131,10 +131,12 @@ def list_accounts(prof=None): try: names = sorted(os.listdir(root)) except FileNotFoundError: - return [] + # 素材根目录还不存在(例如生产只同步了账号库、没搬素材)—— + # 账号库仍要能列出来,不能在这里提前返回。 + names = [] except Exception as e: _log.warning("列账号目录失败(%s): %s", root, e) - return [] + names = [] exts = _media_exts(prof) with _ctx(): # **账号来源 = 素材目录 ∪ 账号库**:账号库里登记了但还没建文件夹的号也要看得见 diff --git a/scripts/tests/test_account_folder.py b/scripts/tests/test_account_folder.py index 947dded..ec0ec19 100644 --- a/scripts/tests/test_account_folder.py +++ b/scripts/tests/test_account_folder.py @@ -281,6 +281,21 @@ with app.app_context(): check('素材文件夹归档了(原文件还在)', bool(_arch) and os.path.isfile(os.path.join(ROOT, _arch, 'a.mp4')), True) +print('=== 11. 素材根目录不存在时,账号库仍要列出来 ===') +with app.app_context(): + db.session.add(DeviceAccount(id='noroot1', device_name='A99', + nickname='只登记没目录', douyin_id='888', + created_at='2026-10-18')) + db.session.commit() + _missing = os.path.join(ROOT, '这个目录不存在') + _rows = af.list_accounts({'source': {'root': _missing}}) + check('根目录缺失也能列出账号库的号', + [r['name'] for r in _rows if r['name'] == '只登记没目录'], + ['只登记没目录']) + _hit = [r for r in _rows if r['name'] == '只登记没目录'][0] + check('没有目录的号 has_dir=False', _hit['has_dir'], False) + check('所属手机来自账号库', _hit['device_name'], 'A99') + print() if fails: print('❌ 失败 %d 项:%s' % (len(fails), ' / '.join(fails)))