0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch.git synced 2024-12-22 13:22:58 -05:00
This commit is contained in:
dragongoose 2023-11-04 19:49:20 -04:00
parent d7d4132b9b
commit b3b121ba31
No known key found for this signature in database
GPG key ID: 01397EEC371CDAA5

View file

@ -1,3 +1,9 @@
const language = localStorage.getItem('language') || 'en-us'
const https = import.meta.env.SAFETWITCH_HTTPS.slice() === 'true'
const protocol = https ? 'https://' : 'http://'
const rootBackendUrl = `${protocol}${import.meta.env.SAFETWITCH_BACKEND_DOMAIN}/`
export function truncate(value: string, length: number) {
if (value.length > length) {
return value.substring(0, length) + '...'
@ -6,8 +12,6 @@ export function truncate(value: string, length: number) {
}
}
const language = localStorage.getItem('language') || 'en-us'
export function abbreviate(text: number) {
return Intl.NumberFormat(language, {
//@ts-ignore
@ -16,10 +20,11 @@ export function abbreviate(text: number) {
}).format(text)
}
const https = import.meta.env.SAFETWITCH_HTTPS.slice() === 'true'
const protocol = https ? 'https://' : 'http://'
const rootBackendUrl = `${protocol}${import.meta.env.SAFETWITCH_BACKEND_DOMAIN}/`
/**
* Gets the response from an endpoint from the backend
* @param endpoint The endpoint to get data from
* @returns The data from the enpoint
*/
export async function getEndpoint(endpoint: string) {
const res = await fetch(rootBackendUrl + endpoint, {
method: 'GET',
@ -41,6 +46,11 @@ export async function getEndpoint(endpoint: string) {
return data
}
/**
* Converts a twitch timestamp (0h0m0s) to seconds
* @param query 0h0m0s
* @returns the seconds of the timestamp
*/
export function getTimeFromQuery(query: string) {
// H, M, S
const x = query.split(/[^0-9.]/g);
@ -52,3 +62,4 @@ export function getTimeFromQuery(query: string) {
time += times[2]
return time
}