This repository was archived by the owner on Nov 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
100 lines (90 loc) · 2.9 KB
/
Copy pathindex.ts
File metadata and controls
100 lines (90 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { serve } from 'bun';
if (process.env.NODE_ENV === 'development') console.debug(`🚧 Running in debug mode!`);
const stringCleanup = (dirty: string) => dirty.replace(/<\/?[^>]+(>|$)/g, '');
serve({
port: process.env.PORT || 3000,
async fetch(req) {
// Extract sessionID from the current URL path
const url = new URL(req.url);
const sessionID = url.pathname.split('/')[1];
if (!sessionID)
return new Response(
`No sessionID provided! Example: "${`${url}`.replace(
'http:',
'https:'
)}S-U-h33tology:fitness"`,
{ status: 400 }
);
// send API request to Resonite to get lnl-net link
const sessionDetailsRaw = await fetch(
`${process.env.RESONITE_API_ENDPOINT}/sessions/${sessionID}`
);
const sessionDetails = await sessionDetailsRaw.json();
// send API request to Resonite to get record details
let recordDetails = null;
if (sessionDetails.correspondingWorldId) {
const recordDetailsRaw = await fetch(
`${process.env.RESONITE_API_ENDPOINT}/users/${sessionDetails.correspondingWorldId.ownerId}/records/${sessionDetails.correspondingWorldId.recordId}`
);
recordDetails = await recordDetailsRaw.json();
}
// verify the existence and redirect to steam
if (sessionDetails.status)
return new Response(sessionDetails.title, {
status: sessionDetails.status,
});
const lnl = sessionDetails.sessionURLs[0];
if (!lnl)
return new Response(`Session "${sessionID}" doesn\'t have a lnl-net link.`, { status: 404 });
const steamLink = `steam://rungameid/2519830//-Open ${encodeURIComponent(lnl)}`;
const postData = [
{
property: 'twitter:title',
content: stringCleanup(sessionDetails.name),
},
{
property: 'twitter:image',
content: `${sessionDetails.thumbnailUrl}`,
},
{
property: 'twitter:card',
content: 'summary_large_image',
},
];
if (recordDetails) {
postData.push(
...[
{
property: 'og:site_name',
content: `${recordDetails.ownerName} - ${stringCleanup(recordDetails.name)}`,
},
{
property: 'twitter:description',
content: recordDetails.description ? recordDetails.description : '',
},
]
);
}
const heads = postData
.map(({ property, content }) => `<meta property="${property}" content="${content}" />`)
.join('\n');
const htmlRes = `
<html>
<head>
${heads}
</head>
<body>
<script> window.location.href = "${steamLink}" </script>
<pre>JS disabled! <a href="${steamLink}">Click here to get redirected to Steam.</a></pre>
</body>
</html>
`;
return new Response(htmlRes, {
status: 200,
headers: {
'content-type': 'text/html',
},
});
// return Response.redirect(steamLink);
},
});