Skip to content

Commit

Permalink
added cache bypass on force update localization files
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyhalight committed Nov 8, 2024
1 parent 3c9430d commit 9f41a77
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
<!-- Фикс vk mobile -->
<!-- добавить чанковую загрузку аудио файла в новом плеере -->
<!-- Вынести HLS в отдельный плеер (?) -->
<!-- Сделать, чтобы при ручном обновление хэшей локализации добавлялся таймстемп для обхода кэша -->

# 1.x [WIP]

- Добавлена возможность использования эксперементальной вариации голосов Яндекса. Новые голоса работают, только при некоторых условиях, во всех остальных случаях используются старые (#897)
- Добавлен обход кэша при получение перевода интерфейса после нажатия на кнопку "Обновить файлы локализации"
- Исправлена некорректная генерация Sec-{Vsubs|Vtrans}-Token заголовков ([vot.js#36](https://github.com/FOSWLY/vot.js/issues/36))

# 1.7.1
Expand Down
2 changes: 1 addition & 1 deletion dist/vot-min.user.js

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions dist/vot.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2777,10 +2777,14 @@ const localizationProvider = new (class {
}
}

async checkUpdates() {
async checkUpdates(force = false) {
debug.log("Check locale updates...");
try {
const res = await GM_fetch(`${localizationUrl}/hashes.json`);
const res = await GM_fetch(
`${localizationUrl}/hashes.json${
force ? `?timestamp=${utils_getTimestamp()}` : ""
}`,
);
if (res.status !== 200) {
throw res.status;
}
Expand Down Expand Up @@ -2812,7 +2816,7 @@ const localizationProvider = new (class {
return;
}

const hash = await this.checkUpdates();
const hash = await this.checkUpdates(force);
await votStorage.set("locale-updated-at", timestamp);
if (!hash) {
return;
Expand All @@ -2821,7 +2825,9 @@ const localizationProvider = new (class {
debug.log("Updating locale...");
try {
const res = await GM_fetch(
`${localizationUrl}/locales/${this.lang}.json`,
`${localizationUrl}/locales/${this.lang}.json${
force ? `?timestamp=${timestamp}` : ""
}`,
);
if (res.status !== 200) {
throw res.status;
Expand Down Expand Up @@ -10113,9 +10119,8 @@ class VideoHandler {

this.votVideoVolumeSlider.input.addEventListener("input", (e) => {
const value = Number(e.target.value);
this.votVideoVolumeSlider.label.querySelector(
"strong",
).textContent = `${value}%`;
this.votVideoVolumeSlider.label.querySelector("strong").textContent =
`${value}%`;
this.setVideoVolume(value / 100);
if (this.data.syncVolume) {
this.syncVolumeWrapper("video", value);
Expand Down Expand Up @@ -10974,9 +10979,8 @@ class VideoHandler {
const newSlidersVolume = Math.round(videoVolume);

this.votVideoVolumeSlider.input.value = newSlidersVolume;
this.votVideoVolumeSlider.label.querySelector(
"strong",
).textContent = `${newSlidersVolume}%`;
this.votVideoVolumeSlider.label.querySelector("strong").textContent =
`${newSlidersVolume}%`;
ui.updateSlider(this.votVideoVolumeSlider.input);

if (this.data.syncVolume === 1) {
Expand Down
14 changes: 10 additions & 4 deletions src/localization/localizationProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ export const localizationProvider = new (class {
}
}

async checkUpdates() {
async checkUpdates(force = false) {
debug.log("Check locale updates...");
try {
const res = await GM_fetch(`${localizationUrl}/hashes.json`);
const res = await GM_fetch(
`${localizationUrl}/hashes.json${
force ? `?timestamp=${getTimestamp()}` : ""
}`,
);
if (res.status !== 200) {
throw res.status;
}
Expand Down Expand Up @@ -76,7 +80,7 @@ export const localizationProvider = new (class {
return;
}

const hash = await this.checkUpdates();
const hash = await this.checkUpdates(force);
await votStorage.set("locale-updated-at", timestamp);
if (!hash) {
return;
Expand All @@ -85,7 +89,9 @@ export const localizationProvider = new (class {
debug.log("Updating locale...");
try {
const res = await GM_fetch(
`${localizationUrl}/locales/${this.lang}.json`,
`${localizationUrl}/locales/${this.lang}.json${
force ? `?timestamp=${timestamp}` : ""
}`,
);
if (res.status !== 200) {
throw res.status;
Expand Down

0 comments on commit 9f41a77

Please sign in to comment.