tangled
alpha
login
or
join now
jordanreger.com
/
htmlsky
0
fork
atom
An HTML-only Bluesky frontend
0
fork
atom
overview
issues
pulls
pipelines
Added old server code
ImOutOfIdeas
2 years ago
6ffec739
17f86006
+87
1 changed file
expand all
collapse all
unified
split
server.ts
+87
server.ts
···
1
1
+
import { serve } from "https://deno.land/std@0.105.0/http/server.ts";
2
2
+
3
3
+
const server = serve({ port: 8000 });
4
4
+
5
5
+
console.log("HTTP webserver running. Access it at: http://localhost:8000/");
6
6
+
7
7
+
for await (const request of server) {
8
8
+
const url = request.url;
9
9
+
let profileContent = "";
10
10
+
11
11
+
const match = url.match(/^\/profile\/(.+)$/);
12
12
+
if (match) {
13
13
+
const handle = match[1];
14
14
+
try {
15
15
+
const response = await fetch(`https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile?actor=${handle}`);
16
16
+
if (response.ok) {
17
17
+
const data = await response.json();
18
18
+
const { avatar, displayName, handle, description, followersCount, followsCount, postsCount } = data;
19
19
+
20
20
+
console.log(data);
21
21
+
22
22
+
if ("" == displayName)
23
23
+
displayName == "No Display Name";
24
24
+
25
25
+
profileContent = `
26
26
+
<div class="profile">
27
27
+
<table width="95%" cellspacing="0" cellpadding="0">
28
28
+
<tr>
29
29
+
<td align="center" valign="middle">
30
30
+
<table width="40%" border="0" cellspacing="0" cellpadding="0">
31
31
+
<tr>
32
32
+
<td align="right">
33
33
+
<nobr>
34
34
+
<h1>${displayName}<br>
35
35
+
<sup><sup><small><small>@${handle}</small></small></sup></sup>
36
36
+
</h1>
37
37
+
</nobr>
38
38
+
<small>
39
39
+
<span>
40
40
+
<nobr>
41
41
+
Followers <strong>${followersCount}</strong>
42
42
+
Following <strong>${followsCount}</strong>
43
43
+
Posts <strong>${postsCount}</strong>
44
44
+
</nobr>
45
45
+
</span>
46
46
+
<small>
47
47
+
</td>
48
48
+
<td> </td>
49
49
+
<td valign="bottom" align="left">
50
50
+
<img alt="" draggable="false" src="${avatar}" width="115">
51
51
+
</td>
52
52
+
53
53
+
</tr>
54
54
+
</table>
55
55
+
</td>
56
56
+
</tr>
57
57
+
</table>
58
58
+
</div>
59
59
+
`;
60
60
+
} else {
61
61
+
profileContent = "<p>Failed to fetch profile data.</p>";
62
62
+
}
63
63
+
} catch (error) {
64
64
+
profileContent = `<p>Error: ${error.message}</p>`;
65
65
+
}
66
66
+
} else {
67
67
+
profileContent = "<p>No profile handle provided in the URL.</p>";
68
68
+
}
69
69
+
70
70
+
const html = `
71
71
+
<!DOCTYPE html>
72
72
+
<html lang="en">
73
73
+
<head>
74
74
+
<meta charset="UTF-8">
75
75
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
76
76
+
<meta name="color-scheme" content="light dark">
77
77
+
<title>HTML Sky</title>
78
78
+
</head>
79
79
+
<body>
80
80
+
${profileContent}
81
81
+
</body>
82
82
+
</html>
83
83
+
`;
84
84
+
85
85
+
request.respond({ status: 200, body: html });
86
86
+
}
87
87
+