Build the full API URL for a file path, scoped under current session's /apps/ directory
(filePath: string, action?: string)
| 11 | |
| 12 | /** Build the full API URL for a file path, scoped under current session's /apps/ directory */ |
| 13 | function apiUrl(filePath: string, action?: string): string { |
| 14 | const session = getSessionPath(); |
| 15 | // Strip leading slash for uniform handling |
| 16 | const cleaned = filePath.startsWith('/') ? filePath.slice(1) : filePath; |
| 17 | // If the path already starts with "apps/", don't add the prefix again |
| 18 | const alreadyPrefixed = cleaned.startsWith('apps/') || cleaned === 'apps'; |
| 19 | const fullPath = session |
| 20 | ? alreadyPrefixed |
| 21 | ? `${session}/${cleaned}` |
| 22 | : `${session}/apps/${cleaned}` |
| 23 | : alreadyPrefixed |
| 24 | ? cleaned |
| 25 | : `apps/${cleaned}`; |
| 26 | let url = `${API_PATH}?path=${encodeURIComponent(fullPath)}`; |
| 27 | if (action) url += `&action=${encodeURIComponent(action)}`; |
| 28 | return url; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * List files in a directory. |
no test coverage detected