Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

Remove TheMembers and VoompPlay course pages and their associated logic

Tonho3a1e7eed2e62
diff --git a/src/routes/courses/afyainternato/+page.svelte b/src/routes/courses/afyainternato/+page.svelte
deleted file mode 100644
index 61d83ab7..00000000
--- a/src/routes/courses/afyainternato/+page.svelte
+++ /dev/null
@@ -1,725 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type AfyaCourse = {
- id: string;
- name: string;
- product_id: string;
- };
-
- let email = $state("");
- let password = $state("");
- let apiKey = $state("");
- let token = $state("");
- let tokenApiKey = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "token">("credentials");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let courses: AfyaCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("afya_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("afya_login", { email, password, apiKey });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("afya_login_token", { token: token.trim(), apiKey: tokenApiKey.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("afya_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("afya_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: AfyaCourse) {
- const status = getCourseDownloadStatus(Number(course.id) || 0);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_afya_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("afya_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "\u2014" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price={course.product_id}
- downloadStatus={getCourseDownloadStatus(Number(course.id) || 0)}
- downloadPercent={getCourseDownloadPercent(Number(course.id) || 0)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Afya Internato</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "token"}
- onclick={() => { loginMode = "token"; error = ""; }}
- >
- Token
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">API Key</span>
- <input
- type="text"
- placeholder="Paste your API key here..."
- bind:value={apiKey}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- <label class="field">
- <span class="field-label">API Key</span>
- <input
- type="text"
- placeholder="Paste your API key here..."
- bind:value={tokenApiKey}
- class="input"
- disabled={loading}
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/alpaclass/+page.svelte b/src/routes/courses/alpaclass/+page.svelte
deleted file mode 100644
index 7838a337..00000000
--- a/src/routes/courses/alpaclass/+page.svelte
+++ /dev/null
@@ -1,616 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type AlpaclassCourse = {
- slug: string;
- name: string;
- author: string;
- };
-
- let token = $state("");
- let platformUrl = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: AlpaclassCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("alpaclass_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("alpaclass_login", {
- token: token.trim(),
- platformUrl: platformUrl.trim(),
- });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("alpaclass_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("alpaclass_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(_courseSlug: string): "idle" | "downloading" | "complete" | "error" {
- return "idle";
- }
-
- function getCourseDownloadPercent(_courseSlug: string): number {
- return 0;
- }
-
- async function downloadCourse(course: AlpaclassCourse) {
- const status = getCourseDownloadStatus(course.slug);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_alpaclass_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("alpaclass_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.slug)}
- <CourseCard
- name={course.name}
- price={course.author}
- downloadStatus={getCourseDownloadStatus(course.slug)}
- downloadPercent={getCourseDownloadPercent(course.slug)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>AlpaClass</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Platform URL</span>
- <input
- type="url"
- placeholder="https://example.alpaclass.com"
- bind:value={platformUrl}
- class="input"
- disabled={loading}
- />
- </label>
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/areademembros/+page.svelte b/src/routes/courses/areademembros/+page.svelte
deleted file mode 100644
index aaf1ab41..00000000
--- a/src/routes/courses/areademembros/+page.svelte
+++ /dev/null
@@ -1,616 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type AreaDeMembrosApiCourse = {
- id: string;
- name: string;
- };
-
- let token = $state("");
- let siteUrl = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: AreaDeMembrosApiCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("areademembros_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("areademembros_login_token", { token: token.trim(), siteUrl: siteUrl.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("areademembros_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("areademembros_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = Number(courseId) || 0;
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = Number(courseId) || 0;
- return downloads.get(numId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: AreaDeMembrosApiCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_areademembros_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("areademembros_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Area de Membros</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Platform URL</span>
- <input
- type="url"
- placeholder="https://example.areademembros.com"
- bind:value={siteUrl}
- class="input"
- disabled={loading}
- />
- </label>
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input { display: none; }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/astronmembers/+page.svelte b/src/routes/courses/astronmembers/+page.svelte
deleted file mode 100644
index 1465a3e8..00000000
--- a/src/routes/courses/astronmembers/+page.svelte
+++ /dev/null
@@ -1,713 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type AstronCourse = {
- id: string;
- name: string;
- slug: string;
- };
-
- let email = $state("");
- let password = $state("");
- let token = $state("");
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
- let siteUrl = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "token">("credentials");
-
- let courses: AstronCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("astronmembers_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("astronmembers_login", { email, password, siteUrl });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("astronmembers_login_token", { token: token.trim(), siteUrl });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("astronmembers_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("astronmembers_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = Number(courseId) || 0;
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = Number(courseId) || 0;
- return downloads.get(numId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: AstronCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_astronmembers_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("astronmembers_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Astron Members</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Login
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "token"}
- onclick={() => { loginMode = "token"; error = ""; }}
- >
- Cookie
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">Site URL</span>
- <input
- type="url"
- placeholder="https://your-site.astronmembers.com"
- bind:value={siteUrl}
- class="input"
- disabled={loading}
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="4"
- ></textarea>
- </label>
- <input type="file" accept=".json,.txt" class="hidden-file-input" bind:this={fileInput} onchange={onFileSelected} />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>Import .json file</button>
- <label class="field">
- <span class="field-label">Site URL</span>
- <input
- type="url"
- placeholder="https://your-site.astronmembers.com"
- bind:value={siteUrl}
- class="input"
- disabled={loading}
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
\ No newline at end of file
diff --git a/src/routes/courses/cademi/+page.svelte b/src/routes/courses/cademi/+page.svelte
deleted file mode 100644
index 406f05ea..00000000
--- a/src/routes/courses/cademi/+page.svelte
+++ /dev/null
@@ -1,722 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type CademiCourse = {
- id: string;
- name: string;
- };
-
- let email = $state("");
- let password = $state("");
- let cookie = $state("");
- let siteUrl = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "cookie">("credentials");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { cookie = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let courses: CademiCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("cademi_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("cademi_login", { email, password, siteUrl: siteUrl.trim() });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleCookieLogin() {
- if (!cookie.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("cademi_login_cookie", { cookie: cookie.trim(), siteUrl: siteUrl.trim() });
- sessionEmail = result || "Cookie";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("cademi_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("cademi_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = Number(courseId) || 0;
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = Number(courseId) || 0;
- return downloads.get(numId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: CademiCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_cademi_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("cademi_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Cademi</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "cookie"}
- onclick={() => { loginMode = "cookie"; error = ""; }}
- >
- Cookie
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">Platform URL</span>
- <input
- type="url"
- placeholder="https://example.cademi.com.br"
- bind:value={siteUrl}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Platform URL</span>
- <input
- type="url"
- placeholder="https://example.cademi.com.br"
- bind:value={siteUrl}
- class="input"
- disabled={loading}
- />
- </label>
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={cookie}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleCookieLogin} disabled={loading || !cookie.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input { display: none; }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/cakto/+page.svelte b/src/routes/courses/cakto/+page.svelte
deleted file mode 100644
index 72255688..00000000
--- a/src/routes/courses/cakto/+page.svelte
+++ /dev/null
@@ -1,693 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type CaktoCourse = {
- id: string;
- name: string;
- image_url: string | null;
- };
-
- let email = $state("");
- let password = $state("");
- let token = $state("");
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "token">("credentials");
-
- let courses: CaktoCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("cakto_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("cakto_login", { email, password });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("cakto_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("cakto_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("cakto_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = Number(courseId) || 0;
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = Number(courseId) || 0;
- return downloads.get(numId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: CaktoCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_cakto_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("cakto_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- imageUrl={course.image_url ?? undefined}
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Cakto</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "token"}
- onclick={() => { loginMode = "token"; error = ""; }}
- >
- Cookie
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="4"
- ></textarea>
- </label>
- <input type="file" accept=".json,.txt" class="hidden-file-input" bind:this={fileInput} onchange={onFileSelected} />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>Import .json file</button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
\ No newline at end of file
diff --git a/src/routes/courses/caktomembers/+page.svelte b/src/routes/courses/caktomembers/+page.svelte
deleted file mode 100644
index 032e414a..00000000
--- a/src/routes/courses/caktomembers/+page.svelte
+++ /dev/null
@@ -1,596 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type CaktoMembersCourse = {
- id: string;
- name: string;
- };
-
- let token = $state("");
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: CaktoMembersCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("caktomembers_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("caktomembers_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("caktomembers_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("caktomembers_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = Number(courseId) || 0;
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = Number(courseId) || 0;
- return downloads.get(numId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: CaktoMembersCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_caktomembers_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("caktomembers_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Cakto Members</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="4"
- ></textarea>
- </label>
- <input type="file" accept=".json,.txt" class="hidden-file-input" bind:this={fileInput} onchange={onFileSelected} />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>Import .json file</button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
\ No newline at end of file
diff --git a/src/routes/courses/curseduca/+page.svelte b/src/routes/courses/curseduca/+page.svelte
deleted file mode 100644
index 8bb30aa0..00000000
--- a/src/routes/courses/curseduca/+page.svelte
+++ /dev/null
@@ -1,724 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type CurseducaCourse = {
- id: string;
- name: string;
- slug: string;
- };
-
- let email = $state("");
- let password = $state("");
- let token = $state("");
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
- let apiKey = $state("");
- let siteUrl = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "token">("credentials");
-
- let courses: CurseducaCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("curseduca_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("curseduca_login", { email, password, siteUrl });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("curseduca_login_token", { token: token.trim(), apiKey: apiKey.trim(), siteUrl });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("curseduca_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("curseduca_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = Number(courseId) || 0;
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = Number(courseId) || 0;
- return downloads.get(numId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: CurseducaCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_curseduca_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("curseduca_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Curseduca</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "token"}
- onclick={() => { loginMode = "token"; error = ""; }}
- >
- Token
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">Site URL</span>
- <input
- type="url"
- placeholder="https://your-site.curseduca.pro"
- bind:value={siteUrl}
- class="input"
- disabled={loading}
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="4"
- ></textarea>
- </label>
- <input type="file" accept=".json,.txt" class="hidden-file-input" bind:this={fileInput} onchange={onFileSelected} />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>Import .json file</button>
- <label class="field">
- <span class="field-label">API Key</span>
- <input
- type="text"
- placeholder="Paste your API key here..."
- bind:value={apiKey}
- class="input"
- disabled={loading}
- />
- </label>
- <label class="field">
- <span class="field-label">Site URL</span>
- <input
- type="url"
- placeholder="https://your-site.curseduca.pro"
- bind:value={siteUrl}
- class="input"
- disabled={loading}
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
\ No newline at end of file
diff --git a/src/routes/courses/datascienceacademy/+page.svelte b/src/routes/courses/datascienceacademy/+page.svelte
deleted file mode 100644
index e255cf5b..00000000
--- a/src/routes/courses/datascienceacademy/+page.svelte
+++ /dev/null
@@ -1,607 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type DsaCourse = {
- id: string;
- name: string;
- slug: string;
- };
-
- let token = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: DsaCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("dsa_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("dsa_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("dsa_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("dsa_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: DsaCourse) {
- const status = getCourseDownloadStatus(Number(course.id) || 0);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_dsa_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("dsa_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- imageUrl={undefined}
- downloadStatus={getCourseDownloadStatus(Number(course.id) || 0)}
- downloadPercent={getCourseDownloadPercent(Number(course.id) || 0)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Data Science Academy</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/eduzznutror/+page.svelte b/src/routes/courses/eduzznutror/+page.svelte
deleted file mode 100644
index 7cc2cda2..00000000
--- a/src/routes/courses/eduzznutror/+page.svelte
+++ /dev/null
@@ -1,621 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type NutrorCourse = {
- id: string;
- name: string;
- hash: string;
- };
-
- let token = $state("");
- let refreshToken = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: NutrorCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("nutror_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("nutror_login_token", {
- token: token.trim(),
- refreshToken: refreshToken.trim() || null,
- });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("nutror_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("nutror_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = Number(courseId) || 0;
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = Number(courseId) || 0;
- return downloads.get(numId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: NutrorCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_nutror_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("nutror_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Eduzz / Nutror</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- <label class="field">
- <span class="field-label">Refresh Token (optional)</span>
- <input
- type="text"
- placeholder="Paste your refresh token here..."
- bind:value={refreshToken}
- class="input"
- disabled={loading}
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input { display: none; }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/entregadigital/+page.svelte b/src/routes/courses/entregadigital/+page.svelte
deleted file mode 100644
index 18abcd04..00000000
--- a/src/routes/courses/entregadigital/+page.svelte
+++ /dev/null
@@ -1,656 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type EntregaDigitalCourse = {
- id: number;
- name: string;
- };
-
- let token = $state("");
- let siteUrl = $state("");
- let appVersion = $state("");
- let deviceId = $state("");
- let osValue = $state("Web");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: EntregaDigitalCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("entregadigital_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("entregadigital_login_token", {
- token: token.trim(),
- siteUrl: siteUrl.trim(),
- appVersion: appVersion.trim(),
- deviceId: deviceId.trim(),
- osValue: osValue.trim(),
- });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("entregadigital_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("entregadigital_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: EntregaDigitalCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_entregadigital_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("entregadigital_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price={""}
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Entrega Digital</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Platform URL</span>
- <input
- type="url"
- placeholder="https://exemplo.entregadigital.app.br"
- bind:value={siteUrl}
- class="input"
- disabled={loading}
- />
- </label>
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- <label class="field">
- <span class="field-label">App Version</span>
- <input
- type="text"
- placeholder="e.g. 1.2.3"
- bind:value={appVersion}
- class="input"
- disabled={loading}
- />
- </label>
- <label class="field">
- <span class="field-label">Device ID</span>
- <input
- type="text"
- placeholder="from network tab"
- bind:value={deviceId}
- class="input"
- disabled={loading}
- />
- </label>
- <label class="field">
- <span class="field-label">OS</span>
- <input
- type="text"
- placeholder="Web"
- bind:value={osValue}
- class="input"
- disabled={loading}
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/estrategia-concursos/+page.svelte b/src/routes/courses/estrategia-concursos/+page.svelte
deleted file mode 100644
index 81ab75d2..00000000
--- a/src/routes/courses/estrategia-concursos/+page.svelte
+++ /dev/null
@@ -1,604 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type EstrategiaConcursosCourse = {
- id: number;
- name: string;
- total_aulas: number;
- };
-
- let token = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: EstrategiaConcursosCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("estrategia_concursos_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("estrategia_concursos_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("estrategia_concursos_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("estrategia_concursos_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: EstrategiaConcursosCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_estrategia_concursos_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("estrategia_concursos_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price={`${course.total_aulas} aulas`}
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Estrat&eacute;gia Concursos</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input { display: none; }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/estrategia-ldi/+page.svelte b/src/routes/courses/estrategia-ldi/+page.svelte
deleted file mode 100644
index e94f3690..00000000
--- a/src/routes/courses/estrategia-ldi/+page.svelte
+++ /dev/null
@@ -1,603 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type EstrategiaLdiCourse = {
- id: string;
- name: string;
- };
-
- let token = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: EstrategiaLdiCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("estrategia_ldi_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("estrategia_ldi_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("estrategia_ldi_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("estrategia_ldi_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(Number(courseId) || 0);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- return downloads.get(Number(courseId) || 0)?.percent ?? 0;
- }
-
- async function downloadCourse(course: EstrategiaLdiCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_estrategia_ldi_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("estrategia_ldi_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Estrat&eacute;gia LDI</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input { display: none; }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/estrategia-militares/+page.svelte b/src/routes/courses/estrategia-militares/+page.svelte
deleted file mode 100644
index 2c80a488..00000000
--- a/src/routes/courses/estrategia-militares/+page.svelte
+++ /dev/null
@@ -1,643 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type EstrategiaMilitaresCourse = {
- id: string;
- name: string;
- slug: string;
- goal_id: string;
- };
-
- let token = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: EstrategiaMilitaresCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("estrategia_militares_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("estrategia_militares_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("estrategia_militares_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- let searchQuery = $state("");
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("estrategia_militares_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- async function handleSearch() {
- if (!searchQuery.trim()) return;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("estrategia_militares_search_courses", { query: searchQuery.trim() });
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? "Search failed";
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(Number(courseId) || 0);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- return downloads.get(Number(courseId) || 0)?.percent ?? 0;
- }
-
- async function downloadCourse(course: EstrategiaMilitaresCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_estrategia_militares_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("estrategia_militares_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- <form class="search-bar" onsubmit={(e) => { e.preventDefault(); handleSearch(); }}>
- <input
- class="input search-input"
- type="text"
- placeholder="Search courses (e.g. Marinha, Exercito, FAB...)"
- bind:value={searchQuery}
- />
- <button class="button" type="submit" disabled={loadingCourses || !searchQuery.trim()}>
- Search
- </button>
- </form>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Estrat&eacute;gia Militares</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .search-bar {
- display: flex;
- gap: calc(var(--padding) / 2);
- width: 100%;
- }
-
- .search-input {
- flex: 1;
- }
-
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input { display: none; }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/fluencyacademy/+page.svelte b/src/routes/courses/fluencyacademy/+page.svelte
deleted file mode 100644
index e9ec3e6b..00000000
--- a/src/routes/courses/fluencyacademy/+page.svelte
+++ /dev/null
@@ -1,701 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type FluencyCourse = {
- id: string;
- name: string;
- program_id: string;
- };
-
- let email = $state("");
- let password = $state("");
- let token = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "token">("credentials");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let courses: FluencyCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("fluencyacademy_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("fluencyacademy_login", { email, password });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("fluencyacademy_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("fluencyacademy_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("fluencyacademy_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = Number(courseId) || 0;
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = Number(courseId) || 0;
- return downloads.get(numId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: FluencyCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_fluencyacademy_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("fluencyacademy_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Fluency Academy</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "token"}
- onclick={() => { loginMode = "token"; error = ""; }}
- >
- Token
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input { display: none; }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/grancursos/+page.svelte b/src/routes/courses/grancursos/+page.svelte
deleted file mode 100644
index 3ac22ce1..00000000
--- a/src/routes/courses/grancursos/+page.svelte
+++ /dev/null
@@ -1,603 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type GranCursosCourse = {
- id: number;
- name: string;
- };
-
- let token = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: GranCursosCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("grancursos_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("grancursos_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("grancursos_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("grancursos_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: GranCursosCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_grancursos_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("grancursos_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Gran Cursos</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input { display: none; }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/greennclub/+page.svelte b/src/routes/courses/greennclub/+page.svelte
deleted file mode 100644
index a5ac00f5..00000000
--- a/src/routes/courses/greennclub/+page.svelte
+++ /dev/null
@@ -1,606 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type GreennCourse = {
- id: number;
- name: string;
- lessons_count: number;
- };
-
- let token = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: GreennCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("greenn_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("greenn_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("greenn_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("greenn_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: GreennCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_greenn_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("greenn_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "\u2014" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price={course.lessons_count === 1 ? "1 lesson" : `${course.lessons_count} lessons`}
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Greenn Club</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/kirvano/+page.svelte b/src/routes/courses/kirvano/+page.svelte
deleted file mode 100644
index e3c9a128..00000000
--- a/src/routes/courses/kirvano/+page.svelte
+++ /dev/null
@@ -1,704 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type KirvanoCourse = {
- id: string;
- name: string;
- seller: string;
- image_url: string | null;
- course_uuid: string;
- };
-
- let email = $state("");
- let password = $state("");
- let token = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "token">("credentials");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let courses: KirvanoCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("kirvano_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("kirvano_login", { email, password });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("kirvano_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("kirvano_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("kirvano_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: KirvanoCourse) {
- const status = getCourseDownloadStatus(Number(course.id) || 0);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_kirvano_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("kirvano_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price={course.seller}
- imageUrl={course.image_url ?? undefined}
- downloadStatus={getCourseDownloadStatus(Number(course.id) || 0)}
- downloadPercent={getCourseDownloadPercent(Number(course.id) || 0)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Kirvano</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "token"}
- onclick={() => { loginMode = "token"; error = ""; }}
- >
- Token
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/masterclass/+page.svelte b/src/routes/courses/masterclass/+page.svelte
deleted file mode 100644
index f5dd433a..00000000
--- a/src/routes/courses/masterclass/+page.svelte
+++ /dev/null
@@ -1,601 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type MasterClassCourse = {
- id: string;
- name: string;
- instructor: string;
- slug: string;
- };
-
- let cookies = $state("");
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { cookies = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
-
- let courses: MasterClassCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- await invoke<string>("masterclass_check_session");
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleCookieLogin() {
- if (!cookies.trim()) return;
- error = "";
- loading = true;
- try {
- await invoke<string>("masterclass_login_cookies", { cookies: cookies.trim() });
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("masterclass_logout");
- } catch {
- }
- loggedIn = false;
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("masterclass_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const hash = hashString(courseId);
- const item = downloads.get(hash);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- return downloads.get(hashString(courseId))?.percent ?? 0;
- }
-
- function hashString(str: string): number {
- let hash = 0;
- for (let i = 0; i < str.length; i++) {
- const char = str.charCodeAt(i);
- hash = ((hash << 5) - hash) + char;
- hash |= 0;
- }
- return Math.abs(hash);
- }
-
- async function downloadCourse(course: MasterClassCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_masterclass_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("masterclass_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">MasterClass</span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.instructor ? `${course.instructor} - ${course.name}` : course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>MasterClass</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={cookies}
- disabled={loading}
- rows="4"
- ></textarea>
- </label>
- <input type="file" accept=".json,.txt" class="hidden-file-input" bind:this={fileInput} onchange={onFileSelected} />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>Import .json file</button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleCookieLogin} disabled={loading || !cookies.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/medcel/+page.svelte b/src/routes/courses/medcel/+page.svelte
deleted file mode 100644
index 6c290d2a..00000000
--- a/src/routes/courses/medcel/+page.svelte
+++ /dev/null
@@ -1,726 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type MedcelCourse = {
- id: string;
- name: string;
- product_id: string;
- };
-
- let email = $state("");
- let password = $state("");
- let token = $state("");
- let apiKey = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "token">("credentials");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let courses: MedcelCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("medcel_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("medcel_login", { email, password, apiKey });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("medcel_login_token", { token: token.trim(), apiKey });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("medcel_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("medcel_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: MedcelCourse) {
- const status = getCourseDownloadStatus(Number(course.id) || 0);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_medcel_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("medcel_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- imageUrl={undefined}
- downloadStatus={getCourseDownloadStatus(Number(course.id) || 0)}
- downloadPercent={getCourseDownloadPercent(Number(course.id) || 0)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Medcel</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "token"}
- onclick={() => { loginMode = "token"; error = ""; }}
- >
- Token
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">X-API-Key</span>
- <input
- type="text"
- placeholder="Enter your API key..."
- bind:value={apiKey}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- <label class="field">
- <span class="field-label">X-API-Key</span>
- <input
- type="text"
- placeholder="Enter your API key..."
- bind:value={apiKey}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/medcof/+page.svelte b/src/routes/courses/medcof/+page.svelte
deleted file mode 100644
index 6eeb91e9..00000000
--- a/src/routes/courses/medcof/+page.svelte
+++ /dev/null
@@ -1,596 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type MedcofCourse = {
- id: string;
- name: string;
- };
-
- let token = $state("");
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: MedcofCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("medcof_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("medcof_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("medcof_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("medcof_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = Number(courseId) || 0;
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = Number(courseId) || 0;
- return downloads.get(numId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: MedcofCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_medcof_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("medcof_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Medcof</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="4"
- ></textarea>
- </label>
- <input type="file" accept=".json,.txt" class="hidden-file-input" bind:this={fileInput} onchange={onFileSelected} />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>Import .json file</button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
\ No newline at end of file
diff --git a/src/routes/courses/medway/+page.svelte b/src/routes/courses/medway/+page.svelte
deleted file mode 100644
index 1f230206..00000000
--- a/src/routes/courses/medway/+page.svelte
+++ /dev/null
@@ -1,605 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type MedwayCourse = {
- id: number;
- name: string;
- };
-
- let token = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: MedwayCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("medway_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("medway_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("medway_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("medway_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: MedwayCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_medway_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("medway_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "\u2014" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price={""}
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Medway</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/memberkit/+page.svelte b/src/routes/courses/memberkit/+page.svelte
deleted file mode 100644
index 75ec78bd..00000000
--- a/src/routes/courses/memberkit/+page.svelte
+++ /dev/null
@@ -1,723 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type MemberkitCourse = {
- id: string;
- name: string;
- slug: string;
- };
-
- let email = $state("");
- let password = $state("");
- let cookie = $state("");
- let siteUrl = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "cookie">("credentials");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { cookie = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let courses: MemberkitCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("memberkit_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("memberkit_login", { email, password, siteUrl: siteUrl.trim() });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleCookieLogin() {
- if (!cookie.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("memberkit_login_cookie", { cookie: cookie.trim(), siteUrl: siteUrl.trim() });
- sessionEmail = result || "Cookie";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("memberkit_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("memberkit_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const numId = Number(courseId) || 0;
- const item = downloads.get(numId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- const numId = Number(courseId) || 0;
- return downloads.get(numId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: MemberkitCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_memberkit_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("memberkit_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>MemberKit</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "cookie"}
- onclick={() => { loginMode = "cookie"; error = ""; }}
- >
- Cookie
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">Platform URL</span>
- <input
- type="url"
- placeholder="https://example.memberkit.com.br"
- bind:value={siteUrl}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Platform URL</span>
- <input
- type="url"
- placeholder="https://example.memberkit.com.br"
- bind:value={siteUrl}
- class="input"
- disabled={loading}
- />
- </label>
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={cookie}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleCookieLogin} disabled={loading || !cookie.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input { display: none; }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/pluralsight/+page.svelte b/src/routes/courses/pluralsight/+page.svelte
deleted file mode 100644
index e4bf8975..00000000
--- a/src/routes/courses/pluralsight/+page.svelte
+++ /dev/null
@@ -1,599 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type PluralsightCourse = {
- id: string;
- name: string;
- };
-
- let cookies = $state("");
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { cookies = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
-
- let courses: PluralsightCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- await invoke<string>("pluralsight_check_session");
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleCookieLogin() {
- if (!cookies.trim()) return;
- error = "";
- loading = true;
- try {
- await invoke<string>("pluralsight_login_cookies", { cookies: cookies.trim() });
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("pluralsight_logout");
- } catch {
- }
- loggedIn = false;
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("pluralsight_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: string): "idle" | "downloading" | "complete" | "error" {
- const hash = hashString(courseId);
- const item = downloads.get(hash);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: string): number {
- return downloads.get(hashString(courseId))?.percent ?? 0;
- }
-
- function hashString(str: string): number {
- let hash = 0;
- for (let i = 0; i < str.length; i++) {
- const char = str.charCodeAt(i);
- hash = ((hash << 5) - hash) + char;
- hash |= 0;
- }
- return Math.abs(hash);
- }
-
- async function downloadCourse(course: PluralsightCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_pluralsight_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("pluralsight_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">Pluralsight</span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price=""
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Pluralsight</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={cookies}
- disabled={loading}
- rows="4"
- ></textarea>
- </label>
- <input type="file" accept=".json,.txt" class="hidden-file-input" bind:this={fileInput} onchange={onFileSelected} />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>Import .json file</button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleCookieLogin} disabled={loading || !cookies.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/themembers/+page.svelte b/src/routes/courses/themembers/+page.svelte
deleted file mode 100644
index 7be38e95..00000000
--- a/src/routes/courses/themembers/+page.svelte
+++ /dev/null
@@ -1,727 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type TheMembersCourse = {
- id: number;
- name: string;
- };
-
- let email = $state("");
- let password = $state("");
- let token = $state("");
- let domain = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let loginMode = $state<"credentials" | "token">("credentials");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let courses: TheMembersCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("themembers_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleLogin() {
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("themembers_login", {
- email,
- password,
- domain: domain.trim(),
- });
- sessionEmail = result || email;
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("themembers_login_token", {
- token: token.trim(),
- domain: domain.trim(),
- });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("themembers_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("themembers_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: TheMembersCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_themembers_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("themembers_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "—" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price={""}
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>TheMembers</h2>
-
- <div class="login-tabs">
- <button
- class="button login-tab"
- class:active={loginMode === "credentials"}
- onclick={() => { loginMode = "credentials"; error = ""; }}
- >
- Email & Password
- </button>
- <button
- class="button login-tab"
- class:active={loginMode === "token"}
- onclick={() => { loginMode = "token"; error = ""; }}
- >
- Token
- </button>
- </div>
-
- {#if loginMode === "credentials"}
- <form class="form" onsubmit={(e) => { e.preventDefault(); handleLogin(); }}>
- <label class="field">
- <span class="field-label">{$t('hotmart.email_label')}</span>
- <input
- type="email"
- placeholder={$t('hotmart.email_placeholder')}
- bind:value={email}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">{$t('hotmart.password_label')}</span>
- <input
- type="password"
- placeholder={$t('hotmart.password_placeholder')}
- bind:value={password}
- class="input"
- disabled={loading}
- required
- />
- </label>
- <label class="field">
- <span class="field-label">Domain</span>
- <input
- type="text"
- placeholder="example.themembers.com.br"
- bind:value={domain}
- class="input"
- disabled={loading}
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button type="submit" class="button" disabled={loading}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </form>
- {:else}
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- <label class="field">
- <span class="field-label">Domain</span>
- <input
- type="text"
- placeholder="example.themembers.com.br"
- bind:value={domain}
- class="input"
- disabled={loading}
- />
- </label>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- {/if}
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .login-tabs {
- display: flex;
- gap: 0;
- }
-
- .login-tab {
- flex: 1;
- border-radius: 0;
- font-size: 12.5px;
- padding: calc(var(--padding) * 0.75) var(--padding);
- }
-
- .login-tab:first-child {
- border-radius: var(--border-radius) 0 0 var(--border-radius);
- }
-
- .login-tab:last-child {
- border-radius: 0 var(--border-radius) var(--border-radius) 0;
- }
-
- .hidden-file-input { display: none; }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>
diff --git a/src/routes/courses/voompplay/+page.svelte b/src/routes/courses/voompplay/+page.svelte
deleted file mode 100644
index 62b3ad11..00000000
--- a/src/routes/courses/voompplay/+page.svelte
+++ /dev/null
@@ -1,606 +0,0 @@
-<script lang="ts">
- import { invoke } from "@tauri-apps/api/core";
- import { open } from "@tauri-apps/plugin-dialog";
- import CourseCard from "$components/hotmart/CourseCard.svelte";
- import { showToast } from "$lib/stores/toast-store.svelte";
- import { getDownloads } from "$lib/stores/download-store.svelte";
- import { getSettings } from "$lib/stores/settings-store.svelte";
- import { t } from "$lib/i18n";
-
- let downloads = $derived(getDownloads());
-
- type VoompCourse = {
- id: number;
- name: string;
- lessons_count: number;
- };
-
- let token = $state("");
- let loading = $state(false);
- let error = $state("");
-
- let fileInput: HTMLInputElement = $state() as HTMLInputElement;
-
- function onFileSelected(e: Event) {
- const input = e.target as HTMLInputElement;
- const file = input.files?.[0];
- if (!file) return;
- const reader = new FileReader();
- reader.onload = () => { token = reader.result as string; };
- reader.readAsText(file);
- input.value = "";
- }
-
- let checking = $state(true);
- let loggedIn = $state(false);
- let sessionEmail = $state("");
-
- let courses: VoompCourse[] = $state([]);
- let loadingCourses = $state(false);
- let coursesError = $state("");
-
- const ITEMS_PER_PAGE = 12;
- let currentPage = $state(1);
-
- let totalPages = $derived(Math.max(1, Math.ceil(courses.length / ITEMS_PER_PAGE)));
- let paginatedCourses = $derived(
- courses.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
- );
-
- let pageNumbers = $derived((): number[] => {
- const pages: number[] = [];
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- if (currentPage > 3) pages.push(-1);
- const start = Math.max(2, currentPage - 1);
- const end = Math.min(totalPages - 1, currentPage + 1);
- for (let i = start; i <= end; i++) pages.push(i);
- if (currentPage < totalPages - 2) pages.push(-1);
- pages.push(totalPages);
- }
- return pages;
- });
-
- function goToPage(page: number) {
- if (page >= 1 && page <= totalPages) {
- currentPage = page;
- }
- }
-
- $effect(() => {
- checkSession();
- });
-
- async function checkSession() {
- try {
- const result = await invoke<string>("voomp_check_session");
- sessionEmail = result;
- loggedIn = true;
- loadCourses();
- } catch {
- loggedIn = false;
- } finally {
- checking = false;
- }
- }
-
- async function handleTokenLogin() {
- if (!token.trim()) return;
- error = "";
- loading = true;
- try {
- const result = await invoke<string>("voomp_login_token", { token: token.trim() });
- sessionEmail = result || "Token";
- loggedIn = true;
- loadCourses();
- } catch (e: any) {
- error = typeof e === "string" ? e : e.message ?? $t('hotmart.unknown_error');
- } finally {
- loading = false;
- }
- }
-
- async function handleLogout() {
- try {
- await invoke("voomp_logout");
- } catch {
- }
- loggedIn = false;
- sessionEmail = "";
- courses = [];
- coursesError = "";
- currentPage = 1;
- }
-
- async function loadCourses() {
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("voomp_list_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- }
- }
-
- function getCourseDownloadStatus(courseId: number): "idle" | "downloading" | "complete" | "error" {
- const item = downloads.get(courseId);
- if (!item) return "idle";
- const s = item.status;
- if (s === "queued" || s === "paused" || s === "seeding") return "downloading";
- return s;
- }
-
- function getCourseDownloadPercent(courseId: number): number {
- return downloads.get(courseId)?.percent ?? 0;
- }
-
- async function downloadCourse(course: VoompCourse) {
- const status = getCourseDownloadStatus(course.id);
- if (status === "downloading") {
- showToast("info", $t("toast.download_already_active"));
- return;
- }
- if (status === "complete") return;
-
- const appSettings = getSettings();
- let outputDir: string | null = null;
-
- if (appSettings?.download.always_ask_path) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- } else {
- outputDir = appSettings?.download.default_output_dir ?? null;
- if (!outputDir) {
- outputDir = await open({ directory: true, title: $t("hotmart.choose_folder") }) as string | null;
- if (!outputDir) return;
- }
- }
-
- try {
- await invoke("start_voomp_course_download", {
- courseJson: JSON.stringify(course),
- outputDir,
- });
- showToast("info", $t("toast.download_preparing"));
- } catch (e: any) {
- const msg = typeof e === "string" ? e : e.message ?? $t("common.error");
- showToast("error", msg);
- }
- }
-
- let refreshing = $state(false);
-
- async function refreshCourses() {
- refreshing = true;
- loadingCourses = true;
- coursesError = "";
- try {
- courses = await invoke("voomp_refresh_courses");
- currentPage = 1;
- } catch (e: any) {
- coursesError = typeof e === "string" ? e : e.message ?? $t('hotmart.courses_error');
- } finally {
- loadingCourses = false;
- refreshing = false;
- }
- }
-</script>
-
-<a href="/courses" class="back-link">
- <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M19 12H5" />
- <path d="M12 19l-7-7 7-7" />
- </svg>
- {$t("courses.back")}
-</a>
-
-{#if checking}
- <div class="page-center">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.checking_session')}</span>
- </div>
-{:else if loggedIn}
- <div class="page-logged">
- <div class="session-bar">
- <span class="session-info">
- {$t('hotmart.logged_as', { email: sessionEmail || "\u2014" })}
- </span>
- <div class="session-actions">
- <button
- class="button"
- onclick={refreshCourses}
- disabled={refreshing}
- aria-label={$t('hotmart.refresh')}
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:spinning={refreshing}>
- <path d="M21 2v6h-6" />
- <path d="M3 12a9 9 0 0115-6.7L21 8" />
- <path d="M3 22v-6h6" />
- <path d="M21 12a9 9 0 01-15 6.7L3 16" />
- </svg>
- </button>
- <button class="button" onclick={handleLogout}>{$t('hotmart.logout')}</button>
- </div>
- </div>
-
- {#if loadingCourses}
- <div class="spinner-section">
- <span class="spinner"></span>
- <span class="spinner-text">{$t('hotmart.loading_courses')}</span>
- </div>
- {:else if coursesError}
- <div class="error-section">
- <p class="error-msg">{coursesError}</p>
- <button class="button" onclick={loadCourses}>{$t('common.retry')}</button>
- </div>
- {:else if courses.length === 0}
- <p class="empty-text">{$t('hotmart.no_courses')}</p>
- {:else}
- <div class="courses-header">
- <h2>{$t('hotmart.courses_title')}</h2>
- <span class="subtext">{courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}</span>
- </div>
-
- <div class="courses-grid">
- {#each paginatedCourses as course (course.id)}
- <CourseCard
- name={course.name}
- price={course.lessons_count === 1 ? "1 lesson" : `${course.lessons_count} lessons`}
- downloadStatus={getCourseDownloadStatus(course.id)}
- downloadPercent={getCourseDownloadPercent(course.id)}
- onDownload={() => downloadCourse(course)}
- />
- {/each}
- </div>
-
- {#if totalPages > 1}
- <div class="pagination">
- <span class="pagination-info">
- {$t('hotmart.page_of', { current: currentPage, total: totalPages })} &middot; {courses.length === 1 ? $t('hotmart.course_count_one', { count: courses.length }) : $t('hotmart.course_count', { count: courses.length })}
- </span>
- <div class="pagination-controls">
- <button
- class="button pagination-btn"
- disabled={currentPage <= 1}
- onclick={() => goToPage(currentPage - 1)}
- >
- &lt;
- </button>
-
- {#each pageNumbers() as page}
- {#if page === -1}
- <span class="pagination-ellipsis">&hellip;</span>
- {:else}
- <button
- class="button pagination-btn"
- class:active={page === currentPage}
- onclick={() => goToPage(page)}
- >
- {page}
- </button>
- {/if}
- {/each}
-
- <button
- class="button pagination-btn"
- disabled={currentPage >= totalPages}
- onclick={() => goToPage(currentPage + 1)}
- >
- &gt;
- </button>
- </div>
- </div>
- {/if}
- {/if}
- </div>
-{:else}
- <div class="page-center">
- <div class="login-card">
- <h2>Voomp Play</h2>
-
- <div class="form">
- <label class="field">
- <span class="field-label">Cookies JSON</span>
- <textarea
- class="input token-textarea"
- placeholder="Paste cookies JSON from browser extension or a raw token"
- bind:value={token}
- disabled={loading}
- rows="5"
- ></textarea>
- </label>
-
- <input
- type="file"
- accept=".json,.txt"
- class="hidden-file-input"
- bind:this={fileInput}
- onchange={onFileSelected}
- />
- <button class="button" onclick={() => fileInput?.click()} disabled={loading}>
- Import .json file
- </button>
-
- {#if error}
- <p class="error-msg">{error}</p>
- {/if}
-
- <button class="button" onclick={handleTokenLogin} disabled={loading || !token.trim()}>
- {#if loading}
- {$t('hotmart.authenticating')}
- {:else}
- {$t('hotmart.login')}
- {/if}
- </button>
- </div>
- </div>
- </div>
-{/if}
-
-<style>
- .back-link {
- display: inline-flex;
- align-items: center;
- gap: 6px;
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- margin-bottom: var(--padding);
- }
-
- @media (hover: hover) {
- .back-link:hover {
- color: var(--secondary);
- }
- }
-
- .page-center {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: calc(100vh - var(--padding) * 4 - 40px);
- gap: var(--padding);
- }
-
- .page-logged {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: calc(var(--padding) * 1.5);
- padding: calc(var(--padding) * 1.5);
- width: 100%;
- }
-
- .page-logged > :global(*) {
- width: 100%;
- max-width: 1200px;
- }
-
- .session-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
-
- .session-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .session-actions {
- display: flex;
- gap: calc(var(--padding) / 2);
- }
-
- .session-bar :global(.button) {
- padding: calc(var(--padding) / 2) var(--padding);
- font-size: 12.5px;
- }
-
- .spinning {
- animation: spin 0.6s linear infinite;
- }
-
- .courses-header {
- display: flex;
- align-items: baseline;
- gap: var(--padding);
- }
-
- .courses-header h2 {
- margin-block: 0;
- }
-
- .subtext {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .courses-grid {
- display: grid;
- grid-template-columns: repeat(4, 1fr);
- gap: var(--padding);
- }
-
- @media (max-width: 1000px) {
- .courses-grid {
- grid-template-columns: repeat(3, 1fr);
- }
- }
-
- @media (max-width: 750px) {
- .courses-grid {
- grid-template-columns: repeat(2, 1fr);
- }
- }
-
- @media (max-width: 535px) {
- .courses-grid {
- grid-template-columns: 1fr;
- }
- }
-
- .pagination {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding-top: var(--padding);
- }
-
- .pagination-info {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .pagination-controls {
- display: flex;
- align-items: center;
- gap: calc(var(--padding) / 3);
- }
-
- .pagination-btn {
- min-width: 36px;
- height: 36px;
- padding: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 14.5px;
- }
-
- .pagination-ellipsis {
- min-width: 36px;
- text-align: center;
- color: var(--gray);
- font-size: 14.5px;
- }
-
- .login-card {
- width: 100%;
- max-width: 400px;
- background: var(--button-elevated);
- border-radius: var(--border-radius);
- padding: calc(var(--padding) * 2);
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) * 1.5);
- }
-
- .login-card h2 {
- margin-block: 0;
- }
-
- .hidden-file-input {
- display: none;
- }
-
- .token-textarea {
- resize: vertical;
- min-height: 80px;
- font-size: 11.5px;
- font-family: var(--font-mono);
- line-height: 1.5;
- }
-
- .form {
- display: flex;
- flex-direction: column;
- gap: var(--padding);
- }
-
- .field {
- display: flex;
- flex-direction: column;
- gap: calc(var(--padding) / 2);
- }
-
- .field-label {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .input {
- width: 100%;
- padding: var(--padding);
- font-size: 14.5px;
- background: var(--button);
- border-radius: var(--border-radius);
- color: var(--secondary);
- border: 1px solid var(--input-border);
- }
-
- .input::placeholder {
- color: var(--gray);
- }
-
- .input:focus-visible {
- border-color: var(--secondary);
- outline: none;
- }
-
- .input:disabled {
- opacity: 0.5;
- cursor: default;
- }
-
- .error-msg {
- color: var(--red);
- font-size: 12.5px;
- font-weight: 500;
- }
-
- .spinner-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 4) 0;
- }
-
- .spinner {
- width: 24px;
- height: 24px;
- border: 2px solid var(--input-border);
- border-top-color: var(--blue);
- border-radius: 50%;
- animation: spin 0.6s linear infinite;
- }
-
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
-
- .spinner-text {
- font-size: 12.5px;
- font-weight: 500;
- color: var(--gray);
- }
-
- .error-section {
- display: flex;
- flex-direction: column;
- align-items: center;
- gap: var(--padding);
- padding: calc(var(--padding) * 2) 0;
- }
-
- .empty-text {
- color: var(--gray);
- font-size: 14.5px;
- text-align: center;
- padding: calc(var(--padding) * 4) 0;
- }
-</style>