@goodandready/dsh-clinebot 0.6.29 → 0.6.31
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/CHANGELOG.md +14 -0
- package/README.md +1 -1
- package/README.ru.md +1 -1
- package/README.zh.md +1 -1
- package/lib/client.js +5 -5
- package/lib/config.js +283 -283
- package/lib/http.js +2 -2
- package/lib/index.js +427 -426
- package/lib/path-safety.js +57 -4
- package/lib/price-sync.js +2 -5
- package/lib/provider-sync.js +258 -275
- package/lib/stats-storage.js +2 -27
- package/lib/transport/cline-transport.js +342 -343
- package/lib/updater.js +4 -9
- package/package.json +117 -117
package/lib/stats-storage.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { readFileSync, writeFileSync, renameSync, mkdirSync, existsSync, copyFileSync, readdirSync, unlinkSync } from 'node:fs'
|
|
9
|
-
import {
|
|
9
|
+
import { resolveDataPath, isSafeDataPath } from './path-safety.js'
|
|
10
10
|
import path from 'node:path'
|
|
11
11
|
import {
|
|
12
12
|
latencyBucketIndex,
|
|
@@ -85,33 +85,8 @@ function localDateKey(date) {
|
|
|
85
85
|
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
/** Get active .dsh directory, respecting DSH_HOME and HOME. */
|
|
89
|
-
function getDshHome() {
|
|
90
|
-
if (process.env.DSH_HOME) return process.env.DSH_HOME
|
|
91
|
-
const home = process.env.HOME || homedir()
|
|
92
|
-
return path.join(home, '.dsh')
|
|
93
|
-
}
|
|
94
|
-
|
|
95
88
|
export function resolvePath(targetPath) {
|
|
96
|
-
|
|
97
|
-
while (unwrapGuard < 5 && targetPath) {
|
|
98
|
-
if (typeof targetPath === 'function') {
|
|
99
|
-
try { targetPath = targetPath() } catch { targetPath = ''; break }
|
|
100
|
-
unwrapGuard += 1
|
|
101
|
-
} else if (typeof targetPath === 'object' && typeof targetPath.get === 'function') {
|
|
102
|
-
try { targetPath = targetPath.get() } catch { targetPath = ''; break }
|
|
103
|
-
unwrapGuard += 1
|
|
104
|
-
} else {
|
|
105
|
-
break
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (typeof targetPath !== 'string') targetPath = ''
|
|
109
|
-
if (!targetPath) return path.join(getDshHome(), 'clinebot-stats.json')
|
|
110
|
-
if (targetPath.startsWith('~/') || targetPath === '~') {
|
|
111
|
-
const home = process.env.HOME || homedir()
|
|
112
|
-
return path.join(home, targetPath.slice(1))
|
|
113
|
-
}
|
|
114
|
-
return path.resolve(targetPath)
|
|
89
|
+
return resolveDataPath(targetPath, 'clinebot-stats.json')
|
|
115
90
|
}
|
|
116
91
|
|
|
117
92
|
/**
|