@lsby/cloudflare-ipv6-ddns 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +3 -2
- package/package.json +4 -1
- package/.eslintrc.cjs +0 -64
- package/.prettierrc +0 -8
- package/.vscode/settings.json +0 -7
- package/src/index.ts +0 -87
- package/src/tools/axios.ts +0 -15
- package/tsconfig.json +0 -110
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ async function 获取IPv6地址() {
|
|
|
14
14
|
throw e;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
async function 增加或更新dns记录(cf句柄, 区域id, 域名, ip地址, 类型, 使用代理 = false, ttl =
|
|
17
|
+
async function 增加或更新dns记录(cf句柄, 区域id, 域名, ip地址, 类型, 使用代理 = false, ttl = 1) {
|
|
18
18
|
console.log('开始增加或修改dns记录...');
|
|
19
19
|
console.log('查询dns记录列表...');
|
|
20
20
|
const 列表 = await cf句柄.dns.records.list({ zone_id: 区域id });
|
|
@@ -41,7 +41,8 @@ async function 增加或更新dns记录(cf句柄, 区域id, 域名, ip地址,
|
|
|
41
41
|
zone_id: 区域id,
|
|
42
42
|
content: ip地址,
|
|
43
43
|
name: 域名,
|
|
44
|
-
proxied
|
|
44
|
+
// 截至 2024年5月2日, 接口实际返回的值包括proxiable和proxied, proxiable总为true, 所以这里使用proxied.
|
|
45
|
+
proxied: 目标.proxied == null ? 使用代理 : 目标.proxied,
|
|
45
46
|
type: 类型,
|
|
46
47
|
comment: 目标.comment || '',
|
|
47
48
|
ttl: 目标.ttl || ttl,
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lsby/cloudflare-ipv6-ddns",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"lsby-cloudflare-ipv6-ddns": "dist/index.js"
|
|
7
7
|
},
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
8
11
|
"dependencies": {
|
|
9
12
|
"axios": "^1.6.8",
|
|
10
13
|
"cloudflare": "^3.1.0",
|
package/.eslintrc.cjs
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
extends: [
|
|
3
|
-
// 避免和prettier冲突
|
|
4
|
-
'prettier',
|
|
5
|
-
],
|
|
6
|
-
|
|
7
|
-
plugins: [
|
|
8
|
-
// 基础ts支持
|
|
9
|
-
'@typescript-eslint',
|
|
10
|
-
// 检查没有使用的引入, 并可以自动修复
|
|
11
|
-
'unused-imports',
|
|
12
|
-
// 排序类属性
|
|
13
|
-
'sort-class-members',
|
|
14
|
-
],
|
|
15
|
-
parser: '@typescript-eslint/parser',
|
|
16
|
-
|
|
17
|
-
// 忽略文件夹
|
|
18
|
-
ignorePatterns: ['node_modules', 'dist'],
|
|
19
|
-
|
|
20
|
-
// 指定ts项目
|
|
21
|
-
root: true,
|
|
22
|
-
parserOptions: { project: true },
|
|
23
|
-
|
|
24
|
-
// 规则
|
|
25
|
-
overrides: [
|
|
26
|
-
{
|
|
27
|
-
files: ['src/**/*.ts', 'src/**/*.tsx'],
|
|
28
|
-
rules: {
|
|
29
|
-
// 必须标注函数返回类型
|
|
30
|
-
'@typescript-eslint/explicit-function-return-type': ['error', {}],
|
|
31
|
-
|
|
32
|
-
// 检查没有使用的变量
|
|
33
|
-
'@typescript-eslint/no-unused-vars': [
|
|
34
|
-
'warn',
|
|
35
|
-
{
|
|
36
|
-
varsIgnorePattern: '^_',
|
|
37
|
-
argsIgnorePattern: '^_',
|
|
38
|
-
destructuredArrayIgnorePattern: '^_',
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
|
|
42
|
-
// 检查没有使用的引入, 并自动修复
|
|
43
|
-
'unused-imports/no-unused-imports': 'error',
|
|
44
|
-
|
|
45
|
-
// 排序类属性
|
|
46
|
-
'sort-class-members/sort-class-members': [
|
|
47
|
-
2,
|
|
48
|
-
{
|
|
49
|
-
order: [
|
|
50
|
-
'[static-properties]',
|
|
51
|
-
'[static-methods]',
|
|
52
|
-
'[properties]',
|
|
53
|
-
'[conventional-private-properties]',
|
|
54
|
-
'constructor',
|
|
55
|
-
'[methods]',
|
|
56
|
-
'[conventional-private-methods]',
|
|
57
|
-
],
|
|
58
|
-
accessorPairPositioning: 'getThenSet',
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
}
|
package/.prettierrc
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"printWidth": 120,
|
|
3
|
-
"trailingComma": "all",
|
|
4
|
-
"semi": false,
|
|
5
|
-
"singleQuote": true,
|
|
6
|
-
"plugins": ["prettier-plugin-packagejson", "@ianvs/prettier-plugin-sort-imports"],
|
|
7
|
-
"importOrder": ["<BUILTIN_MODULES>", "<THIRD_PARTY_MODULES>", "^@([^/]+?)/(.*)$", "^[./]"]
|
|
8
|
-
}
|
package/.vscode/settings.json
DELETED
package/src/index.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import Cloudflare from 'cloudflare'
|
|
3
|
-
import dotenv from 'dotenv'
|
|
4
|
-
import { axios请求 } from './tools/axios.js'
|
|
5
|
-
|
|
6
|
-
async function 获取IPv6地址(): Promise<string> {
|
|
7
|
-
try {
|
|
8
|
-
console.log('开始获取本机ipv6地址...')
|
|
9
|
-
const 响应 = await axios请求<{
|
|
10
|
-
ip: string
|
|
11
|
-
}>({ method: 'GET', url: 'https://api6.ipify.org/?format=json' })
|
|
12
|
-
console.log('成功获取本机ipv6地址: %O', 响应.ip)
|
|
13
|
-
return 响应.ip
|
|
14
|
-
} catch (e) {
|
|
15
|
-
console.log('无法获得ipv6地址')
|
|
16
|
-
throw e
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async function 增加或更新dns记录(
|
|
21
|
-
cf句柄: Cloudflare,
|
|
22
|
-
区域id: string,
|
|
23
|
-
域名: string,
|
|
24
|
-
ip地址: string,
|
|
25
|
-
类型: 'A' | 'AAAA',
|
|
26
|
-
使用代理: boolean = false,
|
|
27
|
-
ttl: number = 3600,
|
|
28
|
-
): Promise<void> {
|
|
29
|
-
console.log('开始增加或修改dns记录...')
|
|
30
|
-
|
|
31
|
-
console.log('查询dns记录列表...')
|
|
32
|
-
const 列表 = await cf句柄.dns.records.list({ zone_id: 区域id })
|
|
33
|
-
|
|
34
|
-
var 目标 = 列表.result.filter((a) => a.name == 域名)[0]
|
|
35
|
-
if (目标 == null) {
|
|
36
|
-
console.log('没有找到域名%O对应的记录, 将新增该记录...', 域名)
|
|
37
|
-
await cf句柄.dns.records.create({
|
|
38
|
-
zone_id: 区域id,
|
|
39
|
-
content: ip地址,
|
|
40
|
-
name: 域名,
|
|
41
|
-
proxied: 使用代理,
|
|
42
|
-
type: 类型,
|
|
43
|
-
comment: '',
|
|
44
|
-
ttl: ttl,
|
|
45
|
-
tags: [],
|
|
46
|
-
})
|
|
47
|
-
console.log('新增记录成功')
|
|
48
|
-
return
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (目标.id == null) throw new Error('无法获得需要的信息')
|
|
52
|
-
|
|
53
|
-
console.log('找到域名%O对应的记录, 将修改该记录', 域名)
|
|
54
|
-
await cf句柄.dns.records.edit(目标.id, {
|
|
55
|
-
zone_id: 区域id,
|
|
56
|
-
content: ip地址,
|
|
57
|
-
name: 域名,
|
|
58
|
-
proxied: 目标.proxiable || 使用代理,
|
|
59
|
-
type: 类型,
|
|
60
|
-
comment: 目标.comment || '',
|
|
61
|
-
ttl: 目标.ttl || ttl,
|
|
62
|
-
tags: 目标.tags || [],
|
|
63
|
-
})
|
|
64
|
-
console.log('修改记录成功')
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async function main(): Promise<void> {
|
|
68
|
-
console.log('开始运行...')
|
|
69
|
-
|
|
70
|
-
dotenv.config()
|
|
71
|
-
|
|
72
|
-
const 令牌 = process.env['CLOUDFLARE_API_TOKEN']
|
|
73
|
-
const 区域id = process.env['CLOUDFLARE_ZONE_ID']
|
|
74
|
-
const 域名 = process.env['DOMAIN']
|
|
75
|
-
|
|
76
|
-
if (!令牌 || !区域id || !域名) {
|
|
77
|
-
console.log('未提供必要的环境变量:CLOUDFLARE_API_TOKEN, CLOUDFLARE_ZONE_ID, DOMAIN, UPDATE_TIME')
|
|
78
|
-
process.exit(1)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const cloudflare = new Cloudflare({ apiToken: 令牌 })
|
|
82
|
-
|
|
83
|
-
const ipv6地址 = await 获取IPv6地址()
|
|
84
|
-
await 增加或更新dns记录(cloudflare, 区域id, 域名, ipv6地址, 'AAAA')
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
await main().catch(console.log)
|
package/src/tools/axios.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import util from 'util'
|
|
2
|
-
import axios, { AxiosError, AxiosRequestConfig } from 'axios'
|
|
3
|
-
|
|
4
|
-
export async function axios请求<返回类型 = any>(options: AxiosRequestConfig<any>): Promise<返回类型> {
|
|
5
|
-
try {
|
|
6
|
-
var r = await axios.request(options)
|
|
7
|
-
return r.data
|
|
8
|
-
} catch (e) {
|
|
9
|
-
if (e instanceof AxiosError && e.response != null) {
|
|
10
|
-
var { status, statusText, data } = e.response
|
|
11
|
-
throw new Error(util.format('axios错误: %O, 错误码: %O, 消息: %O', statusText, status, data))
|
|
12
|
-
}
|
|
13
|
-
throw e
|
|
14
|
-
}
|
|
15
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"include": ["src", ".eslintrc.cjs"],
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
5
|
-
|
|
6
|
-
/* Projects */
|
|
7
|
-
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
8
|
-
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
9
|
-
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
10
|
-
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
11
|
-
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
12
|
-
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
13
|
-
|
|
14
|
-
/* Language and Environment */
|
|
15
|
-
"target": "ESNext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
|
16
|
-
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
17
|
-
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
18
|
-
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
|
19
|
-
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
20
|
-
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
21
|
-
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
22
|
-
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
23
|
-
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
24
|
-
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
25
|
-
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
26
|
-
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
27
|
-
|
|
28
|
-
/* Modules */
|
|
29
|
-
"module": "NodeNext" /* Specify what module code is generated. */,
|
|
30
|
-
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
31
|
-
"moduleResolution": "NodeNext" /* Specify how TypeScript looks up a file from a given module specifier. */,
|
|
32
|
-
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
33
|
-
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
34
|
-
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
35
|
-
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
36
|
-
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
37
|
-
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
38
|
-
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
39
|
-
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
40
|
-
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
41
|
-
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
42
|
-
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
43
|
-
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
44
|
-
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
45
|
-
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
46
|
-
|
|
47
|
-
/* JavaScript Support */
|
|
48
|
-
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
49
|
-
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
50
|
-
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
51
|
-
|
|
52
|
-
/* Emit */
|
|
53
|
-
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
54
|
-
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
55
|
-
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
56
|
-
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
57
|
-
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
58
|
-
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
59
|
-
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
|
|
60
|
-
// "removeComments": true, /* Disable emitting comments. */
|
|
61
|
-
"noEmit": false /* Disable emitting files from a compilation. */,
|
|
62
|
-
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
63
|
-
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
|
64
|
-
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
65
|
-
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
66
|
-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
67
|
-
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
68
|
-
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
69
|
-
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
70
|
-
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
71
|
-
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
72
|
-
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
73
|
-
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
74
|
-
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
75
|
-
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
|
76
|
-
|
|
77
|
-
/* Interop Constraints */
|
|
78
|
-
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
79
|
-
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
80
|
-
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
81
|
-
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
|
82
|
-
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
83
|
-
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
|
84
|
-
|
|
85
|
-
/* Type Checking */
|
|
86
|
-
"strict": true /* Enable all strict type-checking options. */,
|
|
87
|
-
"noImplicitAny": true /* Enable error reporting for expressions and declarations with an implied 'any' type. */,
|
|
88
|
-
"strictNullChecks": true /* When type checking, take into account 'null' and 'undefined'. */,
|
|
89
|
-
"strictFunctionTypes": true /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */,
|
|
90
|
-
"strictBindCallApply": true /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */,
|
|
91
|
-
"strictPropertyInitialization": true /* Check for class properties that are declared but not set in the constructor. */,
|
|
92
|
-
"noImplicitThis": true /* Enable error reporting when 'this' is given the type 'any'. */,
|
|
93
|
-
"useUnknownInCatchVariables": true /* Default catch clause variables as 'unknown' instead of 'any'. */,
|
|
94
|
-
"alwaysStrict": true /* Ensure 'use strict' is always emitted. */,
|
|
95
|
-
// "noUnusedLocals": true /* Enable error reporting when local variables aren't read. */,
|
|
96
|
-
// "noUnusedParameters": true /* Raise an error when a function parameter isn't read. */,
|
|
97
|
-
"exactOptionalPropertyTypes": true /* Interpret optional property types as written, rather than adding 'undefined'. */,
|
|
98
|
-
"noImplicitReturns": true /* Enable error reporting for codepaths that do not explicitly return in a function. */,
|
|
99
|
-
"noFallthroughCasesInSwitch": true /* Enable error reporting for fallthrough cases in switch statements. */,
|
|
100
|
-
"noUncheckedIndexedAccess": true /* Add 'undefined' to a type when accessed using an index. */,
|
|
101
|
-
"noImplicitOverride": true /* Ensure overriding members in derived classes are marked with an override modifier. */,
|
|
102
|
-
"noPropertyAccessFromIndexSignature": true /* Enforces using indexed accessors for keys declared using an indexed type. */,
|
|
103
|
-
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
104
|
-
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
105
|
-
|
|
106
|
-
/* Completeness */
|
|
107
|
-
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
108
|
-
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
109
|
-
}
|
|
110
|
-
}
|