0
Get robots txt file view
One script reply has been approved by the moderators Verified

Return content of a robots.txt file.

Created by hugo697 40 days ago Viewed 3 times
0
Submitted by hugo697 Bun
Verified 40 days ago
1
//native
2
type Botify = {
3
	token: string
4
}
5
/**
6
 * Get robots txt file view
7
 * Return content of a robots.txt file.
8
 */
9
export async function main(
10
	auth: Botify,
11
	username: string,
12
	project_slug: string,
13
	analysis_slug: string,
14
	robots_txt: string,
15
	page: string | undefined,
16
	size: string | undefined
17
) {
18
	const url = new URL(
19
		`https://api.botify.com/analyses/${username}/${project_slug}/${analysis_slug}/staticfiles/robots-txt-indexes/${robots_txt}`
20
	)
21
	for (const [k, v] of [
22
		['page', page],
23
		['size', size]
24
	]) {
25
		if (v !== undefined && v !== '' && k !== undefined) {
26
			url.searchParams.append(k, v)
27
		}
28
	}
29
	const response = await fetch(url, {
30
		method: 'GET',
31
		headers: {
32
			Authorization: 'Token ' + auth.token
33
		},
34
		body: undefined
35
	})
36
	if (!response.ok) {
37
		const text = await response.text()
38
		throw new Error(`${response.status} ${text}`)
39
	}
40
	return await response.text()
41
}
42