MCPcopy
hub / github.com/download-directory/download-directory.github.io / getRepositoryPreview

Function getRepositoryPreview

repository-info.ts:9–34  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

7}
8
9export function getRepositoryPreview(url: string):
10| {error: 'NOT_A_REPOSITORY' | 'NOT_A_DIRECTORY'}
11| {user: string; repository: string; parts: string[]; directory: string} {
12 const [, user, repository, ...restPathParts] = cleanUrl(
13 decodeURIComponent(new URL(url).pathname),
14 ).split('/');
15 const type = restPathParts[0];
16
17 if (!user || !repository) {
18 return {error: 'NOT_A_REPOSITORY'};
19 }
20
21 if (type && type !== 'tree') {
22 return {error: 'NOT_A_DIRECTORY'};
23 }
24
25 const directoryParts = type === 'tree' ? restPathParts.slice(2) : [];
26 const parts = type === 'tree' ? restPathParts.slice(1) : [];
27
28 return {
29 user,
30 repository,
31 parts,
32 directory: directoryParts.join('/'),
33 };
34}
35
36async function parsePath(
37 user: string,

Callers 2

initFunction · 0.85

Calls 1

cleanUrlFunction · 0.85

Tested by

no test coverage detected