Add a setting to clear cache
This commit is contained in:
1 parent
0bbb876a84
commit
55c811adb7
14 files changed
+192
No files matched your search
@@ -7,11 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- A dev setting to clear the cache
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- A bug where bookmarked channels can be duplicated
|
- A bug where bookmarked channels can be duplicated
|
||||||
- A bug where video cast from web app would not play if there's an error dialog on screen
|
- A bug where video cast from web app would not play if there's an error dialog on screen
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Font weight to be less bold
|
||||||
|
|
||||||
## [0.23.5] - 2024-05-19
|
## [0.23.5] - 2024-05-19
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||||
|
import "pkg:/source/utils/CacheUtils.bs"
|
||||||
|
import "pkg:/source/utils/FocusManagement.bs"
|
||||||
|
import "pkg:/source/utils/Locale.bs"
|
||||||
|
|
||||||
|
function Init()
|
||||||
|
m.top.focusable = true
|
||||||
|
m.top.itemSpacings = [8]
|
||||||
|
m.button = m.top.findNode("Button")
|
||||||
|
m.button.observeField("buttonSelected", FuncName(OnButtonSelected))
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnFocusChange() as void
|
||||||
|
if not m.top.focus
|
||||||
|
return
|
||||||
|
end if
|
||||||
|
NodeSetFocus(m.button, true)
|
||||||
|
end function
|
||||||
|
|
||||||
|
function BindPreference(_preferences as object, _key as string)
|
||||||
|
' Do nothing
|
||||||
|
end function
|
||||||
|
|
||||||
|
function OnButtonSelected()
|
||||||
|
CacheUtils.Clear()
|
||||||
|
DialogUtils.ShowDialog(Tr(Locale.Settings.CacheCleared), Tr(Locale.Generic.Success))
|
||||||
|
end function
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<component name="ClearCacheControl" extends="LayoutGroup" includes="Focus">
|
||||||
|
<interface>
|
||||||
|
<field id="displayText" type="string" alias="Button.text" />
|
||||||
|
<field id="description" type="string" alias="DescriptionLabel.text" />
|
||||||
|
<function name="BindPreference" />
|
||||||
|
</interface>
|
||||||
|
<children>
|
||||||
|
<Button
|
||||||
|
id="Button"
|
||||||
|
minWidth="340"
|
||||||
|
showFocusFootprint="true" />
|
||||||
|
<Label id="DescriptionLabel"
|
||||||
|
width="450"
|
||||||
|
color="0xb4b4b4ff"
|
||||||
|
wrap="true">
|
||||||
|
<Font role="font" uri="font:SystemFontFile" size="18" />
|
||||||
|
</Label>
|
||||||
|
</children>
|
||||||
|
</component>
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import "pkg:/source/utils/CacheUtils.bs"
|
||||||
|
|
||||||
|
namespace Http
|
||||||
|
|
||||||
|
class CacheRouter extends HttpRouter
|
||||||
|
|
||||||
|
function new()
|
||||||
|
super()
|
||||||
|
end function
|
||||||
|
|
||||||
|
@delete("/api/cache")
|
||||||
|
function ClearCache(context as object) as boolean
|
||||||
|
response = context.response
|
||||||
|
|
||||||
|
CacheUtils.Clear()
|
||||||
|
response.Default(204, "OK")
|
||||||
|
return true
|
||||||
|
end function
|
||||||
|
|
||||||
|
end class
|
||||||
|
|
||||||
|
end namespace
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import "pkg:/components/parts/AutoBind/OnNodeReadyNoOp.bs"
|
import "pkg:/components/parts/AutoBind/OnNodeReadyNoOp.bs"
|
||||||
import "pkg:/components/Web/PlayletWebServer/Middleware/BookmarksRouter.bs"
|
import "pkg:/components/Web/PlayletWebServer/Middleware/BookmarksRouter.bs"
|
||||||
|
import "pkg:/components/Web/PlayletWebServer/Middleware/CacheRouter.bs"
|
||||||
import "pkg:/components/Web/PlayletWebServer/Middleware/DashRouter.bs"
|
import "pkg:/components/Web/PlayletWebServer/Middleware/DashRouter.bs"
|
||||||
import "pkg:/components/Web/PlayletWebServer/Middleware/DialRouter.bs"
|
import "pkg:/components/Web/PlayletWebServer/Middleware/DialRouter.bs"
|
||||||
import "pkg:/components/Web/PlayletWebServer/Middleware/HomeLayoutRouter.bs"
|
import "pkg:/components/Web/PlayletWebServer/Middleware/HomeLayoutRouter.bs"
|
||||||
@@ -50,6 +51,7 @@ function SetupRoutes(server as object)
|
|||||||
server.UseRouter(new Http.SearchHistoryRouter(server))
|
server.UseRouter(new Http.SearchHistoryRouter(server))
|
||||||
server.UseRouter(new Http.PlayletLibUrlsRouter(server))
|
server.UseRouter(new Http.PlayletLibUrlsRouter(server))
|
||||||
server.UseRouter(new Http.DialRouter(server))
|
server.UseRouter(new Http.DialRouter(server))
|
||||||
|
server.UseRouter(new Http.CacheRouter())
|
||||||
|
|
||||||
etags = new Http.EtagUtils()
|
etags = new Http.EtagUtils()
|
||||||
server.UseRouter(new Http.HttpStaticFilesRouter("/", "libpkg:/www", etags, { staticFiles: true }))
|
server.UseRouter(new Http.HttpStaticFilesRouter("/", "libpkg:/www", etags, { staticFiles: true }))
|
||||||
|
|||||||
@@ -207,6 +207,20 @@
|
|||||||
visibility: "web",
|
visibility: "web",
|
||||||
svelteComponent: "PlayletLibVersionControl",
|
svelteComponent: "PlayletLibVersionControl",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayText: "Clear cache",
|
||||||
|
key: "dev.clear_cache",
|
||||||
|
description: "Clear cache from cachefs: and tmp:",
|
||||||
|
visibility: "web",
|
||||||
|
svelteComponent: "ClearCacheControl",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayText: "Clear cache",
|
||||||
|
key: "dev.clear_cache",
|
||||||
|
description: "Clear cache from cachefs: and tmp:",
|
||||||
|
visibility: "tv",
|
||||||
|
rokuComponent: "ClearCacheControl",
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@@ -1256,5 +1256,17 @@
|
|||||||
<source>Rating</source>
|
<source>Rating</source>
|
||||||
<translation>Rating</translation>
|
<translation>Rating</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Clear cache</source>
|
||||||
|
<translation>Clear cache</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Clear cache from cachefs: and tmp:</source>
|
||||||
|
<translation>Clear cache from cachefs: and tmp:</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Cache cleared.</source>
|
||||||
|
<translation>Cache cleared.</translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
</TS>
|
</TS>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import "pkg:/source/AsyncTask/AsyncTask.bs"
|
||||||
|
import "pkg:/source/AsyncTask/Tasks.bs"
|
||||||
|
|
||||||
|
namespace CacheUtils
|
||||||
|
|
||||||
|
function Clear()
|
||||||
|
AsyncTask.Start(Tasks.ClearCacheTask, invalid)
|
||||||
|
end function
|
||||||
|
|
||||||
|
end namespace
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import "pkg:/source/utils/Logging.bs"
|
||||||
|
|
||||||
|
@asynctask
|
||||||
|
function ClearCacheTask() as object
|
||||||
|
fs = CreateObject("roFileSystem")
|
||||||
|
if fs = invalid
|
||||||
|
LogError("Failed to create roFileSystem object")
|
||||||
|
return invalid
|
||||||
|
end if
|
||||||
|
|
||||||
|
ClearVolume(fs, "tmp:/")
|
||||||
|
ClearVolume(fs, "cachefs:/")
|
||||||
|
|
||||||
|
return invalid
|
||||||
|
end function
|
||||||
|
|
||||||
|
function ClearVolume(fs as object, volume as string)
|
||||||
|
items = fs.GetDirectoryListing(volume)
|
||||||
|
for each item in items
|
||||||
|
fullpath = volume + item
|
||||||
|
|
||||||
|
' Skip logs directory
|
||||||
|
if fullpath = "cachefs:/logs"
|
||||||
|
continue for
|
||||||
|
end if
|
||||||
|
|
||||||
|
if not fs.Delete(fullpath)
|
||||||
|
LogError("Failed to delete:", fullpath)
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
|
||||||
|
LogInfo("Cleared:", volume)
|
||||||
|
end function
|
||||||
@@ -283,6 +283,9 @@ namespace Locale
|
|||||||
UseDevVideoPlayerDescription = "Enable the dev video player. This is an unfinished video player for testing purposes."
|
UseDevVideoPlayerDescription = "Enable the dev video player. This is an unfinished video player for testing purposes."
|
||||||
PlayletLibraryVersion = "Playlet Library version"
|
PlayletLibraryVersion = "Playlet Library version"
|
||||||
PlayletLibraryVersionDescription = "The version of Playlet Lib to use. These correspond to tagged releases on Github. Releases that do not have a playlet-lib.zip file are disabled."
|
PlayletLibraryVersionDescription = "The version of Playlet Lib to use. These correspond to tagged releases on Github. Releases that do not have a playlet-lib.zip file are disabled."
|
||||||
|
ClearCache = "Clear cache"
|
||||||
|
ClearCacheDescription = "Clear cache from cachefs: and tmp:"
|
||||||
|
CacheCleared = "Cache cleared."
|
||||||
end enum
|
end enum
|
||||||
|
|
||||||
@locale
|
@locale
|
||||||
|
|||||||
@@ -265,6 +265,15 @@ export class InvidiousApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static clearCache() {
|
||||||
|
for (let i = localStorage.length - 1; i >= 0; i--) {
|
||||||
|
const key = localStorage.key(i);
|
||||||
|
if (key && key.startsWith("v1:")) {
|
||||||
|
localStorage.removeItem(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO:P2 use more appropriate cache storage
|
// TODO:P2 use more appropriate cache storage
|
||||||
private getCache(url: string, cacheSeconds: number) {
|
private getCache(url: string, cacheSeconds: number) {
|
||||||
const cacheKey = this.getCacheKey(url);
|
const cacheKey = this.getCacheKey(url);
|
||||||
|
|||||||
@@ -132,6 +132,10 @@ export class PlayletApi {
|
|||||||
return await fetch(`${PlayletApi.host()}/api/search-history`, { method: "DELETE" });
|
return await fetch(`${PlayletApi.host()}/api/search-history`, { method: "DELETE" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async clearCache() {
|
||||||
|
return await fetch(`${PlayletApi.host()}/api/cache`, { method: "DELETE" });
|
||||||
|
}
|
||||||
|
|
||||||
static async getBookmarkFeeds() {
|
static async getBookmarkFeeds() {
|
||||||
const response = await fetch(`${PlayletApi.host()}/api/bookmarks/feeds`);
|
const response = await fetch(`${PlayletApi.host()}/api/bookmarks/feeds`);
|
||||||
return await response.json();
|
return await response.json();
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { InvidiousApi } from "lib/Api/InvidiousApi";
|
||||||
|
import { PlayletApi } from "lib/Api/PlayletApi";
|
||||||
|
import { tr } from "lib/Stores";
|
||||||
|
import { get } from "svelte/store";
|
||||||
|
|
||||||
|
const textSizes = ["text-2xl", "text-lg", "text-base", "text-sm", "text-xs"];
|
||||||
|
|
||||||
|
export let displayText: string = "";
|
||||||
|
// svelte-ignore unused-export-let
|
||||||
|
export let key: string = "";
|
||||||
|
export let description: string = "";
|
||||||
|
export let level: number = 0;
|
||||||
|
|
||||||
|
async function clearCache() {
|
||||||
|
await PlayletApi.clearCache();
|
||||||
|
InvidiousApi.clearCache();
|
||||||
|
|
||||||
|
alert(get(tr)("Cache cleared."));
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="m-5">
|
||||||
|
<div class={textSizes[level]}>{$tr(displayText)}</div>
|
||||||
|
<div class="text-xs text-gray-500">{@html $tr(description)}</div>
|
||||||
|
<button class="btn m-1" on:click={clearCache}>{$tr("Clear cache")}</button>
|
||||||
|
</div>
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
import StringControl from "lib/Screens/Settings/SettingControls/StringControl.svelte";
|
import StringControl from "lib/Screens/Settings/SettingControls/StringControl.svelte";
|
||||||
import NumberControl from "./SettingControls/NumberControl.svelte";
|
import NumberControl from "./SettingControls/NumberControl.svelte";
|
||||||
import { tr } from "lib/Stores";
|
import { tr } from "lib/Stores";
|
||||||
|
import ClearCacheControl from "./SettingControls/ClearCacheControl.svelte";
|
||||||
|
|
||||||
const textSizes = ["text-2xl", "text-lg", "text-base", "text-sm", "text-xs"];
|
const textSizes = ["text-2xl", "text-lg", "text-base", "text-sm", "text-xs"];
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@
|
|||||||
|
|
||||||
const customComponents = {
|
const customComponents = {
|
||||||
ClearSearchHistoryControl,
|
ClearSearchHistoryControl,
|
||||||
|
ClearCacheControl,
|
||||||
EditHomeScreenControl,
|
EditHomeScreenControl,
|
||||||
PlayletLibVersionControl,
|
PlayletLibVersionControl,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user