Revert "cookie update"

This reverts commit 551ed77eb0.
This commit is contained in:
2025-12-03 08:06:26 +03:00
parent 551ed77eb0
commit 642aeffcd7
2 changed files with 11 additions and 117 deletions

View File

@@ -1,19 +1,18 @@
<script>
import { Link } from "svelte-routing";
import { createEventDispatcher, onDestroy, onMount, tick } from "svelte";
import { Link } from "svelte-routing";
import { createEventDispatcher, onDestroy, onMount, tick } from "svelte";
import { movieCount } from "../stores/movieStore.js";
import { tvShowCount } from "../stores/tvStore.js";
import { musicCount } from "../stores/musicStore.js";
import { trashCount } from "../stores/trashStore.js";
import { API, apiFetch, authHeaders } from "../utils/api.js";
import { trashCount } from "../stores/trashStore.js";
import { apiFetch } from "../utils/api.js";
export let menuOpen = false;
const dispatch = createEventDispatcher();
let hasMovies = false;
let hasShows = false;
let hasShows = false;
let hasTrash = false;
let hasMusic = false;
let cookieMessage = "";
// Svelte store kullanarak reaktivite sağla
import { writable } from 'svelte/store';
const diskSpaceStore = writable({ totalGB: '0', usedGB: '0', usedPercent: 0 });
@@ -88,11 +87,14 @@ const unsubscribeMusic = musicCount.subscribe((count) => {
// WebSocket bağlantısı kur
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
// Server port'unu doğru almak için
const currentHost = window.location.host;
// Eğer client farklı portta çalışıyorsa, server port'unu manuel belirt
const wsHost = currentHost.includes(':3000') ? currentHost.replace(':3000', ':3001') : currentHost;
const wsUrl = `${wsProtocol}//${wsHost}`;
console.log('🔌 Connecting to WebSocket at:', wsUrl);
// WebSocket bağlantısını global olarak saklayalım
window.diskSpaceWs = new WebSocket(wsUrl);
window.diskSpaceWs.onmessage = (event) => {
@@ -119,42 +121,13 @@ const unsubscribeMusic = musicCount.subscribe((count) => {
window.diskSpaceWs.onclose = () => {
console.log('WebSocket disconnected');
};
return () => {
onDestroy(() => {
if (window.diskSpaceWs && (window.diskSpaceWs.readyState === WebSocket.OPEN || window.diskSpaceWs.readyState === WebSocket.CONNECTING)) {
window.diskSpaceWs.close();
}
};
});
});
async function uploadCookies(file) {
if (!file) return;
cookieMessage = "Yükleniyor...";
try {
const form = new FormData();
form.append("cookies", file);
const res = await fetch(`${API}/api/cookies/upload`, {
method: "POST",
headers: authHeaders(),
body: form
});
if (!res.ok) {
const data = await res.json().catch(() => ({}));
throw new Error(data?.error || `HTTP ${res.status}`);
}
cookieMessage = "Cookie yüklendi.";
} catch (err) {
console.error("🍪 Cookie yükleme hatası:", err);
cookieMessage = "Yükleme başarısız.";
} finally {
setTimeout(() => (cookieMessage = ""), 2500);
}
}
function triggerCookieUpload() {
const input = document.getElementById("cookie-file-input");
if (input) input.click();
}
</script>
<div class="sidebar" class:open={menuOpen}>
@@ -287,53 +260,4 @@ const unsubscribeMusic = musicCount.subscribe((count) => {
</style>
</div>
</div>
<div class="cookie-upload">
<input
id="cookie-file-input"
type="file"
accept=".txt"
style="display: none"
on:change={(e) => uploadCookies(e.target.files?.[0])}
/>
<button class="cookie-btn" type="button" on:click={triggerCookieUpload}>
<i class="fa-solid fa-cookie-bite"></i>
Cookie Yükle
</button>
{#if cookieMessage}
<div class="cookie-msg">{cookieMessage}</div>
{/if}
</div>
</div>
<style>
.cookie-upload {
margin: 12px 10px 0 10px;
display: flex;
flex-direction: column;
gap: 6px;
}
.cookie-btn {
width: 100%;
border: none;
border-radius: 8px;
padding: 8px 10px;
background: #2c3e50;
color: #fff;
cursor: pointer;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
}
.cookie-btn:hover {
background: #243544;
}
.cookie-msg {
font-size: 12px;
color: #e0e0e0;
}
</style>