mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-22 04:25:13 +00:00
fix locales versioning in backend client
This commit is contained in:
parent
9b06347882
commit
7431866d86
4 changed files with 27 additions and 57 deletions
|
@ -1,5 +1,6 @@
|
|||
import tsParser from '@typescript-eslint/parser';
|
||||
import sharedConfig from '../shared/eslint.config.js';
|
||||
import globals from 'globals';
|
||||
|
||||
export default [
|
||||
...sharedConfig,
|
||||
|
@ -43,4 +44,15 @@ export default [
|
|||
}],
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['src/server/web/**/*.js', 'src/server/web/**/*.ts'],
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.browser,
|
||||
LANGS: true,
|
||||
CLIENT_ENTRY: true,
|
||||
LANGS_VERSION: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
|
|
@ -6,36 +6,6 @@
|
|||
'use strict';
|
||||
|
||||
window.onload = async () => {
|
||||
const account = JSON.parse(localStorage.getItem('account'));
|
||||
const i = account.token;
|
||||
|
||||
const api = (endpoint, data = {}) => {
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
// Append a credential
|
||||
if (i) data.i = i;
|
||||
|
||||
// Send request
|
||||
window.fetch(endpoint.indexOf('://') > -1 ? endpoint : `/api/${endpoint}`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
credentials: 'omit',
|
||||
cache: 'no-cache'
|
||||
}).then(async (res) => {
|
||||
const body = res.status === 204 ? null : await res.json();
|
||||
|
||||
if (res.status === 200) {
|
||||
resolve(body);
|
||||
} else if (res.status === 204) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(body.error);
|
||||
}
|
||||
}).catch(reject);
|
||||
});
|
||||
|
||||
return promise;
|
||||
};
|
||||
|
||||
const content = document.getElementById('content');
|
||||
|
||||
document.getElementById('ls').addEventListener('click', () => {
|
||||
|
|
|
@ -31,8 +31,17 @@
|
|||
document.documentElement.classList.add('noborder');
|
||||
}
|
||||
|
||||
// Force update when locales change
|
||||
const langsVersion = LANGS_VERSION;
|
||||
const localeVersion = localStorage.getItem('localeVersion');
|
||||
if (localeVersion !== langsVersion) {
|
||||
console.info(`Updating locales from version ${localeVersion ?? 'N/A'} to ${langsVersion}`);
|
||||
localStorage.removeItem('localeVersion');
|
||||
localStorage.removeItem('locale');
|
||||
}
|
||||
|
||||
//#region Detect language & fetch translations
|
||||
if (!localStorage.hasOwnProperty('locale')) {
|
||||
if (!localStorage.getItem('locale')) {
|
||||
const supportedLangs = LANGS;
|
||||
let lang = localStorage.getItem('lang');
|
||||
if (lang == null || !supportedLangs.includes(lang)) {
|
||||
|
@ -46,37 +55,17 @@
|
|||
}
|
||||
}
|
||||
|
||||
const metaRes = await window.fetch('/api/meta', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({}),
|
||||
credentials: 'omit',
|
||||
cache: 'no-cache',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
if (metaRes.status !== 200) {
|
||||
renderError('META_FETCH');
|
||||
return;
|
||||
}
|
||||
const meta = await metaRes.json();
|
||||
const v = meta.version;
|
||||
if (v == null) {
|
||||
renderError('META_FETCH_V');
|
||||
return;
|
||||
}
|
||||
|
||||
// for https://github.com/misskey-dev/misskey/issues/10202
|
||||
if (lang == null || lang.toString == null || lang.toString() === 'null') {
|
||||
console.error('invalid lang value detected!!!', typeof lang, lang);
|
||||
lang = 'en-US';
|
||||
}
|
||||
|
||||
const localRes = await window.fetch(`/assets/locales/${lang}.${v}.json`);
|
||||
const localRes = await window.fetch(`/assets/locales/${lang}.${langsVersion}.json`);
|
||||
if (localRes.status === 200) {
|
||||
localStorage.setItem('lang', lang);
|
||||
localStorage.setItem('locale', await localRes.text());
|
||||
localStorage.setItem('localeVersion', v);
|
||||
localStorage.setItem('localeVersion', langsVersion);
|
||||
} else {
|
||||
renderError('LOCALE_FETCH');
|
||||
return;
|
||||
|
|
|
@ -88,7 +88,7 @@
|
|||
const themeFontFaceName = 'sharkey-theme-font-face';
|
||||
if (theme) {
|
||||
let existingFontFace;
|
||||
document.fonts.forEach((v,k,s)=>{if (v.family === themeFontFaceName) existingFontFace=v;});
|
||||
document.fonts.forEach((v) => { if (v.family === themeFontFaceName) existingFontFace = v;});
|
||||
if (existingFontFace) document.fonts.delete(existingFontFace);
|
||||
|
||||
const themeProps = JSON.parse(theme);
|
||||
|
@ -102,9 +102,8 @@
|
|||
document.fonts.add(fontFace);
|
||||
fontFace.load().catch(
|
||||
(failure) => {
|
||||
console.log(failure)
|
||||
}
|
||||
);
|
||||
console.log(failure);
|
||||
}, );
|
||||
}
|
||||
for (const [k, v] of Object.entries(themeProps)) {
|
||||
if (k.startsWith('font')) continue;
|
||||
|
|
Loading…
Reference in a new issue