From 9236106a3563baa55298603ed4c43cd98ceadf95 Mon Sep 17 00:00:00 2001 From: Ju4tCode <42488585+yanyongyu@users.noreply.github.com> Date: Sun, 11 Aug 2024 15:31:34 +0800 Subject: [PATCH 1/2] :memo: update localstore docs --- website/docs/best-practice/data-storing.md | 40 ++++++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/website/docs/best-practice/data-storing.md b/website/docs/best-practice/data-storing.md index 0ff78a6d2701..54b06c4248a3 100644 --- a/website/docs/best-practice/data-storing.md +++ b/website/docs/best-practice/data-storing.md @@ -31,17 +31,17 @@ require("nonebot_plugin_localstore") import nonebot_plugin_localstore as store # 获取插件缓存目录 -cache_dir = store.get_cache_dir("plugin_name") +cache_dir = store.get_plugin_cache_dir() # 获取插件缓存文件 -cache_file = store.get_cache_file("plugin_name", "file_name") +cache_file = store.get_plugin_cache_file("file_name") # 获取插件数据目录 -data_dir = store.get_data_dir("plugin_name") +data_dir = store.get_plugin_data_dir() # 获取插件数据文件 -data_file = store.get_data_file("plugin_name", "file_name") +data_file = store.get_plugin_data_file("file_name") # 获取插件配置目录 -config_dir = store.get_config_dir("plugin_name") +config_dir = store.get_plugin_config_dir() # 获取插件配置文件 -config_file = store.get_config_file("plugin_name", "file_name") +config_file = store.get_plugin_config_file("file_name") ``` :::danger 警告 @@ -53,9 +53,35 @@ config_file = store.get_config_file("plugin_name", "file_name") ```python from pathlib import Path -data_file = store.get_data_file("plugin_name", "file_name") +data_file = store.get_plugin_data_file("file_name") # 写入文件内容 data_file.write_text("Hello World!") # 读取文件内容 data = data_file.read_text() ``` + +## 配置项 + +### localstore_cache_dir + +自定义缓存目录 + +```dotenv +LOCALSTORE_CACHE_DIR=/tmp/cache +``` + +### localstore_config_dir + +自定义配置目录 + +```dotenv +LOCALSTORE_CONFIG_DIR=/tmp/config +``` + +### localstore_data_dir + +自定义数据目录 + +```dotenv +LOCALSTORE_DATA_DIR=/tmp/data +``` From fb0a2abe774484832e7dcf0d100198aaeac63c06 Mon Sep 17 00:00:00 2001 From: Ju4tCode <42488585+yanyongyu@users.noreply.github.com> Date: Sun, 11 Aug 2024 20:27:51 +0800 Subject: [PATCH 2/2] :memo: add config default value --- website/docs/best-practice/data-storing.md | 38 ++++++++++++++++++---- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/website/docs/best-practice/data-storing.md b/website/docs/best-practice/data-storing.md index 54b06c4248a3..d9f3a8c59c0b 100644 --- a/website/docs/best-practice/data-storing.md +++ b/website/docs/best-practice/data-storing.md @@ -60,28 +60,54 @@ data_file.write_text("Hello World!") data = data_file.read_text() ``` +:::note 提示 + +对于嵌套插件,子插件的存储目录将位于父插件存储目录下。 + +::: + ## 配置项 ### localstore_cache_dir 自定义缓存目录 +默认值: + +- macOS: `~/Library/Caches/` +- Unix: `~/.cache/` (XDG default) +- Windows: `C:\Users\\AppData\Local\\Cache` + ```dotenv LOCALSTORE_CACHE_DIR=/tmp/cache ``` -### localstore_config_dir +### localstore_data_dir -自定义配置目录 +自定义数据目录 + +默认值: + +- macOS: `~/Library/Application Support/` +- Unix: `~/.local/share/` or in $XDG_DATA_HOME, if defined +- Win XP (not roaming): `C:\Documents and Settings\\Application Data\` +- Win 7 (not roaming): `C:\Users\\AppData\Local\` ```dotenv -LOCALSTORE_CONFIG_DIR=/tmp/config +LOCALSTORE_DATA_DIR=/tmp/data ``` -### localstore_data_dir +### localstore_config_dir -自定义数据目录 +自定义配置目录 + +默认值: + +- macOS: same as user_data_dir +- Unix: `~/.config/` +- Win XP (roaming): `C:\Documents and Settings\\Local Settings\Application Data\` +- Win 7 (roaming): `C:\Users\\AppData\Roaming\` ```dotenv -LOCALSTORE_DATA_DIR=/tmp/data +LOCALSTORE_CONFIG_DIR=/tmp/config ```