MCPcopy Create free account
hub / github.com/VirtualHotBar/NetMount / toRelativePath

Function toRelativePath

src/utils/openlist/openlist.ts:242–261  ·  view source on GitHub ↗
(absolutePath: string)

Source from the content-addressed store, hash-verified

240
241 // 将绝对路径转换为相对路径(基于数据目录)
242 const toRelativePath = (absolutePath: string) => {
243 if (!absolutePath) return absolutePath
244 // 如果已经是相对路径,直接返回
245 if (!isAbsolutePath(absolutePath)) {
246 return absolutePath
247 }
248 // 将路径标准化为使用正斜杠
249 const normalizedPath = absolutePath.replace(/\\/g, '/')
250 let normalizedDataDir = dataDir.replace(/\\/g, '/')
251 // 确保数据目录以斜杠结尾,避免错误匹配
252 if (!normalizedDataDir.endsWith('/')) {
253 normalizedDataDir += '/'
254 }
255 // 如果路径以数据目录开头,转换为相对路径
256 if (normalizedPath.startsWith(normalizedDataDir)) {
257 const relativePath = normalizedPath.substring(normalizedDataDir.length)
258 return relativePath.startsWith('/') ? relativePath.substring(1) : relativePath
259 }
260 return absolutePath
261 }
262
263 // 转换数据库路径为相对路径
264 if (newOpenlistConfig.database?.db_file) {

Callers 1

modifyOpenlistConfigFunction · 0.85

Calls 1

isAbsolutePathFunction · 0.85

Tested by

no test coverage detected