mirror of
https://codeberg.org/Hyperpipe/Hyperpipe
synced 2025-06-28 05:08:00 +02:00
Changes:
- Added Authentication for Piped Accounts - Localization
This commit is contained in:
parent
8548a3646e
commit
de6572eee4
26 changed files with 1045 additions and 596 deletions
|
@ -10,9 +10,3 @@ export function useRand() {
|
|||
const i = Math.floor(Math.random() * c.length);
|
||||
return c[i];
|
||||
}
|
||||
|
||||
export function useRandColor() {
|
||||
const r = Math.random().toString(16);
|
||||
|
||||
return '#' + r.substr(r.length - 6);
|
||||
}
|
||||
|
|
|
@ -45,3 +45,21 @@ export async function getJsonHyp(path) {
|
|||
|
||||
return await getJson('https://' + root + path);
|
||||
}
|
||||
|
||||
export async function getJsonAuth(path, opts) {
|
||||
const root = useStore().getItem('authapi') || 'pipedapi.kavin.rocks';
|
||||
|
||||
return await fetch('https://' + root + path, opts).then(res => res.json());
|
||||
}
|
||||
|
||||
export async function getAuthPlaylists() {
|
||||
if (!!useStore().getItem('auth')) {
|
||||
const res = await getJsonAuth('/user/playlists', {
|
||||
headers: {
|
||||
Authorization: useStore().getItem('auth'),
|
||||
},
|
||||
});
|
||||
|
||||
return res.filter(i => i.name.startsWith('Playlist - '));
|
||||
}
|
||||
}
|
||||
|
|
29
src/scripts/i18n.js
Normal file
29
src/scripts/i18n.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
export const SUPPORTED_LOCALES = [
|
||||
{
|
||||
code: 'en',
|
||||
name: 'English',
|
||||
},
|
||||
];
|
||||
|
||||
export function useT(path) {
|
||||
const { messages, locale, fallbackLocale } = useI18n(),
|
||||
msgs = messages.value?.[locale.value],
|
||||
fallback = messages.value?.[fallbackLocale.value],
|
||||
keys = path.split('.'),
|
||||
translate = msg => keys.reduce((obj, i) => obj?.[i], msg),
|
||||
translated = translate(msgs) || translate(fallback);
|
||||
|
||||
return translated || path;
|
||||
}
|
||||
|
||||
export function useSetupLocale(locale) {
|
||||
import(`@/locales/${locale}.json`)
|
||||
.then(mod => mod.default)
|
||||
.then(mod => {
|
||||
window.i18n.global.messages.value[locale] = mod;
|
||||
});
|
||||
|
||||
window.i18n.global.locale.value = locale;
|
||||
}
|
|
@ -26,30 +26,3 @@ export function useStore() {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function useLazyLoad() {
|
||||
let lazyElems;
|
||||
|
||||
if ('IntersectionObserver' in window) {
|
||||
lazyElems = document.querySelectorAll('.bg-img:not(.lazy)');
|
||||
|
||||
let imgObs = new IntersectionObserver((elems, obs) => {
|
||||
elems.forEach(elem => {
|
||||
setTimeout(() => {
|
||||
if (elem.isIntersecting) {
|
||||
let ele = elem.target;
|
||||
|
||||
ele.classList.add('lazy');
|
||||
imgObs.unobserve(ele);
|
||||
}
|
||||
}, 20);
|
||||
});
|
||||
});
|
||||
|
||||
lazyElems.forEach(img => {
|
||||
imgObs.observe(img);
|
||||
});
|
||||
} else {
|
||||
console.log('Failed');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue