Skip to content

Commit 28f9a03

Browse files
committed
feat: adds domain to link info result
1 parent 778c3a2 commit 28f9a03

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

src/functions/linkValidation.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type LinkInformation = {
77
acceptsRanges: boolean;
88
fileName: string | null;
99
isVideo: boolean;
10+
domain: string;
1011
error?: string;
1112
}
1213

@@ -106,6 +107,7 @@ export async function getLinkInformation(link: string): Promise<LinkInformation>
106107
size: null,
107108
acceptsRanges: false,
108109
fileName: null,
110+
domain: new URL(link).hostname,
109111
isVideo: false,
110112
error: `Failed to fetch link information: ${response.statusText} | ${response.status}`
111113
};
@@ -117,6 +119,7 @@ export async function getLinkInformation(link: string): Promise<LinkInformation>
117119
size: await linkSize(response.headers),
118120
acceptsRanges: await linkAcceptsRanges(response.headers),
119121
fileName: await getLinkName(response.headers, link),
122+
domain: new URL(link).hostname,
120123
isVideo: await isVideoLink(response.headers)
121124
}
122125
return data;
@@ -128,6 +131,13 @@ export async function getLinkInformation(link: string): Promise<LinkInformation>
128131
acceptsRanges: false,
129132
fileName: null,
130133
isVideo: false,
134+
domain: (() => {
135+
try {
136+
return new URL(link).hostname;
137+
} catch {
138+
return "unknown";
139+
}
140+
})(),
131141
error: (error as Error).message
132142
};
133143
}

src/library/tables.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export function linkInfoRows(info: LinkInformation): [string, string][] {
7575
["Accepts Ranges", String(info.acceptsRanges)],
7676
["File Name", info.fileName ?? "—"],
7777
["Is Video", String(info.isVideo)],
78+
["Domain", info.domain],
7879
...(info.error ? ([["Error", info.error]] as [string, string][]) : []),
7980
];
8081
}

0 commit comments

Comments
 (0)