项目介绍
CloudDrive2 可以通过 Webhook 将文件变化通知给 Symedia。下文提供 webhook.toml 配置,并说明服务地址、启用开关和鉴权字段。先确认接收接口能被 CloudDrive2 访问,再用一个测试文件检查通知和后续处理。
cd2配置sa的webhook.toml文件
其中:
base_url = "http://127.0.0.1:8095" 修改为自己nas的ip
# Whether the webhook is enabled
enabled = true 这里设置为 true
# global variables: global variables are used to replace the placeholders in URL and body of the webhook
# {device_name} - The name of the device
# {user_name} - Current user name
# {version} - The version of the application
# {event_category} - The category of the event
# {event_name} - The name of the event
# {event_time} - The time of the event occurred, unix epoch time in seconds
# {send_time} - The time of the data sent, unix epoch time in seconds
# global parameters
[global_params]
# The base URL of the server to send the data to, the server must be able to receive POST requests
base_url = "http://127.0.0.1:8095"
# Whether the webhook is enabled
enabled = true
# The default http headers
[global_params.default_headers]
content-type = "application/json"
user-agent = "clouddrive2/{version}"
authorization = "请填写自己的访问凭据"
# File system watcher webhook configuration
[file_system_watcher]
# The URL of the server to send the data to, the server must be able to receive POST requests
url = "{base_url}/api/v1/webhook/clouddrive2/file_notify?device_name={device_name}&user_name={user_name}&type={event_name}"
# http method, can be "GET" or "POST", if not specified, the default value is POST
method = "POST"
# Whether the file system watcher is enabled
enabled = true
# The body to be sent to the server can be a JSON string
# The following is a sample template for the data to be sent
# the json string should contains at least an array of file changes, each file change item shoud contain the following fields
# {event_category} - The category of the event is "file"
# {event_name} - The name of the event is "notify"
# {action} - The action of file change (create, delete, rename)
# {is_dir} - Whether the file is a directory (false: file, true: directory)
# {source_file} - The source file's path of the action
# {destination_file} - The destination file's path of the action, only valid for action rename(move)
body = '''
{
"device_name": "{device_name}",
"user_name": "{user_name}",
"version": "{version}",
"event_category": "{event_category}",
"event_name": "{event_name}",
"event_time": "{event_time}",
"send_time": "{send_time}",
"data": [
{
"action": "{action}",
"is_dir": "{is_dir}",
"source_file": "{source_file}",
"destination_file": "{destination_file}"
}
]
}
'''
# specify additional http headers for the file system watcher request if required, headers with same name will override in the default headers
[file_system_watcher.headers]
additional_header = "value"
# mount point watcher configuration
[mount_point_watcher]
# The URL of the server to send the data to, the server must be able to receive POST requests
url = "{base_url}/api/v1/webhook/clouddrive2/mount_notify?device_name={device_name}&user_name={user_name}&type={event_name}"
# http method
method = "POST"
# Whether the mount point watcher is enabled
enabled = true
# The body to be sent to the server can be a JSON string
# The following is a sample template for the data to be sent
# the mount_point_watcher should contains at least an array of mount point changes, each mount point change item shoud contain the following fields
# {event_category} - The category of the event is "mount_point"
# {event_name} - The name of the event is "mount" or "unmount"
# {action} - The action of mount point change (mount, unmount)
# {mount_point} - The mount point's path of the action
# {status} - The status of the action (true for success, false for failed)
# {reason} - The failed reason, empty string means success
body = '''
{
"device_name": "{device_name}",
"user_name": "{user_name}",
"version": "{version}",
"event_category": "{event_category}",
"event_name": "{event_name}",
"event_time": "{event_time}",
"send_time": "{send_time}",
"data": [
{
"action": "{action}",
"mount_point": "{mount_point}",
"status": "{status}",
"reason": "{reason}"
}
]
}
'''
# specify additional http headers for the file system watcher request if required, headers with same name will override in the default headers
[mount_point_watcher.headers]
user-agent = "clouddrive2/{version}/mount"
补充:部署与使用
常见问题
- HTTP 请求成功但没有任务:检查接收接口、鉴权、事件类型与规则,不只看状态码。
- 文件变化先于挂载可见时需处理就绪时机,避免立即重试造成重复归档。
更新与备份
备份 Webhook 配置、接收规则、鉴权恢复方法与目录映射;保留可停用通知的回退配置。