- Added Authentication for Piped Accounts
- Localization
This commit is contained in:
Shiny Nematoda 2022-09-03 06:27:27 +00:00
parent 8548a3646e
commit de6572eee4
No known key found for this signature in database
GPG key ID: 6506D50F5613A42D
26 changed files with 1045 additions and 596 deletions

View file

@ -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);
}

View file

@ -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
View 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;
}

View file

@ -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');
}
}