docs: translate to English, upgrade VitePress 1.6.4, add API reference

- Upgrade VitePress from 1.0.0-rc.4 to 1.6.4 (stable)
- Update all dependencies (vue 3.5, typescript 5.6, @vue/tsconfig 0.5)
- Remove defunct Documate AI integration and google-analytics plugin
- Add Google Analytics via head config instead
- Translate all 25+ documentation pages from Chinese to English
- Add comprehensive REST API reference (docs/api/index.md)
- Add v3.2 changelog to sidebar navigation (fixes dead link)
- Update version string from v3.1 to v3.2
- Fix homepage changelog link to point to v3.2
- Update all WebUI screenshots with current v3.2 UI
- Add new screenshots: calendar view, bangumi poster wall
- Remove obsolete files: documate.json, deploy/windows.md, deploy/unix.md
- Update CSS variables for VitePress 1.6.x compatibility

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
Estrella Pan
2026-01-24 09:04:10 +01:00
parent 8694434269
commit f42a5296e7
51 changed files with 3066 additions and 8866 deletions

View File

@@ -1,31 +1,31 @@
# 使用 Docker-cli 部署
# Deploy with Docker CLI
## 新版本提醒
## Note on New Versions
AutoBangumi 2.6 版本后支持直接在 WebUI 中配置,你可以选择直接拉起容器再在 WebUI 中配置。老版本的环境变量配置参数会自动迁移,环境变量配置方式仍然可用,但是仅在第一次启动时生效。
Since AutoBangumi 2.6, you can configure everything directly in the WebUI. You can start the container first and then configure it in the WebUI. Environment variable configuration from older versions will be automatically migrated. Environment variables still work but only take effect on the first startup.
## 创建数据和配置文件夹
## Create Data and Configuration Directories
为了保证 AB 在每次更新之后数据和配置不丢失,推荐使用 Docker volume 或者 bind mount 进行数据和配置的持久化。
To ensure AB's data and configuration persist across updates, we recommend using Docker volumes or bind mounts.
```shell
# 使用 bind mount
# Using bind mount
mkdir -p ${HOME}/AutoBangumi/{config,data}
cd ${HOME}/AutoBangumi
```
Bind mount Docker volume 二选一
Choose either bind mount or Docker volume:
```shell
# 使用 Docker volume
# Using Docker volume
docker volume create AutoBangumi_config
docker volume create AutoBangumi_data
```
## 使用 Docker-cli 部署 AutoBangumi
## Deploy AutoBangumi with Docker CLI
复制以下命令运行即可。
Copy and run the following command.
请确保运行时目录处于AutoBangumi
Make sure your working directory is AutoBangumi.
```shell
docker run -d \
@@ -43,14 +43,14 @@ docker run -d \
ghcr.io/estrellaxd/auto_bangumi:latest
```
如果使用 Docker volume,可以自行替换绑定路径。
If using Docker volumes, replace the bind paths accordingly:
```shell
-v AutoBangumi_config:/app/config \
-v AutoBangumi_data:/app/data \
```
此时 AB WebUI 会自动运行,但是主程序会处于暂停状态,可以进入 `http://abhost:7892` 进行配置。
The AB WebUI will start automatically, but the main program will be paused. Access `http://abhost:7892` to configure it.
此时 AB 会自动把环境变量写入 `config.json` 文件中然后自动运行。
AB will automatically write environment variables to `config.json` and start running.
推荐使用 _[Portainer](https://www.portainer.io)_ 等带有 UI 的 Docker 管理器进行进阶部署
We recommend using _[Portainer](https://www.portainer.io)_ or similar Docker management UIs for advanced deployment.

View File

@@ -1,34 +1,32 @@
# 通过 Docker Compose 部署 AutoBangumi
# Deploy with Docker Compose
现在提供了一键部署的 **AutoBangumi** 的方法,可以使用 `docker-compose.yml` 文件进行部署。
A one-click deployment method for **AutoBangumi** using a `docker-compose.yml` file.
## 安装 Docker Compose
## Install Docker Compose
正常来说安装完 Docker 之后都会自带 `docker-compose`,使用命令:
Docker Compose usually comes bundled with Docker. Check with:
```bash
docker compose -v
```
检查版本即可
如果没有安装,可以使用以下命令安装:
If not installed, install it with:
```bash
$ sudo apt-get update
$ sudo apt-get install docker-compose-plugin
$ sudo apt-get update
$ sudo apt-get install docker-compose-plugin
```
## 部署 **AutoBangumi**
## Deploy **AutoBangumi**
### 创建 AutoBangumi及数据 文件夹
### Create AutoBangumi and Data Directories
```bash
mkdir -p ${HOME}/AutoBangumi/{config,data}
cd ${HOME}/AutoBangumi
```
### 选项1: 自定义 Docker Compose 配置文件
### Option 1: Custom Docker Compose Configuration
```yaml
version: "3.8"
@@ -44,7 +42,7 @@ services:
- "7892:7892"
restart: unless-stopped
dns:
- 223.5.5.5
- 8.8.8.8
network_mode: bridge
environment:
- TZ=Asia/Shanghai
@@ -53,39 +51,36 @@ services:
- UMASK=022
```
复制上面的内容到 `docker-compose.yml` 文件中。
Copy the above content into a `docker-compose.yml` file.
### 选项2: 下载 Docker Compose 配置文件
### Option 2: Download Docker Compose Configuration File
当你不想自己创建 `docker-compose.yml` 文件时,
项目中提供了三种安装方式:
If you don't want to create the `docker-compose.yml` file manually, the project provides pre-made configurations:
- 只安装 **AutoBangumi**
- Install **AutoBangumi** only:
```bash
wget https://raw.githubusercontent.com/EstrellaXD/Auto_Bangumi/main/docs/resource/docker-compose/AutoBangumi/docker-compose.yml
```
- 安装 **qBittorrent** **AutoBangumi**
- Install **qBittorrent** and **AutoBangumi**:
```bash
wget https://raw.githubusercontent.com/EstrellaXD/Auto_Bangumi/main/docs/resource/docker-compose/qBittorrent+AutoBangumi/docker-compose.yml
```
首先选择你要安装的方式,**拷贝上面的命令运行即可**,这一步是下载 `docker-compose.yml` 配置文件,如果需要自定义可以使用文本编辑器对其中的参数进行自定义。
Choose your installation method and run the command to download the `docker-compose.yml` file. You can customize parameters with a text editor if needed.
### 定义环境变量
### Define Environment Variables
如果你是用上面下载的 AB+QB / AB+QB+Plex 的 Docker-Compose 文件,那么你需要定义以下环境变量:
If you're using the downloaded AB+QB Docker Compose file, you need to define the following environment variables:
```shell
export \
QB_PORT=<YOUR_PORT>
```
- `QB_PORT`: 填写你的已经部署的 qBittorrent 端口号,或者想要自定义的端口号,比如: `8080`
- `QB_PORT`: Enter your existing qBittorrent port or your desired custom port, e.g., `8080`
### 拉起 Docker-Compose
### Start Docker Compose
```bash
# 如果配置过了上面的环境变量,请使用下面的方式拉起
docker compose up -d
```

View File

@@ -1,24 +1,24 @@
# 群晖 (DSM 7.2) 部署说明( QNAP 同理)
# Synology NAS (DSM 7.2) Deployment (QNAP Similar)
DSM 7.2 中,已经支持了 Docker Compose,推荐使用 Docker Compose 一键部署本项目。
DSM 7.2 supports Docker Compose, so we recommend using Docker Compose for one-click deployment.
## 创建配置和数据存储文件夹
## Create Configuration and Data Directories
`/volume1/docker/` 下创建 `AutoBangumi` 文件夹,然后在 `AutoBangumi` 文件夹下创建 `config` `data` 文件夹。
Create an `AutoBangumi` folder under `/volume1/docker/`, then create `config` and `data` subfolders inside it.
## 安装 Container Manager (Docker) 套件
## Install Container Manager (Docker) Package
进入套件中心,安装 Container Manager (Docker) 套件。
Open Package Center and install the Container Manager (Docker) package.
![install-docker](../image/dsm/install-docker.png){data-zoomable}
## 通过 Docker compose 安装配置 AB
## Install AB via Docker Compose
点击 **项目**,然后点击 **新建**,选择 **Docker Compose**
Click **Project**, then click **Create**, and select **Docker Compose**.
![new-compose](../image/dsm/new-compose.png){data-zoomable}
复制以下内容填入 **Docker Compose** 中。
Copy and paste the following content into **Docker Compose**:
```yaml
version: "3.4"
@@ -41,19 +41,19 @@ services:
- UMASK=022
```
点击 **下一步**,然后点击 **完成**
Click **Next**, then click **Done**.
![create](../image/dsm/create.png){data-zoomable}
完成创建之后进入 `http://<NAS IP>:7892` 即可进入 AB 并进行配置。
After creation, access `http://<NAS IP>:7892` to enter AB and configure it.
## 通过 Docker compose 安装配置 AB qBittorrent
## Install AB and qBittorrent via Docker Compose
在同时拥有代理和ipv6的情况下群晖nas提供的docker配置ipv6极为复杂推荐直接将AB和qBittorrent安装到host网络下降低工作量。
When you have both a proxy and IPv6, configuring IPv6 in Docker on Synology NAS can be complex. We recommend installing both AB and qBittorrent on the host network to reduce complexity.
以下内容的使用条件为在docker上已经部署好了一个clash代理并能够通过本地ip的指定端口进行访问。
The following configuration assumes you have a Clash proxy deployed in Docker that is accessible via a local IP at a specified port.
参考上一节的内容,将以下内容经过调整填入 **Docker Compose** 中。
Following the previous section, adjust and paste the following content into **Docker Compose**:
```yaml
qbittorrent:
@@ -61,13 +61,13 @@ services:
image: linuxserver/qbittorrent
hostname: qbittorrent
environment:
- PGID=1000 #需要自行修改填入
- PUID=1000 #需要自行修改填入
- PGID=1000 # Modify as needed
- PUID=1000 # Modify as needed
- WEBUI_PORT=8989
- TZ=Asia/Shanghai
volumes:
- ./qb_config:/config
- your_anime_path:/downloads # 注意 修改此处为自己存放动漫的目录,ab 内下载路径填写downloads
- your_anime_path:/downloads # Change this to your anime storage directory. Set download path in AB as /downloads
networks:
- host
restart: unless-stopped
@@ -76,10 +76,10 @@ services:
container_name: AutoBangumi
environment:
- TZ=Asia/Shanghai
- PGID=1000 #需要自行修改填入
- PUID=1000 #需要自行修改填入
- PGID=1000 # Modify as needed
- PUID=1000 # Modify as needed
- UMASK=022
- AB_DOWNLOADER_HOST=127.0.0.1:8989 #建议自行修改端口号
- AB_DOWNLOADER_HOST=127.0.0.1:8989 # Modify port as needed
volumes:
- /volume1/docker/ab/config:/app/config
- /volume1/docker/ab/data:/app/data
@@ -88,7 +88,6 @@ services:
- AB_METHOD=Advance
dns:
- 8.8.8.8
- 223.5.5.5
restart: unless-stopped
image: "ghcr.io/estrellaxd/auto_bangumi:latest"
depends_on:
@@ -96,28 +95,27 @@ services:
```
## 补充说明
## Additional Notes
其中的 PGID PUID 需要自行寻找,群晖的新 NAS 通常应该是:`PUID=1026,PGID=100`qBittorrent 对应的端口号在修改时注意保证所有位置全部修改完成。
The PGID and PUID values need to be determined for your system. For newer Synology NAS devices, they are typically: `PUID=1026, PGID=100`. When modifying the qBittorrent port, make sure to update it in all locations.
如果需要设置代理,请参考: [设置代理](../config/proxy)
For proxy setup, refer to: [Proxy Settings](../config/proxy)
如果使用较低性能的机器,默认的配置有概率会大量占用 **CPU**,使得 AB 无法链接 qB 且 qB WebUI 无法正常登陆的情况。
On lower-performance machines, the default configuration may heavily use the CPU, causing AB to fail connecting to qB and the qB WebUI to become inaccessible.
以 220+ 为例qB 参考配置如下,减少下载与上传的连接数,降低 CPU 占用。
For devices like the 220+, recommended qBittorrent settings to reduce CPU usage:
- 设置 -> 链接 -> 链接限制
- 全局最大连接数: 300
- torrent最大连接数: 60
- 全局上传窗口数上限: 15
- 每个torrent上传窗口数上限: 4
- Settings -> Connections -> Connection Limits
- Global maximum number of connections: 300
- Maximum number of connections per torrent: 60
- Global upload slots limit: 15
- Upload slots per torrent: 4
- BitTorrent
- 最大活跃检查种子数 1
- Torrent排队
- 最大活动的下载数: 3
- 最大活动的上传数: 5
- 最大活动的torrent: 10
- Maximum active checking torrents: 1
- Torrent Queueing
- Maximum active downloads: 3
- Maximum active uploads: 5
- Maximum active torrents: 10
- RSS
- RSS阅读器
- 每个订阅源文章数目最大值: 50
- RSS Reader
- Maximum number of articles per feed: 50

View File

@@ -1,21 +1,21 @@
# 本地部署运行
# Local Deployment
::: warning 警告
本地部署可能会产生一些不可预料的问题,我们强烈推荐您使用 Docker 部署。
::: warning
Local deployment may cause unexpected issues. We strongly recommend using Docker instead.
本地文档更新可能会有延迟,如有疑问请先在 [ISSUE](https://github.com/EstrellaXD/Auto_Bangumi/issues) 中提出。
This documentation may have update delays. If you have questions, please raise them in [Issues](https://github.com/EstrellaXD/Auto_Bangumi/issues).
:::
## 下载最新版本文件
## Download the Latest Release
```bash
VERSION=$(curl -s "https://api.github.com/repos/EstrellaXD/Auto_Bangumi/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
curl -L -O "https://github.com/EstrellaXD/Auto_Bangumi/releases/download/$VERSION/app-v$VERSION.zip"
```
## 解压代码压缩包
## Extract the Archive
UnixWSL 系统可以使用如下命令Windows 系统请自行解压。
On Unix/WSL systems, use the following command. On Windows, extract manually.
```bash
unzip app-v$VERSION.zip -d AutoBangumi
@@ -23,8 +23,9 @@ cd AutoBangumi
```
## 创建虚拟环境并且安装依赖
确认你的电脑本地已经安装了 `python3.10` 以上的版本,以及 `pip` 包管理工具。
## Create Virtual Environment and Install Dependencies
Ensure you have Python 3.10+ and pip installed locally.
```bash
cd src
@@ -32,23 +33,23 @@ python3 -m venv env
python3 pip install -r requirements.txt
```
## 创建配置和数据文件夹
## Create Configuration and Data Directories
```bash
mkdir config
mkdir data
```
## 运行 AutoBangumi
## Run AutoBangumi
```bash
python3 main.py
```
## Windows 开机自启
## Windows Auto-Start on Boot
可以用 `nssm` 来实现开机自启,以下以 `nssm` 为例:
You can use `nssm` for auto-start on boot. Example with `nssm`:
```powershell
nssm install AutoBangumi (Get-Command python).Source

View File

@@ -1,34 +1,33 @@
# 快速开始
# Quick Start
我们推荐你在 Docker 中部署运行 AutoBangumi
部署前请确认已经安装了 [Docker Engine][docker-engine] 或者 [Docker Desktop][docker-desktop]
We recommend deploying AutoBangumi in Docker.
Before deployment, make sure you have [Docker Engine][docker-engine] or [Docker Desktop][docker-desktop] installed.
## 创建数据和配置文件夹
为了保证 AB 在每次更新之后数据和配置不丢失,推荐使用 bind mount 或者 Docker volume 进行数据和配置的持久化。
## Create Data and Configuration Directories
To ensure AB's data and configuration persist across updates, we recommend using bind mounts or Docker volumes.
```shell
# 使用 bind mount
# Using bind mount
mkdir -p ${HOME}/AutoBangumi/{config,data}
cd ${HOME}/AutoBangumi
```
bind mount Docker volume 二选一
Choose either bind mount or Docker volume:
```shell
# 使用 Docker volume
# Using Docker volume
docker volume create AutoBangumi_config
docker volume create AutoBangumi_data
```
## 使用 Docker 部署 AutoBangumi
## Deploy AutoBangumi with Docker
使用以下命令时请确保处于AutoBangumi目录下。
Make sure you are in the AutoBangumi directory when running these commands.
### 选项1: 使用 Docker-cli 部署
### Option 1: Deploy with Docker CLI
复制以下命令运行即可。
Copy and run the following command:
```shell
docker run -d \
@@ -46,9 +45,9 @@ docker run -d \
ghcr.io/estrellaxd/auto_bangumi:latest
```
### 选项2: 使用 Docker-compose 部署
### Option 2: Deploy with Docker Compose
复制以下内容到 `docker-compose.yml` 文件中。
Copy the following content into a `docker-compose.yml` file:
```yaml
version: "3.8"
@@ -65,7 +64,7 @@ services:
network_mode: bridge
restart: unless-stopped
dns:
- 223.5.5.5
- 8.8.8.8
environment:
- TZ=Asia/Shanghai
- PGID=$(id -g)
@@ -73,53 +72,53 @@ services:
- UMASK=022
```
运行以下命令启动容器。
Run the following command to start the container:
```shell
docker compose up -d
```
## 安装 qBittorrent
## Install qBittorrent
如果你没有安装 qBittorrent请先安装 qBittorrent。
If you haven't installed qBittorrent, please install it first:
- [在 Docker 中安装 qBittorrent][qbittorrent-docker]
- [在 Windows/macOS 中安装 qBittorrent][qbittorrent-desktop]
- [在 Linux 中安装 qBittorrent-nox][qbittorrent-nox]
- [Install qBittorrent in Docker][qbittorrent-docker]
- [Install qBittorrent on Windows/macOS][qbittorrent-desktop]
- [Install qBittorrent-nox on Linux][qbittorrent-nox]
## 获取聚合 RSS 链接 (以蜜柑计划的聚合 RSS 为例)
## Get an Aggregated RSS Link (Using Mikan Project as an Example)
进入 [MiKan Project][mikan-project],注册账号并登录,然后点击右下角的 **RSS** 按钮,复制链接。
Visit [Mikan Project][mikan-project], register an account and log in, then click the **RSS** button in the bottom right corner and copy the link.
![mikan-rss](../image/rss/rss-token.png){data-zoomable}
获取的 RSS 地址如下:
The RSS URL will look like:
```txt
https://mikanani.me/RSS/MyBangumi?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# 或者
# or
https://mikanime.tv/RSS/MyBangumi?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```
详细步骤参考 [Mikan RSS][config-rss]
For detailed steps, see [Mikan RSS Setup][config-rss].
## 配置 AutoBangumi
## Configure AutoBangumi
安装好 AB 之后AB 的 WebUI 会自动运行,但是主程序会处于暂停状态,可以进入 `http://abhost:7892` 进行配置。
1. 打开网页后,默认用户名是`admin`默认密码是`adminadmin`。即可进入面板。
进入面板后请及时更改用户名和密码。
2. 填入下载器的地址,端口,用户名和密码。
After installing AB, the WebUI will start automatically, but the main program will be paused. You can access `http://abhost:7892` to configure it.
1. Open the webpage. The default username is `admin` and the default password is `adminadmin`. Change these immediately after first login.
2. Enter your downloader's address, port, username, and password.
![ab-webui](../image/config/downloader.png){width=500}{class=ab-shadow-card}
3. 点击 **Apply** 保存配置,此时 AB 会重启运行,当右上角的圆点变为绿色时,表示 AB 已经正常运行。
3. Click **Apply** to save the configuration. AB will restart, and when the dot in the upper right corner turns green, it indicates AB is running normally.
4. 点击右上角的添加按钮,勾选 **聚合 RSS** 选择解析器类型,填入 Mikan RSS 的地址。
4. Click the **+** button in the upper right corner, check **Aggregated RSS**, select the parser type, and enter your Mikan RSS URL.
![ab-rss](../image/config/add-rss.png){width=500}{class=ab-shadow-card}
等待 AB 解析聚合 RSS解析完成会自动添加番剧并且下载管理。
Wait for AB to parse the aggregated RSS. Once parsing is complete, it will automatically add anime and manage downloads.

View File

@@ -1,41 +0,0 @@
# 如何在本地运行 AutoBangumi
## 克隆项目
```bash
git clone https://github.com/EstrellaXD/Auto_Bangumi.git
```
## 安装依赖
确认你的电脑本地已经安装了 `python3.10` 以上的版本,以及 `pip` 包管理工具。
```bash
python3 pip install -r requirements.txt
```
## 进入源代码目录并且创建版本信息
```bash
cd backend/src
echo "VERSION = 'local'" > module/__version__.py
```
## 下载 WebUI
```bash
wget https://github.com/EstrellaXD/Auto_Bangumi/releases/download/latest/dist.zip
unzip dist.zip
mv dist templates
```
## 创建配置文件夹以及数据文件夹并运行
```bash
mkdir "config"
mkdir "data"
python3 main.py
```

View File

@@ -1,178 +0,0 @@
# Windows 本地部署
::: warning 警告
本地部署可能会产生一些不可预料的问题,我们强烈推荐您使用 Docker 部署。
:::
1. 克隆并进入 AutoBangumi 的 `git` 仓库:
```powershell
git clone https://github.com/EstrellaXD/Auto_Bangumi.git
cd Auto_Bangumi
```
2. 在 `backend\src\module` 目录下创建 `__version__.py` 文件并写入 `VERSION='local', 请注意文件编码格式为 `UTF-8`
3. 新建 `python` 虚拟环境、激活并安装依赖(需保证 `python -V` 打印的版本符合 `Dockerfile` 中的要求,如 `FROM python:3.11-alpine AS APP`
```powershell
python -m venv env
.\env\Scripts\Activate.ps1
python -m pip install -r backend\requirements.txt
```
4. 下载 WebUI 并安装:
```powershell
Invoke-WebRequest -Uri "https://github.com/EstrellaXD/Auto_Bangumi/releases/latest/download/dist.zip" -OutFile "dist.zip"
Expand-Archive -Path "dist.zip"
mv dist\* backend\src\templates
```
5. 创建 `data` 与 `config` 目录和空白的 `config_dev.json`(如果有必要将这些目录存储在其他位置,建议使用 Junction Directory 链接即可)
```powershell
mkdir backend\src\data
mkdir backend\src\config
echo "{}" > backend\src\config\config_dev.json
```
默认情况下PowerShell 输出文件编码为 `UTF-16LE`,你需要将 `config_dev.json` 的编码格式改为 `UTF-8`。
6. 运行程序测试是否配置正确:
```powershell
cd backend\src
python main.py
```
7. 接下来配置成服务以实现开机自启,以下以 `nssm` 为例:
```powershell
nssm install AutoBangumi (Get-Command python).Source
nssm set AutoBangumi AppParameters (Get-Item .\main.py).FullName
nssm set AutoBangumi AppDirectory (Get-Item ..).FullName
nssm set AutoBangumi Start SERVICE_DELAYED_AUTO_START
```
8. [可选] 由于 3.0 版本之前 AutoBangumi 没有修改规则或者批量移动下载位置的功能,可能遇到季名不符合需要 (如《鬼灭之刃 刀匠村篇》被视作一个仅具有一季的独立的影视作品,而不是系列动画的第三季) 或者中途想继续下载但是移出库防止出现在新剧集通知中等情况,可与考虑将下载目录和库目录区分开并用 Junction Directory 相连,这样在管理库时可以随意移动软链接而不影响 AutoBangumi 的工作。比如:
```powershell
### Configurations
$downloadDir = "path\to\download_dir"
$libraryDir = "path\to\library_dir"
$logFile = $(Join-Path -Path $download_dir -ChildPath "downloadWatcher.log")
$subfolderCreationTimeout = 10
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = $downloadDir
$watcher.EnableRaisingEvents = $true
function CreateJunction(
# The path to the folder containing junction targets, e.g. $downloadDir\<ShowName>
# The junction targets are its subfolders e.g. $downloadDir\<ShowName>\<SeasonName>
$targetRoot
) {
# The basename of $targetRoot, e.g. <ShowName>
$targetRootName = Split-Path -Path $targetRoot -Leaf
# The path the folder where junctions are created, e.g. $libraryDir\<ShowName>
$junctionRoot = $(Join-Path -Path $libraryDir -ChildPath $targetRootName)
# Create $junctionRoot if it does not exist
if (!(Test-Path $junctionRoot)) {
New-Item -ItemType Directory -Path $junctionRoot
Add-Content $logFile -Value "[Information] $(Get-Date) New folder created at $junctionRoot mirroring $targetRoot."
}
# Wait up to 10 secs for a subfolder to appear in $targetRoot
# This is because if $targetRoot is newly created the downloader may not have created the subfolder yet
$junctionTargetList = $(Get-ChildItem -Path $targetRoot -Directory)
$subfolderWaitCount = 0
while ($junctionTargetList.Count -eq 0) {
if ($subfolderWaitCount -ge $subfolderCreationTimeout) {
Add-Content $logFile -Value "[Warning] $(Get-Date) No subfolders exist in $targetRoot for junctioning, skipping."
Return
}
Start-Sleep -Seconds 1
try {
$junctionTargetList = $(Get-ChildItem -Path $targetRoot -Directory)
}
# If $targetRoot is removed/renamed during the wait, skip
catch [System.IO.DirectoryNotFoundException] {
Add-Content $logFile -Value "[Warning] $(Get-Date) $targetRoot is removed/renamed during the wait, skipping."
Return
}
$subfolderWaitCount++
}
Get-ChildItem $junctionRoot | Where-Object {$_.LinkType -eq "Junction"} | ForEach-Object {
# If a junction target is non-existent, remove it
if (!(Test-Path $_.Target)) {
Remove-Item $_.FullName
Add-Content $logFile -Value "[Information] $(Get-Date) Junction at $($_.FullName) is removed because its target $($_.Target) is non-existent."
}
else {
# Remove a junction target from $junctionTargetList if a junction in $junctionRoot is already pointing to it
$existingTarget = $_.Target
$junctionTargetList = $junctionTargetList | Where-Object {$_.FullName -ne $existingTarget}
Add-Content $logFile -Value "[Debug] $(Get-Date) $($_.FullName) already exists, skipping."
}
}
# Create junctions for each remaining target in $junctionTargetList
for ($i = 0; $i -lt $junctionTargetList.Count; $i++) {
$junctionTarget = $junctionTargetList[$i]
# The default name for the junction is the name of the junction target it self, e.g. <SeasonName>
$junctionName = $junctionTarget.Name
# If a junction with the same name already exists, append the current date to the name, e.g. <SeasonName>-yyyy-MM-dd
if (Test-Path $(Join-Path -Path $junctionRoot -ChildPath $junctionName)) {
$junctionName = "$junctionName-$(Get-Date -Format "yyyy-MM-dd")"
# If the new name is still taken, append a random string generated by taking first 5 chars from New-Guid to the name, e.g. <SeasonName>-yyyy-MM-dd-<RandomString>
while (Test-Path $(Join-Path -Path $junctionRoot -ChildPath $junctionName)) {
$junctionName = "$junctionName-$((New-Guid).ToString().Substring(0, 5))"
}
}
# Create the junction
New-Item -ItemType Junction -Path $(Join-Path -Path $junctionRoot -ChildPath $junctionName) -Value $junctionTarget.FullName
Add-Content $logFile -Value "[Information] $(Get-Date) New junction created at $(Join-Path -Path $junctionRoot -ChildPath $junctionName) pointing to $junctionTarget."
}
}
$action = {
# Event arguments, see https://learn.microsoft.com/en-us/dotnet/api/system.io.filesystemeventargs
$details = $event.SourceEventArgs
$path = $details.FullPath # Gets the full path of the affected file or directory.
$changeType = $details.ChangeType # Gets the change type, e.g. Created, Deleted, Renamed
Add-Content $logFile -Value "[Debug] $(Get-Date) $changeType event detected at $path."
if (!(Test-Path $path -PathType Container)) {
Add-Content $logFile -Value "[Debug] $(Get-Date) $name is not mirrored because it is not a folder."
Return
}
# If the directory contains .nomirror file, skip
if (Test-Path $(Join-Path -Path $path -ChildPath ".nomirror")) {
Add-Content $logFile -Value "[Debug] $(Get-Date) $path is not mirrored because it contains .nomirror file."
Return
}
# Process the directory as a root of junction targets
$targetRoot = $path
# If the directory is renamed, rename its mirror directory
if ($changeType -eq [System.IO.WatcherChangeTypes]::Renamed) {
$oldJunctionRoot = $(Join-Path -Path $libraryDir -ChildPath $details.OldName)
$newJunctionRoot = $(Join-Path -Path $libraryDir -ChildPath $details.Name)
if (Test-Path $oldJunctionRoot) {
Rename-Item -Path $oldJunctionRoot -NewName $details.Name
Add-Content $logFile -Value "[Information] $(Get-Date) $oldJunctionRoot is renamed to $newJunctionRoot."
}
else {
Add-Content $logFile -Value "[Warning] $(Get-Date) Junction at $oldJunctionRoot does not exist, skipping."
}
}
# If a directory is modified or newly created, update/create its mirror directory by creating/updating junctions to point to its subfolders
if ($changeType -eq [System.IO.WatcherChangeTypes]::Changed -or `
$changeType -eq [System.IO.WatcherChangeTypes]::Renamed -or `
$changeType -eq [System.IO.WatcherChangeTypes]::Created) {
CreateJunction $targetRoot
}
}
Register-ObjectEvent -InputObject $watcher -EventName Created -Action $action
Register-ObjectEvent -InputObject $watcher -EventName Changed -Action $action
Register-ObjectEvent -InputObject $watcher -EventName Renamed -Action $action
while ($true) {Start-Sleep 5}
```
上述脚本定义了一个 FileSystemWatcher 来监控下载目录的变化并镜像到库目录,可以用 `nssm` 安装为服务自动运行。如果需要排除一个目录,则只需要在该目录下新建一个名为 `.nomirror` 的文件即可。