Feature/daisy UI (#28)
* Api and store * Add apis * Add daisy ui * Rename var
This commit is contained in:
1 parent
9031f51d5d
commit
be4ef44338
16 files changed
+1181
-139
No files matched your search
Generated
+931
File diff suppressed because it is too large.
Load diff
@@ -11,11 +11,15 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/vite-plugin-svelte": "^1.1.0",
|
"@sveltejs/vite-plugin-svelte": "^1.1.0",
|
||||||
"@tsconfig/svelte": "^3.0.0",
|
"@tsconfig/svelte": "^3.0.0",
|
||||||
|
"autoprefixer": "^10.4.13",
|
||||||
|
"daisyui": "^2.42.1",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"internal-ip": "^7.0.0",
|
"internal-ip": "^7.0.0",
|
||||||
|
"postcss": "^8.4.19",
|
||||||
"svelte": "^3.52.0",
|
"svelte": "^3.52.0",
|
||||||
"svelte-check": "^2.9.2",
|
"svelte-check": "^2.9.2",
|
||||||
"svelte-preprocess": "^4.10.7",
|
"svelte-preprocess": "^4.10.7",
|
||||||
|
"tailwindcss": "^3.2.4",
|
||||||
"tslib": "^2.4.0",
|
"tslib": "^2.4.0",
|
||||||
"typescript": "^4.6.4",
|
"typescript": "^4.6.4",
|
||||||
"vite": "^3.2.3"
|
"vite": "^3.2.3"
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
module.exports = {
|
||||||
|
plugins: {
|
||||||
|
tailwindcss: {},
|
||||||
|
autoprefixer: {},
|
||||||
|
},
|
||||||
|
}
|
||||||
+16
-29
@@ -1,34 +1,21 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import playletLogo from "./assets/logo-dark.svg";
|
import { onMount } from "svelte";
|
||||||
import Counter from "./lib/Counter.svelte";
|
import InstanceInfo from "./lib/InstanceInfo.svelte";
|
||||||
import CurrentInstance from "./lib/CurrentInstance.svelte";
|
import NavBar from "./lib/NavBar.svelte";
|
||||||
import { GetHost } from "./lib/Host";
|
import PlayVideo from "./lib/PlayVideo.svelte";
|
||||||
|
import ClearSearchHistory from "./lib/ClearSearchHistory.svelte";
|
||||||
|
import { PlayletApi } from "./lib/PlayletApi";
|
||||||
|
import { playletStateStore } from "./lib/Stores";
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
const playletState = await PlayletApi.getState();
|
||||||
|
playletStateStore.set(playletState);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<div>
|
<NavBar />
|
||||||
<img src={playletLogo} class="logo" alt="Playlet Logo" />
|
<InstanceInfo />
|
||||||
</div>
|
<PlayVideo />
|
||||||
<h1>Playlet</h1>
|
<ClearSearchHistory />
|
||||||
|
|
||||||
<div class="card">
|
|
||||||
<Counter />
|
|
||||||
</div>
|
|
||||||
<div class="card">
|
|
||||||
Host: {GetHost()}
|
|
||||||
</div>
|
|
||||||
<div class="card">
|
|
||||||
<CurrentInstance />
|
|
||||||
</div>
|
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<style>
|
|
||||||
.logo {
|
|
||||||
height: 6em;
|
|
||||||
padding: 1.5em;
|
|
||||||
will-change: filter;
|
|
||||||
}
|
|
||||||
.logo:hover {
|
|
||||||
filter: drop-shadow(0 0 2em #646cffaa);
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
+3
-81
@@ -1,81 +1,3 @@
|
|||||||
:root {
|
@tailwind base;
|
||||||
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
|
@tailwind components;
|
||||||
font-size: 16px;
|
@tailwind utilities;
|
||||||
line-height: 24px;
|
|
||||||
font-weight: 400;
|
|
||||||
|
|
||||||
color-scheme: light dark;
|
|
||||||
color: rgba(255, 255, 255, 0.87);
|
|
||||||
background-color: #242424;
|
|
||||||
|
|
||||||
font-synthesis: none;
|
|
||||||
text-rendering: optimizeLegibility;
|
|
||||||
-webkit-font-smoothing: antialiased;
|
|
||||||
-moz-osx-font-smoothing: grayscale;
|
|
||||||
-webkit-text-size-adjust: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
font-weight: 500;
|
|
||||||
color: #646cff;
|
|
||||||
text-decoration: inherit;
|
|
||||||
}
|
|
||||||
a:hover {
|
|
||||||
color: #535bf2;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
display: flex;
|
|
||||||
place-items: center;
|
|
||||||
min-width: 320px;
|
|
||||||
min-height: 100vh;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
font-size: 3.2em;
|
|
||||||
line-height: 1.1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.card {
|
|
||||||
padding: 2em;
|
|
||||||
}
|
|
||||||
|
|
||||||
#app {
|
|
||||||
max-width: 1280px;
|
|
||||||
margin: 0 auto;
|
|
||||||
padding: 2rem;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
button {
|
|
||||||
border-radius: 8px;
|
|
||||||
border: 1px solid transparent;
|
|
||||||
padding: 0.6em 1.2em;
|
|
||||||
font-size: 1em;
|
|
||||||
font-weight: 500;
|
|
||||||
font-family: inherit;
|
|
||||||
background-color: #1a1a1a;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: border-color 0.25s;
|
|
||||||
}
|
|
||||||
button:hover {
|
|
||||||
border-color: #646cff;
|
|
||||||
}
|
|
||||||
button:focus,
|
|
||||||
button:focus-visible {
|
|
||||||
outline: 4px auto -webkit-focus-ring-color;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: light) {
|
|
||||||
:root {
|
|
||||||
color: #213547;
|
|
||||||
background-color: #ffffff;
|
|
||||||
}
|
|
||||||
a:hover {
|
|
||||||
color: #747bff;
|
|
||||||
}
|
|
||||||
button {
|
|
||||||
background-color: #f9f9f9;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { PlayletApi } from "./PlayletApi";
|
||||||
|
|
||||||
|
const clearSearchHistory = async () => {
|
||||||
|
await PlayletApi.clearSearchHistory();
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button class="btn" on:click={clearSearchHistory}>Clear search history</button>
|
||||||
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
let count: number = 0
|
|
||||||
const increment = () => {
|
|
||||||
count += 1
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<button on:click={increment}>
|
|
||||||
count is {count}
|
|
||||||
</button>
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import { onMount } from "svelte";
|
|
||||||
import { GetHost } from "./Host";
|
|
||||||
|
|
||||||
let currentInstance = "N/A";
|
|
||||||
|
|
||||||
onMount(async () => {
|
|
||||||
const response = await fetch(`http://${GetHost()}/api/state`);
|
|
||||||
const state = await response.json();
|
|
||||||
currentInstance = state.invidious.selected_instance;
|
|
||||||
})
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<div>
|
|
||||||
Current Instance: {currentInstance}
|
|
||||||
</div>
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
function GetHost() {
|
function getHost() {
|
||||||
const urlSearchParams = new URLSearchParams(window.location.search);
|
const urlSearchParams = new URLSearchParams(window.location.search);
|
||||||
return urlSearchParams.get('host') ?? window.location.host
|
return urlSearchParams.get('host') ?? window.location.host
|
||||||
}
|
}
|
||||||
|
|
||||||
export { GetHost }
|
export { getHost }
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { PlayletApi } from "./PlayletApi";
|
||||||
|
import { playletStateStore } from "./Stores";
|
||||||
|
|
||||||
|
let selectedInstance;
|
||||||
|
let inputInstance;
|
||||||
|
|
||||||
|
playletStateStore.subscribe((value) => {
|
||||||
|
selectedInstance = value?.invidious?.selected_instance ?? "N/A";
|
||||||
|
inputInstance = selectedInstance;
|
||||||
|
});
|
||||||
|
|
||||||
|
const updateInstance = async () => {
|
||||||
|
await PlayletApi.updateInstances([inputInstance]);
|
||||||
|
// TODO: reload state
|
||||||
|
window.location.reload();
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="form-control">
|
||||||
|
<label class="input-group">
|
||||||
|
<span>Invidious Instance</span>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="http://my-instance.com"
|
||||||
|
class="input input-bordered"
|
||||||
|
bind:value={inputInstance}
|
||||||
|
/>
|
||||||
|
{#if inputInstance !== selectedInstance}
|
||||||
|
<button class="btn" on:click={updateInstance}>Update</button>
|
||||||
|
{/if}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import playletLogo from "../assets/logo-dark.svg";
|
||||||
|
import { PlayletApi } from "./PlayletApi";
|
||||||
|
import { playletStateStore } from "./Stores";
|
||||||
|
|
||||||
|
let version;
|
||||||
|
let loggedIn = false;
|
||||||
|
let auth_url;
|
||||||
|
let selectedInstance;
|
||||||
|
let loggedInInstance;
|
||||||
|
|
||||||
|
playletStateStore.subscribe((value) => {
|
||||||
|
version = value?.app?.version ?? "";
|
||||||
|
loggedIn = value?.invidious?.logged_in;
|
||||||
|
auth_url = value?.invidious?.auth_url;
|
||||||
|
selectedInstance = value?.invidious?.selected_instance;
|
||||||
|
loggedInInstance = value?.invidious?.logged_in_instance;
|
||||||
|
});
|
||||||
|
|
||||||
|
const login = () => {
|
||||||
|
if (!auth_url) {
|
||||||
|
alert("Error with login, please refresh the page.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
window.location = auth_url;
|
||||||
|
};
|
||||||
|
const logout = async () => {
|
||||||
|
await PlayletApi.logout();
|
||||||
|
// TODO: reload state
|
||||||
|
window.location.reload();
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="navbar bg-base-100">
|
||||||
|
<div class="flex-1">
|
||||||
|
<img src={playletLogo} class="btn" alt="Playlet Logo" />
|
||||||
|
<h4 class="label">{version}</h4>
|
||||||
|
</div>
|
||||||
|
<div class="flex-none">
|
||||||
|
{#if loggedIn}
|
||||||
|
<div class="tooltip tooltip-left" data-tip={loggedInInstance}>
|
||||||
|
<button class="btn" on:click={logout}>Logout</button>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<div class="tooltip tooltip-left" data-tip={selectedInstance}>
|
||||||
|
<button class="btn" on:click={login}>Login</button>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { PlayletApi } from "./PlayletApi";
|
||||||
|
|
||||||
|
let videoId;
|
||||||
|
|
||||||
|
function IsValidHttpUrl(string) {
|
||||||
|
let url;
|
||||||
|
try {
|
||||||
|
url = new URL(string);
|
||||||
|
} catch (_) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return url.protocol === "http:" || url.protocol === "https:";
|
||||||
|
}
|
||||||
|
|
||||||
|
function GetVideoId(url) {
|
||||||
|
// Share/Short url
|
||||||
|
const YoutubeUrls = [
|
||||||
|
"https://youtu.be/",
|
||||||
|
"http://youtu.be/",
|
||||||
|
"https://www.youtu.be/",
|
||||||
|
"http://www.youtu.be/",
|
||||||
|
"https://youtube.com/shorts/",
|
||||||
|
"http://youtube.com/shorts/",
|
||||||
|
"https://www.youtube.com/shorts/",
|
||||||
|
"http://www.youtube.com/shorts/",
|
||||||
|
];
|
||||||
|
for (var i in YoutubeUrls) {
|
||||||
|
let youtubeUrl = YoutubeUrls[i];
|
||||||
|
if (url.startsWith(youtubeUrl)) {
|
||||||
|
url = url.replace(youtubeUrl, "");
|
||||||
|
if (url.includes("?")) {
|
||||||
|
url = url.substring(0, url.indexOf("?"));
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// regular url
|
||||||
|
url = new URL(url);
|
||||||
|
const urlSearchParams = new URLSearchParams(url.search);
|
||||||
|
return urlSearchParams.get("v");
|
||||||
|
}
|
||||||
|
|
||||||
|
const playVideo = async () => {
|
||||||
|
let v = videoId;
|
||||||
|
if (IsValidHttpUrl(v)) {
|
||||||
|
v = GetVideoId(v);
|
||||||
|
}
|
||||||
|
if (!v || v.length < 8) {
|
||||||
|
alert("Please set video id");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await PlayletApi.playVideo(v);
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="form-control">
|
||||||
|
<div class="input-group">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Video ID"
|
||||||
|
class="input input-bordered"
|
||||||
|
bind:value={videoId}
|
||||||
|
/>
|
||||||
|
<button class="btn" on:click={playVideo}> Play </button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { getHost } from "./Host";
|
||||||
|
|
||||||
|
export class PlayletApi {
|
||||||
|
static host = () => `http://${getHost()}`
|
||||||
|
|
||||||
|
static async getState() {
|
||||||
|
const response = await fetch(`${PlayletApi.host()}/api/state`);
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
static async logout() {
|
||||||
|
return await PlayletApi.postJson(`${PlayletApi.host()}/api/command`, { command: "logout" });
|
||||||
|
}
|
||||||
|
|
||||||
|
static async playVideo(videoId) {
|
||||||
|
return await PlayletApi.postJson(`${PlayletApi.host()}/api/command`, { command: "play", videoId: videoId });
|
||||||
|
}
|
||||||
|
|
||||||
|
static async clearSearchHistory() {
|
||||||
|
return await PlayletApi.postJson(`${PlayletApi.host()}/api/command`, { command: "clear-search-history" });
|
||||||
|
}
|
||||||
|
|
||||||
|
static async updateInstances(instances) {
|
||||||
|
return await PlayletApi.postJson(`${PlayletApi.host()}/invidious/instances`, instances);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static postJson(url, payload) {
|
||||||
|
return fetch(url, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(payload)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import { writable } from 'svelte/store';
|
||||||
|
|
||||||
|
export const playletStateStore = writable({} as any);
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
/** @type {import('tailwindcss').Config} */
|
||||||
|
module.exports = {
|
||||||
|
content: ['./src/**/*.{html,js,svelte,ts}'],
|
||||||
|
theme: {
|
||||||
|
extend: {}
|
||||||
|
},
|
||||||
|
plugins: [require('daisyui')]
|
||||||
|
};
|
||||||
@@ -3,15 +3,24 @@ namespace Http
|
|||||||
class CorsMiddleware extends HttpRouter
|
class CorsMiddleware extends HttpRouter
|
||||||
private origin
|
private origin
|
||||||
|
|
||||||
function new(origin = "*" as string)
|
function new(origin = "*" as string, headers = "*" as string)
|
||||||
super()
|
super()
|
||||||
|
|
||||||
m.origin = origin
|
m.origin = origin
|
||||||
|
m.headers = headers
|
||||||
|
|
||||||
m.All("*", function(context as object) as boolean
|
m.All("*", function(context as object) as boolean
|
||||||
router = context.router
|
router = context.router
|
||||||
|
request = context.request
|
||||||
response = context.response
|
response = context.response
|
||||||
response.headers["Access-Control-Allow-Origin"] = router.origin
|
response.headers["Access-Control-Allow-Origin"] = router.origin
|
||||||
|
response.headers["Access-Control-Allow-Headers"] = router.headers
|
||||||
|
|
||||||
|
if request.method = "OPTIONS"
|
||||||
|
response.header_only = true
|
||||||
|
response.http_code = 200
|
||||||
|
return true
|
||||||
|
end if
|
||||||
return false
|
return false
|
||||||
end function)
|
end function)
|
||||||
end function
|
end function
|
||||||
|
|||||||
Reference in new issue
Block a user