优化env文件

This commit is contained in:
Julian Freeman
2026-01-05 12:38:13 -04:00
parent f549059e47
commit 660fb811a2
3 changed files with 11 additions and 5 deletions

View File

@@ -1,2 +1,4 @@
NOCODB_TOKEN=
NOCODB_LIST_URL=https://nocodb.example.com/api/v2/tables/xxx/records
NOCODB_LIST_URL=https://nocodb.example.com/api/v2/tables/xxx/records
NOCODB_FIELD_ID=账号ID
NOCODB_FIELD_ALIAS=_最终输出

View File

@@ -1,3 +1,5 @@
# Teams 别名插件
给 Microsoft Teams 好友的名称添加别名。
使用 NocoDB 数据库获取数据。修改 .env 之后别忘了修改 manifest.json 中的 host_permissions

View File

@@ -1,7 +1,9 @@
const NOCODB_CONFIG = {
// Token and URL are loaded from env.js (ENV_SECRETS global variable)
TOKEN: (typeof ENV_SECRETS !== 'undefined' && ENV_SECRETS.NOCODB_TOKEN) ? ENV_SECRETS.NOCODB_TOKEN : "",
LIST_URL: (typeof ENV_SECRETS !== 'undefined' && ENV_SECRETS.NOCODB_LIST_URL) ? ENV_SECRETS.NOCODB_LIST_URL : ""
LIST_URL: (typeof ENV_SECRETS !== 'undefined' && ENV_SECRETS.NOCODB_LIST_URL) ? ENV_SECRETS.NOCODB_LIST_URL : "",
FIELD_ID: (typeof ENV_SECRETS !== 'undefined' && ENV_SECRETS.NOCODB_FIELD_ID) ? ENV_SECRETS.NOCODB_FIELD_ID : "账号ID",
FIELD_ALIAS: (typeof ENV_SECRETS !== 'undefined' && ENV_SECRETS.NOCODB_FIELD_ALIAS) ? ENV_SECRETS.NOCODB_FIELD_ALIAS : "_最终输出"
};
/**
@@ -29,7 +31,7 @@ async function fetchAliasesFromDB() {
// 构建带参数的 URL
const url = new URL(listUrl);
url.searchParams.append("limit", limit);
url.searchParams.append("fields", "账号ID,_最终输出");
url.searchParams.append("fields", `${NOCODB_CONFIG.FIELD_ID},${NOCODB_CONFIG.FIELD_ALIAS}`);
url.searchParams.append("offset", offset);
const response = await fetch(url.toString(), { headers });
@@ -48,9 +50,9 @@ async function fetchAliasesFromDB() {
// 整理数据
rows.forEach(row => {
if (row["账号ID"] && row["_最终输出"]) {
if (row[NOCODB_CONFIG.FIELD_ID] && row[NOCODB_CONFIG.FIELD_ALIAS]) {
// key = 账号ID, value = _最终输出
allAliases[row["账号ID"]] = row["_最终输出"];
allAliases[row[NOCODB_CONFIG.FIELD_ID]] = row[NOCODB_CONFIG.FIELD_ALIAS];
}
});