-
Notifications
You must be signed in to change notification settings - Fork 0
/
+page.server.ts
49 lines (42 loc) · 1.27 KB
/
+page.server.ts
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
import { gdtfShareIDs } from '$lib/gdtfHelpers';
import type { PageServerLoad } from './$types';
import makeFetchCookie from 'fetch-cookie';
async function fetchGLTFAsBase64(id: number) {
const loginURL = 'https://gdtf-share.com/apis/login.php';
const fixtureURL = `https://gdtf-share.com/apis/downloadFile.php?id=${id}`;
const fetchCookie = makeFetchCookie(
fetch,
new makeFetchCookie.toughCookie.CookieJar(undefined, {
allowSpecialUseDomain: true
})
);
await fetchCookie(loginURL, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
},
body: new URLSearchParams({
username: 'bvz0bnurg82v',
password: '8?%7GEp@j=KjgB4a'
})
});
const requestGLTF = fetchCookie(fixtureURL).then(async (response) => {
return {
contentType: response.headers.get('Content-Type') || '',
arrayBuffer: await response.arrayBuffer()
};
});
return {
contentType: (await requestGLTF).contentType,
base64: Buffer.from((await requestGLTF).arrayBuffer).toString('base64')
};
}
export const load = (async () => {
const gdtfFile = fetchGLTFAsBase64(gdtfShareIDs.RobeRobinMegaPointe);
return {
streamed: {
base64: (await gdtfFile).base64,
contentType: (await gdtfFile).contentType
}
};
}) satisfies PageServerLoad;