-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
playlet-lib/src/components/Screens/SettingsScreen/ClearCacheControl.bs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
19 changes: 19 additions & 0 deletions
19
playlet-lib/src/components/Screens/SettingsScreen/ClearCacheControl.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
22 changes: 22 additions & 0 deletions
22
playlet-lib/src/components/Web/PlayletWebServer/Middleware/CacheRouter.bs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
playlet-web/src/lib/Screens/Settings/SettingControls/ClearCacheControl.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters