Add getting comments

This commit is contained in:
Lncvrt committed 2026-02-21 12:19:22 -07:00
1 parent 4292f8137a
commit 0efb404a01
8 files changed
+340 -5

No files matched your search

+20 -2
View File
@@ -5,8 +5,11 @@ export const jsonResponse = (data: any, status = 200) => {
})
}
export const splitGd = (input: string): Record<string, string> => {
const parts = input.split(':')
export const splitGd = (
input: string,
splitKey: string = ':'
): Record<string, string> => {
const parts = input.split(splitKey)
const result: Record<string, string> = {}
for (let i = 0; i < parts.length - 1; i += 2) {
result[parts[i]] = parts[i + 1]
@@ -54,3 +57,18 @@ export const formatTime = (seconds: number): string => {
return parts.join(' ') || '0s'
}
//Taken from https://github.com/GDColon/GDBrowser/blob/master/index.js#L164-L173
export const parseResponse = (responseBody: string, splitter = ':') => {
if (!responseBody || responseBody == '-1') return {}
if (responseBody.startsWith('\nWarning:'))
responseBody = responseBody.split('\n').slice(2).join('\n').trim() // GDPS'es are wild
if (responseBody.startsWith('<br />'))
responseBody = responseBody.split('<br />').slice(2).join('<br />').trim() // Seriously screw this
let response = responseBody.split('#')[0].split(splitter)
let res: any = {}
for (let i = 0; i < response.length; i += 2) {
res[response[i]] = response[i + 1]
}
return res
}