(uri: string)
| 1343 | } |
| 1344 | |
| 1345 | function contentUriToFileUri(uri: string): string | null { |
| 1346 | try { |
| 1347 | const parsed = Uri.parse(uri) as ParsedUri | null; |
| 1348 | if (!parsed || typeof parsed !== "object") return null; |
| 1349 | const { docId, rootUri, isFileUri } = parsed; |
| 1350 | if (!docId) return null; |
| 1351 | |
| 1352 | if (isFileUri && rootUri) { |
| 1353 | return rootUri; |
| 1354 | } |
| 1355 | |
| 1356 | const providerMatch = |
| 1357 | /^content:\/\/com\.((?![:<>"/\\|?*]).*?)\.documents\//.exec( |
| 1358 | rootUri ?? "", |
| 1359 | ); |
| 1360 | const providerId = providerMatch ? providerMatch[1] : null; |
| 1361 | |
| 1362 | let normalized = docId.trim(); |
| 1363 | if (!normalized) return null; |
| 1364 | |
| 1365 | switch (providerId) { |
| 1366 | case "foxdebug.acode": |
| 1367 | case "foxdebug.acodefree": |
| 1368 | normalized = normalized.replace(/:+$/, ""); |
| 1369 | if (!normalized) return null; |
| 1370 | if (normalized.startsWith("raw:/")) { |
| 1371 | normalized = normalized.slice(4); |
| 1372 | } else if (normalized.startsWith("raw:")) { |
| 1373 | normalized = normalized.slice(4); |
| 1374 | } |
| 1375 | if (!normalized.startsWith("/")) return null; |
| 1376 | return buildFileUri(normalized); |
| 1377 | case "android.externalstorage": |
| 1378 | normalized = normalized.replace(/:+$/, ""); |
| 1379 | if (!normalized) return null; |
| 1380 | |
| 1381 | if (normalized.startsWith("/")) { |
| 1382 | return buildFileUri(normalized); |
| 1383 | } |
| 1384 | |
| 1385 | if (normalized.startsWith("raw:/")) { |
| 1386 | return buildFileUri(normalized.slice(4)); |
| 1387 | } |
| 1388 | |
| 1389 | if (normalized.startsWith("raw:")) { |
| 1390 | return buildFileUri(normalized.slice(4)); |
| 1391 | } |
| 1392 | |
| 1393 | const separator = normalized.indexOf(":"); |
| 1394 | if (separator === -1) return null; |
| 1395 | |
| 1396 | const root = normalized.slice(0, separator); |
| 1397 | const remainder = normalized.slice(separator + 1); |
| 1398 | if (!remainder) return null; |
| 1399 | |
| 1400 | switch (root) { |
| 1401 | case "primary": |
| 1402 | return buildFileUri(`/storage/emulated/0/${remainder}`); |
no test coverage detected