feat: support gated/private Hugging Face repos via access token

Add a huggingface_api_key setting (Settings UI, HF_TOKEN /
HUGGING_FACE_HUB_TOKEN env override) and attach it as a Bearer token
to Hugging Face file listing, model card fetching and downloads, so
gated and private repositories can be downloaded once the user has
accepted the repo terms.

- fetch_json/fetch_text accept custom headers; ModelSource gains an
  auth_headers() hook so handlers stay platform-agnostic
- 401/403 from the tree API now explain how to fix (configure token /
  accept gated terms)
- aria2 pre-resolves huggingface.co redirects and strips credentials
  before handing the signed CDN URL to aria2, mirroring the CivitAI
  handling so the token never leaks to the CDN
- settings API exposes huggingface_api_key_set only; the raw key joins
  _NO_SYNC_KEYS
This commit is contained in:
Will Miao
2026-09-25 18:44:06 +08:00
parent 067e605e75
commit 8b7ba59263
23 changed files with 446 additions and 23 deletions
+6
View File
@@ -325,6 +325,12 @@
"civitaiApiKeyConfigured": "Konfiguriert",
"civitaiApiKeyNotConfigured": "Nicht konfiguriert",
"civitaiApiKeySet": "Einrichten",
"huggingfaceApiKey": "[TODO: Translate] Hugging Face Access Token",
"huggingfaceApiKeyPlaceholder": "[TODO: Translate] Enter your Hugging Face access token",
"huggingfaceApiKeyHelp": "[TODO: Translate] Required to download from gated or private Hugging Face repositories. Create a read-only token at huggingface.co/settings/tokens, and accept the repository's terms on its page first.",
"huggingfaceApiKeyConfigured": "[TODO: Translate] Configured",
"huggingfaceApiKeyNotConfigured": "[TODO: Translate] Not configured",
"huggingfaceApiKeySet": "[TODO: Translate] Set up",
"civitaiHost": {
"label": "CivitAI-Host",
"help": "Wählen Sie aus, welche CivitAI-Seite geöffnet wird, wenn Sie „View on CivitAI“-Links verwenden.",
+6
View File
@@ -325,6 +325,12 @@
"civitaiApiKeyConfigured": "Configured",
"civitaiApiKeyNotConfigured": "Not configured",
"civitaiApiKeySet": "Set up",
"huggingfaceApiKey": "Hugging Face Access Token",
"huggingfaceApiKeyPlaceholder": "Enter your Hugging Face access token",
"huggingfaceApiKeyHelp": "Required to download from gated or private Hugging Face repositories. Create a read-only token at huggingface.co/settings/tokens, and accept the repository's terms on its page first.",
"huggingfaceApiKeyConfigured": "Configured",
"huggingfaceApiKeyNotConfigured": "Not configured",
"huggingfaceApiKeySet": "Set up",
"civitaiHost": {
"label": "CivitAI host",
"help": "Choose which CivitAI site opens when using View on CivitAI links.",
+6
View File
@@ -325,6 +325,12 @@
"civitaiApiKeyConfigured": "Configurado",
"civitaiApiKeyNotConfigured": "No configurado",
"civitaiApiKeySet": "Configurar",
"huggingfaceApiKey": "[TODO: Translate] Hugging Face Access Token",
"huggingfaceApiKeyPlaceholder": "[TODO: Translate] Enter your Hugging Face access token",
"huggingfaceApiKeyHelp": "[TODO: Translate] Required to download from gated or private Hugging Face repositories. Create a read-only token at huggingface.co/settings/tokens, and accept the repository's terms on its page first.",
"huggingfaceApiKeyConfigured": "[TODO: Translate] Configured",
"huggingfaceApiKeyNotConfigured": "[TODO: Translate] Not configured",
"huggingfaceApiKeySet": "[TODO: Translate] Set up",
"civitaiHost": {
"label": "Host de CivitAI",
"help": "Elige qué sitio de CivitAI se abre al usar los enlaces de \"View on CivitAI\".",
+6
View File
@@ -325,6 +325,12 @@
"civitaiApiKeyConfigured": "Configuré",
"civitaiApiKeyNotConfigured": "Non configuré",
"civitaiApiKeySet": "Configurer",
"huggingfaceApiKey": "[TODO: Translate] Hugging Face Access Token",
"huggingfaceApiKeyPlaceholder": "[TODO: Translate] Enter your Hugging Face access token",
"huggingfaceApiKeyHelp": "[TODO: Translate] Required to download from gated or private Hugging Face repositories. Create a read-only token at huggingface.co/settings/tokens, and accept the repository's terms on its page first.",
"huggingfaceApiKeyConfigured": "[TODO: Translate] Configured",
"huggingfaceApiKeyNotConfigured": "[TODO: Translate] Not configured",
"huggingfaceApiKeySet": "[TODO: Translate] Set up",
"civitaiHost": {
"label": "Hôte CivitAI",
"help": "Choisissez quel site CivitAI s'ouvre lorsque vous utilisez les liens « View on CivitAI ».",
+6
View File
@@ -325,6 +325,12 @@
"civitaiApiKeyConfigured": "מוגדר",
"civitaiApiKeyNotConfigured": "לא מוגדר",
"civitaiApiKeySet": "הגדר",
"huggingfaceApiKey": "[TODO: Translate] Hugging Face Access Token",
"huggingfaceApiKeyPlaceholder": "[TODO: Translate] Enter your Hugging Face access token",
"huggingfaceApiKeyHelp": "[TODO: Translate] Required to download from gated or private Hugging Face repositories. Create a read-only token at huggingface.co/settings/tokens, and accept the repository's terms on its page first.",
"huggingfaceApiKeyConfigured": "[TODO: Translate] Configured",
"huggingfaceApiKeyNotConfigured": "[TODO: Translate] Not configured",
"huggingfaceApiKeySet": "[TODO: Translate] Set up",
"civitaiHost": {
"label": "מארח CivitAI",
"help": "בחר איזה אתר של CivitAI ייפתח בעת שימוש בקישורי \"View on CivitAI\".",
+6
View File
@@ -325,6 +325,12 @@
"civitaiApiKeyConfigured": "設定済み",
"civitaiApiKeyNotConfigured": "未設定",
"civitaiApiKeySet": "設定",
"huggingfaceApiKey": "[TODO: Translate] Hugging Face Access Token",
"huggingfaceApiKeyPlaceholder": "[TODO: Translate] Enter your Hugging Face access token",
"huggingfaceApiKeyHelp": "[TODO: Translate] Required to download from gated or private Hugging Face repositories. Create a read-only token at huggingface.co/settings/tokens, and accept the repository's terms on its page first.",
"huggingfaceApiKeyConfigured": "[TODO: Translate] Configured",
"huggingfaceApiKeyNotConfigured": "[TODO: Translate] Not configured",
"huggingfaceApiKeySet": "[TODO: Translate] Set up",
"civitaiHost": {
"label": "CivitAI ホスト",
"help": "「View on CivitAI」リンクを使うときに開く CivitAI サイトを選択します。",
+6
View File
@@ -325,6 +325,12 @@
"civitaiApiKeyConfigured": "설정됨",
"civitaiApiKeyNotConfigured": "설정되지 않음",
"civitaiApiKeySet": "설정",
"huggingfaceApiKey": "[TODO: Translate] Hugging Face Access Token",
"huggingfaceApiKeyPlaceholder": "[TODO: Translate] Enter your Hugging Face access token",
"huggingfaceApiKeyHelp": "[TODO: Translate] Required to download from gated or private Hugging Face repositories. Create a read-only token at huggingface.co/settings/tokens, and accept the repository's terms on its page first.",
"huggingfaceApiKeyConfigured": "[TODO: Translate] Configured",
"huggingfaceApiKeyNotConfigured": "[TODO: Translate] Not configured",
"huggingfaceApiKeySet": "[TODO: Translate] Set up",
"civitaiHost": {
"label": "CivitAI 호스트",
"help": "\"View on CivitAI\" 링크를 사용할 때 어떤 CivitAI 사이트를 열지 선택합니다.",
+6
View File
@@ -325,6 +325,12 @@
"civitaiApiKeyConfigured": "Настроен",
"civitaiApiKeyNotConfigured": "Не настроен",
"civitaiApiKeySet": "Настроить",
"huggingfaceApiKey": "[TODO: Translate] Hugging Face Access Token",
"huggingfaceApiKeyPlaceholder": "[TODO: Translate] Enter your Hugging Face access token",
"huggingfaceApiKeyHelp": "[TODO: Translate] Required to download from gated or private Hugging Face repositories. Create a read-only token at huggingface.co/settings/tokens, and accept the repository's terms on its page first.",
"huggingfaceApiKeyConfigured": "[TODO: Translate] Configured",
"huggingfaceApiKeyNotConfigured": "[TODO: Translate] Not configured",
"huggingfaceApiKeySet": "[TODO: Translate] Set up",
"civitaiHost": {
"label": "Хост CivitAI",
"help": "Выберите, какой сайт CivitAI будет открываться при использовании ссылок «View on CivitAI».",
+6
View File
@@ -325,6 +325,12 @@
"civitaiApiKeyConfigured": "已配置",
"civitaiApiKeyNotConfigured": "未配置",
"civitaiApiKeySet": "设置",
"huggingfaceApiKey": "[TODO: Translate] Hugging Face Access Token",
"huggingfaceApiKeyPlaceholder": "[TODO: Translate] Enter your Hugging Face access token",
"huggingfaceApiKeyHelp": "[TODO: Translate] Required to download from gated or private Hugging Face repositories. Create a read-only token at huggingface.co/settings/tokens, and accept the repository's terms on its page first.",
"huggingfaceApiKeyConfigured": "[TODO: Translate] Configured",
"huggingfaceApiKeyNotConfigured": "[TODO: Translate] Not configured",
"huggingfaceApiKeySet": "[TODO: Translate] Set up",
"civitaiHost": {
"label": "CivitAI 站点",
"help": "选择使用“在 CivitAI 中查看”时默认打开的 CivitAI 站点。",
+6
View File
@@ -325,6 +325,12 @@
"civitaiApiKeyConfigured": "已設定",
"civitaiApiKeyNotConfigured": "未設定",
"civitaiApiKeySet": "設定",
"huggingfaceApiKey": "[TODO: Translate] Hugging Face Access Token",
"huggingfaceApiKeyPlaceholder": "[TODO: Translate] Enter your Hugging Face access token",
"huggingfaceApiKeyHelp": "[TODO: Translate] Required to download from gated or private Hugging Face repositories. Create a read-only token at huggingface.co/settings/tokens, and accept the repository's terms on its page first.",
"huggingfaceApiKeyConfigured": "[TODO: Translate] Configured",
"huggingfaceApiKeyNotConfigured": "[TODO: Translate] Not configured",
"huggingfaceApiKeySet": "[TODO: Translate] Set up",
"civitaiHost": {
"label": "CivitAI 站點",
"help": "選擇使用「在 CivitAI 中查看」時預設開啟的 CivitAI 站點。",